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

Re: log --graph draws an orphaned branch with parents

From
Hherr.kaste <herr.kaste@gmail.com>
Date
Nov 3, 2026, 21:51 UTC
Message-ID
<CAFzd1+6fiuT1R3B7aK6mN842g5+EiQ4Qt2_GCS1YFMVs+mXFaQ@mail.gmail.com>
In-Reply-To
<DMLW93TBSOXK.2OLM5O3HGK1ZY@gmail.com>
From 48bbcf965dc630251cc32f38d7efca5e6fb77c5e Mon Sep 17 00:00:00 2001
From: Caspar Duregger <caspar.duregger@gmail.com>
Date: Tue, 3 Nov 2026 22:38:22 +0100
Subject: [PATCH] graph: do not indent visual roots with columns to their right

Since a34c00d96 (graph: indent visual root in graph, 2026-07-14), a visual root that has a child is drawn indented, connected to its child by an extra GRAPH_PRE_ROOT line. When there are columns to the right of the root, this breaks the graph:

*   M
|\
\ |
 * | R
/
| * T
|/
* B

graph_output_pre_root_line() writes the extra " " for the root column without shifting the columns to its right, so they are drawn between two columns. graph_output_commit_line() then pushes them one column to the right, but the following GRAPH_COLLAPSING line is computed from the mapping, which knows nothing about that offset. The column next to R does not continue into the next line, and with more columns to the right of R one of them goes nowhere.

But in this situation the indentation is not needed in the first place. The columns to the right of the root collapse into its column once it is rendered, so the collapsing line always leaves a blank right below the root, and the next commit cannot end up vertically adjacent to it.

Do not consider a commit a visual root when there are columns to its right, which gives:

*   M
|\
* | R
/
| * T
|/
* B
Signed-off-by: Caspar Duregger <caspar.duregger@gmail.com>
---
 graph.c                          | 12 ++++++++++++
 t/t4218-log-graph-indentation.sh | 18 ++++++++++++++++++
 2 files changed, 30 insertions(+)
diff --git a/graph.c b/graph.c
index 28bef1b88..95eef3a95 100644
--- a/graph.c
+++ b/graph.c
@@ -969,10 +969,22 @@ static int graph_is_visual_root(struct git_graph *graph,
  * already a column, so it will not be rendered below, the
  * current commit has to act as the last commit and omit
  * indentation.
+ *
+ * If there are columns to the right of the commit, they collapse
+ * into its column once it is rendered, so nothing can be rendered
+ * right below it and there is no need to indent it.
+ *
+ *   * | <- visual root with a column to its right
+ *    /
+ *   | *
+ *
+ * Indenting it would also push these columns to the right, but
+ * the collapsing code does not know about that offset.
  */
  return graph_is_visual_root_candidate(graph->commit, graph) &&
        !(graph->commit_in_columns &&
  graph->columns[graph->commit_index].is_merge_parent) &&
+       graph->commit_index + 1 >= graph->num_columns &&
        flags->is_next_visible &&
        (!flags->next_has_column || graph->visual_root_depth > 0);
 }
diff --git a/t/t4218-log-graph-indentation.sh b/t/t4218-log-graph-indentation.sh
index 24dc9b497..b3b9f7c14 100755
--- a/t/t4218-log-graph-indentation.sh
+++ b/t/t4218-log-graph-indentation.sh
@@ -449,6 +449,24 @@ test_expect_success 'two unrelated merges' '
  EOF
 '

+test_expect_success 'visual root with columns to its right is not indented' '
+ create_orphan _70 && test_commit 70_A &&
+ git checkout -b _71 && test_commit 71_A &&
+ create_orphan _72 && test_commit 72_A &&
+ TREE=$(git write-tree) &&
+ MERGE=$(git commit-tree $TREE -p _72 -p _70 -m 72_merge) &&
+ git reset --hard $MERGE &&
+ lib_test_check_graph _72 _71 <<-\EOF
+ *   72_merge
+ |\
+ * | 72_A
+ /
+ | * 71_A
+ |/
+ * 70_A
+ EOF
+'
+
 test_expect_success '--max-count treats the last visible commit as
the last commit' '
  lib_test_check_graph --max-count=2 _8 _9 _10 <<-\EOF
   * 10_A
-- 
2.56.0.350.g48bbcf965


Am Di., 3. Nov. 2026 um 22:29 Uhr schrieb Pablo Sabater
<pabloosabaterr@gmail.com>:
>
> On Tue Nov 3, 2026 at 9:27 PM WET, Pablo Sabater wrote:
> >
> > I think I may be able to see how to fix it tomorrow, but I'm quite busy
> > until next week.
>
> I forgot to ask if you want to try to fix it yourself, I'm happy to
> review it :).
>
> Pablo.
>
Previous: Pablo SabaterNext: Pablo Sabater
Message 5 of 9 in “log --graph draws an orphaned branch with parents”
  1. herr.kasteOct 13, 2026
  2. herr.kasteNov 3, 2026
  3. Pablo SabaterNov 3, 2026
  4. Pablo SabaterNov 3, 2026
  5. herr.kasteNov 3, 2026
  6. Pablo SabaterNov 3, 2026
  7. graph: do not indent visual roots with columns to their rightCaspar Duregger, Nov 3, 2026
  8. Pablo SabaterNov 3, 2026
  9. Junio C HamanoNov 4, 2026

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.