]> git.99rst.org Git - git.git/commit
graph: indent visual root in graph
authorPablo Sabater <redacted>
Tue, 14 Jul 2026 12:09:35 +0000 (14:09 +0200)
committerJunio C Hamano <redacted>
Tue, 14 Jul 2026 14:32:51 +0000 (07:32 -0700)
commita34c00d96851009e94ec7618ad5c1464f920c80d
tree9e61f2c95bf87e381dbba10061271e43f22d29c5
parentbf3c696b44eb82f90b25101e36cd79651d1480f8
graph: indent visual root in graph

When rendering a graph, if the history contains multiple "visual roots",
actual roots or commits that look like roots (i.e. have their parents
filtered out) can end up being vertically adjacent to unrelated commits,
falsely appearing to be related.

A fix for this issue was already attempted [1] a while ago.

This happens because the commits fill the space from left to right and
when a visual root ends, its column becomes free for the following
commit even if they are not related. Once this happens the unrelated
commit is rendered below the visual root. Because there is no special
character or way to identify when a visual root is rendered making the
graph confusing.

By indenting the visual roots when there are still commits to show the
vertical adjacency can be avoided.

Add is_visual_root flag to git_graph making it visible in all graph states,
give graph_update() a new function, graph_is_visual_root() to know if the
current commit is a visual root and set is_visual_root.
The different handled cases are:

- If a visual root has children: similar to GRAPH_PRE_COMMIT state when
  octopus merges need space, an edge row needs to be printed to connect
  the child with the indented visual root. A new state GRAPH_PRE_ROOT is
  needed to connect the child with the visual root:

    * child of the visual root
     \ GRAPH_PRE_ROOT
      * visual root indented

- If a visual root is child-less we can skip GRAPH_PRE_ROOT state and
  render the indented commit directly.

      * visual root indented
    * unrelated commit

- If two or more visual roots are adjacent: by having a lookahead to the
  next commit that will be rendered, if the next commit is also a visual
  root and we are on a visual root, meaning two visual root adjacent in
  the history, the top one can omit the indent, making the one below to
  indent only once, if there are more adjacent visual commits, the
  indentation will increase for each adjacent one, cascading.

    * visual root
      * visual root
        * visual root
    * last commit

  Even if the last commit is a root, because there is nothing that will be
  rendered below we can omit the indentation on purpose.

[1]: https://lore.kernel.org/git/xmqqwnwajbuj.fsf@gitster.c.googlers.com/

Helped-by: Kristofer Karlsson <redacted>
Mentored-by: Karthik Nayak <redacted>
Mentored-by: Chandra Pratap <redacted>
Signed-off-by: Pablo Sabater <redacted>
Signed-off-by: Junio C Hamano <redacted>
graph.c
t/meson.build
t/t4218-log-graph-indentation.sh [new file with mode: 0755]
git clone https://git.99rst.org/PROJECT