graph.c: infinite loop in git whatchanged --graph -m

Running "whatchanged --graph -m" on a simple two-head merges can fall into infinite loop. Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michał Kiedrowicz committed Jul 25, 2009 at 01:45 UTC 656197ad380506ca0e8a0355701f9d9a4a398f66
3 files changed +16 -6
Documentation/technical/api-history-graph.txt
+5 -5
@@ -33,11 +33,11 @@ The following utility functions are wrappers around `graph_next_line()` and
33 They can all be called with a NULL graph argument, in which case no graph
34 output will be printed.
35
36 -* `graph_show_commit()` calls `graph_next_line()` until it returns non-zero.
37 - This prints all graph lines up to, and including, the line containing this
38 - commit. Output is printed to stdout. The last line printed does not contain
39 - a terminating newline. This should not be called if the commit line has
40 - already been printed, or it will loop forever.
36 +* `graph_show_commit()` calls `graph_next_line()` and
37 + `graph_is_commit_finished()` until one of them return non-zero. This prints
38 + all graph lines up to, and including, the line containing this commit.
39 + Output is printed to stdout. The last line printed does not contain a
40 + terminating newline.
41
42 * `graph_show_oneline()` calls `graph_next_line()` and prints the result to
43 stdout. The line printed does not contain a terminating newline.
graph.c
+1 -1
@@ -1199,7 +1199,7 @@ void graph_show_commit(struct git_graph *graph)
1199 if (!graph)
1200 return;
1201
1202 - while (!shown_commit_line) {
1202 + while (!shown_commit_line && !graph_is_commit_finished(graph)) {
1203 shown_commit_line = graph_next_line(graph, &msgbuf);
1204 fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
1205 if (!shown_commit_line)
t/t4202-log.sh
+10
@@ -264,6 +264,16 @@ test_expect_success 'log --graph with merge' '
264 test_cmp expect actual
265 '
266
267 +test_expect_success 'log --raw --graph -m with merge' '
268 + git log --raw --graph --oneline -m master | head -n 500 >actual &&
269 + grep "initial" actual
270 +'
271 +
272 +test_expect_success 'diff-tree --graph' '
273 + git diff-tree --graph master^ | head -n 500 >actual &&
274 + grep "one" actual
275 +'
276 +
277 cat > expect <<\EOF
278 * commit master
279 |\ Merge: A B