]> git.ipfire.org Git - thirdparty/git.git/commit - apply.c
git-apply: try threeway first when "--3way" is used
authorJerry Zhang <jerry@skydio.com>
Tue, 6 Apr 2021 23:25:32 +0000 (16:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Apr 2021 00:11:41 +0000 (17:11 -0700)
commit923cd87ac8550a8e277bfeb19198a11b6a8ed854
treec52acf27d606da3c6e8dee0e9bafd010c5986c78
parent2e36527f23b7f6ae15e6f21ac3b08bf3fed6ee48
git-apply: try threeway first when "--3way" is used

The apply_fragments() method of "git apply"
can silently apply patches incorrectly if
a file has repeating contents. In these
cases a three-way merge is capable of applying
it correctly in more situations, and will
show a conflict rather than applying it
incorrectly. However, because the patches
apply "successfully" using apply_fragments(),
git will never fall back to the merge, even
if the "--3way" flag is used, and the user has
no way to ensure correctness by forcing the
three-way merge method.

Change the behavior so that when "--3way" is used,
git will always try the three-way merge first and
will only fall back to apply_fragments() in cases
where blobs are not available or some other error
(but not in the case of a merge conflict).

Since user-facing results will be different,
this has backwards compatibility implications
for users depending on the old behavior. In
addition, the three-way merge will be slower
than direct patch application.

Signed-off-by: Jerry Zhang <jerry@skydio.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-apply.txt
apply.c
t/t4108-apply-threeway.sh