changeset 25621:21a874693619

revset: refactor 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 refactor the code to only have one place to update (and make sure all behave properly). We do not refactor the 'public()' code because it does not have a natively computed set.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Wed, 17 Jun 2015 19:19:57 -0700
parents 5f87f2305ad0
children 85294076adce
files mercurial/revset.py
diffstat 1 files changed, 22 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Tue Jun 16 19:47:46 2015 -0700
+++ b/mercurial/revset.py	Wed Jun 17 19:19:57 2015 -0700
@@ -803,16 +803,6 @@
     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.
@@ -1472,6 +1462,28 @@
     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.
@@ -1730,16 +1742,6 @@
     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