summaryrefslogtreecommitdiff
path: root/graph.c
diff options
context:
space:
mode:
authorJames Coglan <jcoglan@gmail.com>2019-10-15 23:47:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-10-16 02:11:25 (GMT)
commitd62893ecc125767d44a194279bcaffa0d02d2572 (patch)
tree663e39919b1460afe1c0ecfecf47e9efc59e8271 /graph.c
parent0f0f389f12029b1c3745f8ed7aacfe6b2fc7a6cc (diff)
downloadgit-d62893ecc125767d44a194279bcaffa0d02d2572.zip
git-d62893ecc125767d44a194279bcaffa0d02d2572.tar.gz
git-d62893ecc125767d44a194279bcaffa0d02d2572.tar.bz2
graph: commit and post-merge lines for left-skewed merges
Following the introduction of "left-skewed" merges, which are merges whose first parent fuses with another edge to its left, we have some more edge cases to deal with in the display of commit and post-merge lines. The current graph code handles the following cases for edges appearing to the right of the commit (*) on commit lines. A 2-way merge is usually followed by vertical lines: | | | | * | | |\ \ An octopus merge (more than two parents) is always followed by edges sloping to the right: | | \ | | \ | *-. \ | *---. \ | |\ \ \ | |\ \ \ \ A 2-way merge is followed by a right-sloping edge if the commit line immediately follows a post-merge line for a commit that appears in the same column as the current commit, or any column to the left of that: | * | * | | |\ | |\ \ | * \ | | * \ | |\ \ | | |\ \ This commit introduces the following new cases for commit lines. If a 2-way merge skews to the left, then the edges to its right are always vertical lines, even if the commit follows a post-merge line: | | | | |\ | * | | * | |/| | |/| | A commit with 3 parents that skews left is followed by vertical edges: | | | | * | |/|\ \ If a 3-way left-skewed merge commit appears immediately after a post-merge line, then it may be followed the right-sloping edges, just like a 2-way merge that is not skewed. | |\ | * \ |/|\ \ Octopus merges with 4 or more parents that skew to the left will always be followed by right-sloping edges, because the existing columns need to expand around the merge. | | \ | *-. \ |/|\ \ \ On post-merge lines, usually all edges following the current commit slope to the right: | * | | | |\ \ \ However, if the commit is a left-skewed 2-way merge, the edges to its right remain vertical. We also need to display a space after the vertical line descending from the commit marker, whereas this line would normally be followed by a backslash. | * | | |/| | | If a left-skewed merge has more than 2 parents, then the edges to its right are still sloped as they bend around the edges introduced by the merge. | * | | |/|\ \ \ To handle these new cases, we need to know not just how many parents each commit has, but how many new columns it adds to the display; this quantity is recorded in the `edges_added` field for the current commit, and `prev_edges_added` field for the previous commit. Here, "column" refers to visual columns, not the logical columns of the `columns` array. This is because even if all the commit's parents end up fusing with existing edges, they initially introduce distinct edges in the commit and post-merge lines before those edges collapse. For example, a 3-way merge whose 2nd and 3rd parents fuse with existing edges still introduces 2 visual columns that affect the display of edges to their right. | | | \ | | *-. \ | | |\ \ \ | |_|/ / / |/| | / / | | |/ / | |/| | | | | | This merge does not introduce any *logical* columns; there are 4 edges before and after this commit once all edges have collapsed. But it does initially introduce 2 new edges that need to be accommodated by the edges to their right. Signed-off-by: James Coglan <jcoglan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'graph.c')
-rw-r--r--graph.c63
1 files changed, 58 insertions, 5 deletions
diff --git a/graph.c b/graph.c
index e37127f..21edad8 100644
--- a/graph.c
+++ b/graph.c
@@ -217,6 +217,46 @@ struct git_graph {
*/
int merge_layout;
/*
+ * The number of columns added to the graph by the current commit. For
+ * 2-way and octopus merges, this is is usually one less than the
+ * number of parents:
+ *
+ * | | | | | \
+ * | * | | *---. \
+ * | |\ \ | |\ \ \ \
+ * | | | | | | | | | |
+ *
+ * num_parents: 2 num_parents: 4
+ * edges_added: 1 edges_added: 3
+ *
+ * For left-skewed merges, the first parent fuses with its neighbor and
+ * so one less column is added:
+ *
+ * | | | | | \
+ * | * | | *-. \
+ * |/| | |/|\ \ \
+ * | | | | | | | |
+ *
+ * num_parents: 2 num_parents: 4
+ * edges_added: 0 edges_added: 2
+ *
+ * This number determines how edges to the right of the merge are
+ * displayed in commit and post-merge lines; if no columns have been
+ * added then a vertical line should be used where a right-tracking
+ * line would otherwise be used.
+ *
+ * | * \ | * |
+ * | |\ \ |/| |
+ * | | * \ | * |
+ */
+ int edges_added;
+ /*
+ * The number of columns added by the previous commit, which is used to
+ * smooth edges appearing to the right of a commit in a commit line
+ * following a post-merge line.
+ */
+ int prev_edges_added;
+ /*
* The maximum number of columns that can be stored in the columns
* and new_columns arrays. This is also half the number of entries
* that can be stored in the mapping and new_mapping arrays.
@@ -328,6 +368,8 @@ struct git_graph *graph_init(struct rev_info *opt)
graph->commit_index = 0;
graph->prev_commit_index = 0;
graph->merge_layout = 0;
+ graph->edges_added = 0;
+ graph->prev_edges_added = 0;
graph->num_columns = 0;
graph->num_new_columns = 0;
graph->mapping_size = 0;
@@ -689,6 +731,9 @@ void graph_update(struct git_graph *graph, struct commit *commit)
*/
graph_update_columns(graph);
+ graph->prev_edges_added = graph->edges_added;
+ graph->edges_added = graph->num_parents + graph->merge_layout - 2;
+
graph->expansion_row = 0;
/*
@@ -947,12 +992,13 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
if (graph->num_parents > 2)
graph_draw_octopus_merge(graph, line);
- } else if (seen_this && (graph->num_parents > 2)) {
+ } else if (seen_this && (graph->edges_added > 1)) {
graph_line_write_column(line, col, '\\');
- } else if (seen_this && (graph->num_parents == 2)) {
+ } else if (seen_this && (graph->edges_added == 1)) {
/*
- * This is a 2-way merge commit.
- * There is no GRAPH_PRE_COMMIT stage for 2-way
+ * This is either a right-skewed 2-way merge
+ * commit, or a left-skewed 3-way merge.
+ * There is no GRAPH_PRE_COMMIT stage for such
* merges, so this is the first line of output
* for this commit. Check to see what the previous
* line of output was.
@@ -964,6 +1010,7 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
* makes the output look nicer.
*/
if (graph->prev_state == GRAPH_POST_MERGE &&
+ graph->prev_edges_added > 0 &&
graph->prev_commit_index < i)
graph_line_write_column(line, col, '\\');
else
@@ -1033,8 +1080,14 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
else
idx++;
}
+ if (graph->edges_added == 0)
+ graph_line_addch(line, ' ');
+
} else if (seen_this) {
- graph_line_write_column(line, col, '\\');
+ if (graph->edges_added > 0)
+ graph_line_write_column(line, col, '\\');
+ else
+ graph_line_write_column(line, col, '|');
graph_line_addch(line, ' ');
} else {
graph_line_write_column(line, col, '|');