Skip to content

Commit 9a21739

Browse files
committed
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 <[email protected]>
1 parent 57f6ec0 commit 9a21739

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

builtin-unpack-objects.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ static void write_cached_object(struct object *obj)
181181
static int check_object(struct object *obj, int type, void *data)
182182
{
183183
if (!obj)
184-
return 0;
184+
return 1;
185185

186186
if (obj->flags & FLAG_WRITTEN)
187-
return 1;
187+
return 0;
188188

189189
if (type != OBJ_ANY && obj->type != type)
190190
die("object type mismatch");
@@ -195,22 +195,24 @@ static int check_object(struct object *obj, int type, void *data)
195195
if (type != obj->type || type <= 0)
196196
die("object of unexpected type");
197197
obj->flags |= FLAG_WRITTEN;
198-
return 1;
198+
return 0;
199199
}
200200

201201
if (fsck_object(obj, 1, fsck_error_function))
202202
die("Error in object");
203-
if (!fsck_walk(obj, check_object, 0))
203+
if (fsck_walk(obj, check_object, 0))
204204
die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
205205
write_cached_object(obj);
206-
return 1;
206+
return 0;
207207
}
208208

209209
static void write_rest(void)
210210
{
211211
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+
}
214216
}
215217

216218
static void added_object(unsigned nr, enum object_type type,

t/t5531-deep-submodule-push.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)