Skip to contentSkip to conversation

Endless loop in git whatchanged --graph -m

BUG Michał Kiedrowicz 1 participant 2 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

Steps to reproduce:

(Simple merge of two branches)

$ mkdir a && cd a && git init

$ echo file1 > file1
$ git add file1 && git commit -m initial

$ echo file1 >> file1
$ git commit -a -m "commit on master"

$ git checkout -b experimental HEAD^
$ echo file2 > file2
$ git add file2 && git commit -m "commit on experimental"

$ git checkout master && git merge experimental

$ git whatchanged --graph -m
<endless loop here>

Here is a simple patch, which solves this problem by removing constraint from git_show_commit(). I'm not sure if this is the best solution. Maybe some upper layer shouldn't call git_show_commit()?

---

Documentation/technical/api-history-graph.txt +5 -5
index d66e61b..32d961a 100644
@@ -36,11 +36,11 @@ The following utility functions are wrappers around `graph_next_line()` and
 They can all be called with a NULL graph argument, in which case no graph
 output will be printed.
 
-* `graph_show_commit()` calls `graph_next_line()` until it returns non-zero.
-  This prints all graph lines up to, and including, the line containing this
-  commit.  Output is printed to stdout.  The last line printed does not contain
-  a terminating newline.  This should not be called if the commit line has
-  already been printed, or it will loop forever.
+* `graph_show_commit()` calls `graph_next_line()` and
+  `graph_is_commit_finished()` until one of them return non-zero.  This prints
+  all graph lines up to, and including, the line containing this commit.
+  Output is printed to stdout.  The last line printed does not contain a
+  terminating newline.
 
 * `graph_show_oneline()` calls `graph_next_line()` and prints the result to
   stdout.  The line printed does not contain a terminating newline.
graph.c +1 -1
index e466770..049cdbc 100644
@@ -1198,7 +1198,7 @@ void graph_show_commit(struct git_graph *graph)
        if (!graph)
                return;
 
-       while (!shown_commit_line) {
+       while (!shown_commit_line && !graph_is_commit_finished(graph)) {
                shown_commit_line = graph_next_line(graph, &msgbuf);
                fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
                if (!shown_commit_line)
#1 lore raw
Quoted 54 lines · Michał Kiedrowicz

Steps to reproduce:

(Simple merge of two branches)

$ mkdir a && cd a && git init

$ echo file1 > file1
$ git add file1 && git commit -m initial

$ echo file1 >> file1
$ git commit -a -m "commit on master"

$ git checkout -b experimental HEAD^
$ echo file2 > file2
$ git add file2 && git commit -m "commit on experimental"

$ git checkout master && git merge experimental

$ git whatchanged --graph -m
<endless loop here>

Here is a simple patch, which solves this problem by removing constraint from git_show_commit(). I'm not sure if this is the best solution. Maybe some upper layer shouldn't call git_show_commit()?

---

Documentation/technical/api-history-graph.txt +5 -5
index d66e61b..32d961a 100644
@@ -36,11 +36,11 @@ The following utility functions are wrappers around `graph_next_line()` and
 They can all be called with a NULL graph argument, in which case no graph
 output will be printed.
 
-* `graph_show_commit()` calls `graph_next_line()` until it returns non-zero.
-  This prints all graph lines up to, and including, the line containing this
-  commit.  Output is printed to stdout.  The last line printed does not contain
-  a terminating newline.  This should not be called if the commit line has
-  already been printed, or it will loop forever.
+* `graph_show_commit()` calls `graph_next_line()` and
+  `graph_is_commit_finished()` until one of them return non-zero.  This prints
+  all graph lines up to, and including, the line containing this commit.
+  Output is printed to stdout.  The last line printed does not contain a
+  terminating newline.
 
 * `graph_show_oneline()` calls `graph_next_line()` and prints the result to
   stdout.  The line printed does not contain a terminating newline.
graph.c +0 -0
index e466770..049cdbc 100644

graph.c void graph_show_commit(struct git_graph *graph) · line 1204

Quoted 8 lines
graph.c +1 -1
@@ -1198,7 +1198,7 @@ void graph_show_commit(struct git_graph *graph)
        if (!graph)
                return;
 
-       while (!shown_commit_line) {
+       while (!shown_commit_line && !graph_is_commit_finished(graph)) {
                shown_commit_line = graph_next_line(graph, &msgbuf);
                fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
                if (!shown_commit_line)

Hi, has anyone looked at this?

Michał Kiedrowicz