Git development
 help / color / mirror / Atom feed
* [PATCH] graph: do not fuse merge parents into left columns
@ 2026-11-19 19:22 Dominik Maier
  2026-11-20 10:50 ` Caspar Duregger
  2026-11-24 18:05 ` [PATCH v2] graph: do not fuse merge parents with the column to their left Dominik Maier
  0 siblings, 2 replies; 5+ messages in thread
From: Dominik Maier @ 2026-11-19 19:22 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Pablo Sabater, Caspar Duregger, dmnk+artist,
	Dominik Maier

In graph_insert_into_new_columns(), the branch that coalesces a column
into graph->mapping[graph->width - 2] and resets graph->edges_added = -1
is intended for existing columns to the right of a merge commit
(idx < 0) so that two adjacent edges can join immediately as "|\|".

When a merge commit itself is skewed left (merge_layout == 0), its first
parent does not advance graph->width, leaving graph->width - 2 pointing
at the column immediately to the left of the merge commit. If the second
parent of a 4+-parent octopus merge matches that column while idx >= 0,
it overwrites graph->mapping[graph->width - 2] without advancing
graph->width and resets graph->edges_added = -1. Subsequent parents are
placed one slot too far left, leaving the last dashed-parent slot in
graph->mapping[] at -1 and indexing graph->new_columns[-1] in
graph_draw_octopus_merge().

Restrict the right-neighbor edge fusion to existing non-merge columns
(idx < 0) and guard against negative mapping indices in
graph_draw_octopus_merge().

Signed-off-by: Dominik Maier <dmnk@google.com>
---
 graph.c                      |  5 ++++-
 t/t4215-log-skewed-merges.sh | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/graph.c b/graph.c
