746 |
746 |
747 # ok, we couldn't match the hunk. Lets look for offsets and fuzz it |
747 # ok, we couldn't match the hunk. Lets look for offsets and fuzz it |
748 self.hash = {} |
748 self.hash = {} |
749 for x, s in enumerate(self.lines): |
749 for x, s in enumerate(self.lines): |
750 self.hash.setdefault(s, []).append(x) |
750 self.hash.setdefault(s, []).append(x) |
751 if h.hunk[-1][0] != ' ': |
|
752 # if the hunk tried to put something at the bottom of the file |
|
753 # override the start line and use eof here |
|
754 search_start = len(self.lines) |
|
755 else: |
|
756 search_start = orig_start + self.skew |
|
757 |
751 |
758 for fuzzlen in xrange(3): |
752 for fuzzlen in xrange(3): |
759 for toponly in [True, False]: |
753 for toponly in [True, False]: |
760 old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly) |
754 old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly) |
761 |
755 oldstart = oldstart + self.offset + self.skew |
762 cand = self.findlines(old[0][1:], search_start) |
756 oldstart = min(oldstart, len(self.lines)) |
|
757 if old: |
|
758 cand = self.findlines(old[0][1:], oldstart) |
|
759 else: |
|
760 # Only adding lines with no or fuzzed context, just |
|
761 # take the skew in account |
|
762 cand = [oldstart] |
|
763 |
763 for l in cand: |
764 for l in cand: |
764 if diffhelpers.testhunk(old, self.lines, l) == 0: |
765 if not old or diffhelpers.testhunk(old, self.lines, l) == 0: |
765 self.lines[l : l + len(old)] = new |
766 self.lines[l : l + len(old)] = new |
766 self.offset += len(new) - len(old) |
767 self.offset += len(new) - len(old) |
767 self.skew = l - orig_start |
768 self.skew = l - orig_start |
768 self.dirty = True |
769 self.dirty = True |
769 offset = l - orig_start - fuzzlen |
770 offset = l - orig_start - fuzzlen |