Skip to content

Commit 656197a

Browse files
mkiedrowiczgitster
authored andcommitted
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>
1 parent 0ce2e39 commit 656197a

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

Documentation/technical/api-history-graph.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ The following utility functions are wrappers around `graph_next_line()` and
3333
They can all be called with a NULL graph argument, in which case no graph
3434
output will be printed.
3535

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.
4141

4242
* `graph_show_oneline()` calls `graph_next_line()` and prints the result to
4343
stdout. The line printed does not contain a terminating newline.

graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ void graph_show_commit(struct git_graph *graph)
11991199
if (!graph)
12001200
return;
12011201

1202-
while (!shown_commit_line) {
1202+
while (!shown_commit_line && !graph_is_commit_finished(graph)) {
12031203
shown_commit_line = graph_next_line(graph, &msgbuf);
12041204
fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
12051205
if (!shown_commit_line)

t/t4202-log.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ test_expect_success 'log --graph with merge' '
264264
test_cmp expect actual
265265
'
266266

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+
267277
cat > expect <<\EOF
268278
* commit master
269279
|\ Merge: A B

0 commit comments

Comments
 (0)