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

Steve Borho steve at borho.org
Fri Apr 9 17:33:50 CDT 2010


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

diff -r b4e5330e8a45 -r a886b3aa478a 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 b4e5330e8a45 -r a886b3aa478a 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,21 @@
         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:
+                    contents = self.opener("undo.desc", "r").read()
+                    rev, name = contents.split(',',1)
+                    desc = "rolling back %s to revision %s\n" % (name, rev)
+                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