mercurial/patch.py
changeset 11021 c47a1cfad572
parent 11020 dd157720a8ee
child 11022 0429d0d49f92
equal deleted inserted replaced
11020:dd157720a8ee 11021:c47a1cfad572
  1151 def _applydiff(ui, fp, patcher, copyfn, changed, strip=1,
  1151 def _applydiff(ui, fp, patcher, copyfn, changed, strip=1,
  1152                sourcefile=None, eolmode='strict'):
  1152                sourcefile=None, eolmode='strict'):
  1153     rejects = 0
  1153     rejects = 0
  1154     err = 0
  1154     err = 0
  1155     current_file = None
  1155     current_file = None
  1156     gitpatches = None
  1156     cwd = os.getcwd()
  1157     opener = util.opener(os.getcwd())
  1157     opener = util.opener(cwd)
  1158 
  1158 
  1159     def closefile():
  1159     def closefile():
  1160         if not current_file:
  1160         if not current_file:
  1161             return 0
  1161             return 0
  1162         current_file.close()
  1162         current_file.close()
  1164 
  1164 
  1165     for state, values in iterhunks(ui, fp, sourcefile):
  1165     for state, values in iterhunks(ui, fp, sourcefile):
  1166         if state == 'hunk':
  1166         if state == 'hunk':
  1167             if not current_file:
  1167             if not current_file:
  1168                 continue
  1168                 continue
  1169             current_hunk = values
  1169             ret = current_file.apply(values)
  1170             ret = current_file.apply(current_hunk)
       
  1171             if ret >= 0:
  1170             if ret >= 0:
  1172                 changed.setdefault(current_file.fname, None)
  1171                 changed.setdefault(current_file.fname, None)
  1173                 if ret > 0:
  1172                 if ret > 0:
  1174                     err = 1
  1173                     err = 1
  1175         elif state == 'file':
  1174         elif state == 'file':
  1184                                                        first_hunk, strip)
  1183                                                        first_hunk, strip)
  1185                     current_file = patcher(ui, current_file, opener,
  1184                     current_file = patcher(ui, current_file, opener,
  1186                                            missing=missing, eolmode=eolmode)
  1185                                            missing=missing, eolmode=eolmode)
  1187             except PatchError, err:
  1186             except PatchError, err:
  1188                 ui.warn(str(err) + '\n')
  1187                 ui.warn(str(err) + '\n')
  1189                 current_file, current_hunk = None, None
  1188                 current_file = None
  1190                 rejects += 1
  1189                 rejects += 1
  1191                 continue
  1190                 continue
  1192         elif state == 'git':
  1191         elif state == 'git':
  1193             gitpatches = values
  1192             for gp in values:
  1194             cwd = os.getcwd()
       
  1195             for gp in gitpatches:
       
  1196                 if gp.op in ('COPY', 'RENAME'):
  1193                 if gp.op in ('COPY', 'RENAME'):
  1197                     copyfn(gp.oldpath, gp.path, cwd)
  1194                     copyfn(gp.oldpath, gp.path, cwd)
  1198                 changed[gp.path] = gp
  1195                 changed[gp.path] = gp
  1199         else:
  1196         else:
  1200             raise util.Abort(_('unsupported parser state: %s') % state)
  1197             raise util.Abort(_('unsupported parser state: %s') % state)