[PATCH 2 of 2] rollback: add dry-run argument, emit transaction description

Steve Borho steve at borho.org
Sat Apr 10 22:39:31 CDT 2010


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1270851817 18000
# Node ID 233ba481a9b36db0d99869bccb3cf6977a6f8ca2
# Parent  d97789125f1f9fce45d74ff1e75bfbd197a91e1c
rollback: add dry-run argument, emit transaction description

diff -r d97789125f1f -r 233ba481a9b3 hgext/bookmarks.py
--- a/hgext/bookmarks.py	Fri Apr 09 17:23:35 2010 -0500
+++ b/hgext/bookmarks.py	Fri Apr 09 17:23:37 2010 -0500
@@ -241,10 +241,10 @@
                 file.close()
             return mark
 
-        def rollback(self):
+        def rollback(self, *args):
             if os.path.exists(self.join('undo.bookmarks')):
                 util.rename(self.join('undo.bookmarks'), self.join('bookmarks'))
-            return super(bookmark_repo, self).rollback()
+            return super(bookmark_repo, self).rollback(*args)
 
         def lookup(self, key):
             if key in self._bookmarks:
diff -r d97789125f1f -r 233ba481a9b3 mercurial/commands.py
--- a/mercurial/commands.py	Fri Apr 09 17:23:35 2010 -0500
+++ b/mercurial/commands.py	Fri Apr 09 17:23:37 2010 -0500
@@ -2854,7 +2854,7 @@
     finally:
         wlock.release()
 
-def rollback(ui, repo):
+def rollback(ui, repo, **opts):
     """roll back the last transaction
 
     This command should be used with care. There is only one level of
@@ -2881,7 +2881,7 @@
     repository; for example an in-progress pull from the repository
     may fail if a rollback is performed.
     """
-    repo.rollback()
+    repo.rollback(opts.get('dry_run'))
 
 def root(ui, repo):
     """print the root (top) of the current working directory
@@ -3821,7 +3821,7 @@
           ('', 'no-backup', None, _('do not save backup copies of files')),
          ] + walkopts + dryrunopts,
          _('[OPTION]... [-r REV] [NAME]...')),
-    "rollback": (rollback, []),
+    "rollback": (rollback, dryrunopts),
     "root": (root, []),
     "^serve":
         (serve,
diff -r d97789125f1f -r 233ba481a9b3 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Fri Apr 09 17:23:35 2010 -0500
+++ b/mercurial/localrepo.py	Fri Apr 09 17:23:37 2010 -0500
@@ -599,13 +599,25 @@
         finally:
             lock.release()
 
-    def rollback(self):
+    def rollback(self, dryrun=False):
         wlock = lock = None
         try:
             wlock = self.wlock()
             lock = self.lock()
             if os.path.exists(self.sjoin("undo")):
-                self.ui.status(_("rolling back last transaction\n"))
+                try:
+                    args = self.opener("undo.desc", "r").read().split(",")
+                    if len(args) == 3 and self.ui.verbose:
+                        desc = _("rolling back %s (%s) to revision %s\n") % (
+                                 args[1], args[2], args[0])
+                    else:
+                        desc = _("rolling back %s to revision %s\n") % (
+                                 args[1], args[0])
+                except (IOError, IndexError):
+                    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"))


More information about the Mercurial-devel mailing list