@matheusbsbs / matheus-bagliano / commits / c958d3bd0a
Fork 0

graph: fix collapse of multiple edges

This fix resolves the previously-added test_expect_failure in t4215-log-skewed-merges.sh. The issue lies in the "else" condition while updating the mapping inside graph_output_collapsing_line(). In 0f0f389f (graph: tidy up display of left-skewed merges, 2019-10-15), the output of left- skewed merges was changed to allow an immediate horizontal edge in the first parent, output by graph_output_post_merge_line() instead of by graph_output_collapsing_line(). This condensed the first line behavior as follows: Before 0f0f389f: | | | | | | *-. | | | | | | |\ \ | |_|_|_|_|/ | | |/| | | | | / / After 0f0f389f: | | | | | | * | |_|_|_|_|/|\ |/| | | | |/ / | | | | |/| / However, a very subtle issue arose when the second and third parent edges are collapsed in later steps. The second parent edge is now immediately adjacent to a vertical edge. This means that the condition } else if (graph->mapping[i - 1] < 0) { in graph_output_collapsing_line() evaluates as false. The block for this condition was the only place where we connected the target column with the current position with horizontal edge markers. In this case, the final "else" block is run, and the edge is marked as horizontal, but did not back-fill the blank columns between the target and the current edge. Since the second parent edge is marked as horizontal, the third parent edge is not marked as horizontal. This causes the output to continue as follows: Before this change: | | | | | | * | |_|_|_|_|/|\ |/| | | | |/ / | | | | |/| / | | | |/| |/ | | |/| |/| | |/| |/| | | | |/| | | By adding the logic for "filling" a horizontal edge between the target column and the current column, we are able to resolve the issue. After this change: | | | | | | * | |_|_|_|_|/|\ |/| | | | |/ / | | |_|_|/| / | |/| | | |/ | | | |_|/| | | |/| | | This output properly matches the expected blend of the edge behavior before 0f0f389f and the merge commit rendering from 0f0f389f. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jan 8, 2020 at 04:27 UTC c958d3bd0a3781094db6fa8c45776785c98b6c98
2 files changed +9 -3
graph.c
+8 -2
@@ -1233,8 +1233,14 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
1233 * prevent any other edges from moving
1234 * horizontally.
1235 */
1236 - if (horizontal_edge == -1)
1237 - horizontal_edge = i;
1236 + if (horizontal_edge == -1) {
1237 + int j;
1238 + horizontal_edge_target = target;
1239 + horizontal_edge = i - 1;
1240 +
1241 + for (j = (target * 2) + 3; j < (i - 2); j += 2)
1242 + graph->mapping[j] = target;
1243 + }
1244 }
1245 }
1246
t/t4215-log-skewed-merges.sh
+1 -1
@@ -311,7 +311,7 @@ test_expect_success 'log --graph with multiple tips and colors' '
311 test_cmp expect.colors actual.colors
312 '
313
314 -test_expect_failure 'log --graph with multiple tips' '
314 +test_expect_success 'log --graph with multiple tips' '
315 git checkout --orphan 7_1 &&
316 test_commit 7_A &&
317 test_commit 7_B &&