changeset 16121:ccba74472af2 stable

patch: fuzz old and new lines at the same time In theory, the fuzzed offsets for old and new lines should be exactly the same as they are based on hunk parsing. Make it true in practice.
author Patrick Mezard <patrick@mezard.eu>
date Mon, 13 Feb 2012 13:21:00 +0100
parents 5de83d9ca79c
children 9ef3a4a2c6c0
files mercurial/patch.py
diffstat 1 files changed, 11 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Tue Feb 14 14:31:40 2012 +0100
+++ b/mercurial/patch.py	Mon Feb 13 13:21:00 2012 +0100
@@ -728,7 +728,7 @@
             h = h.getnormalized()
 
         # fast case first, no offsets, no fuzz
-        old = h.old()
+        old, new = h.fuzzit(0, False)
         start = h.starta + self.offset
         # zero length hunk ranges already have their start decremented
         if h.lena:
@@ -741,7 +741,7 @@
             if self.remove:
                 self.backend.unlink(self.fname)
             else:
-                self.lines[start : start + h.lena] = h.new()
+                self.lines[start : start + h.lena] = new
                 self.offset += h.lenb - h.lena
                 self.dirty = True
             return 0
@@ -759,14 +759,13 @@
 
         for fuzzlen in xrange(3):
             for toponly in [True, False]:
-                old = h.old(fuzzlen, toponly)
+                old, new = h.fuzzit(fuzzlen, toponly)
 
                 cand = self.findlines(old[0][1:], search_start)
                 for l in cand:
                     if diffhelpers.testhunk(old, self.lines, l) == 0:
-                        newlines = h.new(fuzzlen, toponly)
-                        self.lines[l : l + len(old)] = newlines
-                        self.offset += len(newlines) - len(old)
+                        self.lines[l : l + len(old)] = new
+                        self.offset += len(new) - len(old)
                         self.skew = l - orig_start
                         self.dirty = True
                         offset = l - orig_start - fuzzlen
@@ -971,11 +970,11 @@
     def complete(self):
         return len(self.a) == self.lena and len(self.b) == self.lenb
 
-    def fuzzit(self, l, fuzz, toponly):
+    def _fuzzit(self, old, new, fuzz, toponly):
         # this removes context lines from the top and bottom of list 'l'.  It
         # checks the hunk to make sure only context lines are removed, and then
         # returns a new shortened list of lines.
-        fuzz = min(fuzz, len(l)-1)
+        fuzz = min(fuzz, len(old)-1)
         if fuzz:
             top = 0
             bot = 0
@@ -1005,14 +1004,11 @@
             else:
                 top = min(fuzz, top)
 
-            return l[top:len(l)-bot]
-        return l
+            return old[top:len(old)-bot], new[top:len(new)-bot]
+        return old, new
 
-    def old(self, fuzz=0, toponly=False):
-        return self.fuzzit(self.a, fuzz, toponly)
-
-    def new(self, fuzz=0, toponly=False):
-        return self.fuzzit(self.b, fuzz, toponly)
+    def fuzzit(self, fuzz, toponly):
+        return self._fuzzit(self.a, self.b, fuzz, toponly)
 
 class binhunk(object):
     'A binary patch file. Only understands literals so far.'