Browse code

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>

Tzvetan Mikov authored on 04/11/2014 20:33:37
Showing 2 changed files
... ...
@@ -1164,6 +1164,9 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
1164 1164
 	int i;
1165 1165
 	int nparents = count_parents(commit);
1166 1166
 
1167
+	if (nparents > 1 && rev->first_parent_only)
1168
+		nparents = 1;
1169
+
1167 1170
 	diffqueues = xmalloc(nparents * sizeof(*diffqueues));
1168 1171
 	cand = xmalloc(nparents * sizeof(*cand));
1169 1172
 	parents = xmalloc(nparents * sizeof(*parents));
... ...
@@ -77,4 +77,9 @@ test_expect_success '-L {empty-range} (first -L)' '
77 77
 	git log -L$n:b.c
78 78
 '
79 79
 
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
+
80 85
 test_done