summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-01-31 21:14:57 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-01-31 21:14:57 (GMT)
commit42ace93e41da0abe5a264fb8661f1c7de88206ec (patch)
tree937299b26d761c4b1729f86de23c7cad833261cc /builtin
parente8272fd5fbb4f3a6d264fe0721247efe08aada8f (diff)
parentcce044df7f2392d0c6cb21d6dca94f01ff838727 (diff)
downloadgit-42ace93e41da0abe5a264fb8661f1c7de88206ec.zip
git-42ace93e41da0abe5a264fb8661f1c7de88206ec.tar.gz
git-42ace93e41da0abe5a264fb8661f1c7de88206ec.tar.bz2
Merge branch 'jk/loose-object-fsck'
"git fsck" inspects loose objects more carefully now. * jk/loose-object-fsck: fsck: detect trailing garbage in all object types fsck: parse loose object paths directly sha1_file: add read_loose_object() function t1450: test fsck of packed objects sha1_file: fix error message for alternate objects t1450: refactor loose-object removal
Diffstat (limited to 'builtin')
-rw-r--r--builtin/fsck.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/builtin/fsck.c b/builtin/fsck.c
index f01b81e..4b91ee9 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -362,18 +362,6 @@ static int fsck_obj(struct object *obj)
return 0;
}
-static int fsck_sha1(const unsigned char *sha1)
-{
- struct object *obj = parse_object(sha1);
- if (!obj) {
- errors_found |= ERROR_OBJECT;
- return error("%s: object corrupt or missing",
- sha1_to_hex(sha1));
- }
- obj->flags |= HAS_OBJ;
- return fsck_obj(obj);
-}
-
static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
unsigned long size, void *buffer, int *eaten)
{
@@ -488,9 +476,41 @@ static void get_default_heads(void)
}
}
+static struct object *parse_loose_object(const unsigned char *sha1,
+ const char *path)
+{
+ struct object *obj;
+ void *contents;
+ enum object_type type;
+ unsigned long size;
+ int eaten;
+
+ if (read_loose_object(path, sha1, &type, &size, &contents) < 0)
+ return NULL;
+
+ if (!contents && type != OBJ_BLOB)
+ die("BUG: read_loose_object streamed a non-blob");
+
+ obj = parse_object_buffer(sha1, type, size, contents, &eaten);
+
+ if (!eaten)
+ free(contents);
+ return obj;
+}
+
static int fsck_loose(const unsigned char *sha1, const char *path, void *data)
{
- if (fsck_sha1(sha1))
+ struct object *obj = parse_loose_object(sha1, path);
+
+ if (!obj) {
+ errors_found |= ERROR_OBJECT;
+ error("%s: object corrupt or missing: %s",
+ sha1_to_hex(sha1), path);
+ return 0; /* keep checking other objects */
+ }
+
+ obj->flags = HAS_OBJ;
+ if (fsck_obj(obj))
errors_found |= ERROR_OBJECT;
return 0;
}