git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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,
Previous: Junio C HamanoNext: Frank Lichtenheld
Message 8 of 9 in “[BUG] Submodules problem with subdirectories and pushing”
  1. Frank LichtenheldAug 13, 2009
  2. Frank LichtenheldAug 13, 2009
  3. Fix "unpack-objects --strict"Junio C Hamano, Aug 13, 2009
  4. Martin KoeglerAug 14, 2009
  5. Junio C HamanoAug 14, 2009
  6. Martin KoeglerAug 14, 2009
  7. Junio C HamanoAug 14, 2009
  8. Junio C HamanoAug 14, 2009
  9. Frank LichtenheldAug 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.