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

[PATCH] list-objects.c: don't add an unparsed NULL as a pending tree

From
Junio C Hamano <junio@pobox.com>
Date
Mar 18, 2011, 07:24 UTC
Message-ID
<7vbp18zya3.fsf@alter.siamese.dyndns.org>

"git rev-list --first-parent --boundary $commit^..$commit" segfaults on a merge commit since 8d2dfc4 (process_{tree,blob}: show objects without buffering, 2009-04-10), as it tried to dereference a commit that was discarded as UNINTERESTING without being parsed (hence lacking "tree").

Signed-off-by: Junio C Hamano <junio@pobox.com>
---
 * The test has its own test_commit as I did this patch directly on top of
   8d2dfc4; back then we didn't have the helper in test-lib.sh.  Need to
   remove it when merging up to branches that have 0088496 (test-lib.sh:
   introduce test_commit() and test_merge() helpers, 2009-01-27).
 list-objects.c             |    7 ++++++-
 t/t6110-rev-list-sparse.sh |   27 +++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletions(-)
 create mode 100755 t/t6110-rev-list-sparse.sh
diff --git a/list-objects.c b/list-objects.c
index 5a4af62..518c665 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -147,7 +147,12 @@ void traverse_commit_list(struct rev_info *revs,
 	struct commit *commit;
 
 	while ((commit = get_revision(revs)) != NULL) {
-		add_pending_tree(revs, commit->tree);
+		/*
+		 * an uninteresting boundary commit may not have its tree
+		 * parsed yet, but we are not going to show them anyway
+		 */
+		if (commit->tree)
+			add_pending_tree(revs, commit->tree);
 		show_commit(commit);
 	}
 	for (i = 0; i < revs->pending.nr; i++) {
diff --git a/t/t6110-rev-list-sparse.sh b/t/t6110-rev-list-sparse.sh
new file mode 100755
index 0000000..2a267e8
--- /dev/null
+++ b/t/t6110-rev-list-sparse.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+test_description='operations that cull histories in unusual ways'
+. ./test-lib.sh
+
+test_commit () {
+	echo "$1" >"$1.file" &&
+	git add "$1.file" &&
+	test_tick &&
+	git commit -m "$1"
+}
+
+test_expect_success setup '
+	test_commit A &&
+	test_commit B &&
+	test_commit C &&
+	git checkout -b side HEAD^ &&
+	test_commit D &&
+	test_commit E &&
+	git merge master
+'
+
+test_expect_success 'rev-list --first-parent --boundary' '
+	git rev-list --first-parent --boundary HEAD^..
+'
+
+test_done
-- 
1.7.4.1.408.gb6b16
Message 1 of 1 in “list-objects.c: don't add an unparsed NULL as a pending tree”
  1. list-objects.c: don't add an unparsed NULL as a pending treeJunio C Hamano, Mar 18, 2011

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.