{"thread":{"id":"66883","subject":"[PATCH] graph: do not fuse merge parents into left columns","startedAt":"2026-11-19T19:22:47Z","lastAt":"2026-11-19T19:22:47Z","messageCount":1,"participants":["Dominik Maier"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558876","messageId":"20261119192247.2671852-1-dmnk@google.com","threadId":"66883","inReplyTo":null,"subject":"[PATCH] graph: do not fuse merge parents into left columns","fromName":"Dominik Maier","fromEmail":"dmnk@google.com","sentAt":"2026-11-19T19:22:47Z","receivedAt":"2026-11-19T19:22:47Z","isPatch":true,"sender":{"key":"dmnk@google.com","avatar":null},"body":"In graph_insert_into_new_columns(), the branch that coalesces a column\ninto graph->mapping[graph->width - 2] and resets graph->edges_added = -1\nis intended for existing columns to the right of a merge commit\n(idx < 0) so that two adjacent edges can join immediately as \"|\\|\".\n\nWhen a merge commit itself is skewed left (merge_layout == 0), its first\nparent does not advance graph->width, leaving graph->width - 2 pointing\nat the column immediately to the left of the merge commit. If the second\nparent of a 4+-parent octopus merge matches that column while idx >= 0,\nit overwrites graph->mapping[graph->width - 2] without advancing\ngraph->width and resets graph->edges_added = -1. Subsequent parents are\nplaced one slot too far left, leaving the last dashed-parent slot in\ngraph->mapping[] at -1 and indexing graph->new_columns[-1] in\ngraph_draw_octopus_merge().\n\nRestrict the right-neighbor edge fusion to existing non-merge columns\n(idx < 0) and guard against negative mapping indices in\ngraph_draw_octopus_merge().\n\nSigned-off-by: Dominik Maier <dmnk@google.com>\n---\n graph.c                      |  5 ++++-\n t/t4215-log-skewed-merges.sh | 31 +++++++++++++++++++++++++++++++\n 2 files changed, 35 insertions(+), 1 deletion(-)\n\ndiff --git a/graph.c b/graph.c\nindex 95eef3a95e..a40834a639 100644\n--- a/graph.c\n+++ b/graph.c\n@@ -685,7 +685,8 @@ static void graph_insert_into_new_columns(struct git_graph *graph,\n \t\tmapping_idx = graph->width + (graph->merge_layout - 1) * shift;\n \t\tgraph->width += 2 * graph->merge_layout;\n \n-\t} else if (graph->edges_added > 0 && i == graph->mapping[graph->width - 2]) {\n+\t} else if (idx < 0 && graph->edges_added > 0 &&\n+\t\t   i == graph->mapping[graph->width - 2]) {\n \t\t/*\n \t\t * If some columns have been added by a merge, but this commit\n \t\t * was found in the last existing column, then adjust the\n@@ -1317,6 +1318,8 @@ static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line\n \n \tfor (i = 0; i < dashed_parents; i++) {\n \t\tj = graph->mapping[(graph->commit_index + i + 2) * 2];\n+\t\tif (j < 0)\n+\t\t\tBUG(\"octopus merge mapping uninitialized\");\n \t\tcol = &graph->new_columns[j];\n \n \t\tgraph_line_write_column(line, col, '-');\ndiff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh\nindex eebab71039..632c7d2c97 100755\n--- a/t/t4215-log-skewed-merges.sh\n+++ b/t/t4215-log-skewed-merges.sh\n@@ -509,4 +509,35 @@ test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 pa\n \tEOF\n '\n \n+test_expect_success 'log --graph left-skewed 4-parent octopus merge joining adjacent left column' '\n+\tgit checkout --orphan 8_p &&\n+\ttest_commit 8_root &&\n+\tgit checkout -b 8_pA 8_p && test_commit 8_A &&\n+\tgit checkout -b 8_pB 8_p && test_commit 8_B &&\n+\tgit checkout -b 8_pC 8_p && test_commit 8_C &&\n+\tgit checkout -b 8_pD 8_p && test_commit 8_D &&\n+\tgit checkout -b 8_M 8_pA &&\n+\tgit merge --no-ff 8_pB 8_pC 8_pD -m 8_M &&\n+\tgit checkout 8_pB && test_commit 8_B2 &&\n+\tgit checkout -b 8_TOP 8_pA &&\n+\tgit merge --no-ff 8_pB 8_M -m 8_TOP &&\n+\n+\tlib_test_check_graph --date-order 8_TOP <<-\\EOF\n+\t*-.   8_TOP\n+\t|\\ \\\n+\t| * | 8_B2\n+\t| | *-.   8_M\n+\t| |/|\\ \\\n+\t|/|/ / /\n+\t| | | * 8_D\n+\t| | * | 8_C\n+\t| | |/\n+\t| * / 8_B\n+\t| |/\n+\t* / 8_A\n+\t|/\n+\t* 8_root\n+\tEOF\n+'\n+\n test_done\n-- \n2.56.1.750.gf70dc682cf-goog\n\n\n"}]}