[PATCH 2 of 3 STABLE] patch: make hunk.fuzzit() compute the fuzzed start locations
Patrick Mezard
patrick at mezard.eu
Mon Feb 13 16:02:08 UTC 2012
# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1329137498 -3600
# Branch stable
# Node ID 8711986a875ff4b529073090f81c60d6e868154a
# Parent 400a921ae0029bb08ce36757bf78a4fff1afeee9
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.
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -722,21 +722,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
@@ -753,7 +751,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:
@@ -998,11 +996,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.'
More information about the Mercurial-devel
mailing list