[PATCH 16 of 18] phases: add revset symbol
pierre-yves.david at logilab.fr
pierre-yves.david at logilab.fr
Mon Oct 10 12:28:12 UTC 2011
# HG changeset patch
# User Alain Leufroy <alain.leufroyATgmailMYDOTcom>
# Date 1318246170 -7200
# Node ID 848b4398797886463fdd314a00b37c009878313c
# Parent 6a618fa5bd845b46930e6ef7b66743492a7e17c2
phases: add revset symbol
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -1,8 +1,9 @@
# Mercurial phases support code
#
# Copyright 2011 Pierre-Yves David <pierre-yves.david at ens-lyon.org>
+# Alain Leufroy <alain.leufroy at gmail.com>
# Logilab SA <contact at logilab.fr>
# Augie Fackler <durin42 at gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -4,11 +4,11 @@
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
import re
-import parser, util, error, discovery, hbisect, node
+import parser, util, error, discovery, hbisect, node, phases
import bookmarks as bookmarksmod
import match as matchmod
from i18n import _
elements = {
@@ -708,10 +708,54 @@ def parentspec(repo, subset, x, n):
parents = cl.parentrevs(r)
if len(parents) > 1:
ps.add(parents[1])
return [r for r in subset if r in ps]
+def phase(repo, subset, x):
+ """phase(num, [set])
+
+ The set of all changesets in set that has a phase to num.
+
+ * num is a number or a range:
+
+ ``phase(1)`` => all changesets that are in phase 1
+ ``phase(:1, :15)`` => changetsets that have a phase up to 1
+ with a rev up to 15
+
+ """
+ args = getargs(x, 1, 2, 'phase takes one or two arguments')
+
+ phase_args = args[0]
+ if phase_args[0] not in ('symbol', 'range'):
+ raise error.ParseError(
+ _("phase expects a number or range as first argument."))
+ if phase_args[0] == 'symbol':
+ if not phase_args[1].isdigit():
+ raise error.ParseError(
+ _("phase expects a number or range as first argument."))
+ ps = [int(phase_args[1])]
+ else:
+ try:
+ start, end = phase_args[1][1], phase_args[2][1]
+ start = int(start)
+ end = int(len(phases.allphases)) if end == 'tip' else int(end) + 1
+ ps = range(start, end)
+ except ValueError, TypeError:
+ raise error.ParseError(
+ _("phase expects a number or range as first argument."))
+
+ if not set(ps).issubset(set(phases.allphases)):
+ raise error.ParseError(
+ _("first argument of phase must be a subrange of %d...%d"
+ % (min(phases.allphases), max(phases.allphases))))
+
+ if subset is None:
+ subset = range(len(repo))
+ if len(args) == 2:
+ subset = getset(repo, subset, args[1])
+ return [r for r in reversed(subset) if repo._phasesrev.get(r, phases.allphases[-1]) in ps]
+
def present(repo, subset, x):
"""``present(set)``
An empty set, if any revision in set isn't found; otherwise,
all revisions in set.
"""
@@ -873,10 +917,11 @@ symbols = {
"modifies": modifies,
"outgoing": outgoing,
"p1": p1,
"p2": p2,
"parents": parents,
+ "phase": phase,
"present": present,
"removes": removes,
"rev": rev,
"reverse": reverse,
"roots": roots,
diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -81,10 +81,11 @@ Simpliest test: change the phase of the
2 0 C
1 0 B
0 0 A
Test creating changeset as secret
+---------------------------------
$ mkcommit H --secret
$ hglog
7 2 H
6 1 G
@@ -137,10 +138,73 @@ check secret changeset are not pulled
pulling from ../initialrepo
searching for changes
no changes found
+Revset symbol
+-------------
+ $ cd ../initialrepo
+ $ hg phase -p1 -r7
+ $ hglog
+ 8 2 I
+ 7 1 H
+ 6 0 G
+ 5 0 F
+ 4 0 E
+ 3 0 D
+ 2 0 C
+ 1 0 B
+ 0 0 A
+Revset symbol allow to get revision that are under a particular phase.
+The ``phase`` symbol takes almost 2 arguments.
+:phase: the requested phase
+:set: a revision set to filter depending to the given phase
+Giving no argument raises an error
+ $ hg log -r 'phase()'
+ hg: parse error: phase takes one or two arguments
+ [255]
+
+The first argument shall be a phase:
+
+ $ hg log -r 'phase(alain)'
+ hg: parse error: phase expects a number or range as first argument.
+ [255]
+ $ hg log -r 'phase(255)'
+ hg: parse error: first argument of phase must be a subrange of 0...2
+ [255]
+
+With only the first argument, phase returns any revision under the requested phase
+ $ hglog -r 'phase(0)'
+ 6 0 G
+ 5 0 F
+ 4 0 E
+ 3 0 D
+ 2 0 C
+ 1 0 B
+ 0 0 A
+
+With only the first argument, phase returns any revision under the requested phase
+ $ hglog -r 'phase(0, 3:)'
+ 6 0 G
+ 5 0 F
+ 4 0 E
+ 3 0 D
+ $ hglog -r 'phase(1, 3:8)'
+ 7 1 H
+ $ hglog -r 'phase(2)'
+ 8 2 I
+
+It is also possible to specify a range as phase:
+ $ hglog -r 'phase(:1, 5:8)'
+ 7 1 H
+ 6 0 G
+ 5 0 F
+
+ $ hglog -r 'phase(1:, 3:8)'
+ 8 2 I
+ 7 1 H
+
More information about the Mercurial-devel
mailing list