graph: smooth appearance of collapsing edges on commit lines

When a graph contains edges that are in the process of collapsing to the left, but those edges cross a commit line, the effect is that the edges have a jagged appearance: * |\ | * | \ *-. \ |\ \ \ | | * | | * | | | |/ / * | | |/ / * | |/ * We already takes steps to smooth edges like this when they're expanding; when an edge appears to the right of a merge commit marker on a GRAPH_COMMIT line immediately following a GRAPH_POST_MERGE line, we render it as a `\`: * \ |\ \ | * \ | |\ \ We can make a similar improvement to collapsing edges, making them easier to follow and giving the overall graph a feeling of increased symmetry: * |\ | * | \ *-. \ |\ \ \ | | * | | * | | | |/ / * / / |/ / * / |/ * To do this, we introduce a new special case for edges on GRAPH_COMMIT lines that immediately follow a GRAPH_COLLAPSING line. By retaining a copy of the `mapping` array used to render the GRAPH_COLLAPSING line in the `old_mapping` array, we can determine that an edge is collapsing through the GRAPH_COMMIT line and should be smoothed. Signed-off-by: James Coglan <jcoglan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

James Coglan committed Oct 15, 2019 at 23:47 UTC 479db18bc0c38ed610fba56f3cc98abd7977e695
6 files changed +35 -26
graph.c
+13 -4
@@ -297,10 +297,10 @@ struct git_graph {
297 */
298 int *mapping;
299 /*
300 - * A temporary array for computing the next mapping state
301 - * while we are outputting a mapping line. This is stored as part
302 - * of the git_graph simply so we don't have to allocate a new
303 - * temporary array each time we have to output a collapsing line.
300 + * A copy of the contents of the mapping array from the last commit,
301 + * which we use to improve the display of columns that are tracking
302 + * from right to left through a commit line. We also use this to
303 + * avoid allocating a fresh array when we compute the next mapping.
304 */
305 int *old_mapping;
306 /*
@@ -1015,6 +1015,10 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
1015 graph_line_write_column(line, col, '\\');
1016 else
1017 graph_line_write_column(line, col, '|');
1018 + } else if (graph->prev_state == GRAPH_COLLAPSING &&
1019 + graph->old_mapping[2 * i + 1] == i &&
1020 + graph->mapping[2 * i] < i) {
1021 + graph_line_write_column(line, col, '/');
1022 } else {
1023 graph_line_write_column(line, col, '|');
1024 }
@@ -1211,6 +1215,11 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
1215 }
1216 }
1217
1218 + /*
1219 + * Copy the current mapping array into old_mapping
1220 + */
1221 + COPY_ARRAY(graph->old_mapping, graph->mapping, graph->mapping_size);
1222 +
1223 /*
1224 * The new mapping may be 1 smaller than the old mapping
1225 */
t/t3430-rebase-merges.sh
+1 -1
@@ -408,7 +408,7 @@ test_expect_success 'octopus merges' '
408 | | * three
409 | * | two
410 | |/
411 - * | one
411 + * / one
412 |/
413 o before-octopus
414 EOF
t/t4202-log.sh
+1 -1
@@ -667,7 +667,7 @@ cat > expect <<\EOF
667 * | | fifth
668 * | | fourth
669 |/ /
670 -* | third
670 +* / third
671 |/
672 * second
673 * initial
t/t4214-log-graph-octopus.sh
+16 -16
@@ -31,9 +31,9 @@ test_expect_success 'log --graph with tricky octopus merge, no color' '
31 | | | * 4
32 | | * | 3
33 | | |/
34 - | * | 2
34 + | * / 2
35 | |/
36 - * | 1
36 + * / 1
37 |/
38 * initial
39 EOF
@@ -51,9 +51,9 @@ test_expect_success 'log --graph with tricky octopus merge with colors' '
51 <RED>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 4
52 <RED>|<RESET> <YELLOW>|<RESET> * <MAGENTA>|<RESET> 3
53 <RED>|<RESET> <YELLOW>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
54 - <RED>|<RESET> * <MAGENTA>|<RESET> 2
54 + <RED>|<RESET> * <MAGENTA>/<RESET> 2
55 <RED>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
56 - * <MAGENTA>|<RESET> 1
56 + * <MAGENTA>/<RESET> 1
57 <MAGENTA>|<RESET><MAGENTA>/<RESET>
58 * initial
59 EOF
@@ -72,9 +72,9 @@ test_expect_success 'log --graph with normal octopus merge, no color' '
72 | | | * 4
73 | | * | 3
74 | | |/
75 - | * | 2
75 + | * / 2
76 | |/
77 - * | 1
77 + * / 1
78 |/
79 * initial
80 EOF
@@ -90,9 +90,9 @@ test_expect_success 'log --graph with normal octopus merge with colors' '
90 <RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET> * 4
91 <RED>|<RESET> <GREEN>|<RESET> * <BLUE>|<RESET> 3
92 <RED>|<RESET> <GREEN>|<RESET> <BLUE>|<RESET><BLUE>/<RESET>
93 - <RED>|<RESET> * <BLUE>|<RESET> 2
93 + <RED>|<RESET> * <BLUE>/<RESET> 2
94 <RED>|<RESET> <BLUE>|<RESET><BLUE>/<RESET>
95 - * <BLUE>|<RESET> 1
95 + * <BLUE>/<RESET> 1
96 <BLUE>|<RESET><BLUE>/<RESET>
97 * initial
98 EOF
@@ -110,9 +110,9 @@ test_expect_success 'log --graph with normal octopus merge and child, no color'
110 | | | * 4
111 | | * | 3
112 | | |/
113 - | * | 2
113 + | * / 2
114 | |/
115 - * | 1
115 + * / 1
116 |/
117 * initial
118 EOF
@@ -129,9 +129,9 @@ test_expect_failure 'log --graph with normal octopus and child merge with colors
129 <GREEN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 4
130 <GREEN>|<RESET> <YELLOW>|<RESET> * <MAGENTA>|<RESET> 3
131 <GREEN>|<RESET> <YELLOW>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
132 - <GREEN>|<RESET> * <MAGENTA>|<RESET> 2
132 + <GREEN>|<RESET> * <MAGENTA>/<RESET> 2
133 <GREEN>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
134 - * <MAGENTA>|<RESET> 1
134 + * <MAGENTA>/<RESET> 1
135 <MAGENTA>|<RESET><MAGENTA>/<RESET>
136 * initial
137 EOF
@@ -150,9 +150,9 @@ test_expect_success 'log --graph with tricky octopus merge and its child, no col
150 | | | * 4
151 | | * | 3
152 | | |/
153 - | * | 2
153 + | * / 2
154 | |/
155 - * | 1
155 + * / 1
156 |/
157 * initial
158 EOF
@@ -171,9 +171,9 @@ test_expect_failure 'log --graph with tricky octopus merge and its child with co
171 <RED>|<RESET> <BLUE>|<RESET> <MAGENTA>|<RESET> * 4
172 <RED>|<RESET> <BLUE>|<RESET> * <CYAN>|<RESET> 3
173 <RED>|<RESET> <BLUE>|<RESET> <CYAN>|<RESET><CYAN>/<RESET>
174 - <RED>|<RESET> * <CYAN>|<RESET> 2
174 + <RED>|<RESET> * <CYAN>/<RESET> 2
175 <RED>|<RESET> <CYAN>|<RESET><CYAN>/<RESET>
176 - * <CYAN>|<RESET> 1
176 + * <CYAN>/<RESET> 1
177 <CYAN>|<RESET><CYAN>/<RESET>
178 * initial
179 EOF
t/t4215-log-skewed-merges.sh
+2 -2
@@ -17,7 +17,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh
17 | | * D
18 | * | C
19 | |/
20 - * | B
20 + * / B
21 |/
22 * A
23 EOF
@@ -85,7 +85,7 @@ test_expect_success 'log --graph with nested left-skewed merge' '
85 | * | 1_D
86 * | | 1_C
87 |/ /
88 - * | 1_B
88 + * / 1_B
89 |/
90 * 1_A
91 EOF
t/t6016-rev-list-graph-simplify-history.sh
+2 -2
@@ -154,7 +154,7 @@ test_expect_success '--graph --full-history -- bar.txt' '
154 echo "* | $A4" >> expected &&
155 echo "|\\ \\ " >> expected &&
156 echo "| |/ " >> expected &&
157 - echo "* | $A3" >> expected &&
157 + echo "* / $A3" >> expected &&
158 echo "|/ " >> expected &&
159 echo "* $A2" >> expected &&
160 git rev-list --graph --full-history --all -- bar.txt > actual &&
@@ -255,7 +255,7 @@ test_expect_success '--graph --boundary ^C3' '
255 echo "* | | | $A3" >> expected &&
256 echo "o | | | $A2" >> expected &&
257 echo "|/ / / " >> expected &&
258 - echo "o | | $A1" >> expected &&
258 + echo "o / / $A1" >> expected &&
259 echo " / / " >> expected &&
260 echo "| o $C3" >> expected &&
261 echo "|/ " >> expected &&