hgext/record.py
changeset 6951 c8c9ce0ed3ee
parent 6760 4faaa0535ea7
parent 6950 381a892159d9
child 6965 98abbcf9fbdf
equal deleted inserted replaced
6948:359e93ceee3a 6951:c8c9ce0ed3ee
   153         self.hunk = hunk
   153         self.hunk = hunk
   154         self.added, self.removed = countchanges(self.hunk)
   154         self.added, self.removed = countchanges(self.hunk)
   155 
   155 
   156     def write(self, fp):
   156     def write(self, fp):
   157         delta = len(self.before) + len(self.after)
   157         delta = len(self.before) + len(self.after)
       
   158         if self.after and self.after[-1] == '\\ No newline at end of file\n':
       
   159             delta -= 1
   158         fromlen = delta + self.removed
   160         fromlen = delta + self.removed
   159         tolen = delta + self.added
   161         tolen = delta + self.added
   160         fp.write('@@ -%d,%d +%d,%d @@%s\n' %
   162         fp.write('@@ -%d,%d +%d,%d @@%s\n' %
   161                  (self.fromline, fromlen, self.toline, tolen,
   163                  (self.fromline, fromlen, self.toline, tolen,
   162                   self.proc and (' ' + self.proc)))
   164                   self.proc and (' ' + self.proc)))
   204 
   206 
   205         def addhunk(self, hunk):
   207         def addhunk(self, hunk):
   206             if self.context:
   208             if self.context:
   207                 self.before = self.context
   209                 self.before = self.context
   208                 self.context = []
   210                 self.context = []
   209             self.hunk = data
   211             self.hunk = hunk
   210 
   212 
   211         def newfile(self, hdr):
   213         def newfile(self, hdr):
   212             self.addcontext([])
   214             self.addcontext([])
   213             h = header(hdr)
   215             h = header(hdr)
   214             self.stream.append(h)
   216             self.stream.append(h)
   465             if backups:
   467             if backups:
   466                 hg.revert(repo, repo.dirstate.parents()[0], backups.has_key)
   468                 hg.revert(repo, repo.dirstate.parents()[0], backups.has_key)
   467 
   469 
   468             # 3b. (apply)
   470             # 3b. (apply)
   469             if dopatch:
   471             if dopatch:
   470                 ui.debug('applying patch\n')
   472                 try:
   471                 ui.debug(fp.getvalue())
   473                     ui.debug('applying patch\n')
   472                 patch.internalpatch(fp, ui, 1, repo.root)
   474                     ui.debug(fp.getvalue())
       
   475                     patch.internalpatch(fp, ui, 1, repo.root)
       
   476                 except patch.PatchError, err:
       
   477                     s = str(err)
       
   478                     if s:
       
   479                         raise util.Abort(s)
       
   480                     else:
       
   481                         raise util.Abort(_('patch failed to apply'))
   473             del fp
   482             del fp
   474 
   483 
   475             # 4. We prepared working directory according to filtered patch.
   484             # 4. We prepared working directory according to filtered patch.
   476             #    Now is the time to delegate the job to commit/qrefresh or the like!
   485             #    Now is the time to delegate the job to commit/qrefresh or the like!
   477 
   486