[PATCH 1 of 2 STABLE] mq: ensure all mq commits are made with secretcommit()

Patrick Mezard patrick at mezard.eu
Tue Feb 7 11:54:12 CST 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1328636833 -3600
# Branch stable
# Node ID 196141af90f59bdf05681481e2c5bc6439129708
# Parent  2e8f4b82c551014a5895b3dfc5858f2341bd7f41
mq: ensure all mq commits are made with secretcommit()

Having a common code path helps fixing things globally.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -257,21 +257,23 @@
                 ci += 1
             del self.comments[ci]
 
-def secretcommit(repo, *args, **kwargs):
+def secretcommit(repo, phase, *args, **kwargs):
     """helper dedicated to ensure a commit are secret
 
     It should be used instead of repo.commit inside the mq source
     """
-    if not repo.ui.configbool('mq', 'secret', False):
-        return repo.commit(*args, **kwargs)
-
-    backup = repo.ui.backupconfig('phases', 'new-commit')
+    if phase is None:
+        if repo.ui.configbool('mq', 'secret', False):
+            phase = phases.secret
+    if phase is not None:
+        backup = repo.ui.backupconfig('phases', 'new-commit')
     try:
-        # ensure we create a secret changeset
-        repo.ui.setconfig('phases', 'new-commit', phases.secret)
+        if phase is not None:
+            repo.ui.setconfig('phases', 'new-commit', phase)
         return repo.commit(*args, **kwargs)
     finally:
-        repo.ui.restoreconfig(backup)
+        if phase is not None:
+            repo.ui.restoreconfig(backup)
 
 class queue(object):
     def __init__(self, ui, path, patchdir=None):
@@ -575,7 +577,7 @@
         ret = hg.merge(repo, rev)
         if ret:
             raise util.Abort(_("update returned %d") % ret)
-        n = secretcommit(repo, ctx.description(), ctx.user(), force=True)
+        n = secretcommit(repo, None, ctx.description(), ctx.user(), force=True)
         if n is None:
             raise util.Abort(_("repo commit failed"))
         try:
@@ -615,7 +617,7 @@
             # the first patch in the queue is never a merge patch
             #
             pname = ".hg.patches.merge.marker"
-            n = repo.commit('[mq]: merge marker', force=True)
+            n = secretcommit(repo, None, '[mq]: merge marker', force=True)
             self.removeundo(repo)
             self.applied.append(statusentry(n, pname))
             self.applieddirty = True
@@ -746,7 +748,7 @@
 
             match = scmutil.matchfiles(repo, files or [])
             oldtip = repo['tip']
-            n = secretcommit(repo, message, ph.user, ph.date, match=match,
+            n = secretcommit(repo, None, message, ph.user, ph.date, match=match,
                              force=True)
             if repo['tip'] == oldtip:
                 raise util.Abort(_("qpush exactly duplicates child changeset"))
@@ -987,7 +989,7 @@
                 if util.safehasattr(msg, '__call__'):
                     msg = msg()
                 commitmsg = msg and msg or ("[mq]: %s" % patchfn)
-                n = secretcommit(repo, commitmsg, user, date, match=match,
+                n = secretcommit(repo, None, commitmsg, user, date, match=match,
                                  force=True)
                 if n is None:
                     raise util.Abort(_("repo commit failed"))
@@ -1539,15 +1541,11 @@
 
             try:
                 # might be nice to attempt to roll back strip after this
-                backup = repo.ui.backupconfig('phases', 'new-commit')
-                try:
-                    # Ensure we create a new changeset in the same phase than
-                    # the old one.
-                    repo.ui.setconfig('phases', 'new-commit', oldphase)
-                    n = repo.commit(message, user, ph.date, match=match,
-                                    force=True)
-                finally:
-                    repo.ui.restoreconfig(backup)
+
+                # Ensure we create a new changeset in the same phase than
+                # the old one.
+                n = secretcommit(repo, oldphase, message, user, ph.date,
+                                 match=match, force=True)
                 # only write patch after a successful commit
                 patchf.close()
                 self.applied.append(statusentry(n, patchfn))


More information about the Mercurial-devel mailing list