summaryrefslogtreecommitdiff
path: root/builtin-unpack-objects.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-08-13 19:41:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-08-14 07:52:08 (GMT)
commit9a217391e931763d168d177decfe5e962d306bac (patch)
tree8e01ee3af4f2159667b1488a6f54c5eccab6a279 /builtin-unpack-objects.c
parent57f6ec029090f64377ec5c0926b6e2e39b0caa4f (diff)
downloadgit-9a217391e931763d168d177decfe5e962d306bac.zip
git-9a217391e931763d168d177decfe5e962d306bac.tar.gz
git-9a217391e931763d168d177decfe5e962d306bac.tar.bz2
Fix "unpack-objects --strict"
When unpack-objects is run under the --strict option, objects that have pointers to other objects are verified for the reachability at the end, by calling check_object() on each of them, and letting check_object to walk the reachable objects from them using fsck_walk() recursively. The function however misunderstands the semantics of fsck_walk() function when it makes a call to it, setting itself as the callback. fsck_walk() expects the callback function to return a non-zero value to signal an error (negative value causes an immediate abort, positive value is still an error but allows further checks on sibling objects) and return zero to signal a success. The function however returned 1 on some non error cases, and to cover up this mistake, complained only when fsck_walk() did not detect any error. To fix this double-bug, make the function return zero on all success cases, and also check for non-zero return from fsck_walk() for an error. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-unpack-objects.c')
-rw-r--r--builtin-unpack-objects.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c
index 8e831be..bae00ea 100644
--- a/builtin-unpack-objects.c
+++ b/builtin-unpack-objects.c
@@ -181,10 +181,10 @@ static void write_cached_object(struct object *obj)
static int check_object(struct object *obj, int type, void *data)
{
if (!obj)
- return 0;
+ return 1;
if (obj->flags & FLAG_WRITTEN)
- return 1;
+ return 0;
if (type != OBJ_ANY && obj->type != type)
die("object type mismatch");
@@ -195,22 +195,24 @@ static int check_object(struct object *obj, int type, void *data)
if (type != obj->type || type <= 0)
die("object of unexpected type");
obj->flags |= FLAG_WRITTEN;
- return 1;
+ return 0;
}
if (fsck_object(obj, 1, fsck_error_function))
die("Error in object");
- if (!fsck_walk(obj, check_object, 0))
+ if (fsck_walk(obj, check_object, 0))
die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
write_cached_object(obj);
- return 1;
+ return 0;
}
static void write_rest(void)
{
unsigned i;
- for (i = 0; i < nr_objects; i++)
- check_object(obj_list[i].obj, OBJ_ANY, 0);
+ for (i = 0; i < nr_objects; i++) {
+ if (obj_list[i].obj)
+ check_object(obj_list[i].obj, OBJ_ANY, 0);
+ }
}
static void added_object(unsigned nr, enum object_type type,