Mercurial > public > mercurial-scm > hg-stable
diff mercurial/localrepo.py @ 14266:89e7d35e0ef0 stable
fix bookmarks rollback behavior
Before this patch undo.bookmarks was created on bookmarks write and
not with other transaction-related files. There were two issues: first
is that if you have changed bookmarks few times after a transaction
happened, rollback will give you a state which can point to
non-existing revision. Second is that if you have not changed
bookmarks after a transaction, rollback will touch your state anyway.
This change also adds `localrepo._writejournal` method, which can be
used by other extensions to save their transaction-related backup in
right time.
author | Alexander Solovyov <alexander@solovyov.net> |
---|---|
date | Sun, 01 May 2011 13:07:00 +0200 |
parents | 044e1356327d |
children | a55a0045704c 4d958d1bb072 |
line wrap: on
line diff
--- a/mercurial/localrepo.py Fri May 06 15:37:38 2011 +0300 +++ b/mercurial/localrepo.py Sun May 01 13:07:00 2011 +0200 @@ -669,6 +669,17 @@ raise error.RepoError( _("abandoned transaction found - run hg recover")) + journalfiles = self._writejournal(desc) + renames = [(x, undoname(x)) for x in journalfiles] + + tr = transaction.transaction(self.ui.warn, self.sopener, + self.sjoin("journal"), + aftertrans(renames), + self.store.createmode) + self._transref = weakref.ref(tr) + return tr + + def _writejournal(self, desc): # save dirstate for rollback try: ds = self.opener("dirstate").read() @@ -679,16 +690,15 @@ encoding.fromlocal(self.dirstate.branch())) self.opener("journal.desc", "w").write("%d\n%s\n" % (len(self), desc)) - renames = [(self.sjoin("journal"), self.sjoin("undo")), - (self.join("journal.dirstate"), self.join("undo.dirstate")), - (self.join("journal.branch"), self.join("undo.branch")), - (self.join("journal.desc"), self.join("undo.desc"))] - tr = transaction.transaction(self.ui.warn, self.sopener, - self.sjoin("journal"), - aftertrans(renames), - self.store.createmode) - self._transref = weakref.ref(tr) - return tr + bkname = self.join('bookmarks') + if os.path.exists(bkname): + util.copyfile(bkname, self.join('journal.bookmarks')) + else: + self.opener('journal.bookmarks', 'w').write('') + + return (self.sjoin('journal'), self.join('journal.dirstate'), + self.join('journal.branch'), self.join('journal.desc'), + self.join('journal.bookmarks')) def recover(self): lock = self.lock() @@ -2027,6 +2037,11 @@ util.rename(src, dest) return a +def undoname(fn): + base, name = os.path.split(fn) + assert name.startswith('journal') + return os.path.join(base, name.replace('journal', 'undo', 1)) + def instance(ui, path, create): return localrepository(ui, util.drop_scheme('file', path), create)