Skip to content

Commit afff27f

Browse files
committed
log: --remerge-diff needs to keep around commit parents
To show a remerge diff, the merge needs to be recreated. For that to work, the merge base(s) need to be found, which means that the commits' parents have to be traversed until common ancestors are found (if any). However, one optimization that hails all the way back to cb11574 (Some more memory leak avoidance, 2006-06-17) is to release the commit's list of parents immediately after showing it. This can break the merge base computation. Note that it matters more clearly when traversing the commits in reverse: In that instance, if a parent of a merge commit has been shown as part of the `git log` command, by the time the merge commit's diff needs to be computed, that parent commit's list of parent commits will have been set to `NULL` and as a result no merge base will be found. Let's fix this by special-casing the `remerge_diff` mode, similar to what we did with reflogs in f35650d (log: do not free parents when walking reflog, 2017-07-07). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent bea9ecd commit afff27f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

builtin/log.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,14 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
522522
* but we didn't actually show the commit.
523523
*/
524524
rev->max_count++;
525-
if (!rev->reflog_info) {
525+
if (!rev->reflog_info && !rev->remerge_diff) {
526526
/*
527527
* We may show a given commit multiple times when
528-
* walking the reflogs.
528+
* walking the reflogs. Therefore we still need it.
529+
*
530+
* Likewise, we potentially still need the parents
531+
* of * already shown commits to determine merge
532+
* bases when showing remerge diffs.
529533
*/
530534
free_commit_buffer(the_repository->parsed_objects,
531535
commit);

t/t4069-remerge-diff.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,11 @@ test_expect_success 'remerge-diff turns off history simplification' '
317317
test_cmp expect actual
318318
'
319319

320+
test_expect_success 'remerge-diff with --reverse' '
321+
git log -1 --remerge-diff --oneline ab_resolution^ >expect &&
322+
git log -1 --remerge-diff --oneline ab_resolution >>expect &&
323+
git log -2 --remerge-diff --oneline ab_resolution --reverse >actual &&
324+
test_cmp expect actual
325+
'
326+
320327
test_done

0 commit comments

Comments
 (0)