]> git.ipfire.org Git - thirdparty/git.git/commit
log: --remerge-diff needs to keep around commit parents
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 12 Dec 2024 10:29:12 +0000 (10:29 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 13 Dec 2024 14:56:10 +0000 (06:56 -0800)
commitf94bfa151623d7e675db9465ae7ff0b33e4825f3
treebc0f0dafd06c8f5e03eeb03e5fb00cee438cf3a5
parentdbecc617f75eea6ee5d05823a38b91223ff22b11
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 _and to set that parent
list to `NULL`_. This can break the merge base computation.

This problem is most obvious 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 (even if one
should be found).

Traversing commits in reverse is far from the only circumstance in which
this problem occurs, though. There are many avenues to traversing at
least one commit in the revision walk that will later be part of a merge
base computation, for example when not even walking any revisions in
`git show <merge1> <merge2>` where `<merge1>` is part of the commit
graph between the parents of `<merge2>`.

Another way to force a scenario where a commit is traversed before it
has to be traversed again as part of a merge base computation is to
start with two revisions (where the first one is reachable from the
second but not in a first-parent ancestry) and show the commit log with
`--topo-order` and `--first-parent`.

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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
t/t4069-remerge-diff.sh