Subject: [GSoC RFC PATCH v2 0/1] graph: add indentation for commits preceded by a parentless commit

From: Pablo Sabater <[email-masked]>
Date: Sat, 4 Apr 2026 11:24:24 +0200

When having a history with multiple root commits or commits
that act like roots (they have excluded parents), let's call
them parentless, and drawing the history near them, the
graphing engine renders the commits one below the other, seeming
that they are related.

e.g.:

  * parentless-B
  * child-A2
  * child-A1
  * parentless-A

This issue has been attempted multiple times:
  https://lore.kernel.org/git/[email-masked]/

This happens because the engine prints left to right from the first free
column and these parentless commits for the next row, their column
becomes empty and the engine fills that gap with the next commit (child-A2)
seeming that parentless-B and child-A2 are related when they are not.

The actual implementation is very minimal.
This patch makes the parentless commits to be kept alive at least one more row to avoid
that, indenting the next commit to the next column and then clean the mapping
letting the indented commit to naturally collapse to the column where the
parentless commit was.

e.g.:

  * parentless-B
    * child-A2
   /
  * child-A1
  * parentless-A

This is done by adding a is_placeholder flag to the columns, the parentless
commit is actually there but marked as a placeholder

e.g.:

   * parentless-B
  (B) * child-A2
    /
   * child-A1
   * parentless-A

(B) would be parentless-B column with the placeholder flag active.

By teaching the rendering function to print a padding ' ' when meeting a
placeholder column hides them, printing the second example.

There could also be the case where there are multiple parentless commits

without the patch:

  * A parentless
  * B parentless
  * C parentless
  * D1 child
  * D parentless

with the patch, the indentation cascades:

  * A parentless
    * B parentless
      * C parentless
        * D1 child
     _ /
    /
   /
  * D parentless

the _ / might look weird but that's how the collapsing rendering does it
for big gaps, this case being from the 4th column to the 0th column.

Another patch could change the collapsing rendering for placeholders?
I haven't done it to keep it minimal, but a follow up could make it
to be straight '/'. This would make it bigger but easier for the eye to follow.
IMO is not worth it, but opinions are welcome.

The patch also adds tests for different cases like a parentless commit
preceding multiple parents merges and the examples above.

There could be some edge cases still so any testing is very welcome.

PSA: the tests are on t4215-log-skewed-merges.sh, which is not very related,
     but other graph related tests have +140 tests, and this one has less than
     20 and some of them are also not very related and differ in style.
     A cleanup patch before this renaming the file and style of the tests is fine?

Changes from v1:

- Changed to parentless commits instead of root commits to make it more generic
- Fixed the branch names to pass CI and fixed tests style.

Pablo Sabater (1):
  graph: add indentation for commits preceded by a parentless commit

 graph.c                      |  70 ++++++++++++++++++--
 t/t4215-log-skewed-merges.sh | 124 +++++++++++++++++++++++++++++++++++
 2 files changed, 188 insertions(+), 6 deletions(-)

base-commit: 8de2f1b07a8053d7f1aad70dc1131d6afcf5a28a
-- 
2.43.0