@matheusbsbs / matheus-bagliano / commits / 0d251c3291
Fork 0

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 eaf158f8 ("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 0f0f389f12 (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 <peff@peff.net> Reported-by: Bradley Smith <brad@brad-smith.co.uk> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jan 7, 2020 at 21:27 UTC 0d251c3291e4618325465a06186556b18be26adf
2 files changed +42 -4
graph.c
-4
@@ -1219,13 +1219,9 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
1219 *
1220 * The space just to the left of this
1221 * branch should always be empty.
1222 - *
1223 - * The branch to the left of that space
1224 - * should be our eventual target.
1222 */
1223 assert(graph->mapping[i - 1] > target);
1224 assert(graph->mapping[i - 2] < 0);
1228 - assert(graph->mapping[i - 3] == target);
1225 graph->mapping[i - 2] = target;
1226 /*
1227 * Mark this branch as the horizontal edge to
t/t4215-log-skewed-merges.sh
+42
@@ -240,4 +240,46 @@ test_expect_success 'log --graph with octopus merge with column joining its penu
240 EOF
241 '
242
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 +
285 test_done