Mercurial > hg > mercurial-crew-with-dirclash
comparison hgext/mq.py @ 4418:0532491f7476
MQ: tidy up if a qpush is interrupted.
This aborts the transaction, makes sure the dirtied dirstate isn't
written out, and cleans up the working directory.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Tue, 08 May 2007 12:16:02 -0700 |
parents | f700ea2b0689 |
children | 94cb7561337d |
comparison
equal
deleted
inserted
replaced
4416:bb1800a7d7e1 | 4418:0532491f7476 |
---|---|
419 return (False, files, False) | 419 return (False, files, False) |
420 | 420 |
421 return (True, files, fuzz) | 421 return (True, files, fuzz) |
422 | 422 |
423 def apply(self, repo, series, list=False, update_status=True, | 423 def apply(self, repo, series, list=False, update_status=True, |
424 strict=False, patchdir=None, merge=None, wlock=None): | 424 strict=False, patchdir=None, merge=None, wlock=None, |
425 all_files={}): | |
426 tr = repo.transaction() | |
427 try: | |
428 ret = self._apply(tr, repo, series, list, update_status, | |
429 strict, patchdir, merge, wlock, | |
430 all_files=all_files) | |
431 tr.close() | |
432 self.save_dirty() | |
433 return ret | |
434 except: | |
435 try: | |
436 tr.abort() | |
437 finally: | |
438 repo.reload() | |
439 repo.wreload() | |
440 raise | |
441 | |
442 def _apply(self, tr, repo, series, list=False, update_status=True, | |
443 strict=False, patchdir=None, merge=None, wlock=None, | |
444 all_files={}): | |
425 # TODO unify with commands.py | 445 # TODO unify with commands.py |
426 if not patchdir: | 446 if not patchdir: |
427 patchdir = self.path | 447 patchdir = self.path |
428 err = 0 | 448 err = 0 |
429 if not wlock: | 449 if not wlock: |
430 wlock = repo.wlock() | 450 wlock = repo.wlock() |
431 lock = repo.lock() | 451 lock = repo.lock() |
432 tr = repo.transaction() | |
433 n = None | 452 n = None |
434 for patchname in series: | 453 for patchname in series: |
435 pushable, reason = self.pushable(patchname) | 454 pushable, reason = self.pushable(patchname) |
436 if not pushable: | 455 if not pushable: |
437 self.explain_pushable(patchname, all_patches=True) | 456 self.explain_pushable(patchname, all_patches=True) |
452 if list: | 471 if list: |
453 message.append("\nimported patch %s" % patchname) | 472 message.append("\nimported patch %s" % patchname) |
454 message = '\n'.join(message) | 473 message = '\n'.join(message) |
455 | 474 |
456 (patcherr, files, fuzz) = self.patch(repo, pf) | 475 (patcherr, files, fuzz) = self.patch(repo, pf) |
476 all_files.update(files) | |
457 patcherr = not patcherr | 477 patcherr = not patcherr |
458 | 478 |
459 if merge and files: | 479 if merge and files: |
460 # Mark as removed/merged and update dirstate parent info | 480 # Mark as removed/merged and update dirstate parent info |
461 removed = [] | 481 removed = [] |
490 | 510 |
491 if fuzz and strict: | 511 if fuzz and strict: |
492 self.ui.warn("fuzz found when applying patch, stopping\n") | 512 self.ui.warn("fuzz found when applying patch, stopping\n") |
493 err = 1 | 513 err = 1 |
494 break | 514 break |
495 tr.close() | |
496 return (err, n) | 515 return (err, n) |
497 | 516 |
498 def delete(self, repo, patches, opts): | 517 def delete(self, repo, patches, opts): |
499 realpatches = [] | 518 realpatches = [] |
500 for patch in patches: | 519 for patch in patches: |
825 patch = self.series[start] | 844 patch = self.series[start] |
826 end = start + 1 | 845 end = start + 1 |
827 else: | 846 else: |
828 end = self.series.index(patch, start) + 1 | 847 end = self.series.index(patch, start) + 1 |
829 s = self.series[start:end] | 848 s = self.series[start:end] |
830 if mergeq: | 849 all_files = {} |
831 ret = self.mergepatch(repo, mergeq, s, wlock) | 850 try: |
832 else: | 851 if mergeq: |
833 ret = self.apply(repo, s, list, wlock=wlock) | 852 ret = self.mergepatch(repo, mergeq, s, wlock) |
853 else: | |
854 ret = self.apply(repo, s, list, wlock=wlock, | |
855 all_files=all_files) | |
856 except: | |
857 self.ui.warn(_('cleaning up working directory...')) | |
858 node = repo.dirstate.parents()[0] | |
859 hg.revert(repo, node, None, wlock) | |
860 unknown = repo.status(wlock=wlock)[4] | |
861 # only remove unknown files that we know we touched or | |
862 # created while patching | |
863 for f in unknown: | |
864 if f in all_files: | |
865 util.unlink(repo.wjoin(f)) | |
866 self.ui.warn(_('done\n')) | |
867 raise | |
834 top = self.applied[-1].name | 868 top = self.applied[-1].name |
835 if ret[0]: | 869 if ret[0]: |
836 self.ui.write("Errors during apply, please fix and refresh %s\n" % | 870 self.ui.write("Errors during apply, please fix and refresh %s\n" % |
837 top) | 871 top) |
838 else: | 872 else: |
1789 return 1 | 1823 return 1 |
1790 mergeq = queue(ui, repo.join(""), newpath) | 1824 mergeq = queue(ui, repo.join(""), newpath) |
1791 ui.warn("merging with queue at: %s\n" % mergeq.path) | 1825 ui.warn("merging with queue at: %s\n" % mergeq.path) |
1792 ret = q.push(repo, patch, force=opts['force'], list=opts['list'], | 1826 ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
1793 mergeq=mergeq) | 1827 mergeq=mergeq) |
1794 q.save_dirty() | |
1795 return ret | 1828 return ret |
1796 | 1829 |
1797 def pop(ui, repo, patch=None, **opts): | 1830 def pop(ui, repo, patch=None, **opts): |
1798 """pop the current patch off the stack""" | 1831 """pop the current patch off the stack""" |
1799 localupdate = True | 1832 localupdate = True |