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>
This commit is contained in:
James Coglan
2019-10-15 23:47:57 +00:00
committed by Junio C Hamano
parent 0195285b95
commit 479db18bc0
6 changed files with 35 additions and 26 deletions

17
graph.c
View File

@ -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;
/*
@ -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, '|');
}
@ -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
*/