mercurial/patch.py
branchstable
changeset 37803 72f6498c040b
parent 37764 5e67c20915a7
child 38081 b403e87df069
equal deleted inserted replaced
37802:090c89a8db32 37803:72f6498c040b
    26     hex,
    26     hex,
    27     short,
    27     short,
    28 )
    28 )
    29 from . import (
    29 from . import (
    30     copies,
    30     copies,
    31     diffhelpers,
    31     diffhelper,
    32     encoding,
    32     encoding,
    33     error,
    33     error,
    34     mail,
    34     mail,
    35     mdiff,
    35     mdiff,
    36     pathutil,
    36     pathutil,
   798         oldstart += self.offset
   798         oldstart += self.offset
   799         orig_start = oldstart
   799         orig_start = oldstart
   800         # if there's skew we want to emit the "(offset %d lines)" even
   800         # if there's skew we want to emit the "(offset %d lines)" even
   801         # when the hunk cleanly applies at start + skew, so skip the
   801         # when the hunk cleanly applies at start + skew, so skip the
   802         # fast case code
   802         # fast case code
   803         if self.skew == 0 and diffhelpers.testhunk(old, self.lines, oldstart):
   803         if self.skew == 0 and diffhelper.testhunk(old, self.lines, oldstart):
   804             if self.remove:
   804             if self.remove:
   805                 self.backend.unlink(self.fname)
   805                 self.backend.unlink(self.fname)
   806             else:
   806             else:
   807                 self.lines[oldstart:oldstart + len(old)] = new
   807                 self.lines[oldstart:oldstart + len(old)] = new
   808                 self.offset += len(new) - len(old)
   808                 self.offset += len(new) - len(old)
   825                     # Only adding lines with no or fuzzed context, just
   825                     # Only adding lines with no or fuzzed context, just
   826                     # take the skew in account
   826                     # take the skew in account
   827                     cand = [oldstart]
   827                     cand = [oldstart]
   828 
   828 
   829                 for l in cand:
   829                 for l in cand:
   830                     if not old or diffhelpers.testhunk(old, self.lines, l):
   830                     if not old or diffhelper.testhunk(old, self.lines, l):
   831                         self.lines[l : l + len(old)] = new
   831                         self.lines[l : l + len(old)] = new
   832                         self.offset += len(new) - len(old)
   832                         self.offset += len(new) - len(old)
   833                         self.skew = l - orig_start
   833                         self.skew = l - orig_start
   834                         self.dirty = True
   834                         self.dirty = True
   835                         offset = l - orig_start - fuzzlen
   835                         offset = l - orig_start - fuzzlen
  1257         else:
  1257         else:
  1258             self.lenb = int(self.lenb)
  1258             self.lenb = int(self.lenb)
  1259         self.starta = int(self.starta)
  1259         self.starta = int(self.starta)
  1260         self.startb = int(self.startb)
  1260         self.startb = int(self.startb)
  1261         try:
  1261         try:
  1262             diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb,
  1262             diffhelper.addlines(lr, self.hunk, self.lena, self.lenb,
  1263                                  self.a, self.b)
  1263                                 self.a, self.b)
  1264         except error.ParseError as e:
  1264         except error.ParseError as e:
  1265             raise PatchError(_("bad hunk #%d: %s") % (self.number, e))
  1265             raise PatchError(_("bad hunk #%d: %s") % (self.number, e))
  1266         # if we hit eof before finishing out the hunk, the last line will
  1266         # if we hit eof before finishing out the hunk, the last line will
  1267         # be zero length.  Lets try to fix it up.
  1267         # be zero length.  Lets try to fix it up.
  1268         while len(self.hunk[-1]) == 0:
  1268         while len(self.hunk[-1]) == 0:
  1377         self._fixnewline(lr)
  1377         self._fixnewline(lr)
  1378 
  1378 
  1379     def _fixnewline(self, lr):
  1379     def _fixnewline(self, lr):
  1380         l = lr.readline()
  1380         l = lr.readline()
  1381         if l.startswith('\ '):
  1381         if l.startswith('\ '):
  1382             diffhelpers.fixnewline(self.hunk, self.a, self.b)
  1382             diffhelper.fixnewline(self.hunk, self.a, self.b)
  1383         else:
  1383         else:
  1384             lr.push(l)
  1384             lr.push(l)
  1385 
  1385 
  1386     def complete(self):
  1386     def complete(self):
  1387         return len(self.a) == self.lena and len(self.b) == self.lenb
  1387         return len(self.a) == self.lena and len(self.b) == self.lenb