[PATCH 2 of 8 clfilter-part1] clfilter: introduce a `hassecret` function

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Thu Sep 20 12:12:09 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1346673919 -7200
# Node ID 6f6959da20332766c1a0150dc596ed5274efc09e
# Parent  6c1fb5e0f1e814d651b63cd22bfcaeaa2acdad89
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
@@ -386,5 +386,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