##// END OF EJS Templates
patch: make patch()/internalpatch() always update the dirstate
Patrick Mezard -
r14260:00a88158 default
parent child Browse files
Show More
@@ -614,17 +614,14 b' class queue(object):'
614 patchfile: name of patch file'''
614 patchfile: name of patch file'''
615 files = {}
615 files = {}
616 try:
616 try:
617 try:
617 fuzz = patchmod.patch(self.ui, repo, patchfile, strip=1,
618 fuzz = patchmod.patch(patchfile, self.ui, strip=1,
618 cwd=repo.root, files=files, eolmode=None)
619 cwd=repo.root, files=files, eolmode=None)
619 return (True, list(files), fuzz)
620 finally:
621 files = patchmod.updatedir(self.ui, repo, files)
622 return (True, files, fuzz)
623 except Exception, inst:
620 except Exception, inst:
624 self.ui.note(str(inst) + '\n')
621 self.ui.note(str(inst) + '\n')
625 if not self.ui.verbose:
622 if not self.ui.verbose:
626 self.ui.warn(_("patch failed, unable to continue (try -v)\n"))
623 self.ui.warn(_("patch failed, unable to continue (try -v)\n"))
627 return (False, files, False)
624 return (False, list(files), False)
628
625
629 def apply(self, repo, series, list=False, update_status=True,
626 def apply(self, repo, series, list=False, update_status=True,
630 strict=False, patchdir=None, merge=None, all_files=None):
627 strict=False, patchdir=None, merge=None, all_files=None):
@@ -477,12 +477,8 b' def dorecord(ui, repo, commitfunc, *pats'
477 try:
477 try:
478 ui.debug('applying patch\n')
478 ui.debug('applying patch\n')
479 ui.debug(fp.getvalue())
479 ui.debug(fp.getvalue())
480 pfiles = {}
480 patch.internalpatch(ui, repo, fp, 1, repo.root,
481 try:
481 eolmode=None)
482 patch.internalpatch(fp, ui, 1, repo.root, files=pfiles,
483 eolmode=None)
484 finally:
485 patch.updatedir(ui, repo, pfiles)
486 except patch.PatchError, err:
482 except patch.PatchError, err:
487 raise util.Abort(str(err))
483 raise util.Abort(str(err))
488 del fp
484 del fp
@@ -224,15 +224,12 b' class transplanter(object):'
224 if patchfile:
224 if patchfile:
225 try:
225 try:
226 files = {}
226 files = {}
227 try:
227 patch.patch(self.ui, repo, patchfile, cwd=repo.root,
228 patch.patch(patchfile, self.ui, cwd=repo.root,
228 files=files, eolmode=None)
229 files=files, eolmode=None)
229 files = list(files)
230 if not files:
230 if not files:
231 self.ui.warn(_('%s: empty changeset')
231 self.ui.warn(_('%s: empty changeset') % revlog.hex(node))
232 % revlog.hex(node))
232 return None
233 return None
234 finally:
235 files = patch.updatedir(self.ui, repo, files)
236 except Exception, inst:
233 except Exception, inst:
237 seriespath = os.path.join(self.path, 'series')
234 seriespath = os.path.join(self.path, 'series')
238 if os.path.exists(seriespath):
235 if os.path.exists(seriespath):
@@ -2623,12 +2623,9 b' def import_(ui, repo, patch1, *patches, '
2623 repo.dirstate.setbranch(branch or 'default')
2623 repo.dirstate.setbranch(branch or 'default')
2624
2624
2625 files = {}
2625 files = {}
2626 try:
2626 patch.patch(ui, repo, tmpname, strip=strip, cwd=repo.root,
2627 patch.patch(tmpname, ui, strip=strip, cwd=repo.root,
2627 files=files, eolmode=None, similarity=sim / 100.0)
2628 files=files, eolmode=None)
2628 files = list(files)
2629 finally:
2630 files = patch.updatedir(ui, repo, files,
2631 similarity=sim / 100.0)
2632 if opts.get('no_commit'):
2629 if opts.get('no_commit'):
2633 if message:
2630 if message:
2634 msgs.append(message)
2631 msgs.append(message)
@@ -428,7 +428,7 b' class patchfile(object):'
428
428
429 def writelines(self, fname, lines):
429 def writelines(self, fname, lines):
430 # Ensure supplied data ends in fname, being a regular file or
430 # Ensure supplied data ends in fname, being a regular file or
431 # a symlink. cmdutil.updatedir will -too magically- take care
431 # a symlink. _updatedir will -too magically- take care
432 # of setting it to the proper type afterwards.
432 # of setting it to the proper type afterwards.
433 st_mode = None
433 st_mode = None
434 islink = os.path.islink(fname)
434 islink = os.path.islink(fname)
@@ -1101,7 +1101,7 b' def applydiff(ui, fp, changed, strip=1, '
1101 read in binary mode. Otherwise, line endings are ignored when
1101 read in binary mode. Otherwise, line endings are ignored when
1102 patching then normalized according to 'eolmode'.
1102 patching then normalized according to 'eolmode'.
1103
1103
1104 Callers probably want to call 'cmdutil.updatedir' after this to
1104 Callers probably want to call '_updatedir' after this to
1105 apply certain categories of changes not done by this function.
1105 apply certain categories of changes not done by this function.
1106 """
1106 """
1107 return _applydiff(ui, fp, patchfile, copyfile, changed, strip=strip,
1107 return _applydiff(ui, fp, patchfile, copyfile, changed, strip=strip,
@@ -1157,7 +1157,7 b' def _applydiff(ui, fp, patcher, copyfn, '
1157 return -1
1157 return -1
1158 return err
1158 return err
1159
1159
1160 def updatedir(ui, repo, patches, similarity=0):
1160 def _updatedir(ui, repo, patches, similarity=0):
1161 '''Update dirstate after patch application according to metadata'''
1161 '''Update dirstate after patch application according to metadata'''
1162 if not patches:
1162 if not patches:
1163 return []
1163 return []
@@ -1237,7 +1237,8 b' def _externalpatch(patcher, patchname, u'
1237 util.explainexit(code)[0])
1237 util.explainexit(code)[0])
1238 return fuzz
1238 return fuzz
1239
1239
1240 def internalpatch(patchobj, ui, strip, cwd, files=None, eolmode='strict'):
1240 def internalpatch(ui, repo, patchobj, strip, cwd, files=None, eolmode='strict',
1241 similarity=0):
1241 """use builtin patch to apply <patchobj> to the working directory.
1242 """use builtin patch to apply <patchobj> to the working directory.
1242 returns whether patch was applied with fuzz factor."""
1243 returns whether patch was applied with fuzz factor."""
1243
1244
@@ -1263,11 +1264,14 b' def internalpatch(patchobj, ui, strip, c'
1263 os.chdir(curdir)
1264 os.chdir(curdir)
1264 if fp != patchobj:
1265 if fp != patchobj:
1265 fp.close()
1266 fp.close()
1267 touched = _updatedir(ui, repo, files, similarity)
1268 files.update(dict.fromkeys(touched))
1266 if ret < 0:
1269 if ret < 0:
1267 raise PatchError(_('patch failed to apply'))
1270 raise PatchError(_('patch failed to apply'))
1268 return ret > 0
1271 return ret > 0
1269
1272
1270 def patch(patchname, ui, strip=1, cwd=None, files=None, eolmode='strict'):
1273 def patch(ui, repo, patchname, strip=1, cwd=None, files=None, eolmode='strict',
1274 similarity=0):
1271 """Apply <patchname> to the working directory.
1275 """Apply <patchname> to the working directory.
1272
1276
1273 'eolmode' specifies how end of lines should be handled. It can be:
1277 'eolmode' specifies how end of lines should be handled. It can be:
@@ -1284,8 +1288,14 b' def patch(patchname, ui, strip=1, cwd=No'
1284 files = {}
1288 files = {}
1285 try:
1289 try:
1286 if patcher:
1290 if patcher:
1287 return _externalpatch(patcher, patchname, ui, strip, cwd, files)
1291 try:
1288 return internalpatch(patchname, ui, strip, cwd, files, eolmode)
1292 return _externalpatch(patcher, patchname, ui, strip, cwd,
1293 files)
1294 finally:
1295 touched = _updatedir(ui, repo, files, similarity)
1296 files.update(dict.fromkeys(touched))
1297 return internalpatch(ui, repo, patchname, strip, cwd, files, eolmode,
1298 similarity)
1289 except PatchError, err:
1299 except PatchError, err:
1290 raise util.Abort(str(err))
1300 raise util.Abort(str(err))
1291
1301
General Comments 0
You need to be logged in to leave comments. Login now