]> granicus.if.org Git - git/commitdiff
line-log: fix crash when --first-parent is used
authorTzvetan Mikov <tmikov@gmail.com>
Tue, 4 Nov 2014 20:33:37 +0000 (12:33 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Nov 2014 20:47:35 +0000 (12:47 -0800)
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>
line-log.c
t/t4211-line-log.sh

index c2d01dccc2a12a767c442de58ed78df130699d74..fe04c9d109e682145e6b761f7f2de27779cf76a2 100644 (file)
@@ -1164,6 +1164,9 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
        int i;
        int nparents = count_parents(commit);
 
+       if (nparents > 1 && rev->first_parent_only)
+               nparents = 1;
+
        diffqueues = xmalloc(nparents * sizeof(*diffqueues));
        cand = xmalloc(nparents * sizeof(*cand));
        parents = xmalloc(nparents * sizeof(*parents));
index 7665d6785c1a91ed0171e8cac61174ebee9b9a37..3be25a3a7f0cb39cad496417c5e718bcfd33cfb4 100755 (executable)
@@ -77,4 +77,9 @@ test_expect_success '-L {empty-range} (first -L)' '
        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