mercurial/patch.py
changeset 49284 d44e3c45f0e4
parent 48946 642e31cb55f0
child 49306 2e726c934fcd
equal deleted inserted replaced
49283:44b26349127b 49284:d44e3c45f0e4
   862         # ok, we couldn't match the hunk. Lets look for offsets and fuzz it
   862         # ok, we couldn't match the hunk. Lets look for offsets and fuzz it
   863         self.hash = {}
   863         self.hash = {}
   864         for x, s in enumerate(self.lines):
   864         for x, s in enumerate(self.lines):
   865             self.hash.setdefault(s, []).append(x)
   865             self.hash.setdefault(s, []).append(x)
   866 
   866 
   867         for fuzzlen in pycompat.xrange(
   867         for fuzzlen in range(self.ui.configint(b"patch", b"fuzz") + 1):
   868             self.ui.configint(b"patch", b"fuzz") + 1
       
   869         ):
       
   870             for toponly in [True, False]:
   868             for toponly in [True, False]:
   871                 old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly)
   869                 old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly)
   872                 oldstart = oldstart + self.offset + self.skew
   870                 oldstart = oldstart + self.offset + self.skew
   873                 oldstart = min(oldstart, len(self.lines))
   871                 oldstart = min(oldstart, len(self.lines))
   874                 if old:
   872                 if old:
  1429         if aend is None:
  1427         if aend is None:
  1430             aend = self.starta
  1428             aend = self.starta
  1431         self.lena = int(aend) - self.starta
  1429         self.lena = int(aend) - self.starta
  1432         if self.starta:
  1430         if self.starta:
  1433             self.lena += 1
  1431             self.lena += 1
  1434         for x in pycompat.xrange(self.lena):
  1432         for x in range(self.lena):
  1435             l = lr.readline()
  1433             l = lr.readline()
  1436             if l.startswith(b'---'):
  1434             if l.startswith(b'---'):
  1437                 # lines addition, old block is empty
  1435                 # lines addition, old block is empty
  1438                 lr.push(l)
  1436                 lr.push(l)
  1439                 break
  1437                 break
  1464             bend = self.startb
  1462             bend = self.startb
  1465         self.lenb = int(bend) - self.startb
  1463         self.lenb = int(bend) - self.startb
  1466         if self.startb:
  1464         if self.startb:
  1467             self.lenb += 1
  1465             self.lenb += 1
  1468         hunki = 1
  1466         hunki = 1
  1469         for x in pycompat.xrange(self.lenb):
  1467         for x in range(self.lenb):
  1470             l = lr.readline()
  1468             l = lr.readline()
  1471             if l.startswith(br'\ '):
  1469             if l.startswith(br'\ '):
  1472                 # XXX: the only way to hit this is with an invalid line range.
  1470                 # XXX: the only way to hit this is with an invalid line range.
  1473                 # The no-eol marker is not counted in the line range, but I
  1471                 # The no-eol marker is not counted in the line range, but I
  1474                 # guess there are diff(1) out there which behave differently.
  1472                 # guess there are diff(1) out there which behave differently.
  1545         fuzz = min(fuzz, len(old))
  1543         fuzz = min(fuzz, len(old))
  1546         if fuzz:
  1544         if fuzz:
  1547             top = 0
  1545             top = 0
  1548             bot = 0
  1546             bot = 0
  1549             hlen = len(self.hunk)
  1547             hlen = len(self.hunk)
  1550             for x in pycompat.xrange(hlen - 1):
  1548             for x in range(hlen - 1):
  1551                 # the hunk starts with the @@ line, so use x+1
  1549                 # the hunk starts with the @@ line, so use x+1
  1552                 if self.hunk[x + 1].startswith(b' '):
  1550                 if self.hunk[x + 1].startswith(b' '):
  1553                     top += 1
  1551                     top += 1
  1554                 else:
  1552                 else:
  1555                     break
  1553                     break
  1556             if not toponly:
  1554             if not toponly:
  1557                 for x in pycompat.xrange(hlen - 1):
  1555                 for x in range(hlen - 1):
  1558                     if self.hunk[hlen - bot - 1].startswith(b' '):
  1556                     if self.hunk[hlen - bot - 1].startswith(b' '):
  1559                         bot += 1
  1557                         bot += 1
  1560                     else:
  1558                     else:
  1561                         break
  1559                         break
  1562 
  1560