# HG changeset patch # User Greg Ward # Date 1316223486 14400 # Node ID 3d44e68360a68f1c6540ea65423f5b1f74ce091b # Parent 9b904d6798507885f8168ae5827c184a27871ee3 rollback: refactor for readability; cosmetics. - clarify how we parse undo.desc - fix bad grammar in an error message - factor out ui local - rename some local variables - standardize string quoting diff -r 9b904d679850 -r 3d44e68360a6 mercurial/localrepo.py --- a/mercurial/localrepo.py Sat Sep 17 14:55:55 2011 -0500 +++ b/mercurial/localrepo.py Fri Sep 16 21:38:06 2011 -0400 @@ -768,44 +768,49 @@ release(lock, wlock) def _rollback(self, dryrun): + ui = self.ui 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]) + args = self.opener.read('undo.desc').splitlines() + (oldlen, desc, detail) = (int(args[0]), args[1], None) + if len(args) >= 3: + detail = args[2] + oldtip = oldlen - 1 + + if detail and ui.verbose: + msg = (_('repository tip rolled back to revision %s' + ' (undo %s: %s)\n') + % (oldtip, desc, detail)) + else: + msg = (_('repository tip rolled back to revision %s' + ' (undo %s)\n') + % (oldtip, desc)) except IOError: - desc = _("rolling back unknown transaction\n") - self.ui.status(desc) + msg = _('rolling back unknown transaction\n') + ui.status(msg) if dryrun: return 0 - transaction.rollback(self.sopener, self.sjoin("undo"), - self.ui.warn) - util.rename(self.join("undo.dirstate"), self.join("dirstate")) + transaction.rollback(self.sopener, self.sjoin('undo'), 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") + 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()) + 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) + 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) + ui.status(_('working directory now based on ' + 'revision %d\n') % parents) return 0 def invalidatecaches(self): diff -r 9b904d679850 -r 3d44e68360a6 tests/test-rollback.t --- a/tests/test-rollback.t Sat Sep 17 14:55:55 2011 -0500 +++ b/tests/test-rollback.t Fri Sep 16 21:38:06 2011 -0400 @@ -59,7 +59,7 @@ $ rm .hg/undo.branch $ hg rollback repository tip rolled back to revision 0 (undo commit) - named branch could not be reset, current branch is still: test + named branch could not be reset: current branch is still 'test' working directory now based on revision 0 $ hg branch test