Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 15130:3d44e68360a6
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
author | Greg Ward <greg@gerg.ca> |
---|---|
date | Fri, 16 Sep 2011 21:38:06 -0400 |
parents | a21ccf4412d5 |
children | 7c26ce9edbd2 |
comparison
equal
deleted
inserted
replaced
15129:9b904d679850 | 15130:3d44e68360a6 |
---|---|
766 return 1 | 766 return 1 |
767 finally: | 767 finally: |
768 release(lock, wlock) | 768 release(lock, wlock) |
769 | 769 |
770 def _rollback(self, dryrun): | 770 def _rollback(self, dryrun): |
771 try: | 771 ui = self.ui |
772 args = self.opener.read("undo.desc").splitlines() | 772 try: |
773 if len(args) >= 3 and self.ui.verbose: | 773 args = self.opener.read('undo.desc').splitlines() |
774 desc = _("repository tip rolled back to revision %s" | 774 (oldlen, desc, detail) = (int(args[0]), args[1], None) |
775 " (undo %s: %s)\n") % ( | 775 if len(args) >= 3: |
776 int(args[0]) - 1, args[1], args[2]) | 776 detail = args[2] |
777 elif len(args) >= 2: | 777 oldtip = oldlen - 1 |
778 desc = _("repository tip rolled back to revision %s" | 778 |
779 " (undo %s)\n") % ( | 779 if detail and ui.verbose: |
780 int(args[0]) - 1, args[1]) | 780 msg = (_('repository tip rolled back to revision %s' |
781 ' (undo %s: %s)\n') | |
782 % (oldtip, desc, detail)) | |
783 else: | |
784 msg = (_('repository tip rolled back to revision %s' | |
785 ' (undo %s)\n') | |
786 % (oldtip, desc)) | |
781 except IOError: | 787 except IOError: |
782 desc = _("rolling back unknown transaction\n") | 788 msg = _('rolling back unknown transaction\n') |
783 self.ui.status(desc) | 789 ui.status(msg) |
784 if dryrun: | 790 if dryrun: |
785 return 0 | 791 return 0 |
786 transaction.rollback(self.sopener, self.sjoin("undo"), | 792 transaction.rollback(self.sopener, self.sjoin('undo'), ui.warn) |
787 self.ui.warn) | 793 util.rename(self.join('undo.dirstate'), self.join('dirstate')) |
788 util.rename(self.join("undo.dirstate"), self.join("dirstate")) | |
789 if os.path.exists(self.join('undo.bookmarks')): | 794 if os.path.exists(self.join('undo.bookmarks')): |
790 util.rename(self.join('undo.bookmarks'), | 795 util.rename(self.join('undo.bookmarks'), |
791 self.join('bookmarks')) | 796 self.join('bookmarks')) |
792 try: | 797 try: |
793 branch = self.opener.read("undo.branch") | 798 branch = self.opener.read('undo.branch') |
794 self.dirstate.setbranch(branch) | 799 self.dirstate.setbranch(branch) |
795 except IOError: | 800 except IOError: |
796 self.ui.warn(_("named branch could not be reset, " | 801 ui.warn(_('named branch could not be reset: ' |
797 "current branch is still: %s\n") | 802 'current branch is still \'%s\'\n') |
798 % self.dirstate.branch()) | 803 % self.dirstate.branch()) |
799 self.invalidate() | 804 self.invalidate() |
800 self.dirstate.invalidate() | 805 self.dirstate.invalidate() |
801 self.destroyed() | 806 self.destroyed() |
802 parents = tuple([p.rev() for p in self.parents()]) | 807 parents = tuple([p.rev() for p in self.parents()]) |
803 if len(parents) > 1: | 808 if len(parents) > 1: |
804 self.ui.status(_("working directory now based on " | 809 ui.status(_('working directory now based on ' |
805 "revisions %d and %d\n") % parents) | 810 'revisions %d and %d\n') % parents) |
806 else: | 811 else: |
807 self.ui.status(_("working directory now based on " | 812 ui.status(_('working directory now based on ' |
808 "revision %d\n") % parents) | 813 'revision %d\n') % parents) |
809 return 0 | 814 return 0 |
810 | 815 |
811 def invalidatecaches(self): | 816 def invalidatecaches(self): |
812 try: | 817 try: |
813 delattr(self, '_tagscache') | 818 delattr(self, '_tagscache') |