From bd9d0367f7a5b8fb0b15c830e0c9862efddc8849 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 8 Nov 2024 11:35:34 +0100 Subject: [PATCH] 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 cb115748ec0d (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 f35650dff6a4 (log: do not free parents when walking reflog, 2017-07-07). Signed-off-by: Johannes Schindelin --- builtin/log.c | 2 +- t/t4069-remerge-diff.sh | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/builtin/log.c b/builtin/log.c index c0a8bb95e9830b..a297c6caf59b01 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -522,7 +522,7 @@ 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. diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh index 07323ebafe0d0c..d71564d29c65e3 100755 --- a/t/t4069-remerge-diff.sh +++ b/t/t4069-remerge-diff.sh @@ -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 4d00047^ >expect && + git log -1 --remerge-diff --oneline 4d00047 >>expect && + git log -2 --remerge-diff --oneline 4d00047 --reverse >actual && + test_cmp expect actual +' + test_done