Re: [PATCH] Fix "unpack-objects --strict"
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 14, 2009, 07:41 UTC
- Message-ID
- <7vhbwasuz8.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20090814060307.GA31721@auto.tuwien.ac.at>
Martin Koegler <mkoegler@auto.tuwien.ac.at> writes:
Show 7 quoted lines
> What about this check: >> @@ -184,7 +184,7 @@ static int check_object(struct object *obj, int type, void *data) >> if (!obj) >> return 0; > > This is neccessary to skip already written objects (eg. blobs, > obj_list[i].obj == NULL).
You can fix that issue by teaching write_rest() to check what it feeds check_object(), can't you?
> I'm not sure, if fsck_walk can call check_object with obj == NULL > under some (rare) conditions. If yes, the return code should be > changed to 1.
I think that is a sensible change to signal an error regardless. For example, fsck_walk_tree() will make a callback to you (meaning, walk() function pointer points at your check_object() function) like this:
while (tree_entry(&desc, &entry)) {
int result;if (S_ISGITLINK(entry.mode)) continue; if (S_ISDIR(entry.mode)) result = walk(&lookup_tree(entry.sha1)->object, OBJ_TREE, data);
so while you are checking a tree object you received, upon hitting a subtree of that tree, it will lookup_tree() it, and if that tree is missing, you will be called with NULL.
On top of the previous patch, a fix would look like this, I think, but please double check.
Thanks.
builtin-unpack-objects.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c index 2522c2d..bae00ea 100644 --- a/builtin-unpack-objects.c +++ b/builtin-unpack-objects.c @@ -181,7 +181,7 @@ 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 0; @@ -209,8 +209,10 @@ static int check_object(struct object *obj, int type, void *data) 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,