Hello Andreas!

On Sat, Jul 18, 2015 at 10:25:52PM +0200, Andreas Grünbacher wrote:
> 
> I have tried removing this heuristic in the past. The result was lots
> of misapplied patches. I couldn't think of a better heuristic either.
> Changing these kinds of things is difficult: for example, distributions
> are using patch for applying hundreds of thousands of patches
> automatically during package builds. These kinds of mis-applied
> patches are relatively likely not to not lead to subsequent errors
> (like syntax errors in a C file).

I agree it is hard.  Another weird effect we saw was with repetitive
code.  The context for a patch existed twice in the same C file.  Git
picked one of them, patch the other.  Because some of us use git
quiltimport and other use quilt we eventually noticed the problem.  And
only because we had a compiler error - backtracking from runtime
failures to misapplied patches would be a nightmare.

Not sure if git-apply actually solves your problem with misapplied
patches or just cheats.  The problem for git is easier because git tends
to apply patches only once, while patch (through quilt, etc.) reapplies
the same patches hundreds of time onto a changing codebase.  Patch needs
to be 100x more reliable than git just for parity.

One option to solve my problem would be to disable the heuristic if you
have enough context.  By default patch could require three lines of
context on both sides to disable the heuristic.  Any less and it better
be near the beginning or end.

If we do that, we might also add a -C parameter similar to git-apply.
Thinking about these problems I am very tempted to use 5-line context
instead of 3-line context by default.  That will reduce the rate of
misapplied patches.  And patch -C5 would require 5-line context to
disable the heuristic.

Not sure.  This is a harder problem than I thought.

Jörn

--
Logic can convince but only emotion can motivate.
-- Jonathan Alter

Reply via email to