Skip to content

Commit

Permalink
log: --remerge-diff needs to keep around commit parents
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dscho committed Nov 11, 2024
1 parent bea9ecd commit afff27f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,14 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
* but we didn't actually show the commit.
*/
rev->max_count++;
if (!rev->reflog_info) {
if (!rev->reflog_info && !rev->remerge_diff) {
/*
* We may show a given commit multiple times when
* walking the reflogs.
* walking the reflogs. Therefore we still need it.
*
* Likewise, we potentially still need the parents
* of * already shown commits to determine merge
* bases when showing remerge diffs.
*/
free_commit_buffer(the_repository->parsed_objects,
commit);
Expand Down
7 changes: 7 additions & 0 deletions t/t4069-remerge-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,11 @@ test_expect_success 'remerge-diff turns off history simplification' '
test_cmp expect actual
'

test_expect_success 'remerge-diff with --reverse' '
git log -1 --remerge-diff --oneline ab_resolution^ >expect &&
git log -1 --remerge-diff --oneline ab_resolution >>expect &&
git log -2 --remerge-diff --oneline ab_resolution --reverse >actual &&
test_cmp expect actual
'

test_done

0 comments on commit afff27f

Please sign in to comment.