diff -r 0912d8df5e19 -r 94cb7561337d hgext/mq.py --- a/hgext/mq.py Tue May 08 11:42:48 2007 -0500 +++ b/hgext/mq.py Tue May 08 13:08:20 2007 -0700 @@ -435,7 +435,27 @@ return (True, files, fuzz) def apply(self, repo, series, list=False, update_status=True, - strict=False, patchdir=None, merge=None, wlock=None): + strict=False, patchdir=None, merge=None, wlock=None, + all_files={}): + tr = repo.transaction() + try: + ret = self._apply(tr, repo, series, list, update_status, + strict, patchdir, merge, wlock, + all_files=all_files) + tr.close() + self.save_dirty() + return ret + except: + try: + tr.abort() + finally: + repo.reload() + repo.wreload() + raise + + def _apply(self, tr, repo, series, list=False, update_status=True, + strict=False, patchdir=None, merge=None, wlock=None, + all_files={}): # TODO unify with commands.py if not patchdir: patchdir = self.path @@ -443,7 +463,6 @@ if not wlock: wlock = repo.wlock() lock = repo.lock() - tr = repo.transaction() n = None for patchname in series: pushable, reason = self.pushable(patchname) @@ -468,6 +487,7 @@ message = '\n'.join(message) (patcherr, files, fuzz) = self.patch(repo, pf) + all_files.update(files) patcherr = not patcherr if merge and files: @@ -506,7 +526,6 @@ self.ui.warn("fuzz found when applying patch, stopping\n") err = 1 break - tr.close() self.removeundo(repo) return (err, n) @@ -860,10 +879,25 @@ else: end = self.series.index(patch, start) + 1 s = self.series[start:end] - if mergeq: - ret = self.mergepatch(repo, mergeq, s, wlock) - else: - ret = self.apply(repo, s, list, wlock=wlock) + all_files = {} + try: + if mergeq: + ret = self.mergepatch(repo, mergeq, s, wlock) + else: + ret = self.apply(repo, s, list, wlock=wlock, + all_files=all_files) + except: + self.ui.warn(_('cleaning up working directory...')) + node = repo.dirstate.parents()[0] + hg.revert(repo, node, None, wlock) + unknown = repo.status(wlock=wlock)[4] + # only remove unknown files that we know we touched or + # created while patching + for f in unknown: + if f in all_files: + util.unlink(repo.wjoin(f)) + self.ui.warn(_('done\n')) + raise top = self.applied[-1].name if ret[0]: self.ui.write("Errors during apply, please fix and refresh %s\n" % @@ -1837,7 +1871,6 @@ ui.warn("merging with queue at: %s\n" % mergeq.path) ret = q.push(repo, patch, force=opts['force'], list=opts['list'], mergeq=mergeq) - q.save_dirty() return ret def pop(ui, repo, patch=None, **opts):