Skip to content

Commit

Permalink
graph: smooth appearance of collapsing edges on commit lines
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jcoglan authored and gitster committed Oct 16, 2019
1 parent 0195285 commit 479db18
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 26 deletions.
17 changes: 13 additions & 4 deletions graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ struct git_graph {
*/
int *mapping;
/*
* A temporary array for computing the next mapping state
* while we are outputting a mapping line. This is stored as part
* of the git_graph simply so we don't have to allocate a new
* temporary array each time we have to output a collapsing line.
* A copy of the contents of the mapping array from the last commit,
* which we use to improve the display of columns that are tracking
* from right to left through a commit line. We also use this to
* avoid allocating a fresh array when we compute the next mapping.
*/
int *old_mapping;
/*
Expand Down Expand Up @@ -1015,6 +1015,10 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
graph_line_write_column(line, col, '\\');
else
graph_line_write_column(line, col, '|');
} else if (graph->prev_state == GRAPH_COLLAPSING &&
graph->old_mapping[2 * i + 1] == i &&
graph->mapping[2 * i] < i) {
graph_line_write_column(line, col, '/');
} else {
graph_line_write_column(line, col, '|');
}
Expand Down Expand Up @@ -1211,6 +1215,11 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
}
}

/*
* Copy the current mapping array into old_mapping
*/
COPY_ARRAY(graph->old_mapping, graph->mapping, graph->mapping_size);

/*
* The new mapping may be 1 smaller than the old mapping
*/
Expand Down
2 changes: 1 addition & 1 deletion t/t3430-rebase-merges.sh
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ test_expect_success 'octopus merges' '
| | * three
| * | two
| |/
* | one
* / one
|/
o before-octopus
EOF
Expand Down
2 changes: 1 addition & 1 deletion t/t4202-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ cat > expect <<\EOF
* | | fifth
* | | fourth
|/ /
* | third
* / third
|/
* second
* initial
Expand Down
32 changes: 16 additions & 16 deletions t/t4214-log-graph-octopus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ test_expect_success 'log --graph with tricky octopus merge, no color' '
| | | * 4
| | * | 3
| | |/
| * | 2
| * / 2
| |/
* | 1
* / 1
|/
* initial
EOF
Expand All @@ -51,9 +51,9 @@ test_expect_success 'log --graph with tricky octopus merge with colors' '
<RED>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 4
<RED>|<RESET> <YELLOW>|<RESET> * <MAGENTA>|<RESET> 3
<RED>|<RESET> <YELLOW>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
<RED>|<RESET> * <MAGENTA>|<RESET> 2
<RED>|<RESET> * <MAGENTA>/<RESET> 2
<RED>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
* <MAGENTA>|<RESET> 1
* <MAGENTA>/<RESET> 1
<MAGENTA>|<RESET><MAGENTA>/<RESET>
* initial
EOF
Expand All @@ -72,9 +72,9 @@ test_expect_success 'log --graph with normal octopus merge, no color' '
| | | * 4
| | * | 3
| | |/
| * | 2
| * / 2
| |/
* | 1
* / 1
|/
* initial
EOF
Expand All @@ -90,9 +90,9 @@ test_expect_success 'log --graph with normal octopus merge with colors' '
<RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET> * 4
<RED>|<RESET> <GREEN>|<RESET> * <BLUE>|<RESET> 3
<RED>|<RESET> <GREEN>|<RESET> <BLUE>|<RESET><BLUE>/<RESET>
<RED>|<RESET> * <BLUE>|<RESET> 2
<RED>|<RESET> * <BLUE>/<RESET> 2
<RED>|<RESET> <BLUE>|<RESET><BLUE>/<RESET>
* <BLUE>|<RESET> 1
* <BLUE>/<RESET> 1
<BLUE>|<RESET><BLUE>/<RESET>
* initial
EOF
Expand All @@ -110,9 +110,9 @@ test_expect_success 'log --graph with normal octopus merge and child, no color'
| | | * 4
| | * | 3
| | |/
| * | 2
| * / 2
| |/
* | 1
* / 1
|/
* initial
EOF
Expand All @@ -129,9 +129,9 @@ test_expect_failure 'log --graph with normal octopus and child merge with colors
<GREEN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 4
<GREEN>|<RESET> <YELLOW>|<RESET> * <MAGENTA>|<RESET> 3
<GREEN>|<RESET> <YELLOW>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
<GREEN>|<RESET> * <MAGENTA>|<RESET> 2
<GREEN>|<RESET> * <MAGENTA>/<RESET> 2
<GREEN>|<RESET> <MAGENTA>|<RESET><MAGENTA>/<RESET>
* <MAGENTA>|<RESET> 1
* <MAGENTA>/<RESET> 1
<MAGENTA>|<RESET><MAGENTA>/<RESET>
* initial
EOF
Expand All @@ -150,9 +150,9 @@ test_expect_success 'log --graph with tricky octopus merge and its child, no col
| | | * 4
| | * | 3
| | |/
| * | 2
| * / 2
| |/
* | 1
* / 1
|/
* initial
EOF
Expand All @@ -171,9 +171,9 @@ test_expect_failure 'log --graph with tricky octopus merge and its child with co
<RED>|<RESET> <BLUE>|<RESET> <MAGENTA>|<RESET> * 4
<RED>|<RESET> <BLUE>|<RESET> * <CYAN>|<RESET> 3
<RED>|<RESET> <BLUE>|<RESET> <CYAN>|<RESET><CYAN>/<RESET>
<RED>|<RESET> * <CYAN>|<RESET> 2
<RED>|<RESET> * <CYAN>/<RESET> 2
<RED>|<RESET> <CYAN>|<RESET><CYAN>/<RESET>
* <CYAN>|<RESET> 1
* <CYAN>/<RESET> 1
<CYAN>|<RESET><CYAN>/<RESET>
* initial
EOF
Expand Down
4 changes: 2 additions & 2 deletions t/t4215-log-skewed-merges.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh
| | * D
| * | C
| |/
* | B
* / B
|/
* A
EOF
Expand Down Expand Up @@ -85,7 +85,7 @@ test_expect_success 'log --graph with nested left-skewed merge' '
| * | 1_D
* | | 1_C
|/ /
* | 1_B
* / 1_B
|/
* 1_A
EOF
Expand Down
4 changes: 2 additions & 2 deletions t/t6016-rev-list-graph-simplify-history.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ test_expect_success '--graph --full-history -- bar.txt' '
echo "* | $A4" >> expected &&
echo "|\\ \\ " >> expected &&
echo "| |/ " >> expected &&
echo "* | $A3" >> expected &&
echo "* / $A3" >> expected &&
echo "|/ " >> expected &&
echo "* $A2" >> expected &&
git rev-list --graph --full-history --all -- bar.txt > actual &&
Expand Down Expand Up @@ -255,7 +255,7 @@ test_expect_success '--graph --boundary ^C3' '
echo "* | | | $A3" >> expected &&
echo "o | | | $A2" >> expected &&
echo "|/ / / " >> expected &&
echo "o | | $A1" >> expected &&
echo "o / / $A1" >> expected &&
echo " / / " >> expected &&
echo "| o $C3" >> expected &&
echo "|/ " >> expected &&
Expand Down

0 comments on commit 479db18

Please sign in to comment.