index 95eef3a95e..a40834a639 100644
--- a/graph.c
+++ b/graph.c
@@ -685,7 +685,8 @@ static void graph_insert_into_new_columns(struct git_graph *graph,
 		mapping_idx = graph->width + (graph->merge_layout - 1) * shift;
 		graph->width += 2 * graph->merge_layout;
 
-	} else if (graph->edges_added > 0 && i == graph->mapping[graph->width - 2]) {
+	} else if (idx < 0 && graph->edges_added > 0 &&
+		   i == graph->mapping[graph->width - 2]) {
 		/*
 		 * If some columns have been added by a merge, but this commit
 		 * was found in the last existing column, then adjust the
@@ -1317,6 +1318,8 @@ static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line
 
 	for (i = 0; i < dashed_parents; i++) {
 		j = graph->mapping[(graph->commit_index + i + 2) * 2];
+		if (j < 0)
+			BUG("octopus merge mapping uninitialized");
 		col = &graph->new_columns[j];
 
 		graph_line_write_column(line, col, '-');
diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh
index eebab71039..632c7d2c97 100755
--- a/t/t4215-log-skewed-merges.sh
+++ b/t/t4215-log-skewed-merges.sh
@@ -509,4 +509,35 @@ test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 pa
 	EOF
 '
 
+test_expect_success 'log --graph left-skewed 4-parent octopus merge joining adjacent left column' '
+	git checkout --orphan 8_p &&
+	test_commit 8_root &&
+	git checkout -b 8_pA 8_p && test_commit 8_A &&
+	git checkout -b 8_pB 8_p && test_commit 8_B &&
+	git checkout -b 8_pC 8_p && test_commit 8_C &&
+	git checkout -b 8_pD 8_p && test_commit 8_D &&
+	git checkout -b 8_M 8_pA &&
+	git merge --no-ff 8_pB 8_pC 8_pD -m 8_M &&
+	git checkout 8_pB && test_commit 8_B2 &&
+	git checkout -b 8_TOP 8_pA &&
+	git merge --no-ff 8_pB 8_M -m 8_TOP &&
+
+	lib_test_check_graph --date-order 8_TOP <<-\EOF
+	*-.   8_TOP
+	|\ \
+	| * | 8_B2
+	| | *-.   8_M
+	| |/|\ \
+	|/|/ / /
+	| | | * 8_D
+	| | * | 8_C
+	| | |/
+	| * / 8_B
+	| |/
+	* / 8_A
+	|/
+	* 8_root
+	EOF
+'
+
 test_done
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] graph: do not fuse merge parents into left columns
  2026-11-19 19:22 [PATCH] graph: do not fuse merge parents into left columns Dominik Maier
@ 2026-11-20 10:50 ` Caspar Duregger
  2026-11-24 18:05 ` [PATCH v2] graph: do not fuse merge parents with the column to their left Dominik Maier
  1 sibling, 0 replies; 5+ messages in thread
From: Caspar Duregger @ 2026-11-20 10:50 UTC (permalink / raw)
  To: Dominik Maier; +Cc: git, Junio C Hamano, Pablo Sabater, dmnk+artist

Hi!

The fix (idx < 0) generally is correct, you undersell it in the
commit message, and also a reproduction with just 3 parents is
possible.

sh
test_expect_success 'log --graph with left-skewed merge into its left
neighbor' '
        git checkout --orphan 8_p &&
        test_commit 8_root &&
        git checkout -b 8_pA 8_p && test_commit 8_A &&
        git checkout -b 8_pB 8_p && test_commit 8_B &&
        git checkout -b 8_pC 8_p && test_commit 8_C &&
        TREE=$(git write-tree) &&
        test_tick &&
        M=$(git commit-tree $TREE -p 8_A -p 8_B -p 8_C -m 8_M) &&
        test_tick &&
        TOP=$(git commit-tree $TREE -p 8_A -p 8_B -p $M -m 8_TOP) &&

        lib_test_check_graph $TOP <<-\EOF
        *-.   8_TOP
        |\ \
        | | *   8_M
        | |/|\
        |/|/ /
        | | * 8_C
        | * | 8_B
        | |/
        * / 8_A
        |/
        * 8_root
        EOF
'

I'm not sure if usage of BUG is correct here, sure we can assert
but that leads to a crash and without it it would lead to just
a garbage drawing.  That is a matter of project policy so others
have to judge that.

Your commit message is very technical and I had to read the code
to get a grasp on it actually.


graph: do not fuse merge parents with the column to their left

When a merge is skewed to the left and its second parent is the
column right next to it, the edge to that parent is lost:

        | | * M                | | *   M
        | |/|\                 | |/|\
        |/| |         =>       |/|/ /
        | | * C                | | * C

With four or more parents it gets worse: drawing the dashes of the
octopus reads outside the columns array.

graph_insert_into_new_columns() has a shortcut that lets a column to
the right of a merge join the merge's last edge right away ("|\|").
It compares against the last edge added so far.  For a left-skewed
merge, the first parent does not add an edge, so when the second
parent comes up, that "last edge" is the column to the left of the
merge, and the shortcut wrongly swallows the parent's own edge.

Only take the shortcut for columns that are not parents of the
merge, which is the case it was written for.  Also BUG() in
graph_draw_octopus_merge() instead of indexing new_columns[-1] if the
mapping is ever incomplete.

Regards
Caspar Duregger

Am Do., 19. Nov. 2026 um 20:22 Uhr schrieb Dominik Maier <dmnk@google.com>:
>
> In graph_insert_into_new_columns(), the branch that coalesces a column
> into graph->mapping[graph->width - 2] and resets graph->edges_added = -1
> is intended for existing columns to the right of a merge commit
> (idx < 0) so that two adjacent edges can join immediately as "|\|".
>
> When a merge commit itself is skewed left (merge_layout == 0), its first
> parent does not advance graph->width, leaving graph->width - 2 pointing
> at the column immediately to the left of the merge commit. If the second
> parent of a 4+-parent octopus merge matches that column while idx >= 0,
> it overwrites graph->mapping[graph->width - 2] without advancing
> graph->width and resets graph->edges_added = -1. Subsequent parents are
> placed one slot too far left, leaving the last dashed-parent slot in
> graph->mapping[] at -1 and indexing graph->new_columns[-1] in
> graph_draw_octopus_merge().
>
> Restrict the right-neighbor edge fusion to existing non-merge columns
> (idx < 0) and guard against negative mapping indices in
> graph_draw_octopus_merge().
>
> Signed-off-by: Dominik Maier <dmnk@google.com>
> ---
>  graph.c                      |  5 ++++-
>  t/t4215-log-skewed-merges.sh | 31 +++++++++++++++++++++++++++++++
>  2 files changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/graph.c b/graph.c
> index 95eef3a95e..a40834a639 100644
> --- a/graph.c
> +++ b/graph.c
> @@ -685,7 +685,8 @@ static void graph_insert_into_new_columns(struct git_graph *graph,
>                 mapping_idx = graph->width + (graph->merge_layout - 1) * shift;
>                 graph->width += 2 * graph->merge_layout;
>
> -       } else if (graph->edges_added > 0 && i == graph->mapping[graph->width - 2]) {
> +       } else if (idx < 0 && graph->edges_added > 0 &&
> +                  i == graph->mapping[graph->width - 2]) {
>                 /*
>                  * If some columns have been added by a merge, but this commit
>                  * was found in the last existing column, then adjust the
> @@ -1317,6 +1318,8 @@ static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line
>
>         for (i = 0; i < dashed_parents; i++) {
>                 j = graph->mapping[(graph->commit_index + i + 2) * 2];
> +               if (j < 0)
> +                       BUG("octopus merge mapping uninitialized");
>                 col = &graph->new_columns[j];
>
>                 graph_line_write_column(line, col, '-');
> diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh
> index eebab71039..632c7d2c97 100755
> --- a/t/t4215-log-skewed-merges.sh
> +++ b/t/t4215-log-skewed-merges.sh
> @@ -509,4 +509,35 @@ test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 pa
>         EOF
>  '
>
> +test_expect_success 'log --graph left-skewed 4-parent octopus merge joining adjacent left column' '
> +       git checkout --orphan 8_p &&
> +       test_commit 8_root &&
> +       git checkout -b 8_pA 8_p && test_commit 8_A &&
> +       git checkout -b 8_pB 8_p && test_commit 8_B &&
> +       git checkout -b 8_pC 8_p && test_commit 8_C &&
> +       git checkout -b 8_pD 8_p && test_commit 8_D &&
> +       git checkout -b 8_M 8_pA &&
> +       git merge --no-ff 8_pB 8_pC 8_pD -m 8_M &&
> +       git checkout 8_pB && test_commit 8_B2 &&
> +       git checkout -b 8_TOP 8_pA &&
> +       git merge --no-ff 8_pB 8_M -m 8_TOP &&
> +
> +       lib_test_check_graph --date-order 8_TOP <<-\EOF
> +       *-.   8_TOP
> +       |\ \
> +       | * | 8_B2
> +       | | *-.   8_M
> +       | |/|\ \
> +       |/|/ / /
> +       | | | * 8_D
> +       | | * | 8_C
> +       | | |/
> +       | * / 8_B
> +       | |/
> +       * / 8_A
> +       |/
> +       * 8_root
> +       EOF
> +'
> +
>  test_done
> --
> 2.56.1.750.gf70dc682cf-goog
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] graph: do not fuse merge parents with the column to their left
  2026-11-19 19:22 [PATCH] graph: do not fuse merge parents into left columns Dominik Maier
  2026-11-20 10:50 ` Caspar Duregger
@ 2026-11-24 18:05 ` Dominik Maier
  2026-11-25  9:37   ` Caspar Duregger
  2026-11-26  7:17   ` Junio C Hamano
  1 sibling, 2 replies; 5+ messages in thread
From: Dominik Maier @ 2026-11-24 18:05 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Caspar Duregger, Pablo Sabater, dmnk+artist

When a merge is skewed to the left and its second parent is the column
right next to it, the edge to that parent is lost:

	| | * M                | | *   M
	| |/|\                 | |/|\
	|/| |         =>       |/|/ /
	| | * C                | | * C

With four or more parents it gets worse: the remaining parents shift
one slot too far left, leaving the last dashed-parent entry in
graph->mapping[] at -1 and reading before graph->new_columns[0] in
graph_draw_octopus_merge().

graph_insert_into_new_columns() has a shortcut that lets a column to
the right of a merge join the merge's last edge right away ("|\|").
It compares against the last edge added so far. For a left-skewed
merge, the first parent does not add an edge, so when the second parent
comes up, that "last edge" is the column to the left of the merge, and
the shortcut swallows the parent's own edge.

Only take the shortcut for existing non-parent columns (idx < 0), which
is the case it was written for.

Helped-by: Caspar Duregger <caspar.duregger@gmail.com>
Signed-off-by: Dominik Maier <dmnk@google.com>
---
Changes in v2:
- Reword commit message to show the 3-parent missing-edge case alongside
  the 4+-parent out-of-bounds read, add the 3-parent test, and drop the
  extra BUG() in graph_draw_octopus_merge() (Caspar Duregger).

 graph.c                      |  3 ++-
 t/t4215-log-skewed-merges.sh | 52 ++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/graph.c b/graph.c
index 95eef3a95e..c55b1fb5aa 100644
--- a/graph.c
+++ b/graph.c
@@ -685,7 +685,8 @@ static void graph_insert_into_new_columns(struct git_graph *graph,
 		mapping_idx = graph->width + (graph->merge_layout - 1) * shift;
 		graph->width += 2 * graph->merge_layout;
 
-	} else if (graph->edges_added > 0 && i == graph->mapping[graph->width - 2]) {
+	} else if (idx < 0 && graph->edges_added > 0 &&
+		   i == graph->mapping[graph->width - 2]) {
 		/*
 		 * If some columns have been added by a merge, but this commit
 		 * was found in the last existing column, then adjust the
diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh
index eebab71039..359383a8ad 100755
--- a/t/t4215-log-skewed-merges.sh
+++ b/t/t4215-log-skewed-merges.sh
@@ -509,4 +509,56 @@ test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 pa
 	EOF
 '
 
+test_expect_success 'log --graph with left-skewed merge into its left neighbor' '
+	git checkout --orphan 8_p &&
+	test_commit 8_root &&
+	git checkout -b 8_pA 8_p && test_commit 8_A &&
+	git checkout -b 8_pB 8_p && test_commit 8_B &&
+	git checkout -b 8_pC 8_p && test_commit 8_C &&
+	TREE=$(git write-tree) &&
+	test_tick &&
+	M=$(git commit-tree $TREE -p 8_pA -p 8_pB -p 8_pC -m 8_M) &&
+	test_tick &&
+	TOP=$(git commit-tree $TREE -p 8_pA -p 8_pB -p $M -m 8_TOP) &&
+
+	lib_test_check_graph $TOP <<-\EOF
+	*-.   8_TOP
+	|\ \
+	| | *   8_M
+	| |/|\
+	|/|/ /
+	| | * 8_C
+	| * | 8_B
+	| |/
+	* / 8_A
+	|/
+	* 8_root
+	EOF
+'
+
+test_expect_success 'log --graph with left-skewed 4-parent octopus into left neighbor' '
+	git checkout -b 8_pD 8_p && test_commit 8_D &&
+	TREE=$(git write-tree) &&
+	test_tick &&
+	M4=$(git commit-tree $TREE -p 8_pA -p 8_pB -p 8_pC -p 8_pD -m 8_M4) &&
+	test_tick &&
+	TOP4=$(git commit-tree $TREE -p 8_pA -p 8_pB -p $M4 -m 8_TOP4) &&
+
+	lib_test_check_graph $TOP4 <<-\EOF
+	*-.   8_TOP4
+	|\ \
+	| | *-.   8_M4
+	| |/|\ \
+	|/|/ / /
+	| | | * 8_D
+	| | * | 8_C
+	| | |/
+	| * / 8_B
+	| |/
+	* / 8_A
+	|/
+	* 8_root
+	EOF
+'
+
 test_done

Range-diff against v1:
1:  e28b8150c7 ! 1:  a2e27b8fa9 graph: do not fuse merge parents into left columns
    @@ Metadata
     Author: Dominik Maier <dmnk@google.com>
     
      ## Commit message ##
    -    graph: do not fuse merge parents into left columns
    +    graph: do not fuse merge parents with the column to their left
     
    -    In graph_insert_into_new_columns(), the branch that coalesces a column
    -    into graph->mapping[graph->width - 2] and resets graph->edges_added = -1
    -    is intended for existing columns to the right of a merge commit
    -    (idx < 0) so that two adjacent edges can join immediately as "|\|".
    +    When a merge is skewed to the left and its second parent is the column
    +    right next to it, the edge to that parent is lost:
     
    -    When a merge commit itself is skewed left (merge_layout == 0), its first
    -    parent does not advance graph->width, leaving graph->width - 2 pointing
    -    at the column immediately to the left of the merge commit. If the second
    -    parent of a 4+-parent octopus merge matches that column while idx >= 0,
    -    it overwrites graph->mapping[graph->width - 2] without advancing
    -    graph->width and resets graph->edges_added = -1. Subsequent parents are
    -    placed one slot too far left, leaving the last dashed-parent slot in
    -    graph->mapping[] at -1 and indexing graph->new_columns[-1] in
    -    graph_draw_octopus_merge().
    +            | | * M                | | *   M
    +            | |/|\                 | |/|\
    +            |/| |         =>       |/|/ /
    +            | | * C                | | * C
     
    -    Restrict the right-neighbor edge fusion to existing non-merge columns
    -    (idx < 0) and guard against negative mapping indices in
    +    With four or more parents it gets worse: the remaining parents shift
    +    one slot too far left, leaving the last dashed-parent entry in
    +    graph->mapping[] at -1 and reading before graph->new_columns[0] in
         graph_draw_octopus_merge().
     
    +    graph_insert_into_new_columns() has a shortcut that lets a column to
    +    the right of a merge join the merge's last edge right away ("|\|").
    +    It compares against the last edge added so far. For a left-skewed
    +    merge, the first parent does not add an edge, so when the second parent
    +    comes up, that "last edge" is the column to the left of the merge, and
    +    the shortcut swallows the parent's own edge.
    +
    +    Only take the shortcut for existing non-parent columns (idx < 0), which
    +    is the case it was written for.
    +
    +    Helped-by: Caspar Duregger <caspar.duregger@gmail.com>
         Signed-off-by: Dominik Maier <dmnk@google.com>
     
      ## graph.c ##
    @@ graph.c: static void graph_insert_into_new_columns(struct git_graph *graph,
      		/*
      		 * If some columns have been added by a merge, but this commit
      		 * was found in the last existing column, then adjust the
    -@@ graph.c: static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line
    - 
    - 	for (i = 0; i < dashed_parents; i++) {
    - 		j = graph->mapping[(graph->commit_index + i + 2) * 2];
    -+		if (j < 0)
    -+			BUG("octopus merge mapping uninitialized");
    - 		col = &graph->new_columns[j];
    - 
    - 		graph_line_write_column(line, col, '-');
     
      ## t/t4215-log-skewed-merges.sh ##
     @@ t/t4215-log-skewed-merges.sh: test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 pa
      	EOF
      '
      
    -+test_expect_success 'log --graph left-skewed 4-parent octopus merge joining adjacent left column' '
    ++test_expect_success 'log --graph with left-skewed merge into its left neighbor' '
     +	git checkout --orphan 8_p &&
     +	test_commit 8_root &&
     +	git checkout -b 8_pA 8_p && test_commit 8_A &&
     +	git checkout -b 8_pB 8_p && test_commit 8_B &&
     +	git checkout -b 8_pC 8_p && test_commit 8_C &&
    -+	git checkout -b 8_pD 8_p && test_commit 8_D &&
    -+	git checkout -b 8_M 8_pA &&
    -+	git merge --no-ff 8_pB 8_pC 8_pD -m 8_M &&
    -+	git checkout 8_pB && test_commit 8_B2 &&
    -+	git checkout -b 8_TOP 8_pA &&
    -+	git merge --no-ff 8_pB 8_M -m 8_TOP &&
    ++	TREE=$(git write-tree) &&
    ++	test_tick &&
    ++	M=$(git commit-tree $TREE -p 8_pA -p 8_pB -p 8_pC -m 8_M) &&
    ++	test_tick &&
    ++	TOP=$(git commit-tree $TREE -p 8_pA -p 8_pB -p $M -m 8_TOP) &&
     +
    -+	lib_test_check_graph --date-order 8_TOP <<-\EOF
    ++	lib_test_check_graph $TOP <<-\EOF
     +	*-.   8_TOP
     +	|\ \
    -+	| * | 8_B2
    -+	| | *-.   8_M
    ++	| | *   8_M
    ++	| |/|\
    ++	|/|/ /
    ++	| | * 8_C
    ++	| * | 8_B
    ++	| |/
    ++	* / 8_A
    ++	|/
    ++	* 8_root
    ++	EOF
    ++'
    ++
    ++test_expect_success 'log --graph with left-skewed 4-parent octopus into left neighbor' '
    ++	git checkout -b 8_pD 8_p && test_commit 8_D &&
    ++	TREE=$(git write-tree) &&
    ++	test_tick &&
    ++	M4=$(git commit-tree $TREE -p 8_pA -p 8_pB -p 8_pC -p 8_pD -m 8_M4) &&
    ++	test_tick &&
    ++	TOP4=$(git commit-tree $TREE -p 8_pA -p 8_pB -p $M4 -m 8_TOP4) &&
    ++
    ++	lib_test_check_graph $TOP4 <<-\EOF
    ++	*-.   8_TOP4
    ++	|\ \
    ++	| | *-.   8_M4
     +	| |/|\ \
     +	|/|/ / /
     +	| | | * 8_D
-- 
2.56.1.831.g720f3f5937-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] graph: do not fuse merge parents with the column to their left
  2026-11-24 18:05 ` [PATCH v2] graph: do not fuse merge parents with the column to their left Dominik Maier
@ 2026-11-25  9:37   ` Caspar Duregger
  2026-11-26  7:17   ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Caspar Duregger @ 2026-11-25  9:37 UTC (permalink / raw)
  To: Dominik Maier; +Cc: git, Junio C Hamano, Pablo Sabater, dmnk+artist

LGTM

Regards
Caspar

Am Di., 24. Nov. 2026 um 19:06 Uhr schrieb Dominik Maier <dmnk@google.com>:
>
> When a merge is skewed to the left and its second parent is the column
> right next to it, the edge to that parent is lost:
>
>         | | * M                | | *   M
>         | |/|\                 | |/|\
>         |/| |         =>       |/|/ /
>         | | * C                | | * C
>
> With four or more parents it gets worse: the remaining parents shift
> one slot too far left, leaving the last dashed-parent entry in
> graph->mapping[] at -1 and reading before graph->new_columns[0] in
> graph_draw_octopus_merge().
>
> graph_insert_into_new_columns() has a shortcut that lets a column to
> the right of a merge join the merge's last edge right away ("|\|").
> It compares against the last edge added so far. For a left-skewed
> merge, the first parent does not add an edge, so when the second parent
> comes up, that "last edge" is the column to the left of the merge, and
> the shortcut swallows the parent's own edge.
>
> Only take the shortcut for existing non-parent columns (idx < 0), which
> is the case it was written for.
>
> Helped-by: Caspar Duregger <caspar.duregger@gmail.com>
> Signed-off-by: Dominik Maier <dmnk@google.com>
> ---
> Changes in v2:
> - Reword commit message to show the 3-parent missing-edge case alongside
>   the 4+-parent out-of-bounds read, add the 3-parent test, and drop the
>   extra BUG() in graph_draw_octopus_merge() (Caspar Duregger).
>
>  graph.c                      |  3 ++-
>  t/t4215-log-skewed-merges.sh | 52 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 54 insertions(+), 1 deletion(-)
>
> diff --git a/graph.c b/graph.c
> index 95eef3a95e..c55b1fb5aa 100644
> --- a/graph.c
> +++ b/graph.c
> @@ -685,7 +685,8 @@ static void graph_insert_into_new_columns(struct git_graph *graph,
>                 mapping_idx = graph->width + (graph->merge_layout - 1) * shift;
>                 graph->width += 2 * graph->merge_layout;
>
> -       } else if (graph->edges_added > 0 && i == graph->mapping[graph->width - 2]) {
> +       } else if (idx < 0 && graph->edges_added > 0 &&
> +                  i == graph->mapping[graph->width - 2]) {
>                 /*
>                  * If some columns have been added by a merge, but this commit
>                  * was found in the last existing column, then adjust the
> diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh
> index eebab71039..359383a8ad 100755
> --- a/t/t4215-log-skewed-merges.sh
> +++ b/t/t4215-log-skewed-merges.sh
> @@ -509,4 +509,56 @@ test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 pa
>         EOF
>  '
>
> +test_expect_success 'log --graph with left-skewed merge into its left neighbor' '
> +       git checkout --orphan 8_p &&
> +       test_commit 8_root &&
> +       git checkout -b 8_pA 8_p && test_commit 8_A &&
> +       git checkout -b 8_pB 8_p && test_commit 8_B &&
> +       git checkout -b 8_pC 8_p && test_commit 8_C &&
> +       TREE=$(git write-tree) &&
> +       test_tick &&
> +       M=$(git commit-tree $TREE -p 8_pA -p 8_pB -p 8_pC -m 8_M) &&
> +       test_tick &&
> +       TOP=$(git commit-tree $TREE -p 8_pA -p 8_pB -p $M -m 8_TOP) &&
> +
> +       lib_test_check_graph $TOP <<-\EOF
> +       *-.   8_TOP
> +       |\ \
> +       | | *   8_M
> +       | |/|\
> +       |/|/ /
> +       | | * 8_C
> +       | * | 8_B
> +       | |/
> +       * / 8_A
> +       |/
> +       * 8_root
> +       EOF
> +'
> +
> +test_expect_success 'log --graph with left-skewed 4-parent octopus into left neighbor' '
> +       git checkout -b 8_pD 8_p && test_commit 8_D &&
> +       TREE=$(git write-tree) &&
> +       test_tick &&
> +       M4=$(git commit-tree $TREE -p 8_pA -p 8_pB -p 8_pC -p 8_pD -m 8_M4) &&
> +       test_tick &&
> +       TOP4=$(git commit-tree $TREE -p 8_pA -p 8_pB -p $M4 -m 8_TOP4) &&
> +
> +       lib_test_check_graph $TOP4 <<-\EOF
> +       *-.   8_TOP4
> +       |\ \
> +       | | *-.   8_M4
> +       | |/|\ \
> +       |/|/ / /
> +       | | | * 8_D
> +       | | * | 8_C
> +       | | |/
> +       | * / 8_B
> +       | |/
> +       * / 8_A
> +       |/
> +       * 8_root
> +       EOF
> +'
> +
>  test_done
>
> Range-diff against v1:
> 1:  e28b8150c7 ! 1:  a2e27b8fa9 graph: do not fuse merge parents into left columns
>     @@ Metadata
>      Author: Dominik Maier <dmnk@google.com>
>
>       ## Commit message ##
>     -    graph: do not fuse merge parents into left columns
>     +    graph: do not fuse merge parents with the column to their left
>
>     -    In graph_insert_into_new_columns(), the branch that coalesces a column
>     -    into graph->mapping[graph->width - 2] and resets graph->edges_added = -1
>     -    is intended for existing columns to the right of a merge commit
>     -    (idx < 0) so that two adjacent edges can join immediately as "|\|".
>     +    When a merge is skewed to the left and its second parent is the column
>     +    right next to it, the edge to that parent is lost:
>
>     -    When a merge commit itself is skewed left (merge_layout == 0), its first
>     -    parent does not advance graph->width, leaving graph->width - 2 pointing
>     -    at the column immediately to the left of the merge commit. If the second
>     -    parent of a 4+-parent octopus merge matches that column while idx >= 0,
>     -    it overwrites graph->mapping[graph->width - 2] without advancing
>     -    graph->width and resets graph->edges_added = -1. Subsequent parents are
>     -    placed one slot too far left, leaving the last dashed-parent slot in
>     -    graph->mapping[] at -1 and indexing graph->new_columns[-1] in
>     -    graph_draw_octopus_merge().
>     +            | | * M                | | *   M
>     +            | |/|\                 | |/|\
>     +            |/| |         =>       |/|/ /
>     +            | | * C                | | * C
>
>     -    Restrict the right-neighbor edge fusion to existing non-merge columns
>     -    (idx < 0) and guard against negative mapping indices in
>     +    With four or more parents it gets worse: the remaining parents shift
>     +    one slot too far left, leaving the last dashed-parent entry in
>     +    graph->mapping[] at -1 and reading before graph->new_columns[0] in
>          graph_draw_octopus_merge().
>
>     +    graph_insert_into_new_columns() has a shortcut that lets a column to
>     +    the right of a merge join the merge's last edge right away ("|\|").
>     +    It compares against the last edge added so far. For a left-skewed
>     +    merge, the first parent does not add an edge, so when the second parent
>     +    comes up, that "last edge" is the column to the left of the merge, and
>     +    the shortcut swallows the parent's own edge.
>     +
>     +    Only take the shortcut for existing non-parent columns (idx < 0), which
>     +    is the case it was written for.
>     +
>     +    Helped-by: Caspar Duregger <caspar.duregger@gmail.com>
>          Signed-off-by: Dominik Maier <dmnk@google.com>
>
>       ## graph.c ##
>     @@ graph.c: static void graph_insert_into_new_columns(struct git_graph *graph,
>                 /*
>                  * If some columns have been added by a merge, but this commit
>                  * was found in the last existing column, then adjust the
>     -@@ graph.c: static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line
>     -
>     -   for (i = 0; i < dashed_parents; i++) {
>     -           j = graph->mapping[(graph->commit_index + i + 2) * 2];
>     -+          if (j < 0)
>     -+                  BUG("octopus merge mapping uninitialized");
>     -           col = &graph->new_columns[j];
>     -
>     -           graph_line_write_column(line, col, '-');
>
>       ## t/t4215-log-skewed-merges.sh ##
>      @@ t/t4215-log-skewed-merges.sh: test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 pa
>         EOF
>       '
>
>     -+test_expect_success 'log --graph left-skewed 4-parent octopus merge joining adjacent left column' '
>     ++test_expect_success 'log --graph with left-skewed merge into its left neighbor' '
>      +  git checkout --orphan 8_p &&
>      +  test_commit 8_root &&
>      +  git checkout -b 8_pA 8_p && test_commit 8_A &&
>      +  git checkout -b 8_pB 8_p && test_commit 8_B &&
>      +  git checkout -b 8_pC 8_p && test_commit 8_C &&
>     -+  git checkout -b 8_pD 8_p && test_commit 8_D &&
>     -+  git checkout -b 8_M 8_pA &&
>     -+  git merge --no-ff 8_pB 8_pC 8_pD -m 8_M &&
>     -+  git checkout 8_pB && test_commit 8_B2 &&
>     -+  git checkout -b 8_TOP 8_pA &&
>     -+  git merge --no-ff 8_pB 8_M -m 8_TOP &&
>     ++  TREE=$(git write-tree) &&
>     ++  test_tick &&
>     ++  M=$(git commit-tree $TREE -p 8_pA -p 8_pB -p 8_pC -m 8_M) &&
>     ++  test_tick &&
>     ++  TOP=$(git commit-tree $TREE -p 8_pA -p 8_pB -p $M -m 8_TOP) &&
>      +
>     -+  lib_test_check_graph --date-order 8_TOP <<-\EOF
>     ++  lib_test_check_graph $TOP <<-\EOF
>      +  *-.   8_TOP
>      +  |\ \
>     -+  | * | 8_B2
>     -+  | | *-.   8_M
>     ++  | | *   8_M
>     ++  | |/|\
>     ++  |/|/ /
>     ++  | | * 8_C
>     ++  | * | 8_B
>     ++  | |/
>     ++  * / 8_A
>     ++  |/
>     ++  * 8_root
>     ++  EOF
>     ++'
>     ++
>     ++test_expect_success 'log --graph with left-skewed 4-parent octopus into left neighbor' '
>     ++  git checkout -b 8_pD 8_p && test_commit 8_D &&
>     ++  TREE=$(git write-tree) &&
>     ++  test_tick &&
>     ++  M4=$(git commit-tree $TREE -p 8_pA -p 8_pB -p 8_pC -p 8_pD -m 8_M4) &&
>     ++  test_tick &&
>     ++  TOP4=$(git commit-tree $TREE -p 8_pA -p 8_pB -p $M4 -m 8_TOP4) &&
>     ++
>     ++  lib_test_check_graph $TOP4 <<-\EOF
>     ++  *-.   8_TOP4
>     ++  |\ \
>     ++  | | *-.   8_M4
>      +  | |/|\ \
>      +  |/|/ / /
>      +  | | | * 8_D
> --
> 2.56.1.831.g720f3f5937-goog
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] graph: do not fuse merge parents with the column to their left
  2026-11-24 18:05 ` [PATCH v2] graph: do not fuse merge parents with the column to their left Dominik Maier
  2026-11-25  9:37   ` Caspar Duregger
@ 2026-11-26  7:17   ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2026-11-26  7:17 UTC (permalink / raw)
  To: Dominik Maier; +Cc: git, Caspar Duregger, Pablo Sabater, dmnk+artist

Dominik Maier <dmnk@google.com> writes:

> When a merge is skewed to the left and its second parent is the column
> right next to it, the edge to that parent is lost:
>
> 	| | * M                | | *   M
> 	| |/|\                 | |/|\
> 	|/| |         =>       |/|/ /
> 	| | * C                | | * C

Having this diagram makes the visual breakage much easier to follow than
in v1.

This only happens for merges with at least three parents, correct?
Because a two-parent left-skewed merge sets '.edges_added' to 0 and
skips the shortcut altogether.  If that is the case, it might be worth
saying in the commit log message.

The diagram already makes that clear enough in context.

> Only take the shortcut for existing non-parent columns (idx < 0), which
> is the case it was written for.

Small wording nit here.

In graph_update_columns(), calling graph_insert_into_new_columns() with
(idx == -1) happens for existing columns passing past the merge, and
when the shortcut triggers, that existing column actually matches the
merge's final parent.

Instead of saying "existing non-parent columns (idx < 0)", phrasing
"existing columns passing past the merge (idx < 0)" may be more exact,
though the code change itself is completely clear.

Looking at the two callers of graph_insert_into_new_columns() (both are
in graph_update_columns()) confirms why idx < 0 is the correct guard to
add to fix the issue.

Let's queue this and mark the topic as ready for 'next'.

> Helped-by: Caspar Duregger <caspar.duregger@gmail.com>
> Signed-off-by: Dominik Maier <dmnk@google.com>

Thanks, both of you.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-26  7:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 19:22 [PATCH] graph: do not fuse merge parents into left columns Dominik Maier
2026-11-20 10:50 ` Caspar Duregger
2026-11-24 18:05 ` [PATCH v2] graph: do not fuse merge parents with the column to their left Dominik Maier
2026-11-25  9:37   ` Caspar Duregger
2026-11-26  7:17   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox