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

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Wed Jan 18 10:33:08 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1326902029 -3600
# Node ID dc8d8aa6e8ac490fcafd074d570df0787ee0ee69
# Parent  307dca32399fa1b8d5aef669d540ed4a51477fd5
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
@@ -44,11 +44,11 @@ create other, independent patch queues w
 
 from mercurial.i18n import _
 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
 
 commands.norepo += " qclone"
 
@@ -249,10 +249,23 @@ class patchheader(object):
         for mi in self.message:
             while mi != self.comments[ci]:
                 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
+    """
+    backup = repo.ui.backupconfig('phases', 'new-commit')
+    try:
+        # ensure we create a secret changeset
+        repo.ui.setconfig('phases', 'new-commit', phases.secret)
+        return repo.commit(*args, **kwargs)
+    finally:
+        repo.ui.restoreconfig(backup)
+
 class queue(object):
     def __init__(self, ui, path, patchdir=None):
         self.basepath = path
         try:
             fh = open(os.path.join(path, 'patches.queue'))
@@ -551,11 +564,11 @@ class queue(object):
 
         ctx = repo[rev]
         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:
             ph = patchheader(mergeq.join(patch), self.plainmode)
         except:
@@ -721,12 +734,12 @@ class queue(object):
                     repo.dirstate.merge(f)
                 p1, p2 = repo.dirstate.parents()
                 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"))
 
             if update_status:
                 self.applied.append(statusentry(n, patchname))
@@ -950,11 +963,12 @@ class queue(object):
                     if date:
                         p.write("# Date %s %s\n\n" % date)
                 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:
                     self.fullseries[insert:insert] = [patchfn]
                     self.applied.append(statusentry(n, patchfn))
@@ -1492,12 +1506,12 @@ class queue(object):
                 repo.dirstate.invalidate()
                 raise
 
             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))
             except:
                 ctx = repo[cparents[0]]
diff --git a/tests/test-mq.t b/tests/test-mq.t
--- a/tests/test-mq.t
+++ b/tests/test-mq.t
@@ -146,12 +146,16 @@ qinit -c should create both files if the
   $ hg init e
   $ cd e
   $ 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
   $ echo status >> .hg/patches/.hgignore
   $ echo bleh >> .hg/patches/.hgignore
@@ -295,10 +299,12 @@ Dump the tag cache to ensure that it has
   1 [\da-f]{40} (re)
   
   $ hg qpush
   applying test.patch
   now at: test.patch
+  $ hg phase -r qbase
+  2: secret
   $ hg tags > /dev/null
 
 .hg/cache/tags (post qpush):
 
   $ cat .hg/cache/tags


More information about the Mercurial-devel mailing list