bug-patch
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-patch] two different hunks erroneously get applied to the very same


From: Benno Schulenberg
Subject: [bug-patch] two different hunks erroneously get applied to the very same spot
Date: Sat, 2 Sep 2017 18:11:55 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1


Hi,

When two hunks in a patch have the exact same context, and in the
file that the patch applies to one of the two contexts has changed
a bit (in such a way that hunk #1 would apply fine with fuzz 1),
then *both* hunks mistakenly get applied to the place where the
context hasn't changed.

For an example, see the attached file and patch.  Apply the patch
with 'patch -p1 <goes-wrong.patch' and see the output:

patching file testor.c
Hunk #1 succeeded at 44 (offset 37 lines).

It does not say anything about hunk #2 -- which is wrong, because
after applying hunk #1 in the wrong place, the context for hunk #2
has changed, and it can only apply the second hunk with fuzz 2.


Expected behavior: at the very least, 'patch' should mention that
hunk #2 was applied with fuzz 2.  And maybe patching should fail
entirely, because when both hunks get applied to the same spot,
also hunk #1 has in the end result factually been applied with
fuzz 2.

The ideal behavior would be that 'patch' tries to minimize the
overall amount of fuzz.  When it notices that applying hunk #1
with an offset of 37 lines results in a total fuzz of 2 (or 4),
it should try to apply hunk #1 with fuzz 1.  When it does that,
it will see that hunk #2 applies cleanly, so the total amount
of fuzz will be just 1, which is better than 2.  So the fuzz 1
alternative should be chosen.

(I could also imagine that patch would make use of the function
name mentioned in the @@ line: applying a hunk outside of that
function would count as fuzz 1.5, so that it becomes better to
accept a little fuzz within a function than to accept a perfect
match outside of that function.)

Benno

Attachment: testor.c
Description: Text Data

Attachment: goes-wrong.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]