git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] Endless loop in git whatchanged --graph -m

From
Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Date
Jul 24, 2009, 23:45 UTC
Message-ID
<20090725014500.66680dc3@gmail.com>
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()?

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
---
diff --git a/Documentation/technical/api-history-graph.txt b/Documentation/technical/api-history-graph.txt
index d66e61b..32d961a 100644
--- a/Documentation/technical/api-history-graph.txt
+++ b/Documentation/technical/api-history-graph.txt
@@ -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.
diff --git a/graph.c b/graph.c
index e466770..049cdbc 100644
--- a/graph.c
+++ b/graph.c
@@ -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)
Next: Michał Kiedrowicz
Message 1 of 2 in “[BUG] Endless loop in git whatchanged --graph -m”
  1. Michał KiedrowiczJul 24, 2009
  2. Michał KiedrowiczJul 29, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.