[PATCH 02 of 17 RFC] clfilter: introduce a `hassecret` function

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Mon Sep 3 07:58:26 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1346673919 -7200
# Node ID 123b6a0821ac10dfe7029f2952e631eac14a5a4b
# Parent  6fc61331ccf67395a7530361ce90cb308e663668
clfilter: introduce a `hassecret` function

We can only use copy clone if the cloned repo do not have any secret changeset.
The current method for that is to run the "secret()" revset on the remote repo.
But with proper filtering of hidden or unserved revision by the remote this
revset won't return any revision even if some exist remotely. This changeset
adds an explicit function to know if a repo have any secret revision or not.

The other option would be to disable filtering for the query but I prefer the
approach above, lighter both regarding code and performance.

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -8,11 +8,11 @@
 
 from i18n import _
 from lock import release
 from node import hex, nullid
 import localrepo, bundlerepo, httppeer, sshpeer, statichttprepo, bookmarks
-import lock, util, extensions, error, node, scmutil
+import lock, util, extensions, error, node, scmutil, phases
 import cmdutil, discovery
 import merge as mergemod
 import verify as verifymod
 import errno, os, shutil
 
@@ -301,11 +301,11 @@ def clone(ui, peeropts, source, dest=Non
         if islocal(dest):
             dircleanup = DirCleanup(dest)
 
         copy = False
         if (srcrepo and srcrepo.cancopy() and islocal(dest)
-            and not srcrepo.revs("secret()")):
+            and not phases.hassecret(srcrepo)):
             copy = not pull and not rev
 
         if copy:
             try:
                 # we use a lock here because if we race with commit, we
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -383,5 +383,8 @@ def newcommitphase(ui):
             return int(v)
         except ValueError:
             msg = _("phases.new-commit: not a valid phase name ('%s')")
             raise error.ConfigError(msg % v)
 
+def hassecret(repo):
+    """utility function that check if a repo have any secret changeset."""
+    return bool(repo._phasecache.phaseroots[2])


More information about the Mercurial-devel mailing list