Skip to content

Commit a8787c5

Browse files
tmikovgitster
authored andcommitted
line-log: fix crash when --first-parent is used
line-log tries to access all parents of a commit, but only the first parent has been loaded if "--first-parent" is specified, resulting in a crash. Limit the number of parents to one if "--first-parent" is specified. Reported-by: Eric N. Vander Weele <[email protected]> Signed-off-by: Tzvetan Mikov <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1762224 commit a8787c5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

line-log.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,9 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
11641164
int i;
11651165
int nparents = count_parents(commit);
11661166

1167+
if (nparents > 1 && rev->first_parent_only)
1168+
nparents = 1;
1169+
11671170
diffqueues = xmalloc(nparents * sizeof(*diffqueues));
11681171
cand = xmalloc(nparents * sizeof(*cand));
11691172
parents = xmalloc(nparents * sizeof(*parents));

t/t4211-line-log.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ test_expect_success '-L {empty-range} (first -L)' '
7777
git log -L$n:b.c
7878
'
7979

80+
test_expect_success '-L with --first-parent and a merge' '
81+
git checkout parallel-change &&
82+
git log --first-parent -L 1,1:b.c
83+
'
84+
8085
test_done

0 commit comments

Comments
 (0)