##// END OF EJS Templates
patch: make hunk.fuzzit() compute the fuzzed start locations...
Patrick Mezard -
r16122:9ef3a4a2 stable
parent child Browse files
Show More
@@ -728,21 +728,19 b' class patchfile(object):'
728 h = h.getnormalized()
728 h = h.getnormalized()
729
729
730 # fast case first, no offsets, no fuzz
730 # fast case first, no offsets, no fuzz
731 old, new = h.fuzzit(0, False)
731 old, oldstart, new, newstart = h.fuzzit(0, False)
732 start = h.starta + self.offset
732 oldstart += self.offset
733 # zero length hunk ranges already have their start decremented
733 orig_start = oldstart
734 if h.lena:
735 start -= 1
736 orig_start = start
737 # if there's skew we want to emit the "(offset %d lines)" even
734 # if there's skew we want to emit the "(offset %d lines)" even
738 # when the hunk cleanly applies at start + skew, so skip the
735 # when the hunk cleanly applies at start + skew, so skip the
739 # fast case code
736 # fast case code
740 if self.skew == 0 and diffhelpers.testhunk(old, self.lines, start) == 0:
737 if (self.skew == 0 and
738 diffhelpers.testhunk(old, self.lines, oldstart) == 0):
741 if self.remove:
739 if self.remove:
742 self.backend.unlink(self.fname)
740 self.backend.unlink(self.fname)
743 else:
741 else:
744 self.lines[start : start + h.lena] = new
742 self.lines[oldstart:oldstart + len(old)] = new
745 self.offset += h.lenb - h.lena
743 self.offset += len(new) - len(old)
746 self.dirty = True
744 self.dirty = True
747 return 0
745 return 0
748
746
@@ -759,7 +757,7 b' class patchfile(object):'
759
757
760 for fuzzlen in xrange(3):
758 for fuzzlen in xrange(3):
761 for toponly in [True, False]:
759 for toponly in [True, False]:
762 old, new = h.fuzzit(fuzzlen, toponly)
760 old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly)
763
761
764 cand = self.findlines(old[0][1:], search_start)
762 cand = self.findlines(old[0][1:], search_start)
765 for l in cand:
763 for l in cand:
@@ -1004,11 +1002,19 b' class hunk(object):'
1004 else:
1002 else:
1005 top = min(fuzz, top)
1003 top = min(fuzz, top)
1006
1004
1007 return old[top:len(old)-bot], new[top:len(new)-bot]
1005 return old[top:len(old)-bot], new[top:len(new)-bot], top
1008 return old, new
1006 return old, new, 0
1009
1007
1010 def fuzzit(self, fuzz, toponly):
1008 def fuzzit(self, fuzz, toponly):
1011 return self._fuzzit(self.a, self.b, fuzz, toponly)
1009 old, new, top = self._fuzzit(self.a, self.b, fuzz, toponly)
1010 oldstart = self.starta + top
1011 newstart = self.startb + top
1012 # zero length hunk ranges already have their start decremented
1013 if self.lena:
1014 oldstart -= 1
1015 if self.lenb:
1016 newstart -= 1
1017 return old, oldstart, new, newstart
1012
1018
1013 class binhunk(object):
1019 class binhunk(object):
1014 'A binary patch file. Only understands literals so far.'
1020 'A binary patch file. Only understands literals so far.'
General Comments 0
You need to be logged in to leave comments. Login now