Skip to content

Commit 67051ec

Browse files
committed
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 <[email protected]>
1 parent 9bbf738 commit 67051ec

6 files changed

+35
-26
lines changed

graph.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ struct git_graph {
297297
*/
298298
int *mapping;
299299
/*
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.
304304
*/
305305
int *old_mapping;
306306
/*
@@ -1015,6 +1015,10 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
10151015
graph_line_write_column(line, col, '\\');
10161016
else
10171017
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, '/');
10181022
} else {
10191023
graph_line_write_column(line, col, '|');
10201024
}
@@ -1211,6 +1215,11 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
12111215
}
12121216
}
12131217

1218+
/*
1219+
* Copy the current mapping array into old_mapping
1220+
*/
1221+
COPY_ARRAY(graph->old_mapping, graph->mapping, graph->mapping_size);
1222+
12141223
/*
12151224
* The new mapping may be 1 smaller than the old mapping
12161225
*/

t/t3430-rebase-merges.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ test_expect_success 'octopus merges' '
408408
| | * three
409409
| * | two
410410
| |/
411-
* | one
411+
* / one
412412
|/
413413
o before-octopus
414414
EOF

t/t4202-log.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ cat > expect <<\EOF
667667
* | | fifth
668668
* | | fourth
669669
|/ /
670-
* | third
670+
* / third
671671
|/
672672
* second
673673
* initial

t/t4214-log-graph-octopus.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ test_expect_success 'log --graph with tricky octopus merge, no color' '
3131
| | | * 4
3232
| | * | 3
3333
| | |/
34-
| * | 2
34+
| * / 2
3535
| |/
36-
* | 1
36+
* / 1
3737
|/
3838
* initial
3939
EOF
@@ -51,9 +51,9 @@ test_expect_success 'log --graph with tricky octopus merge with colors' '
5151
<RED>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 4
5252
<RED>|<RESET> <YELLOW>|<RESET> * <MAGENTA>|<RESET> 3
5353
<RED>|<RESET> <YELLOW>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
54-
<RED>|<RESET> * <MAGENTA>|<RESET> 2
54+
<RED>|<RESET> * <MAGENTA>/<RESET> 2
5555
<RED>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
56-
* <MAGENTA>|<RESET> 1
56+
* <MAGENTA>/<RESET> 1
5757
<MAGENTA>|<RESET><MAGENTA>/<RESET>
5858
* initial
5959
EOF
@@ -72,9 +72,9 @@ test_expect_success 'log --graph with normal octopus merge, no color' '
7272
| | | * 4
7373
| | * | 3
7474
| | |/
75-
| * | 2
75+
| * / 2
7676
| |/
77-
* | 1
77+
* / 1
7878
|/
7979
* initial
8080
EOF
@@ -90,9 +90,9 @@ test_expect_success 'log --graph with normal octopus merge with colors' '
9090
<RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET> * 4
9191
<RED>|<RESET> <GREEN>|<RESET> * <BLUE>|<RESET> 3
9292
<RED>|<RESET> <GREEN>|<RESET> <BLUE>|<RESET><BLUE>/<RESET>
93-
<RED>|<RESET> * <BLUE>|<RESET> 2
93+
<RED>|<RESET> * <BLUE>/<RESET> 2
9494
<RED>|<RESET> <BLUE>|<RESET><BLUE>/<RESET>
95-
* <BLUE>|<RESET> 1
95+
* <BLUE>/<RESET> 1
9696
<BLUE>|<RESET><BLUE>/<RESET>
9797
* initial
9898
EOF
@@ -110,9 +110,9 @@ test_expect_success 'log --graph with normal octopus merge and child, no color'
110110
| | | * 4
111111
| | * | 3
112112
| | |/
113-
| * | 2
113+
| * / 2
114114
| |/
115-
* | 1
115+
* / 1
116116
|/
117117
* initial
118118
EOF
@@ -129,9 +129,9 @@ test_expect_failure 'log --graph with normal octopus and child merge with colors
129129
<GREEN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 4
130130
<GREEN>|<RESET> <YELLOW>|<RESET> * <MAGENTA>|<RESET> 3
131131
<GREEN>|<RESET> <YELLOW>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
132-
<GREEN>|<RESET> * <MAGENTA>|<RESET> 2
132+
<GREEN>|<RESET> * <MAGENTA>/<RESET> 2
133133
<GREEN>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
134-
* <MAGENTA>|<RESET> 1
134+
* <MAGENTA>/<RESET> 1
135135
<MAGENTA>|<RESET><MAGENTA>/<RESET>
136136
* initial
137137
EOF
@@ -150,9 +150,9 @@ test_expect_success 'log --graph with tricky octopus merge and its child, no col
150150
| | | * 4
151151
| | * | 3
152152
| | |/
153-
| * | 2
153+
| * / 2
154154
| |/
155-
* | 1
155+
* / 1
156156
|/
157157
* initial
158158
EOF
@@ -171,9 +171,9 @@ test_expect_failure 'log --graph with tricky octopus merge and its child with co
171171
<RED>|<RESET> <BLUE>|<RESET> <MAGENTA>|<RESET> * 4
172172
<RED>|<RESET> <BLUE>|<RESET> * <CYAN>|<RESET> 3
173173
<RED>|<RESET> <BLUE>|<RESET> <CYAN>|<RESET><CYAN>/<RESET>
174-
<RED>|<RESET> * <CYAN>|<RESET> 2
174+
<RED>|<RESET> * <CYAN>/<RESET> 2
175175
<RED>|<RESET> <CYAN>|<RESET><CYAN>/<RESET>
176-
* <CYAN>|<RESET> 1
176+
* <CYAN>/<RESET> 1
177177
<CYAN>|<RESET><CYAN>/<RESET>
178178
* initial
179179
EOF

t/t4215-log-skewed-merges.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh
1717
| | * D
1818
| * | C
1919
| |/
20-
* | B
20+
* / B
2121
|/
2222
* A
2323
EOF
@@ -85,7 +85,7 @@ test_expect_success 'log --graph with nested left-skewed merge' '
8585
| * | 1_D
8686
* | | 1_C
8787
|/ /
88-
* | 1_B
88+
* / 1_B
8989
|/
9090
* 1_A
9191
EOF

t/t6016-rev-list-graph-simplify-history.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ test_expect_success '--graph --full-history -- bar.txt' '
154154
echo "* | $A4" >> expected &&
155155
echo "|\\ \\ " >> expected &&
156156
echo "| |/ " >> expected &&
157-
echo "* | $A3" >> expected &&
157+
echo "* / $A3" >> expected &&
158158
echo "|/ " >> expected &&
159159
echo "* $A2" >> expected &&
160160
git rev-list --graph --full-history --all -- bar.txt > actual &&
@@ -255,7 +255,7 @@ test_expect_success '--graph --boundary ^C3' '
255255
echo "* | | | $A3" >> expected &&
256256
echo "o | | | $A2" >> expected &&
257257
echo "|/ / / " >> expected &&
258-
echo "o | | $A1" >> expected &&
258+
echo "o / / $A1" >> expected &&
259259
echo " / / " >> expected &&
260260
echo "| o $C3" >> expected &&
261261
echo "|/ " >> expected &&

0 commit comments

Comments
 (0)