Skip to content

Commit 6e7d0ef

Browse files
committed
list-objects.c: don't add an unparsed NULL as a pending tree
"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 <[email protected]>
1 parent 8d2dfc4 commit 6e7d0ef

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

list-objects.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ void traverse_commit_list(struct rev_info *revs,
147147
struct commit *commit;
148148

149149
while ((commit = get_revision(revs)) != NULL) {
150-
add_pending_tree(revs, commit->tree);
150+
/*
151+
* an uninteresting boundary commit may not have its tree
152+
* parsed yet, but we are not going to show them anyway
153+
*/
154+
if (commit->tree)
155+
add_pending_tree(revs, commit->tree);
151156
show_commit(commit);
152157
}
153158
for (i = 0; i < revs->pending.nr; i++) {

t/t6110-rev-list-sparse.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
test_description='operations that cull histories in unusual ways'
4+
. ./test-lib.sh
5+
6+
test_commit () {
7+
echo "$1" >"$1.file" &&
8+
git add "$1.file" &&
9+
test_tick &&
10+
git commit -m "$1"
11+
}
12+
13+
test_expect_success setup '
14+
test_commit A &&
15+
test_commit B &&
16+
test_commit C &&
17+
git checkout -b side HEAD^ &&
18+
test_commit D &&
19+
test_commit E &&
20+
git merge master
21+
'
22+
23+
test_expect_success 'rev-list --first-parent --boundary' '
24+
git rev-list --first-parent --boundary HEAD^..
25+
'
26+
27+
test_done

0 commit comments

Comments
 (0)