From: Caspar Duregger <caspar.duregger@gmail.com>
To: git@vger.kernel.org
Cc: pabloosabaterr@gmail.com, gitster@pobox.com, krka@spotify.com,
karthik.188@gmail.com, chandrapratap3519@gmail.com,
Caspar Duregger <caspar.duregger@gmail.com>
Subject: [PATCH] graph: do not indent visual roots with columns to their right
Date: Wed, 4 Nov 2026 00:11:53 +0100 [thread overview]
Message-ID: <20261103231153.289762-1-caspar.duregger@gmail.com> (raw)
In-Reply-To: <CAFzd1+4Jx_sWvMrV10gi9400BBNJOUXW0WwsypiM7yCh5x8fow@mail.gmail.com>
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.windows.3
next prev parent reply other threads:[~2026-11-03 23:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 19:00 log --graph draws an orphaned branch with parents herr.kaste
2026-11-03 19:25 ` herr.kaste
2026-11-03 21:27 ` Pablo Sabater
2026-11-03 21:29 ` Pablo Sabater
2026-11-03 21:51 ` herr.kaste
2026-11-03 22:40 ` Pablo Sabater
2026-11-03 23:11 ` Caspar Duregger [this message]
2026-11-03 23:39 ` [PATCH] graph: do not indent visual roots with columns to their right Pablo Sabater
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261103231153.289762-1-caspar.duregger@gmail.com \
--to=caspar.duregger@gmail.com \
--cc=chandrapratap3519@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=krka@spotify.com \
--cc=pabloosabaterr@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox