@matheusbsbs / matheus-bagliano / commits / 9a217391e9
Fork 0

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>

Junio C Hamano committed Aug 13, 2009 at 12:41 UTC 9a217391e931763d168d177decfe5e962d306bac
2 files changed +44 -7
builtin-unpack-objects.c
+9 -7
@@ -181,10 +181,10 @@ static void write_cached_object(struct object *obj)
181 static int check_object(struct object *obj, int type, void *data)
182 {
183 if (!obj)
184 - return 0;
184 + return 1;
185
186 if (obj->flags & FLAG_WRITTEN)
187 - return 1;
187 + return 0;
188
189 if (type != OBJ_ANY && obj->type != type)
190 die("object type mismatch");
@@ -195,22 +195,24 @@ static int check_object(struct object *obj, int type, void *data)
195 if (type != obj->type || type <= 0)
196 die("object of unexpected type");
197 obj->flags |= FLAG_WRITTEN;
198 - return 1;
198 + return 0;
199 }
200
201 if (fsck_object(obj, 1, fsck_error_function))
202 die("Error in object");
203 - if (!fsck_walk(obj, check_object, 0))
203 + if (fsck_walk(obj, check_object, 0))
204 die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
205 write_cached_object(obj);
206 - return 1;
206 + return 0;
207 }
208
209 static void write_rest(void)
210 {
211 unsigned i;
212 - for (i = 0; i < nr_objects; i++)
213 - check_object(obj_list[i].obj, OBJ_ANY, 0);
212 + for (i = 0; i < nr_objects; i++) {
213 + if (obj_list[i].obj)
214 + check_object(obj_list[i].obj, OBJ_ANY, 0);
215 + }
216 }
217
218 static void added_object(unsigned nr, enum object_type type,
t/t5531-deep-submodule-push.sh new
+35
@@ -0,0 +1,35 @@
1 +#!/bin/sh
2 +
3 +test_description='unpack-objects'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 + mkdir pub.git &&
9 + GIT_DIR=pub.git git init --bare
10 + GIT_DIR=pub.git git config receive.fsckobjects true &&
11 + mkdir work &&
12 + (
13 + cd work &&
14 + git init &&
15 + mkdir -p gar/bage &&
16 + (
17 + cd gar/bage &&
18 + git init &&
19 + >junk &&
20 + git add junk &&
21 + git commit -m "Initial junk"
22 + ) &&
23 + git add gar/bage &&
24 + git commit -m "Initial superproject"
25 + )
26 +'
27 +
28 +test_expect_success push '
29 + (
30 + cd work &&
31 + git push ../pub.git master
32 + )
33 +'
34 +
35 +test_done