Mercurial > evolve
diff hgext/obsolete.py @ 52:62bdc2567099
Rollback support
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Thu, 08 Sep 2011 17:32:51 +0200 |
parents | d98e06ab8320 |
children | 0bcbf690dfca |
line wrap: on
line diff
--- a/hgext/obsolete.py Thu Sep 08 17:15:20 2011 +0200 +++ b/hgext/obsolete.py Thu Sep 08 17:32:51 2011 +0200 @@ -5,6 +5,7 @@ # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. +import os from mercurial import util from mercurial import context @@ -15,6 +16,7 @@ from mercurial import discovery from mercurial import error from mercurial.node import hex, bin +from mercurial.lock import release # Patch changectx ############################# @@ -119,6 +121,8 @@ opull = repo.pull opush = repo.push + orollback = repo.rollback + o_writejournal = repo._writejournal class obsoletingrepo(repo.__class__): @@ -222,6 +226,39 @@ pass #unknow revision (but keep propagating the data self._writeobsrels() + ### rollback support + + def _writejournal(self, desc): + entries = list(o_writejournal(desc)) + filename = 'obsolete-relations' + filepath = self.join(filename) + if os.path.exists(filepath): + journalname = 'journal.' + filename + journalpath = self.join(journalname) + util.copyfile(filepath, journalpath) + entries.append(journalpath) + return tuple(entries) + + def rollback(self, dryrun=False): + wlock = lock = None + try: + wlock = self.wlock() + lock = self.lock() + ret = orollback(dryrun) + if not (ret or dryrun): #rollback did not failed + src = self.join('undo.obsolete-relations') + dst = self.join('obsolete-relations') + if os.path.exists(src): + util.rename(src, dst) + elif os.path.exists(dst): #unlink in any case + os.unlink(dst) + # invalidate cache + self.__dict__.pop('_obssubrels', None) + self.__dict__.pop('_obsobjrels', None) + return ret + finally: + release(lock, wlock) + repo.__class__ = obsoletingrepo