mercurial/patch.py
changeset 7147 94cf0d1f48a3
parent 7106 4674706b5b95
child 7148 7d84e5b00e29
equal deleted inserted replaced
7146:266324983681 7147:94cf0d1f48a3
   986                              current_hunk.desc))
   986                              current_hunk.desc))
   987 
   987 
   988     if hunknum == 0 and dopatch and not gitworkdone:
   988     if hunknum == 0 and dopatch and not gitworkdone:
   989         raise NoHunks
   989         raise NoHunks
   990 
   990 
   991 def applydiff(ui, fp, changed, strip=1, sourcefile=None, reverse=False,
   991 def applydiff(ui, fp, changed, strip=1, sourcefile=None, reverse=False):
   992               rejmerge=None, updatedir=None):
       
   993     """reads a patch from fp and tries to apply it.  The dict 'changed' is
   992     """reads a patch from fp and tries to apply it.  The dict 'changed' is
   994        filled in with all of the filenames changed by the patch.  Returns 0
   993        filled in with all of the filenames changed by the patch.  Returns 0
   995        for a clean patch, -1 if any rejects were found and 1 if there was
   994        for a clean patch, -1 if any rejects were found and 1 if there was
   996        any fuzz."""
   995        any fuzz."""
   997 
   996 
  1002 
  1001 
  1003     def closefile():
  1002     def closefile():
  1004         if not current_file:
  1003         if not current_file:
  1005             return 0
  1004             return 0
  1006         current_file.close()
  1005         current_file.close()
  1007         if rejmerge:
       
  1008             rejmerge(current_file)
       
  1009         return len(current_file.rej)
  1006         return len(current_file.rej)
  1010 
  1007 
  1011     for state, values in iterhunks(ui, fp, sourcefile):
  1008     for state, values in iterhunks(ui, fp, sourcefile):
  1012         if state == 'hunk':
  1009         if state == 'hunk':
  1013             if not current_file:
  1010             if not current_file:
  1045         else:
  1042         else:
  1046             raise util.Abort(_('unsupported parser state: %s') % state)
  1043             raise util.Abort(_('unsupported parser state: %s') % state)
  1047 
  1044 
  1048     rejects += closefile()
  1045     rejects += closefile()
  1049 
  1046 
  1050     if updatedir and gitpatches:
       
  1051         updatedir(gitpatches)
       
  1052     if rejects:
  1047     if rejects:
  1053         return -1
  1048         return -1
  1054     return err
  1049     return err
  1055 
  1050 
  1056 def diffopts(ui, opts={}, untrusted=False):
  1051 def diffopts(ui, opts={}, untrusted=False):