Mercurial > hg
changeset 15097:cda7a87c1871
rollback: improve readability; clarify that the return value is an int.
author | Greg Ward <greg-hg@gerg.ca> |
---|---|
date | Sun, 11 Sep 2011 21:21:58 -0400 |
parents | 868282fa29d8 |
children | edf7ae547b0e |
files | mercurial/localrepo.py |
diffstat | 1 files changed, 42 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/localrepo.py Mon Aug 22 22:50:52 2011 +0200 +++ b/mercurial/localrepo.py Sun Sep 11 21:21:58 2011 -0400 @@ -760,50 +760,54 @@ wlock = self.wlock() lock = self.lock() if os.path.exists(self.sjoin("undo")): - try: - args = self.opener.read("undo.desc").splitlines() - if len(args) >= 3 and self.ui.verbose: - desc = _("repository tip rolled back to revision %s" - " (undo %s: %s)\n") % ( - int(args[0]) - 1, args[1], args[2]) - elif len(args) >= 2: - desc = _("repository tip rolled back to revision %s" - " (undo %s)\n") % ( - int(args[0]) - 1, args[1]) - except IOError: - desc = _("rolling back unknown transaction\n") - self.ui.status(desc) - if dryrun: - return - transaction.rollback(self.sopener, self.sjoin("undo"), - self.ui.warn) - util.rename(self.join("undo.dirstate"), self.join("dirstate")) - if os.path.exists(self.join('undo.bookmarks')): - util.rename(self.join('undo.bookmarks'), - self.join('bookmarks')) - try: - branch = self.opener.read("undo.branch") - self.dirstate.setbranch(branch) - except IOError: - self.ui.warn(_("named branch could not be reset, " - "current branch is still: %s\n") - % self.dirstate.branch()) - self.invalidate() - self.dirstate.invalidate() - self.destroyed() - parents = tuple([p.rev() for p in self.parents()]) - if len(parents) > 1: - self.ui.status(_("working directory now based on " - "revisions %d and %d\n") % parents) - else: - self.ui.status(_("working directory now based on " - "revision %d\n") % parents) + return self._rollback(dryrun) else: self.ui.warn(_("no rollback information available\n")) return 1 finally: release(lock, wlock) + def _rollback(self, dryrun): + try: + args = self.opener.read("undo.desc").splitlines() + if len(args) >= 3 and self.ui.verbose: + desc = _("repository tip rolled back to revision %s" + " (undo %s: %s)\n") % ( + int(args[0]) - 1, args[1], args[2]) + elif len(args) >= 2: + desc = _("repository tip rolled back to revision %s" + " (undo %s)\n") % ( + int(args[0]) - 1, args[1]) + except IOError: + desc = _("rolling back unknown transaction\n") + self.ui.status(desc) + if dryrun: + return 0 + transaction.rollback(self.sopener, self.sjoin("undo"), + self.ui.warn) + util.rename(self.join("undo.dirstate"), self.join("dirstate")) + if os.path.exists(self.join('undo.bookmarks')): + util.rename(self.join('undo.bookmarks'), + self.join('bookmarks')) + try: + branch = self.opener.read("undo.branch") + self.dirstate.setbranch(branch) + except IOError: + self.ui.warn(_("named branch could not be reset, " + "current branch is still: %s\n") + % self.dirstate.branch()) + self.invalidate() + self.dirstate.invalidate() + self.destroyed() + parents = tuple([p.rev() for p in self.parents()]) + if len(parents) > 1: + self.ui.status(_("working directory now based on " + "revisions %d and %d\n") % parents) + else: + self.ui.status(_("working directory now based on " + "revision %d\n") % parents) + return 0 + def invalidatecaches(self): try: delattr(self, '_tagscache')