[PATCH 2 of 9 phases] mq: have mq create secret changeset only

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Jan 17 17:37:43 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1326839603 -3600
# Node ID 4470b206110b6004a42f086c0915695be0c3683a
# Parent  353d1385f6ff36fafb291c8bf46474d9b17bfc7d
mq: have mq create secret changeset only

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -46,7 +46,7 @@
 from mercurial.node import bin, hex, short, nullid, nullrev
 from mercurial.lock import release
 from mercurial import commands, cmdutil, hg, scmutil, util, revset
-from mercurial import repair, extensions, url, error
+from mercurial import repair, extensions, url, error, phases
 from mercurial import patch as patchmod
 import os, re, errno, shutil
 
@@ -251,6 +251,19 @@
                 ci += 1
             del self.comments[ci]
 
+def secretcommit(repo, *args, **kwargs):
+    """helper dedicated to ensure a commit are secret
+
+    It should be used instead of repo.commit inside the mq source
+    """
+    bckdata = repo.ui.backupconfig('phases', 'new-commit')
+    try:
+        # ensure we won't create a secret changeset
+        repo.ui.setconfig('phases', 'new-commit', phases.secret)
+        return repo.commit(*args, **kwargs)
+    finally:
+        repo.ui.restoreconfig(bckdata)
+
 class queue(object):
     def __init__(self, ui, path, patchdir=None):
         self.basepath = path
@@ -553,7 +566,7 @@
         ret = hg.merge(repo, rev)
         if ret:
             raise util.Abort(_("update returned %d") % ret)
-        n = repo.commit(ctx.description(), ctx.user(), force=True)
+        n = secretcommit(repo, ctx.description(), ctx.user(), force=True)
         if n is None:
             raise util.Abort(_("repo commit failed"))
         try:
@@ -723,8 +736,8 @@
                 repo.dirstate.setparents(p1, merge)
 
             match = scmutil.matchfiles(repo, files or [])
-            n = repo.commit(message, ph.user, ph.date, match=match, force=True)
-
+            n = secretcommit(repo, message, ph.user, ph.date, match=match,
+                             force=True)
             if n is None:
                 raise util.Abort(_("repository commit failed"))
 
@@ -952,7 +965,8 @@
                 if util.safehasattr(msg, '__call__'):
                     msg = msg()
                 commitmsg = msg and msg or ("[mq]: %s" % patchfn)
-                n = repo.commit(commitmsg, user, date, match=match, force=True)
+                n = secretcommit(repo, commitmsg, user, date, match=match,
+                                 force=True)
                 if n is None:
                     raise util.Abort(_("repo commit failed"))
                 try:
@@ -1494,8 +1508,8 @@
 
             try:
                 # might be nice to attempt to roll back strip after this
-                n = repo.commit(message, user, ph.date, match=match,
-                                force=True)
+                n = secretcommit(repo, message, user, ph.date, match=match,
+                                 force=True)
                 # only write patch after a successful commit
                 patchf.close()
                 self.applied.append(statusentry(n, patchfn))
diff --git a/tests/test-mq.t b/tests/test-mq.t
--- a/tests/test-mq.t
+++ b/tests/test-mq.t
@@ -148,8 +148,12 @@
   $ hg qnew A
   $ checkundo qnew
   $ echo foo > foo
+  $ hg phase -r qbase
+  0: secret
   $ hg add foo
   $ hg qrefresh
+  $ hg phase -r qbase
+  0: secret
   $ hg qnew B
   $ echo >> foo
   $ hg qrefresh
@@ -297,6 +301,8 @@
   $ hg qpush
   applying test.patch
   now at: test.patch
+  $ hg phase -r qbase
+  2: secret
   $ hg tags > /dev/null
 
 .hg/cache/tags (post qpush):


More information about the Mercurial-devel mailing list