Skip to content

Commit 0d251c3

Browse files
derrickstoleegitster
authored andcommitted
graph: drop assert() for merge with two collapsing parents
When "git log --graph" shows a merge commit that has two collapsing lines, like: | | | | * | |_|_|/| |/| | |/ | | |/| | |/| | | * | | * | | | we trigger an assert(): graph.c:1228: graph_output_collapsing_line: Assertion `graph->mapping[i - 3] == target' failed. The assert was introduced by eaf158f ("graph API: Use horizontal lines for more compact graphs", 2009-04-21), which is quite old. This assert is trying to say that when we complete a horizontal line with a single slash, it is because we have reached our target. It is actually the _second_ collapsing line that hits this assert. The reason we are in this code path is because we are collapsing the first line, and in that case we are hitting our target now that the horizontal line is complete. However, the second line cannot be a horizontal line, so it will collapse without horizontal lines. In this case, it is inappropriate to assert that we have reached our target, as we need to continue for another column before reaching the target. Dropping the assert is safe here. The new behavior in 0f0f389 (graph: tidy up display of left-skewed merges, 2019-10-15) caused the behavior change that made this assertion failure possible. In addition to making the assert possible, it also changed how multiple edges collapse. In a larger example, the current code will output a collapse as follows: | | | | | | * | |_|_|_|_|/|\ |/| | | | |/ / | | | | |/| / | | | |/| |/ | | |/| |/| | |/| |/| | | | |/| | | | | * | | | However, the intended collapse should allow multiple horizontal lines as follows: | | | | | | * | |_|_|_|_|/|\ |/| | | | |/ / | | |_|_|/| / | |/| | | |/ | | | |_|/| | | |/| | | | | * | | | This behavior is not corrected by this change, but is noted for a later update. Helped-by: Jeff King <[email protected]> Reported-by: Bradley Smith <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 042ed3e commit 0d251c3

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

graph.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,13 +1219,9 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
12191219
*
12201220
* The space just to the left of this
12211221
* branch should always be empty.
1222-
*
1223-
* The branch to the left of that space
1224-
* should be our eventual target.
12251222
*/
12261223
assert(graph->mapping[i - 1] > target);
12271224
assert(graph->mapping[i - 2] < 0);
1228-
assert(graph->mapping[i - 3] == target);
12291225
graph->mapping[i - 2] = target;
12301226
/*
12311227
* Mark this branch as the horizontal edge to

t/t4215-log-skewed-merges.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,46 @@ test_expect_success 'log --graph with octopus merge with column joining its penu
240240
EOF
241241
'
242242

243+
test_expect_success 'log --graph with multiple tips' '
244+
git checkout --orphan 6_1 &&
245+
test_commit 6_A &&
246+
git branch 6_2 &&
247+
git branch 6_4 &&
248+
test_commit 6_B &&
249+
git branch 6_3 &&
250+
test_commit 6_C &&
251+
git checkout 6_2 && test_commit 6_D &&
252+
git checkout 6_3 && test_commit 6_E &&
253+
git checkout -b 6_5 6_1 &&
254+
git merge --no-ff 6_2 -m 6_F &&
255+
git checkout 6_4 && test_commit 6_G &&
256+
git checkout 6_3 &&
257+
git merge --no-ff 6_4 -m 6_H &&
258+
git checkout 6_1 &&
259+
git merge --no-ff 6_2 -m 6_I &&
260+
261+
check_graph 6_1 6_3 6_5 <<-\EOF
262+
* 6_I
263+
|\
264+
| | * 6_H
265+
| | |\
266+
| | | * 6_G
267+
| | * | 6_E
268+
| | | | * 6_F
269+
| |_|_|/|
270+
|/| | |/
271+
| | |/|
272+
| |/| |
273+
| * | | 6_D
274+
| | |/
275+
| |/|
276+
* | | 6_C
277+
| |/
278+
|/|
279+
* | 6_B
280+
|/
281+
* 6_A
282+
EOF
283+
'
284+
243285
test_done

0 commit comments

Comments
 (0)