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

[PATCH] revision.c: drop missing objects from cmdline

From
Matthew DeVore <matvore@google.com>
Date
Oct 23, 2018, 21:57 UTC
Message-ID
<20181023215745.245333-1-matvore@google.com>

No code which reads cmdline in struct rev_info can handle NULL objects in cmdline.rev[i].item, so stop adding them to the cmdline.rev array. Objects in cmdline are NULL when the given object is promisor and --exclude-promisor-objects is enabled.

This new behavior avoids a segmentation fault in the added test case in t0410.

We could simply die if add_rev_cmdline is called with a NULL item, (rather than warn if --exclude-promisor-objects is set) but because the amended test case already expects the command to finish successfully, difference and show a warning. Note that this command:

	git rev-list --objects --missing=print $missing_hash

Already fails with a "fatal: bad object HASH" message and this patch does not change that.

Signed-off-by: Matthew DeVore <matvore@google.com>
---
 revision.c               | 12 ++++++++++++
 t/t0410-partial-clone.sh | 11 ++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/revision.c b/revision.c
index a1ddb9e11c..8724dca2e2 100644
--- a/revision.c
+++ b/revision.c
@@ -1148,6 +1148,18 @@ static void add_rev_cmdline(struct rev_info *revs,
 			    int whence,
 			    unsigned flags)
 {
+	if (!item) {
+		/*
+		 * item is likely a promisor object returned from get_reference.
+		 */
+		if (revs->exclude_promisor_objects) {
+			warning(_("ignoring missing object %s"), name);
+			return;
+		} else {
+			die(_("missing object %s"), name);
+		}
+	}
+
 	struct rev_cmdline_info *info = &revs->cmdline;
 	unsigned int nr = info->nr;
 
diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh
index ba3887f178..e02cd3f818 100755
--- a/t/t0410-partial-clone.sh
+++ b/t/t0410-partial-clone.sh
@@ -366,7 +366,16 @@ test_expect_success 'rev-list accepts missing and promised objects on command li
 
 	git -C repo config core.repositoryformatversion 1 &&
 	git -C repo config extensions.partialclone "arbitrary string" &&
-	git -C repo rev-list --exclude-promisor-objects --objects "$COMMIT" "$TREE" "$BLOB"
+
+	printf "warning: ignoring missing object %s\n" \
+	       "$COMMIT" "$TREE" "$BLOB" >expect &&
+	git -C repo rev-list --objects \
+		--exclude-promisor-objects "$COMMIT" "$TREE" "$BLOB" 2>actual &&
+	test_cmp expect actual &&
+
+	git -C repo rev-list --objects-edge-aggressive \
+		--exclude-promisor-objects "$COMMIT" "$TREE" "$BLOB" 2>actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
-- 
2.19.1.568.g152ad8e336-goog
Next: Junio C Hamano
Message 1 of 7 in “revision.c: drop missing objects from cmdline”
  1. revision.c: drop missing objects from cmdlineMatthew DeVore, Oct 23, 2018
  2. Junio C HamanoOct 24, 2018
  3. Matthew DeVoreOct 25, 2018
  4. list-objects.c: don't segfault for missing cmdline objectsMatthew DeVore, Oct 25, 2018
  5. Junio C HamanoOct 29, 2018
  6. list-objects.c: don't segfault for missing cmdline objectsMatthew DeVore, Dec 5, 2018
  7. Junio C HamanoDec 6, 2018

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.