changeset 16122:9ef3a4a2c6c0 stable

patch: make hunk.fuzzit() compute the fuzzed start locations - It moves hunks processing weirdness where it belongs - It helps reusing said weirdness whenever fuzzit() is called, like during the actual hunk fuzzing.
author Patrick Mezard <patrick@mezard.eu>
date Mon, 13 Feb 2012 13:51:38 +0100
parents ccba74472af2
children b0c7525f826d
files mercurial/patch.py
diffstat 1 files changed, 19 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Mon Feb 13 13:21:00 2012 +0100
+++ b/mercurial/patch.py	Mon Feb 13 13:51:38 2012 +0100
@@ -728,21 +728,19 @@
             h = h.getnormalized()
 
         # fast case first, no offsets, no fuzz
-        old, new = h.fuzzit(0, False)
-        start = h.starta + self.offset
-        # zero length hunk ranges already have their start decremented
-        if h.lena:
-            start -= 1
-        orig_start = start
+        old, oldstart, new, newstart = h.fuzzit(0, False)
+        oldstart += self.offset
+        orig_start = oldstart
         # if there's skew we want to emit the "(offset %d lines)" even
         # when the hunk cleanly applies at start + skew, so skip the
         # fast case code
-        if self.skew == 0 and diffhelpers.testhunk(old, self.lines, start) == 0:
+        if (self.skew == 0 and
+            diffhelpers.testhunk(old, self.lines, oldstart) == 0):
             if self.remove:
                 self.backend.unlink(self.fname)
             else:
-                self.lines[start : start + h.lena] = new
-                self.offset += h.lenb - h.lena
+                self.lines[oldstart:oldstart + len(old)] = new
+                self.offset += len(new) - len(old)
                 self.dirty = True
             return 0
 
@@ -759,7 +757,7 @@
 
         for fuzzlen in xrange(3):
             for toponly in [True, False]:
-                old, new = h.fuzzit(fuzzlen, toponly)
+                old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly)
 
                 cand = self.findlines(old[0][1:], search_start)
                 for l in cand:
@@ -1004,11 +1002,19 @@
             else:
                 top = min(fuzz, top)
 
-            return old[top:len(old)-bot], new[top:len(new)-bot]
-        return old, new
+            return old[top:len(old)-bot], new[top:len(new)-bot], top
+        return old, new, 0
 
     def fuzzit(self, fuzz, toponly):
-        return self._fuzzit(self.a, self.b, fuzz, toponly)
+        old, new, top = self._fuzzit(self.a, self.b, fuzz, toponly)
+        oldstart = self.starta + top
+        newstart = self.startb + top
+        # zero length hunk ranges already have their start decremented
+        if self.lena:
+            oldstart -= 1
+        if self.lenb:
+            newstart -= 1
+        return old, oldstart, new, newstart
 
 class binhunk(object):
     'A binary patch file. Only understands literals so far.'