# HG changeset patch # User Pierre-Yves David # Date 1434593997 25200 # Node ID 21a874693619d565277e8ddf3ff3842d05464c93 # Parent 5f87f2305ad05e6bf01f0a4973099e962203b953 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. diff -r 5f87f2305ad0 -r 21a874693619 mercurial/revset.py --- 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 """ + 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