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 <ericvw@gmail.com>
Signed-off-by: Tzvetan Mikov <tmikov@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Tzvetan Mikov 2014-11-04 12:33:37 -08:00 коммит произвёл Junio C Hamano
Родитель 1762224ddb
Коммит a8787c5c1c
2 изменённых файлов: 8 добавлений и 0 удалений

Просмотреть файл

@ -1164,6 +1164,9 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
int i; int i;
int nparents = count_parents(commit); int nparents = count_parents(commit);
if (nparents > 1 && rev->first_parent_only)
nparents = 1;
diffqueues = xmalloc(nparents * sizeof(*diffqueues)); diffqueues = xmalloc(nparents * sizeof(*diffqueues));
cand = xmalloc(nparents * sizeof(*cand)); cand = xmalloc(nparents * sizeof(*cand));
parents = xmalloc(nparents * sizeof(*parents)); parents = xmalloc(nparents * sizeof(*parents));

Просмотреть файл

@ -77,4 +77,9 @@ test_expect_success '-L {empty-range} (first -L)' '
git log -L$n:b.c git log -L$n:b.c
' '
test_expect_success '-L with --first-parent and a merge' '
git checkout parallel-change &&
git log --first-parent -L 1,1:b.c
'
test_done test_done