summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--graph.c63
-rwxr-xr-xt/t4215-log-skewed-merges.sh147
2 files changed, 203 insertions, 7 deletions
diff --git a/graph.c b/graph.c
index e37127f5ab..21edad8085 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, '|');
diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh
index dc187b5caf..e673cdb6f7 100755
--- a/t/t4215-log-skewed-merges.sh
+++ b/t/t4215-log-skewed-merges.sh
@@ -11,7 +11,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh
| * G
| |\
| | * F
- | * \ E
+ | * | E
|/|\ \
| | |/
| | * D
@@ -43,7 +43,7 @@ test_expect_success 'log --graph with left-skewed merge' '
| | | | * 0_G
| |_|_|/|
|/| | | |
- | | | * \ 0_F
+ | | | * | 0_F
| |_|/|\ \
|/| | | |/
| | | | * 0_E
@@ -73,4 +73,147 @@ test_expect_success 'log --graph with left-skewed merge' '
test_cmp expect actual
'
+test_expect_success 'log --graph with nested left-skewed merge' '
+ cat >expect <<-\EOF &&
+ * 1_H
+ |\
+ | * 1_G
+ | |\
+ | | * 1_F
+ | * | 1_E
+ |/| |
+ | * | 1_D
+ * | | 1_C
+ |/ /
+ * | 1_B
+ |/
+ * 1_A
+ EOF
+
+ git checkout --orphan 1_p &&
+ test_commit 1_A &&
+ test_commit 1_B &&
+ test_commit 1_C &&
+ git checkout -b 1_q @^ && test_commit 1_D &&
+ git checkout 1_p && git merge --no-ff 1_q -m 1_E &&
+ git checkout -b 1_r @~3 && test_commit 1_F &&
+ git checkout 1_p && git merge --no-ff 1_r -m 1_G &&
+ git checkout @^^ && git merge --no-ff 1_p -m 1_H &&
+
+ git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'log --graph with nested left-skewed merge following normal merge' '
+ cat >expect <<-\EOF &&
+ * 2_K
+ |\
+ | * 2_J
+ | |\
+ | | * 2_H
+ | | |\
+ | | * | 2_G
+ | |/| |
+ | | * | 2_F
+ | * | | 2_E
+ | |/ /
+ | * | 2_D
+ * | | 2_C
+ | |/
+ |/|
+ * | 2_B
+ |/
+ * 2_A
+ EOF
+
+ git checkout --orphan 2_p &&
+ test_commit 2_A &&
+ test_commit 2_B &&
+ test_commit 2_C &&
+ git checkout -b 2_q @^^ &&
+ test_commit 2_D &&
+ test_commit 2_E &&
+ git checkout -b 2_r @^ && test_commit 2_F &&
+ git checkout 2_q &&
+ git merge --no-ff 2_r -m 2_G &&
+ git merge --no-ff 2_p^ -m 2_H &&
+ git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J &&
+ git checkout 2_p && git merge --no-ff 2_s -m 2_K &&
+
+ git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'log --graph with nested right-skewed merge following left-skewed merge' '
+ cat >expect <<-\EOF &&
+ * 3_J
+ |\
+ | * 3_H
+ | |\
+ | | * 3_G
+ | * | 3_F
+ |/| |
+ | * | 3_E
+ | |\ \
+ | | |/
+ | | * 3_D
+ | * | 3_C
+ | |/
+ | * 3_B
+ |/
+ * 3_A
+ EOF
+
+ git checkout --orphan 3_p &&
+ test_commit 3_A &&
+ git checkout -b 3_q &&
+ test_commit 3_B &&
+ test_commit 3_C &&
+ git checkout -b 3_r @^ &&
+ test_commit 3_D &&
+ git checkout 3_q && git merge --no-ff 3_r -m 3_E &&
+ git checkout 3_p && git merge --no-ff 3_q -m 3_F &&
+ git checkout 3_r && test_commit 3_G &&
+ git checkout 3_p && git merge --no-ff 3_r -m 3_H &&
+ git checkout @^^ && git merge --no-ff 3_p -m 3_J &&
+
+ git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'log --graph with right-skewed merge following a left-skewed one' '
+ cat >expect <<-\EOF &&
+ * 4_H
+ |\
+ | * 4_G
+ | |\
+ | * | 4_F
+ |/| |
+ | * | 4_E
+ | |\ \
+ | | * | 4_D
+ | |/ /
+ |/| |
+ | | * 4_C
+ | |/
+ | * 4_B
+ |/
+ * 4_A
+ EOF
+
+ git checkout --orphan 4_p &&
+ test_commit 4_A &&
+ test_commit 4_B &&
+ test_commit 4_C &&
+ git checkout -b 4_q @^^ && test_commit 4_D &&
+ git checkout -b 4_r 4_p^ && git merge --no-ff 4_q -m 4_E &&
+ git checkout -b 4_s 4_p^^ &&
+ git merge --no-ff 4_r -m 4_F &&
+ git merge --no-ff 4_p -m 4_G &&
+ git checkout @^^ && git merge --no-ff 4_s -m 4_H &&
+
+ git log --graph --date-order --pretty=tformat:%s | sed "s/ *$//" >actual &&
+ test_cmp expect actual
+'
+
test_done