bug-patch
[Top][All Lists]
Advanced

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

Re: [bug-patch] is this a bug?


From: Andreas Grünbacher
Subject: Re: [bug-patch] is this a bug?
Date: Fri, 1 Feb 2019 12:08:27 +0100

Am Fr., 1. Feb. 2019 um 05:05 Uhr schrieb Steve Summit <address@hidden>:
>
> Andreas wrote:
> > ...the patch could only be applied by ignoring one line of context.
> > This may seem surprising, but patch assumes that hunks that have more
> > context at the beginning than at the end must apply at the end...
>
> That is surprising.  Thanks for the explanation.
>
> Is there a document anywhere that describes patch's algorithm
> in full?  "Comparing and Merging Files" by MacKenzie, Eggert,
> and Stallman seems to have most of it, but it doesn't mention
> this nuance.

I'm not aware of anything beyond the man page:

       With context diffs, and to a lesser extent with normal diffs, patch can
       detect  when the line numbers mentioned in the patch are incorrect, and
       attempts to find the correct place to apply each hunk of the patch.  As
       a first guess, it takes the line number mentioned for the hunk, plus or
       minus any offset used in applying the previous hunk.  If  that  is  not
       the correct place, patch scans both forwards and backwards for a set of
       lines matching the context given in the hunk.  First patch looks for  a
       place where all lines of the context match.  If no such place is found,
       and it's a context diff, and the maximum fuzz factor is  set  to  1  or
       more, then another scan takes place ignoring the first and last line of
       context.  If that fails, and the maximum fuzz factor is  set  to  2  or
       more,  the  first  two  and  last two lines of context are ignored, and
       another scan is made.  (The default maximum fuzz factor is 2.)

       Hunks with less prefix context  than  suffix  context  (after  applying
       fuzz)  must  apply  at the start of the file if their first line number
       is 1.  Hunks with more prefix context than suffix context (after apply‐
       ing fuzz) must apply at the end of the file.

> > Always be careful with patches that apply with fuzz. When applying
> > patches automatically, use option -F0.
>
> Or in any case, use option -Fn, where n is less than the context
> in your diff.  (And it doesn't make the patch succeed in my case,
> but at least it fails instead of applying wrongly.)
>
> I wonder if it would be worthwhile to have a companion to -Fn,
> perhaps -Cm, meaning "don't strip fuzz to leave less than m lines
> of context".  I'd find that easier to think about, especially if
> for whatever reason I couldn't predict the contextitude of the
> incoming patches.

It also depends on the type of the file how much context makes sense,
and hopefully the creator of the patch will have thought about it
before creating a patch with particularly little context. An
additional option won't make the fact go away that when a patch
applies with fuzz, you should really check the result.

Andreas



reply via email to

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