[PATCH 2 of 3] revset: factor the non public phase code

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Jun 18 12:05:21 CDT 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1434593997 25200
#      Wed Jun 17 19:19:57 2015 -0700
# Node ID 77ad3d42d8fa78b13f19683512f913185a9d4fb9
# Parent  36571390de341e29fe38d0fe53d30016834d3afe
revset: factor the non public phase code

Code for draft and secret are the same. We'll make it more complex to take
advantages of the set recomputed in C, so we first factor the code to only have
one place to update (and make sure all behave properlies).

We do not factor the 'public()' code because it does not have a natively
computed set.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -801,20 +801,10 @@ def divergent(repo, subset, x):
     # i18n: "divergent" is a keyword
     getargs(x, 0, 0, _("divergent takes no arguments"))
     divergent = obsmod.getrevs(repo, 'divergent')
     return subset & divergent
 
-def draft(repo, subset, x):
-    """``draft()``
-    Changeset in draft phase."""
-    # i18n: "draft" is a keyword
-    getargs(x, 0, 0, _("draft takes no arguments"))
-    phase = repo._phasecache.phase
-    target = phases.draft
-    condition = lambda r: phase(repo, r) == target
-    return subset.filter(condition, cache=False)
-
 def extinct(repo, subset, x):
     """``extinct()``
     Obsolete changesets with obsolete descendants only.
     """
     # i18n: "extinct" is a keyword
@@ -1470,10 +1460,32 @@ def parents(repo, subset, x):
         for r in getset(repo, fullreposet(repo), x):
             ps.update(cl.parentrevs(r))
     ps -= set([node.nullrev])
     return subset & ps
 
+def _phase(repo, subset, target):
+    """helper to select all rev in phase <target>"""
+    phase = repo._phasecache.phase
+    condition = lambda r: phase(repo, r) == target
+    return subset.filter(condition, cache=False)
+
+def draft(repo, subset, x):
+    """``draft()``
+    Changeset in draft phase."""
+    # i18n: "draft" is a keyword
+    getargs(x, 0, 0, _("draft takes no arguments"))
+    target = phases.draft
+    return _phase(repo, subset, target)
+
+def secret(repo, subset, x):
+    """``secret()``
+    Changeset in secret phase."""
+    # i18n: "secret" is a keyword
+    getargs(x, 0, 0, _("secret takes no arguments"))
+    target = phases.secret
+    return _phase(repo, subset, target)
+
 def parentspec(repo, subset, x, n):
     """``set^0``
     The set.
     ``set^1`` (or ``set^``), ``set^2``
     First or second parent, respectively, of all changesets in set.
@@ -1728,20 +1740,10 @@ def roots(repo, subset, x):
     s = getset(repo, fullreposet(repo), x)
     subset = subset & s# baseset([r for r in s if r in subset])
     cs = _children(repo, subset, s)
     return subset - cs
 
-def secret(repo, subset, x):
-    """``secret()``
-    Changeset in secret phase."""
-    # i18n: "secret" is a keyword
-    getargs(x, 0, 0, _("secret takes no arguments"))
-    phase = repo._phasecache.phase
-    target = phases.secret
-    condition = lambda r: phase(repo, r) == target
-    return subset.filter(condition, cache=False)
-
 def sort(repo, subset, x):
     """``sort(set[, [-]key...])``
     Sort set by keys. The default sort order is ascending, specify a key
     as ``-key`` to sort in descending order.
 


More information about the Mercurial-devel mailing list