Skip to content
Snippets Groups Projects
Commit ccba74472af2 authored by Patrick Mézard's avatar Patrick Mézard
Browse files

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.
parent 5de83d9ca79c
No related branches found
No related tags found
No related merge requests found
......@@ -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,8 +759,8 @@
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:
......@@ -763,10 +763,9 @@
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,7 +970,7 @@
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.
......@@ -975,7 +974,7 @@
# 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,6 +1004,6 @@
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
......@@ -1010,9 +1009,6 @@
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.'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment