]> git.ipfire.org Git - thirdparty/git.git/commit - merge-recursive.c
merge-recursive: exit early if index != head
authorElijah Newren <newren@gmail.com>
Sat, 17 Aug 2019 18:41:29 +0000 (11:41 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Aug 2019 17:08:03 +0000 (10:08 -0700)
commit98a1d3d88895a1cbc01b88627776bb4e2bfd6b84
tree11bef202a5847f892ccc164f104becf19e24082f
parent9822175d2b349be1ed7a704d3a56dc912f5a7510
merge-recursive: exit early if index != head

We had a rule to enforce that the index matches head, but it was found
at the beginning of merge_trees() and would only trigger when
opt->call_depth was 0.  Since merge_recursive() doesn't call
merge_trees() until after returning from recursing, this meant that the
check wasn't triggered by merge_recursive() until it had first finished
all the intermediate merges to create virtual merge bases.  That is a
potentially huge amount of computation (and writing of intermediate
merge results into the .git/objects directory) before it errors out and
says, in effect, "Sorry, I can't do any merging because you have some
local changes that would be overwritten."

Further, not enforcing this requirement earlier allowed other bugs (such
as an unintentional unconditional dropping and reloading of the index in
merge_recursive() even when no recursion was necessary), to mask bugs in
other callers (which were fixed in the commit prior to this one).

Make sure we do the index == head check at the beginning of the merge,
and error out immediately if it fails.  While we're at it, fix a small
leak in the show-the-error codepath.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merge-recursive.c