[PATCH] patch: add fuzz config flag (issue4697)

Matt Mackall mpm at selenic.com
Thu Jun 18 23:25:18 CDT 2015


# HG changeset patch
# User Matt Mackall <mpm at selenic.com>
# Date 1434660160 18000
#      Thu Jun 18 15:42:40 2015 -0500
# Node ID ade1f430c985ab55865326300e9092032af19de9
# Parent  6c48f012d37e67c3a0a33960a442340e494af9cc
patch: add fuzz config flag (issue4697)

diff -r 6c48f012d37e -r ade1f430c985 mercurial/help/config.txt
--- a/mercurial/help/config.txt	Mon Jun 15 16:06:17 2015 -0700
+++ b/mercurial/help/config.txt	Thu Jun 18 15:42:40 2015 -0500
@@ -1093,6 +1093,11 @@
     of line, patch line endings are preserved.
     Default: strict.
 
+``fuzz``
+    The number of lines of 'fuzz' to allow when applying patches. This
+    controls how much context the patcher is allowed to ignore when
+    trying to apply a patch.
+    Default: 2
 
 ``paths``
 ---------
diff -r 6c48f012d37e -r ade1f430c985 mercurial/patch.py
--- a/mercurial/patch.py	Mon Jun 15 16:06:17 2015 -0700
+++ b/mercurial/patch.py	Thu Jun 18 15:42:40 2015 -0500
@@ -773,7 +773,7 @@
         for x, s in enumerate(self.lines):
             self.hash.setdefault(s, []).append(x)
 
-        for fuzzlen in xrange(3):
+        for fuzzlen in xrange(self.ui.configint("patch", "fuzz", 2) + 1):
             for toponly in [True, False]:
                 old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly)
                 oldstart = oldstart + self.offset + self.skew
diff -r 6c48f012d37e -r ade1f430c985 tests/test-import.t
--- a/tests/test-import.t	Mon Jun 15 16:06:17 2015 -0700
+++ b/tests/test-import.t	Thu Jun 18 15:42:40 2015 -0500
@@ -492,6 +492,13 @@
   $ echo line0 >> a
   $ hg ci -m brancha
   created new head
+  $ hg import --config patch.fuzz=0 -v fuzzy-tip.patch
+  applying fuzzy-tip.patch
+  patching file a
+  Hunk #1 FAILED at 0
+  1 out of 1 hunks FAILED -- saving rejects to file a.rej
+  abort: patch failed to apply
+  [255]
   $ hg import --no-commit -v fuzzy-tip.patch
   applying fuzzy-tip.patch
   patching file a


More information about the Mercurial-devel mailing list