mercurial/revset.py
author Lucas Moscovicz <lmoscovicz@fb.com>
Thu, 06 Feb 2014 17:18:11 -0800
changeset 20610 34bb07e70c68
parent 20609 56ecc82fcd67
child 20611 6490f8385391
permissions -rw-r--r--
revset: added filter method to revset classes This method will replace the creation of lazysets inside the revset methods. Instead, the classes that handle lazy structures will create them based on their current order.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
# revset.py - revision set queries for mercurial
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
#
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
# Copyright 2010 Matt Mackall <mpm@selenic.com>
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
#
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     7
16834
cafd8a8fb713 util: subclass deque for Python 2.4 backwards compatibility
Bryan O'Sullivan <bryano@fb.com>
parents: 16825
diff changeset
     8
import re
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
     9
import parser, util, error, discovery, hbisect, phases
16417
b4b0c6931e11 revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents: 16415
diff changeset
    10
import node
12085
6f833fc3ccab Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents: 11944
diff changeset
    11
import match as matchmod
13593
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 13506
diff changeset
    12
from i18n import _
15726
9b822edecb4c i18n: use "encoding.lower()" to normalize specified string for revset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15596
diff changeset
    13
import encoding
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17424
diff changeset
    14
import obsolete as obsmod
20286
760151697a4f revset: make default kind of pattern for "contains()" rooted at cwd
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20285
diff changeset
    15
import pathutil
18251
a6483f827512 revset: retrieve hidden from filteredrevs
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18071
diff changeset
    16
import repoview
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    17
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    18
def _revancestors(repo, revs, followfirst):
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    19
    """Like revlog.ancestors(), but supports followfirst."""
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    20
    cut = followfirst and 1 or None
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    21
    cl = repo.changelog
16834
cafd8a8fb713 util: subclass deque for Python 2.4 backwards compatibility
Bryan O'Sullivan <bryano@fb.com>
parents: 16825
diff changeset
    22
    visit = util.deque(revs)
16417
b4b0c6931e11 revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents: 16415
diff changeset
    23
    seen = set([node.nullrev])
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    24
    while visit:
16803
107a3270a24a cleanup: use the deque type where appropriate
Bryan O'Sullivan <bryano@fb.com>
parents: 16778
diff changeset
    25
        for parent in cl.parentrevs(visit.popleft())[:cut]:
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    26
            if parent not in seen:
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    27
                visit.append(parent)
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    28
                seen.add(parent)
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    29
                yield parent
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    30
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    31
def _revdescendants(repo, revs, followfirst):
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    32
    """Like revlog.descendants() but supports followfirst."""
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    33
    cut = followfirst and 1 or None
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    34
    cl = repo.changelog
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    35
    first = min(revs)
16417
b4b0c6931e11 revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents: 16415
diff changeset
    36
    nullrev = node.nullrev
b4b0c6931e11 revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents: 16415
diff changeset
    37
    if first == nullrev:
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    38
        # Are there nodes with a null first parent and a non-null
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    39
        # second one? Maybe. Do we care? Probably not.
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    40
        for i in cl:
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    41
            yield i
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    42
        return
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    43
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    44
    seen = set(revs)
17804
5a511d255301 clfilter: remove use of xrange in revset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17786
diff changeset
    45
    for i in cl.revs(first + 1):
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    46
        for x in cl.parentrevs(i)[:cut]:
16417
b4b0c6931e11 revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents: 16415
diff changeset
    47
            if x != nullrev and x in seen:
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    48
                seen.add(i)
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    49
                yield i
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    50
                break
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
    51
16862
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    52
def _revsbetween(repo, roots, heads):
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    53
    """Return all paths between roots and heads, inclusive of both endpoint
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    54
    sets."""
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    55
    if not roots:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
    56
        return baseset([])
16862
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    57
    parentrevs = repo.changelog.parentrevs
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
    58
    visit = baseset(heads)
16862
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    59
    reachable = set()
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    60
    seen = {}
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    61
    minroot = min(roots)
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    62
    roots = set(roots)
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    63
    # open-code the post-order traversal due to the tiny size of
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    64
    # sys.getrecursionlimit()
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    65
    while visit:
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    66
        rev = visit.pop()
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    67
        if rev in roots:
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    68
            reachable.add(rev)
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    69
        parents = parentrevs(rev)
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    70
        seen[rev] = parents
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    71
        for parent in parents:
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    72
            if parent >= minroot and parent not in seen:
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    73
                visit.append(parent)
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    74
    if not reachable:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
    75
        return baseset([])
16862
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    76
    for rev in sorted(seen):
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    77
        for parent in seen[rev]:
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    78
            if parent in reachable:
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    79
                reachable.add(rev)
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
    80
    return baseset(sorted(reachable))
16862
b6efeb27e733 revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents: 16861
diff changeset
    81
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    82
elements = {
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    83
    "(": (20, ("group", 1, ")"), ("func", 1, ")")),
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
    84
    "~": (18, None, ("ancestor", 18)),
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
    85
    "^": (18, None, ("parent", 18), ("parentpost", 18)),
12616
e797fdf91df4 revset: lower precedence of minus infix (issue2361)
Matt Mackall <mpm@selenic.com>
parents: 12615
diff changeset
    86
    "-": (5, ("negate", 19), ("minus", 5)),
11278
7df88cdf47fd revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents: 11275
diff changeset
    87
    "::": (17, ("dagrangepre", 17), ("dagrange", 17),
7df88cdf47fd revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents: 11275
diff changeset
    88
           ("dagrangepost", 17)),
7df88cdf47fd revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents: 11275
diff changeset
    89
    "..": (17, ("dagrangepre", 17), ("dagrange", 17),
7df88cdf47fd revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents: 11275
diff changeset
    90
           ("dagrangepost", 17)),
7df88cdf47fd revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents: 11275
diff changeset
    91
    ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    92
    "not": (10, ("not", 10)),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    93
    "!": (10, ("not", 10)),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    94
    "and": (5, None, ("and", 5)),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    95
    "&": (5, None, ("and", 5)),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    96
    "or": (4, None, ("or", 4)),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    97
    "|": (4, None, ("or", 4)),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    98
    "+": (4, None, ("or", 4)),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    99
    ",": (2, None, ("list", 2)),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   100
    ")": (0, None, None),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   101
    "symbol": (0, ("symbol",), None),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   102
    "string": (0, ("string",), None),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   103
    "end": (0, None, None),
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   104
}
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   105
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   106
keywords = set(['and', 'or', 'not'])
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   107
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   108
def tokenize(program):
17886
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   109
    '''
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   110
    Parse a revset statement into a stream of tokens
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   111
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   112
    Check that @ is a valid unquoted token character (issue3686):
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   113
    >>> list(tokenize("@::"))
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   114
    [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)]
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   115
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   116
    '''
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   117
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   118
    pos, l = 0, len(program)
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   119
    while pos < l:
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   120
        c = program[pos]
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   121
        if c.isspace(): # skip inter-token whitespace
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   122
            pass
11278
7df88cdf47fd revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents: 11275
diff changeset
   123
        elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
11289
4215ce511134 revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents: 11284
diff changeset
   124
            yield ('::', None, pos)
11278
7df88cdf47fd revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents: 11275
diff changeset
   125
            pos += 1 # skip ahead
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   126
        elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully
11289
4215ce511134 revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents: 11284
diff changeset
   127
            yield ('..', None, pos)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   128
            pos += 1 # skip ahead
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   129
        elif c in "():,-|&+!~^": # handle simple operators
11289
4215ce511134 revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents: 11284
diff changeset
   130
            yield (c, None, pos)
12408
78a97859b90d revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents: 12401
diff changeset
   131
        elif (c in '"\'' or c == 'r' and
78a97859b90d revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents: 12401
diff changeset
   132
              program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
78a97859b90d revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents: 12401
diff changeset
   133
            if c == 'r':
78a97859b90d revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents: 12401
diff changeset
   134
                pos += 1
78a97859b90d revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents: 12401
diff changeset
   135
                c = program[pos]
78a97859b90d revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents: 12401
diff changeset
   136
                decode = lambda x: x
78a97859b90d revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents: 12401
diff changeset
   137
            else:
78a97859b90d revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents: 12401
diff changeset
   138
                decode = lambda x: x.decode('string-escape')
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   139
            pos += 1
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   140
            s = pos
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   141
            while pos < l: # find closing quote
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   142
                d = program[pos]
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   143
                if d == '\\': # skip over escaped characters
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   144
                    pos += 2
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   145
                    continue
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   146
                if d == c:
12408
78a97859b90d revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents: 12401
diff changeset
   147
                    yield ('string', decode(program[s:pos]), s)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   148
                    break
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   149
                pos += 1
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   150
            else:
11383
de544774ebea revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents: 11349
diff changeset
   151
                raise error.ParseError(_("unterminated string"), s)
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16661
diff changeset
   152
        # gather up a symbol/keyword
17886
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   153
        elif c.isalnum() or c in '._@' or ord(c) > 127:
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   154
            s = pos
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   155
            pos += 1
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   156
            while pos < l: # find end of symbol
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   157
                d = program[pos]
17886
d8905e2c1301 revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents: 17829
diff changeset
   158
                if not (d.isalnum() or d in "._/@" or ord(d) > 127):
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   159
                    break
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   160
                if d == '.' and program[pos - 1] == '.': # special case for ..
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   161
                    pos -= 1
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   162
                    break
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   163
                pos += 1
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   164
            sym = program[s:pos]
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   165
            if sym in keywords: # operator keywords
11289
4215ce511134 revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents: 11284
diff changeset
   166
                yield (sym, None, s)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   167
            else:
11289
4215ce511134 revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents: 11284
diff changeset
   168
                yield ('symbol', sym, s)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   169
            pos -= 1
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   170
        else:
11383
de544774ebea revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents: 11349
diff changeset
   171
            raise error.ParseError(_("syntax error"), pos)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   172
        pos += 1
11289
4215ce511134 revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents: 11284
diff changeset
   173
    yield ('end', None, pos)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   174
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   175
# helpers
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   176
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   177
def getstring(x, err):
11406
42408cd43f55 revset: fix up contains/getstring when no args passed
Matt Mackall <mpm@selenic.com>
parents: 11404
diff changeset
   178
    if x and (x[0] == 'string' or x[0] == 'symbol'):
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   179
        return x[1]
11289
4215ce511134 revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents: 11284
diff changeset
   180
    raise error.ParseError(err)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   181
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   182
def getlist(x):
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   183
    if not x:
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   184
        return []
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   185
    if x[0] == 'list':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   186
        return getlist(x[1]) + [x[2]]
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   187
    return [x]
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   188
11339
744d5b73f776 revset: improve filter argument handling
Matt Mackall <mpm@selenic.com>
parents: 11304
diff changeset
   189
def getargs(x, min, max, err):
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   190
    l = getlist(x)
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   191
    if len(l) < min or (max >= 0 and len(l) > max):
11289
4215ce511134 revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents: 11284
diff changeset
   192
        raise error.ParseError(err)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   193
    return l
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   194
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   195
def getset(repo, subset, x):
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   196
    if not x:
11383
de544774ebea revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents: 11349
diff changeset
   197
        raise error.ParseError(_("missing argument"))
20527
bde426f18e0a revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20526
diff changeset
   198
    s = methods[x[0]](repo, subset, *x[1:])
bde426f18e0a revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20526
diff changeset
   199
    if util.safehasattr(s, 'set'):
bde426f18e0a revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20526
diff changeset
   200
        return s
bde426f18e0a revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20526
diff changeset
   201
    return baseset(s)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   202
17003
42c472877825 revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17002
diff changeset
   203
def _getrevsource(repo, r):
42c472877825 revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17002
diff changeset
   204
    extra = repo[r].extra()
42c472877825 revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17002
diff changeset
   205
    for label in ('source', 'transplant_source', 'rebase_source'):
42c472877825 revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17002
diff changeset
   206
        if label in extra:
42c472877825 revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17002
diff changeset
   207
            try:
42c472877825 revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17002
diff changeset
   208
                return repo[extra[label]].rev()
42c472877825 revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17002
diff changeset
   209
            except error.RepoLookupError:
42c472877825 revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17002
diff changeset
   210
                pass
42c472877825 revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17002
diff changeset
   211
    return None
42c472877825 revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 17002
diff changeset
   212
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   213
# operator methods
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   214
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   215
def stringset(repo, subset, x):
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   216
    x = repo[x].rev()
11282
e581f3acc338 revset: fix up tests
Matt Mackall <mpm@selenic.com>
parents: 11280
diff changeset
   217
    if x == -1 and len(subset) == len(repo):
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   218
        return baseset([-1])
13938
e44ebd2a142a revset: optimize stringset when subset == entire repo
Idan Kamara <idankk86@gmail.com>
parents: 13932
diff changeset
   219
    if len(subset) == len(repo) or x in subset:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   220
        return baseset([x])
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   221
    return baseset([])
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   222
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   223
def symbolset(repo, subset, x):
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   224
    if x in symbols:
11383
de544774ebea revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents: 11349
diff changeset
   225
        raise error.ParseError(_("can't use %s here") % x)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   226
    return stringset(repo, subset, x)
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   227
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   228
def rangeset(repo, subset, x, y):
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   229
    cl = baseset(repo.changelog)
18473
692cbda1eb50 revset: evaluate sub expressions correctly (issue3775)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18411
diff changeset
   230
    m = getset(repo, cl, x)
692cbda1eb50 revset: evaluate sub expressions correctly (issue3775)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18411
diff changeset
   231
    n = getset(repo, cl, y)
11456
88abbb046e66 revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents: 11446
diff changeset
   232
88abbb046e66 revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents: 11446
diff changeset
   233
    if not m or not n:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   234
        return baseset([])
11456
88abbb046e66 revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents: 11446
diff changeset
   235
    m, n = m[0], n[-1]
88abbb046e66 revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents: 11446
diff changeset
   236
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   237
    if m < n:
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   238
        r = spanset(repo, m, n + 1)
11456
88abbb046e66 revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents: 11446
diff changeset
   239
    else:
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   240
        r = spanset(repo, m, n - 1)
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   241
    return r & subset
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   242
16860
e1aa1ed30030 revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents: 16859
diff changeset
   243
def dagrange(repo, subset, x, y):
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   244
    r = spanset(repo)
18991
c1af1fb314bc log: fix behavior with empty repositories (issue3497)
Alexander Plavin <me@aplavin.ru>
parents: 18779
diff changeset
   245
    xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
20365
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
   246
    s = subset.set()
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   247
    return baseset([r for r in xs if r in s])
16860
e1aa1ed30030 revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents: 16859
diff changeset
   248
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   249
def andset(repo, subset, x, y):
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   250
    return getset(repo, getset(repo, subset, x), y)
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   251
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   252
def orset(repo, subset, x, y):
13932
34f577007ffe revsets: preserve ordering with the or operator
Augie Fackler <durin42@gmail.com>
parents: 13915
diff changeset
   253
    xl = getset(repo, subset, x)
20366
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
   254
    yl = getset(repo, subset - xl, y)
20418
454c143b9955 revset: minor changes adding baseset to revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20417
diff changeset
   255
    return xl + yl
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   256
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   257
def notset(repo, subset, x):
20366
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
   258
    return subset - getset(repo, subset, x)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   259
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   260
def listset(repo, subset, a, b):
11383
de544774ebea revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents: 11349
diff changeset
   261
    raise error.ParseError(_("can't use a list in this context"))
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   262
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   263
def func(repo, subset, a, b):
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   264
    if a[0] == 'symbol' and a[1] in symbols:
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   265
        return symbols[a[1]](repo, subset, b)
11383
de544774ebea revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents: 11349
diff changeset
   266
    raise error.ParseError(_("not a function: %s") % a[1])
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   267
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   268
# functions
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   269
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   270
def adds(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   271
    """``adds(pattern)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   272
    Changesets that add a file matching pattern.
20289
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   273
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   274
    The pattern without explicit kind like ``glob:`` is expected to be
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   275
    relative to the current directory and match against a file or a
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   276
    directory.
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   277
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   278
    # i18n: "adds" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   279
    pat = getstring(x, _("adds requires a pattern"))
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   280
    return checkstatus(repo, subset, pat, 1)
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   281
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   282
def ancestor(repo, subset, x):
18536
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   283
    """``ancestor(*changeset)``
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   284
    Greatest common ancestor of the changesets.
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   285
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   286
    Accepts 0 or more changesets.
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   287
    Will return empty list when passed no args.
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   288
    Greatest common ancestor of a single changeset is that changeset.
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   289
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   290
    # i18n: "ancestor" is a keyword
18536
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   291
    l = getlist(x)
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   292
    rl = spanset(repo)
18536
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   293
    anc = None
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   294
18536
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   295
    # (getset(repo, rl, i) for i in l) generates a list of lists
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   296
    rev = repo.changelog.rev
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   297
    ancestor = repo.changelog.ancestor
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   298
    node = repo.changelog.node
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   299
    for revs in (getset(repo, rl, i) for i in l):
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   300
        for r in revs:
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   301
            if anc is None:
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   302
                anc = r
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   303
            else:
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   304
                anc = rev(ancestor(node(anc), node(r)))
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   305
ae645d4f084c revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents: 18495
diff changeset
   306
    if anc is not None and anc in subset:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   307
        return baseset([anc])
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   308
    return baseset([])
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   309
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   310
def _ancestors(repo, subset, x, followfirst=False):
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   311
    args = getset(repo, spanset(repo), x)
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   312
    if not args:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   313
        return baseset([])
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   314
    s = set(_revancestors(repo, args, followfirst)) | set(args)
20393
b0638b5b004d revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20367
diff changeset
   315
    return baseset([r for r in subset if r in s])
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   316
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   317
def ancestors(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   318
    """``ancestors(set)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   319
    Changesets that are ancestors of a changeset in set.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   320
    """
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   321
    return _ancestors(repo, subset, x)
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   322
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   323
def _firstancestors(repo, subset, x):
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   324
    # ``_firstancestors(set)``
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   325
    # Like ``ancestors(set)`` but follows only the first parents.
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   326
    return _ancestors(repo, subset, x, followfirst=True)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   327
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   328
def ancestorspec(repo, subset, x, n):
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   329
    """``set~n``
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16661
diff changeset
   330
    Changesets that are the Nth ancestor (first parents only) of a changeset
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16661
diff changeset
   331
    in set.
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   332
    """
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   333
    try:
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   334
        n = int(n[1])
14851
f96c354493d7 revsets: actually catch type error on tip^p1(tip) (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14842
diff changeset
   335
    except (TypeError, ValueError):
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   336
        raise error.ParseError(_("~ expects a number"))
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   337
    ps = set()
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   338
    cl = repo.changelog
20424
1da346bad3d8 revset: minor changes adding baseset to revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20418
diff changeset
   339
    for r in getset(repo, baseset(cl), x):
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   340
        for i in range(n):
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   341
            r = cl.parentrevs(r)[0]
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   342
        ps.add(r)
20393
b0638b5b004d revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20367
diff changeset
   343
    return baseset([r for r in subset if r in ps])
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
   344
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   345
def author(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   346
    """``author(string)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   347
    Alias for ``user(string)``.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   348
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   349
    # i18n: "author" is a keyword
15726
9b822edecb4c i18n: use "encoding.lower()" to normalize specified string for revset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15596
diff changeset
   350
    n = encoding.lower(getstring(x, _("author requires a string")))
16823
b23bacb230c9 revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents: 16822
diff changeset
   351
    kind, pattern, matcher = _substringmatcher(n)
20448
92f6f2db3cf4 revset: added lazyset implementation to author revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20447
diff changeset
   352
    return lazyset(subset, lambda x: matcher(encoding.lower(repo[x].user())))
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   353
15134
81adf7777f8f revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15133
diff changeset
   354
def bisect(repo, subset, x):
81adf7777f8f revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15133
diff changeset
   355
    """``bisect(string)``
15153
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   356
    Changesets marked in the specified bisect status:
15136
18219c0789ae revset.bisect: add new 'range' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15135
diff changeset
   357
15153
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   358
    - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17390
diff changeset
   359
    - ``goods``, ``bads``      : csets topologically good/bad
15153
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   360
    - ``range``              : csets taking part in the bisection
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   361
    - ``pruned``             : csets that are goods, bads or skipped
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   362
    - ``untested``           : csets whose fate is yet unknown
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   363
    - ``ignored``            : csets ignored due to DAG topology
16647
14913fcb30c6 bisect: track the current changeset (issue3382)
Bryan O'Sullivan <bryano@fb.com>
parents: 16640
diff changeset
   364
    - ``current``            : the cset currently being bisected
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   365
    """
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   366
    # i18n: "bisect" is a keyword
15135
f19de58af225 revset.bisect: move bisect() code to hbisect.py
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15134
diff changeset
   367
    status = getstring(x, _("bisect requires a string")).lower()
16467
7f59900e3f8b revset: fix O(n**2) behaviour of bisect() (issue3381)
Bryan O'Sullivan <bryano@fb.com>
parents: 16453
diff changeset
   368
    state = set(hbisect.get(repo, status))
20393
b0638b5b004d revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20367
diff changeset
   369
    return baseset([r for r in subset if r in state])
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   370
15134
81adf7777f8f revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15133
diff changeset
   371
# Backward-compatibility
81adf7777f8f revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15133
diff changeset
   372
# - no help entry so that we do not advertise it any more
81adf7777f8f revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15133
diff changeset
   373
def bisected(repo, subset, x):
81adf7777f8f revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15133
diff changeset
   374
    return bisect(repo, subset, x)
81adf7777f8f revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15133
diff changeset
   375
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   376
def bookmark(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   377
    """``bookmark([name])``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   378
    The named bookmark or all bookmarks.
16822
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   379
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   380
    If `name` starts with `re:`, the remainder of the name is treated as
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   381
    a regular expression. To match a bookmark that actually starts with `re:`,
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   382
    use the prefix `literal:`.
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   383
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   384
    # i18n: "bookmark" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   385
    args = getargs(x, 0, 1, _('bookmark takes one or no arguments'))
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   386
    if args:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   387
        bm = getstring(args[0],
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   388
                       # i18n: "bookmark" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   389
                       _('the argument to bookmark must be a string'))
16822
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   390
        kind, pattern, matcher = _stringmatcher(bm)
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   391
        if kind == 'literal':
18495
8260fa9f30b9 bookmarks: don't use bookmarks.listbookmarks in local computations
Kevin Bullock <kbullock@ringworld.org>
parents: 18473
diff changeset
   392
            bmrev = repo._bookmarks.get(bm, None)
16822
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   393
            if not bmrev:
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   394
                raise util.Abort(_("bookmark '%s' does not exist") % bm)
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   395
            bmrev = repo[bmrev].rev()
20450
4f1aed2c7a7e revset: added lazyset implementation bookmark revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20449
diff changeset
   396
            return lazyset(subset, lambda r: r == bmrev)
16822
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   397
        else:
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   398
            matchrevs = set()
18495
8260fa9f30b9 bookmarks: don't use bookmarks.listbookmarks in local computations
Kevin Bullock <kbullock@ringworld.org>
parents: 18473
diff changeset
   399
            for name, bmrev in repo._bookmarks.iteritems():
16822
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   400
                if matcher(name):
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   401
                    matchrevs.add(bmrev)
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   402
            if not matchrevs:
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   403
                raise util.Abort(_("no bookmarks exist that match '%s'")
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   404
                                 % pattern)
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   405
            bmrevs = set()
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   406
            for bmrev in matchrevs:
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   407
                bmrevs.add(repo[bmrev].rev())
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
   408
            return subset & bmrevs
16822
da55d8a77390 revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents: 16821
diff changeset
   409
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   410
    bms = set([repo[r].rev()
18495
8260fa9f30b9 bookmarks: don't use bookmarks.listbookmarks in local computations
Kevin Bullock <kbullock@ringworld.org>
parents: 18473
diff changeset
   411
               for r in repo._bookmarks.values()])
20450
4f1aed2c7a7e revset: added lazyset implementation bookmark revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20449
diff changeset
   412
    return lazyset(subset, lambda r: r in bms)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   413
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   414
def branch(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   415
    """``branch(string or set)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   416
    All changesets belonging to the given branch or the branches of the given
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   417
    changesets.
16821
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   418
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   419
    If `string` starts with `re:`, the remainder of the name is treated as
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   420
    a regular expression. To match a branch that actually starts with `re:`,
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   421
    use the prefix `literal:`.
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   422
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   423
    try:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   424
        b = getstring(x, '')
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   425
    except error.ParseError:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   426
        # not a string, but another revspec, e.g. tip()
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   427
        pass
16821
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   428
    else:
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   429
        kind, pattern, matcher = _stringmatcher(b)
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   430
        if kind == 'literal':
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   431
            # note: falls through to the revspec case if no branch with
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   432
            # this name exists
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   433
            if pattern in repo.branchmap():
20445
507261c0914f revset: added lazyset implementation to branch revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20443
diff changeset
   434
                return lazyset(subset, lambda r: matcher(repo[r].branch()))
16821
0946502fd3d5 revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents: 16820
diff changeset
   435
        else:
20445
507261c0914f revset: added lazyset implementation to branch revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20443
diff changeset
   436
            return lazyset(subset, lambda r: matcher(repo[r].branch()))
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   437
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   438
    s = getset(repo, spanset(repo), x)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   439
    b = set()
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   440
    for r in s:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   441
        b.add(repo[r].branch())
20365
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
   442
    s = s.set()
20445
507261c0914f revset: added lazyset implementation to branch revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20443
diff changeset
   443
    return lazyset(subset, lambda r: r in s or repo[r].branch() in b)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   444
17829
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   445
def bumped(repo, subset, x):
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   446
    """``bumped()``
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   447
    Mutable changesets marked as successors of public changesets.
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   448
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   449
    Only non-public and non-obsolete changesets can be `bumped`.
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   450
    """
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   451
    # i18n: "bumped" is a keyword
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   452
    getargs(x, 0, 0, _("bumped takes no arguments"))
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   453
    bumped = obsmod.getrevs(repo, 'bumped')
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
   454
    return subset & bumped
17829
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   455
17913
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
   456
def bundle(repo, subset, x):
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
   457
    """``bundle()``
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
   458
    Changesets in the bundle.
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
   459
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
   460
    Bundle must be specified by the -R option."""
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
   461
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
   462
    try:
18411
8b0f0dd56cec bundlerepo: improve performance for bundle() revset expression
Mads Kiilerich <madski@unity3d.com>
parents: 18382
diff changeset
   463
        bundlerevs = repo.changelog.bundlerevs
17913
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
   464
    except AttributeError:
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
   465
        raise util.Abort(_("no bundle provided - specify with -R"))
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
   466
    return subset & bundlerevs
17913
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
   467
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   468
def checkstatus(repo, subset, pat, field):
16521
592701c8eac6 revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents: 16467
diff changeset
   469
    hasset = matchmod.patkind(pat) == 'set'
20457
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   470
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   471
    def matches(x):
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   472
        m = None
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   473
        fname = None
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   474
        c = repo[x]
16521
592701c8eac6 revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents: 16467
diff changeset
   475
        if not m or hasset:
592701c8eac6 revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents: 16467
diff changeset
   476
            m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
592701c8eac6 revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents: 16467
diff changeset
   477
            if not m.anypats() and len(m.files()) == 1:
592701c8eac6 revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents: 16467
diff changeset
   478
                fname = m.files()[0]
592701c8eac6 revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents: 16467
diff changeset
   479
        if fname is not None:
592701c8eac6 revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents: 16467
diff changeset
   480
            if fname not in c.files():
20457
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   481
                return False
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   482
        else:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   483
            for f in c.files():
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   484
                if m(f):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   485
                    break
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   486
            else:
20457
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   487
                return False
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   488
        files = repo.status(c.p1().node(), c.node())[field]
16521
592701c8eac6 revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents: 16467
diff changeset
   489
        if fname is not None:
592701c8eac6 revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents: 16467
diff changeset
   490
            if fname in files:
20457
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   491
                return True
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   492
        else:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   493
            for f in files:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   494
                if m(f):
20457
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   495
                    return True
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   496
ed7b674824a3 revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20456
diff changeset
   497
    return lazyset(subset, matches)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   498
16396
03e408a122c4 revset: avoid set duplication in roots()
Patrick Mezard <patrick@mezard.eu>
parents: 16395
diff changeset
   499
def _children(repo, narrow, parentset):
15899
476a981fdf34 revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents: 15898
diff changeset
   500
    cs = set()
18063
34a1a639d835 revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents: 17980
diff changeset
   501
    if not parentset:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   502
        return baseset(cs)
15899
476a981fdf34 revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents: 15898
diff changeset
   503
    pr = repo.changelog.parentrevs
18063
34a1a639d835 revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents: 17980
diff changeset
   504
    minrev = min(parentset)
16394
f3df7d34791e revset: do not ignore input revisions in roots()
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
   505
    for r in narrow:
18063
34a1a639d835 revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents: 17980
diff changeset
   506
        if r <= minrev:
34a1a639d835 revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents: 17980
diff changeset
   507
            continue
15899
476a981fdf34 revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents: 15898
diff changeset
   508
        for p in pr(r):
16396
03e408a122c4 revset: avoid set duplication in roots()
Patrick Mezard <patrick@mezard.eu>
parents: 16395
diff changeset
   509
            if p in parentset:
15899
476a981fdf34 revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents: 15898
diff changeset
   510
                cs.add(r)
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   511
    return baseset(cs)
15899
476a981fdf34 revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents: 15898
diff changeset
   512
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   513
def children(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   514
    """``children(set)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   515
    Child changesets of changesets in set.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   516
    """
20365
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
   517
    s = getset(repo, baseset(repo), x).set()
15899
476a981fdf34 revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents: 15898
diff changeset
   518
    cs = _children(repo, subset, s)
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
   519
    return subset & cs
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   520
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   521
def closed(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   522
    """``closed()``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   523
    Changeset is closed.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   524
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   525
    # i18n: "closed" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   526
    getargs(x, 0, 0, _("closed takes no arguments"))
20479
c38e5556d87b revset: added lazyset implementation to closed revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20461
diff changeset
   527
    return lazyset(subset, lambda r: repo[r].closesbranch())
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   528
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   529
def contains(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   530
    """``contains(pattern)``
14357
cb4ff8ef466b merge with stable
Martin Geisler <mg@aragost.com>
parents: 14343 14356
diff changeset
   531
    Revision contains a file matching pattern. See :hg:`help patterns`
cb4ff8ef466b merge with stable
Martin Geisler <mg@aragost.com>
parents: 14343 14356
diff changeset
   532
    for information about file patterns.
20289
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   533
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   534
    The pattern without explicit kind like ``glob:`` is expected to be
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   535
    relative to the current directory and match against a file exactly
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   536
    for efficiency.
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   537
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   538
    # i18n: "contains" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   539
    pat = getstring(x, _("contains requires a pattern"))
20461
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   540
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   541
    def matches(x):
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   542
        if not matchmod.patkind(pat):
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   543
            pats = pathutil.canonpath(repo.root, repo.getcwd(), pat)
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   544
            if pats in repo[x]:
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   545
                return True
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   546
        else:
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   547
            c = repo[x]
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   548
            m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
15964
6e37b8282aa2 revsets: provide contexts for filesets
Matt Mackall <mpm@selenic.com>
parents: 15949
diff changeset
   549
            for f in c.manifest():
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   550
                if m(f):
20461
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   551
                    return True
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   552
        return False
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   553
abd8e56a1038 revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20460
diff changeset
   554
    return lazyset(subset, matches)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   555
17002
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   556
def converted(repo, subset, x):
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   557
    """``converted([id])``
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   558
    Changesets converted from the given identifier in the old repository if
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   559
    present, or all converted changesets if no identifier is specified.
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   560
    """
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   561
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   562
    # There is exactly no chance of resolving the revision, so do a simple
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   563
    # string compare and hope for the best
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   564
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   565
    rev = None
17002
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   566
    # i18n: "converted" is a keyword
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   567
    l = getargs(x, 0, 1, _('converted takes one or no arguments'))
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   568
    if l:
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   569
        # i18n: "converted" is a keyword
17002
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   570
        rev = getstring(l[0], _('converted requires a revision'))
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   571
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   572
    def _matchvalue(r):
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   573
        source = repo[r].extra().get('convert_revision', None)
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   574
        return source is not None and (rev is None or source.startswith(rev))
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   575
20480
ada89e5b5b0c revset: added lazyset implementation to converted revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20479
diff changeset
   576
    return lazyset(subset, lambda r: _matchvalue(r))
17002
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
   577
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   578
def date(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   579
    """``date(interval)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   580
    Changesets within the interval, see :hg:`help dates`.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   581
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   582
    # i18n: "date" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   583
    ds = getstring(x, _("date requires a string"))
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   584
    dm = util.matchdate(ds)
20449
ad2f1512eaa6 revset: added lazyset implementation to date revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20448
diff changeset
   585
    return lazyset(subset, lambda x: dm(repo[x].date()[0]))
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   586
14650
93731b3efd0d revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14649
diff changeset
   587
def desc(repo, subset, x):
93731b3efd0d revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14649
diff changeset
   588
    """``desc(string)``
93731b3efd0d revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14649
diff changeset
   589
    Search commit message for string. The match is case-insensitive.
93731b3efd0d revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14649
diff changeset
   590
    """
93731b3efd0d revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14649
diff changeset
   591
    # i18n: "desc" is a keyword
15726
9b822edecb4c i18n: use "encoding.lower()" to normalize specified string for revset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15596
diff changeset
   592
    ds = encoding.lower(getstring(x, _("desc requires a string")))
20452
a685d9870eb5 revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20451
diff changeset
   593
a685d9870eb5 revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20451
diff changeset
   594
    def matches(x):
a685d9870eb5 revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20451
diff changeset
   595
        c = repo[x]
a685d9870eb5 revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20451
diff changeset
   596
        return ds in encoding.lower(c.description())
a685d9870eb5 revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20451
diff changeset
   597
a685d9870eb5 revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20451
diff changeset
   598
    return lazyset(subset, matches)
14650
93731b3efd0d revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14649
diff changeset
   599
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   600
def _descendants(repo, subset, x, followfirst=False):
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   601
    args = getset(repo, spanset(repo), x)
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   602
    if not args:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   603
        return baseset([])
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   604
    s = set(_revdescendants(repo, args, followfirst)) | set(args)
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   605
    return subset & s
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   606
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   607
def descendants(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   608
    """``descendants(set)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   609
    Changesets which are descendants of changesets in set.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   610
    """
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   611
    return _descendants(repo, subset, x)
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   612
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   613
def _firstdescendants(repo, subset, x):
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   614
    # ``_firstdescendants(set)``
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   615
    # Like ``descendants(set)`` but follows only the first parents.
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   616
    return _descendants(repo, subset, x, followfirst=True)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   617
17186
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   618
def destination(repo, subset, x):
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   619
    """``destination([set])``
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   620
    Changesets that were created by a graft, transplant or rebase operation,
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   621
    with the given revisions specified as the source.  Omitting the optional set
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   622
    is the same as passing all().
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   623
    """
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   624
    if x is not None:
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   625
        args = getset(repo, spanset(repo), x).set()
17186
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   626
    else:
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   627
        args = getall(repo, spanset(repo), x).set()
17186
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   628
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   629
    dests = set()
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   630
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   631
    # subset contains all of the possible destinations that can be returned, so
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   632
    # iterate over them and see if their source(s) were provided in the args.
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   633
    # Even if the immediate src of r is not in the args, src's source (or
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   634
    # further back) may be.  Scanning back further than the immediate src allows
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   635
    # transitive transplants and rebases to yield the same results as transitive
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   636
    # grafts.
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   637
    for r in subset:
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   638
        src = _getrevsource(repo, r)
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   639
        lineage = None
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   640
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   641
        while src is not None:
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   642
            if lineage is None:
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   643
                lineage = list()
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   644
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   645
            lineage.append(r)
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   646
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   647
            # The visited lineage is a match if the current source is in the arg
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   648
            # set.  Since every candidate dest is visited by way of iterating
17494
74801685aaa2 spelling: further
timeless@mozdev.org
parents: 17291
diff changeset
   649
            # subset, any dests further back in the lineage will be tested by a
17186
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   650
            # different iteration over subset.  Likewise, if the src was already
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   651
            # selected, the current lineage can be selected without going back
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   652
            # further.
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   653
            if src in args or src in dests:
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   654
                dests.update(lineage)
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   655
                break
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   656
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   657
            r = src
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   658
            src = _getrevsource(repo, r)
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   659
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   660
    return baseset([r for r in subset if r in dests])
17186
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
   661
18071
bea754715961 obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18063
diff changeset
   662
def divergent(repo, subset, x):
bea754715961 obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18063
diff changeset
   663
    """``divergent()``
bea754715961 obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18063
diff changeset
   664
    Final successors of changesets with an alternative set of final successors.
bea754715961 obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18063
diff changeset
   665
    """
bea754715961 obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18063
diff changeset
   666
    # i18n: "divergent" is a keyword
bea754715961 obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18063
diff changeset
   667
    getargs(x, 0, 0, _("divergent takes no arguments"))
bea754715961 obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18063
diff changeset
   668
    divergent = obsmod.getrevs(repo, 'divergent')
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   669
    return baseset([r for r in subset if r in divergent])
18071
bea754715961 obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18063
diff changeset
   670
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
   671
def draft(repo, subset, x):
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
   672
    """``draft()``
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
   673
    Changeset in draft phase."""
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   674
    # i18n: "draft" is a keyword
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
   675
    getargs(x, 0, 0, _("draft takes no arguments"))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16647
diff changeset
   676
    pc = repo._phasecache
20451
ac7cebf45eb4 revset: added lazyset implementation to draft revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20450
diff changeset
   677
    return lazyset(subset, lambda r: pc.phase(repo, r) == phases.draft)
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
   678
17173
c621f84dbb35 obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17171
diff changeset
   679
def extinct(repo, subset, x):
c621f84dbb35 obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17171
diff changeset
   680
    """``extinct()``
17291
2d6bbf87f7b4 revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents: 17272
diff changeset
   681
    Obsolete changesets with obsolete descendants only.
2d6bbf87f7b4 revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents: 17272
diff changeset
   682
    """
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   683
    # i18n: "extinct" is a keyword
17258
5822345e9e46 revset: use appropriate predicate name in error messages
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17244
diff changeset
   684
    getargs(x, 0, 0, _("extinct takes no arguments"))
17825
3cc06457f15e obsolete: rename `getobscache` into `getrevs`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17804
diff changeset
   685
    extincts = obsmod.getrevs(repo, 'extinct')
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
   686
    return subset & extincts
17173
c621f84dbb35 obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17171
diff changeset
   687
16661
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   688
def extra(repo, subset, x):
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   689
    """``extra(label, [value])``
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   690
    Changesets with the given label in the extra metadata, with the given
16824
f3b8c82a559c revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents: 16823
diff changeset
   691
    optional value.
f3b8c82a559c revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents: 16823
diff changeset
   692
f3b8c82a559c revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents: 16823
diff changeset
   693
    If `value` starts with `re:`, the remainder of the value is treated as
f3b8c82a559c revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents: 16823
diff changeset
   694
    a regular expression. To match a value that actually starts with `re:`,
f3b8c82a559c revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents: 16823
diff changeset
   695
    use the prefix `literal:`.
f3b8c82a559c revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents: 16823
diff changeset
   696
    """
16661
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   697
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   698
    # i18n: "extra" is a keyword
16661
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   699
    l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments'))
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   700
    # i18n: "extra" is a keyword
16661
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   701
    label = getstring(l[0], _('first argument to extra must be a string'))
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   702
    value = None
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   703
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   704
    if len(l) > 1:
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   705
        # i18n: "extra" is a keyword
16661
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   706
        value = getstring(l[1], _('second argument to extra must be a string'))
16824
f3b8c82a559c revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents: 16823
diff changeset
   707
        kind, value, matcher = _stringmatcher(value)
16661
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   708
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   709
    def _matchvalue(r):
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   710
        extra = repo[r].extra()
16824
f3b8c82a559c revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents: 16823
diff changeset
   711
        return label in extra and (value is None or matcher(extra[label]))
16661
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
   712
20481
a5d7081a4c34 revset: added lazyset implementation to extra revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20480
diff changeset
   713
    return lazyset(subset, lambda r: _matchvalue(r))
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
   714
14342
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   715
def filelog(repo, subset, x):
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   716
    """``filelog(pattern)``
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   717
    Changesets connected to the specified filelog.
17244
483aa765f6c4 revset: add explanation about difference between 'filelog()' and 'file()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17186
diff changeset
   718
17265
c30307eeec4b revset: polish explanation of the difference between file() and filelog()
Greg Ward <greg@gerg.ca>
parents: 17259
diff changeset
   719
    For performance reasons, ``filelog()`` does not show every changeset
c30307eeec4b revset: polish explanation of the difference between file() and filelog()
Greg Ward <greg@gerg.ca>
parents: 17259
diff changeset
   720
    that affects the requested file(s). See :hg:`help log` for details. For
c30307eeec4b revset: polish explanation of the difference between file() and filelog()
Greg Ward <greg@gerg.ca>
parents: 17259
diff changeset
   721
    a slower, more accurate result, use ``file()``.
20289
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   722
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   723
    The pattern without explicit kind like ``glob:`` is expected to be
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   724
    relative to the current directory and match against a file exactly
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   725
    for efficiency.
14342
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   726
    """
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   727
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   728
    # i18n: "filelog" is a keyword
14342
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   729
    pat = getstring(x, _("filelog requires a pattern"))
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   730
    s = set()
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   731
15964
6e37b8282aa2 revsets: provide contexts for filesets
Matt Mackall <mpm@selenic.com>
parents: 15949
diff changeset
   732
    if not matchmod.patkind(pat):
20288
b61ad01c4e73 revset: use "canonpath()" for "filelog()" pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20287
diff changeset
   733
        f = pathutil.canonpath(repo.root, repo.getcwd(), pat)
20287
f3cef19befb1 revset: avoid loop for "match.files()" having always one element for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20286
diff changeset
   734
        fl = repo.file(f)
f3cef19befb1 revset: avoid loop for "match.files()" having always one element for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20286
diff changeset
   735
        for fr in fl:
f3cef19befb1 revset: avoid loop for "match.files()" having always one element for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20286
diff changeset
   736
            s.add(fl.linkrev(fr))
14342
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   737
    else:
20288
b61ad01c4e73 revset: use "canonpath()" for "filelog()" pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20287
diff changeset
   738
        m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None])
14342
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   739
        for f in repo[None]:
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   740
            if m(f):
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   741
                fl = repo.file(f)
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   742
                for fr in fl:
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   743
                    s.add(fl.linkrev(fr))
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   744
20393
b0638b5b004d revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20367
diff changeset
   745
    return baseset([r for r in subset if r in s])
14342
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
   746
15117
0ab1c3a1f3b2 revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents: 15116
diff changeset
   747
def first(repo, subset, x):
0ab1c3a1f3b2 revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents: 15116
diff changeset
   748
    """``first(set, [n])``
0ab1c3a1f3b2 revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents: 15116
diff changeset
   749
    An alias for limit().
0ab1c3a1f3b2 revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents: 15116
diff changeset
   750
    """
0ab1c3a1f3b2 revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents: 15116
diff changeset
   751
    return limit(repo, subset, x)
0ab1c3a1f3b2 revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents: 15116
diff changeset
   752
16185
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   753
def _follow(repo, subset, x, name, followfirst=False):
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   754
    l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name)
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   755
    c = repo['.']
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   756
    if l:
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   757
        x = getstring(l[0], _("%s expected a filename") % name)
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   758
        if x in c:
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   759
            cx = c[x]
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   760
            s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst))
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   761
            # include the revision responsible for the most recent version
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   762
            s.add(cx.linkrev())
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   763
        else:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   764
            return baseset([])
16185
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   765
    else:
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
   766
        s = set(_revancestors(repo, [c.rev()], followfirst)) | set([c.rev()])
16185
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   767
20393
b0638b5b004d revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20367
diff changeset
   768
    return baseset([r for r in subset if r in s])
16185
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   769
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   770
def follow(repo, subset, x):
14343
9ed227f79e47 revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents: 14342
diff changeset
   771
    """``follow([file])``
9ed227f79e47 revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents: 14342
diff changeset
   772
    An alias for ``::.`` (ancestors of the working copy's first parent).
9ed227f79e47 revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents: 14342
diff changeset
   773
    If a filename is specified, the history of the given file is followed,
9ed227f79e47 revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents: 14342
diff changeset
   774
    including copies.
9ed227f79e47 revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents: 14342
diff changeset
   775
    """
16185
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   776
    return _follow(repo, subset, x, 'follow')
14343
9ed227f79e47 revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents: 14342
diff changeset
   777
16174
0a73c4bd9f47 graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents: 16161
diff changeset
   778
def _followfirst(repo, subset, x):
0a73c4bd9f47 graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents: 16161
diff changeset
   779
    # ``followfirst([file])``
0a73c4bd9f47 graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents: 16161
diff changeset
   780
    # Like ``follow([file])`` but follows only the first parent of
0a73c4bd9f47 graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents: 16161
diff changeset
   781
    # every revision or file revision.
16185
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16181
diff changeset
   782
    return _follow(repo, subset, x, '_followfirst', followfirst=True)
14343
9ed227f79e47 revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents: 14342
diff changeset
   783
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   784
def getall(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   785
    """``all()``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   786
    All changesets, the same as ``0:tip``.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   787
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   788
    # i18n: "all" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   789
    getargs(x, 0, 0, _("all takes no arguments"))
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   790
    return subset
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   791
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   792
def grep(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   793
    """``grep(regex)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   794
    Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
14357
cb4ff8ef466b merge with stable
Martin Geisler <mg@aragost.com>
parents: 14343 14356
diff changeset
   795
    to ensure special escape characters are handled correctly. Unlike
cb4ff8ef466b merge with stable
Martin Geisler <mg@aragost.com>
parents: 14343 14356
diff changeset
   796
    ``keyword(string)``, the match is case-sensitive.
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   797
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   798
    try:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   799
        # i18n: "grep" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   800
        gr = re.compile(getstring(x, _("grep requires a string")))
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   801
    except re.error, e:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   802
        raise error.ParseError(_('invalid match pattern: %s') % e)
20453
6aa7dcae6bd8 revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20452
diff changeset
   803
6aa7dcae6bd8 revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20452
diff changeset
   804
    def matches(x):
6aa7dcae6bd8 revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20452
diff changeset
   805
        c = repo[x]
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   806
        for e in c.files() + [c.user(), c.description()]:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   807
            if gr.search(e):
20453
6aa7dcae6bd8 revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20452
diff changeset
   808
                return True
6aa7dcae6bd8 revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20452
diff changeset
   809
        return False
6aa7dcae6bd8 revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20452
diff changeset
   810
6aa7dcae6bd8 revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20452
diff changeset
   811
    return lazyset(subset, matches)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   812
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   813
def _matchfiles(repo, subset, x):
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   814
    # _matchfiles takes a revset list of prefixed arguments:
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   815
    #
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   816
    #   [p:foo, i:bar, x:baz]
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   817
    #
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   818
    # builds a match object from them and filters subset. Allowed
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   819
    # prefixes are 'p:' for regular patterns, 'i:' for include
16181
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   820
    # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   821
    # a revision identifier, or the empty string to reference the
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   822
    # working directory, from which the match object is
16411
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   823
    # initialized. Use 'd:' to set the default matching mode, default
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   824
    # to 'glob'. At most one 'r:' and 'd:' argument can be passed.
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   825
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   826
    # i18n: "_matchfiles" is a keyword
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   827
    l = getargs(x, 1, -1, _("_matchfiles requires at least one argument"))
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   828
    pats, inc, exc = [], [], []
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   829
    hasset = False
16411
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   830
    rev, default = None, None
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   831
    for arg in l:
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   832
        # i18n: "_matchfiles" is a keyword
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   833
        s = getstring(arg, _("_matchfiles requires string arguments"))
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   834
        prefix, value = s[:2], s[2:]
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   835
        if prefix == 'p:':
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   836
            pats.append(value)
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   837
        elif prefix == 'i:':
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   838
            inc.append(value)
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   839
        elif prefix == 'x:':
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   840
            exc.append(value)
16181
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   841
        elif prefix == 'r:':
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   842
            if rev is not None:
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   843
                # i18n: "_matchfiles" is a keyword
16181
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   844
                raise error.ParseError(_('_matchfiles expected at most one '
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   845
                                         'revision'))
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   846
            rev = value
16411
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   847
        elif prefix == 'd:':
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   848
            if default is not None:
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   849
                # i18n: "_matchfiles" is a keyword
16411
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   850
                raise error.ParseError(_('_matchfiles expected at most one '
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   851
                                         'default mode'))
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   852
            default = value
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   853
        else:
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
   854
            # i18n: "_matchfiles" is a keyword
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   855
            raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix)
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   856
        if not hasset and matchmod.patkind(value) == 'set':
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   857
            hasset = True
16411
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   858
    if not default:
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   859
        default = 'glob'
20458
8dabcc889e33 revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20457
diff changeset
   860
8dabcc889e33 revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20457
diff changeset
   861
    def matches(x):
8dabcc889e33 revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20457
diff changeset
   862
        m = None
8dabcc889e33 revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20457
diff changeset
   863
        c = repo[x]
16181
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   864
        if not m or (hasset and rev is None):
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   865
            ctx = c
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   866
            if rev is not None:
1fd352aa08fc graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents: 16174
diff changeset
   867
                ctx = repo[rev or None]
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   868
            m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc,
16411
4c2edcd84175 graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents: 16409
diff changeset
   869
                               exclude=exc, ctx=ctx, default=default)
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   870
        for f in c.files():
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   871
            if m(f):
20458
8dabcc889e33 revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20457
diff changeset
   872
                return True
8dabcc889e33 revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20457
diff changeset
   873
        return False
8dabcc889e33 revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20457
diff changeset
   874
8dabcc889e33 revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20457
diff changeset
   875
    return lazyset(subset, matches)
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   876
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   877
def hasfile(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   878
    """``file(pattern)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   879
    Changesets affecting files matched by pattern.
17244
483aa765f6c4 revset: add explanation about difference between 'filelog()' and 'file()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17186
diff changeset
   880
17265
c30307eeec4b revset: polish explanation of the difference between file() and filelog()
Greg Ward <greg@gerg.ca>
parents: 17259
diff changeset
   881
    For a faster but less accurate result, consider using ``filelog()``
c30307eeec4b revset: polish explanation of the difference between file() and filelog()
Greg Ward <greg@gerg.ca>
parents: 17259
diff changeset
   882
    instead.
20289
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   883
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
   884
    This predicate uses ``glob:`` as the default kind of pattern.
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   885
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   886
    # i18n: "file" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   887
    pat = getstring(x, _("file requires a pattern"))
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
   888
    return _matchfiles(repo, subset, ('string', 'p:' + pat))
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   889
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   890
def head(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   891
    """``head()``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   892
    Changeset is a named branch head.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   893
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   894
    # i18n: "head" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   895
    getargs(x, 0, 0, _("head takes no arguments"))
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   896
    hs = set()
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   897
    for b, ls in repo.branchmap().iteritems():
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   898
        hs.update(repo[h].rev() for h in ls)
20393
b0638b5b004d revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20367
diff changeset
   899
    return baseset([r for r in subset if r in hs])
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   900
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   901
def heads(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   902
    """``heads(set)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   903
    Members of set with no children in set.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   904
    """
20366
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
   905
    s = getset(repo, subset, x)
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
   906
    ps = parents(repo, subset, x)
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
   907
    return s - ps
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   908
17390
74b44f25b4b1 revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents: 17291
diff changeset
   909
def hidden(repo, subset, x):
74b44f25b4b1 revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents: 17291
diff changeset
   910
    """``hidden()``
74b44f25b4b1 revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents: 17291
diff changeset
   911
    Hidden changesets.
74b44f25b4b1 revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents: 17291
diff changeset
   912
    """
74b44f25b4b1 revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents: 17291
diff changeset
   913
    # i18n: "hidden" is a keyword
74b44f25b4b1 revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents: 17291
diff changeset
   914
    getargs(x, 0, 0, _("hidden takes no arguments"))
18382
f3b21beb9802 filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents: 18251
diff changeset
   915
    hiddenrevs = repoview.filterrevs(repo, 'visible')
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
   916
    return subset & hiddenrevs
17390
74b44f25b4b1 revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents: 17291
diff changeset
   917
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   918
def keyword(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   919
    """``keyword(string)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   920
    Search commit message, user name, and names of changed files for
14357
cb4ff8ef466b merge with stable
Martin Geisler <mg@aragost.com>
parents: 14343 14356
diff changeset
   921
    string. The match is case-insensitive.
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   922
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   923
    # i18n: "keyword" is a keyword
15726
9b822edecb4c i18n: use "encoding.lower()" to normalize specified string for revset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15596
diff changeset
   924
    kw = encoding.lower(getstring(x, _("keyword requires a string")))
20447
abb91b74f758 revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20446
diff changeset
   925
abb91b74f758 revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20446
diff changeset
   926
    def matches(r):
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   927
        c = repo[r]
20447
abb91b74f758 revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20446
diff changeset
   928
        return util.any(kw in encoding.lower(t) for t in c.files() + [c.user(),
abb91b74f758 revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20446
diff changeset
   929
            c.description()])
abb91b74f758 revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20446
diff changeset
   930
abb91b74f758 revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20446
diff changeset
   931
    return lazyset(subset, matches)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   932
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   933
def limit(repo, subset, x):
15116
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   934
    """``limit(set, [n])``
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   935
    First n members of set, defaulting to 1.
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   936
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   937
    # i18n: "limit" is a keyword
15116
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   938
    l = getargs(x, 1, 2, _("limit requires one or two arguments"))
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   939
    try:
15116
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   940
        lim = 1
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   941
        if len(l) == 2:
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   942
            # i18n: "limit" is a keyword
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   943
            lim = int(getstring(l[1], _("limit requires a number")))
14851
f96c354493d7 revsets: actually catch type error on tip^p1(tip) (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14842
diff changeset
   944
    except (TypeError, ValueError):
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   945
        # i18n: "limit" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   946
        raise error.ParseError(_("limit expects a number"))
20365
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
   947
    ss = subset.set()
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   948
    os = getset(repo, spanset(repo), l[0])
20446
d258486604f4 revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20445
diff changeset
   949
    bs = baseset([])
d258486604f4 revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20445
diff changeset
   950
    it = iter(os)
d258486604f4 revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20445
diff changeset
   951
    for x in xrange(lim):
d258486604f4 revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20445
diff changeset
   952
        try:
d258486604f4 revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20445
diff changeset
   953
            y = it.next()
d258486604f4 revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20445
diff changeset
   954
            if y in ss:
d258486604f4 revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20445
diff changeset
   955
                bs.append(y)
d258486604f4 revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20445
diff changeset
   956
        except (StopIteration):
d258486604f4 revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20445
diff changeset
   957
            break
d258486604f4 revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20445
diff changeset
   958
    return bs
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   959
14061
611d2f8a4ba2 revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents: 14057
diff changeset
   960
def last(repo, subset, x):
15116
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   961
    """``last(set, [n])``
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   962
    Last n members of set, defaulting to 1.
14061
611d2f8a4ba2 revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents: 14057
diff changeset
   963
    """
611d2f8a4ba2 revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents: 14057
diff changeset
   964
    # i18n: "last" is a keyword
15116
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   965
    l = getargs(x, 1, 2, _("last requires one or two arguments"))
14061
611d2f8a4ba2 revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents: 14057
diff changeset
   966
    try:
15116
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   967
        lim = 1
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   968
        if len(l) == 2:
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   969
            # i18n: "last" is a keyword
d8501bcbb221 revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents: 14901
diff changeset
   970
            lim = int(getstring(l[1], _("last requires a number")))
14851
f96c354493d7 revsets: actually catch type error on tip^p1(tip) (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14842
diff changeset
   971
    except (TypeError, ValueError):
14061
611d2f8a4ba2 revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents: 14057
diff changeset
   972
        # i18n: "last" is a keyword
611d2f8a4ba2 revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents: 14057
diff changeset
   973
        raise error.ParseError(_("last expects a number"))
20365
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
   974
    ss = subset.set()
20534
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   975
    os = getset(repo, spanset(repo), l[0])
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   976
    os.reverse()
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   977
    bs = baseset([])
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   978
    it = iter(os)
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   979
    for x in xrange(lim):
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   980
        try:
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   981
            y = it.next()
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   982
            if y in ss:
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   983
                bs.append(y)
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   984
        except (StopIteration):
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   985
            break
4849f574aa24 revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20527
diff changeset
   986
    return bs
14061
611d2f8a4ba2 revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents: 14057
diff changeset
   987
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   988
def maxrev(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   989
    """``max(set)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   990
    Changeset with highest revision number in set.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   991
    """
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
   992
    os = getset(repo, spanset(repo), x)
14153
f8047a059ca0 revset: avoid over-aggresive optimizations of non-filtering functions (issue2549)
Mads Kiilerich <mads@kiilerich.com>
parents: 14098
diff changeset
   993
    if os:
f8047a059ca0 revset: avoid over-aggresive optimizations of non-filtering functions (issue2549)
Mads Kiilerich <mads@kiilerich.com>
parents: 14098
diff changeset
   994
        m = max(os)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   995
        if m in subset:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   996
            return baseset([m])
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
   997
    return baseset([])
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   998
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
   999
def merge(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1000
    """``merge()``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1001
    Changeset is a merge changeset.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1002
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1003
    # i18n: "merge" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1004
    getargs(x, 0, 0, _("merge takes no arguments"))
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1005
    cl = repo.changelog
20454
47fd57f650e5 revset: added lazyset implementation to merge revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20453
diff changeset
  1006
    return lazyset(subset, lambda r: cl.parentrevs(r)[1] != -1)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1007
17753
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1008
def branchpoint(repo, subset, x):
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1009
    """``branchpoint()``
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1010
    Changesets with more than one child.
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1011
    """
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1012
    # i18n: "branchpoint" is a keyword
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1013
    getargs(x, 0, 0, _("branchpoint takes no arguments"))
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1014
    cl = repo.changelog
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1015
    if not subset:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1016
        return baseset([])
17753
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1017
    baserev = min(subset)
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1018
    parentscount = [0]*(len(repo) - baserev)
17785
ac5c9c8046f7 clfilter: use changelog to iterate over the repo in branchpoint
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17753
diff changeset
  1019
    for r in cl.revs(start=baserev + 1):
17753
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1020
        for p in cl.parentrevs(r):
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1021
            if p >= baserev:
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1022
                parentscount[p - baserev] += 1
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1023
    return baseset([r for r in subset if (parentscount[r - baserev] > 1)])
17753
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1024
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1025
def minrev(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1026
    """``min(set)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1027
    Changeset with lowest revision number in set.
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1028
    """
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
  1029
    os = getset(repo, spanset(repo), x)
14153
f8047a059ca0 revset: avoid over-aggresive optimizations of non-filtering functions (issue2549)
Mads Kiilerich <mads@kiilerich.com>
parents: 14098
diff changeset
  1030
    if os:
f8047a059ca0 revset: avoid over-aggresive optimizations of non-filtering functions (issue2549)
Mads Kiilerich <mads@kiilerich.com>
parents: 14098
diff changeset
  1031
        m = min(os)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1032
        if m in subset:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1033
            return baseset([m])
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1034
    return baseset([])
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1035
20498
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1036
def _missingancestors(repo, subset, x):
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1037
    # i18n: "_missingancestors" is a keyword
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1038
    revs, bases = getargs(x, 2, 2,
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1039
                          _("_missingancestors requires two arguments"))
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1040
    rs = baseset(repo)
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1041
    revs = getset(repo, rs, revs)
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1042
    bases = getset(repo, rs, bases)
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1043
    missing = set(repo.changelog.findmissingrevs(bases, revs))
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1044
    return baseset([r for r in subset if r in missing])
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1045
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1046
def modifies(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1047
    """``modifies(pattern)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1048
    Changesets modifying files matched by pattern.
20289
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
  1049
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
  1050
    The pattern without explicit kind like ``glob:`` is expected to be
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
  1051
    relative to the current directory and match against a file or a
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
  1052
    directory.
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1053
    """
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1054
    # i18n: "modifies" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1055
    pat = getstring(x, _("modifies requires a pattern"))
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1056
    return checkstatus(repo, subset, pat, 0)
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1057
16417
b4b0c6931e11 revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents: 16415
diff changeset
  1058
def node_(repo, subset, x):
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1059
    """``id(string)``
12859
76066903ae08 revset: fix missing dot in docstring
Wagner Bruna <wbruna@yahoo.com>
parents: 12855
diff changeset
  1060
    Revision non-ambiguously specified by the given hex string prefix.
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1061
    """
12815
079a618ea89d revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents: 12786
diff changeset
  1062
    # i18n: "id" is a keyword
12736
7e14e67e6622 revset: use 'requires' instead of 'wants' in error message
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12733
diff changeset
  1063
    l = getargs(x, 1, 1, _("id requires one argument"))
12815
079a618ea89d revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents: 12786
diff changeset
  1064
    # i18n: "id" is a keyword
12736
7e14e67e6622 revset: use 'requires' instead of 'wants' in error message
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12733
diff changeset
  1065
    n = getstring(l[0], _("id requires a string"))
12716
c7e619e30ba3 revset: add id() and rev() to allow explicitly referring to changes by hash or rev
Augie Fackler <durin42@gmail.com>
parents: 12715
diff changeset
  1066
    if len(n) == 40:
c7e619e30ba3 revset: add id() and rev() to allow explicitly referring to changes by hash or rev
Augie Fackler <durin42@gmail.com>
parents: 12715
diff changeset
  1067
        rn = repo[n].rev()
c7e619e30ba3 revset: add id() and rev() to allow explicitly referring to changes by hash or rev
Augie Fackler <durin42@gmail.com>
parents: 12715
diff changeset
  1068
    else:
16735
47b8ec0eb7fb revset: fix traceback for bogus revisions in id(rev)
Matt Harbison <matt_harbison@yahoo.com>
parents: 16640
diff changeset
  1069
        rn = None
47b8ec0eb7fb revset: fix traceback for bogus revisions in id(rev)
Matt Harbison <matt_harbison@yahoo.com>
parents: 16640
diff changeset
  1070
        pm = repo.changelog._partialmatch(n)
47b8ec0eb7fb revset: fix traceback for bogus revisions in id(rev)
Matt Harbison <matt_harbison@yahoo.com>
parents: 16640
diff changeset
  1071
        if pm is not None:
47b8ec0eb7fb revset: fix traceback for bogus revisions in id(rev)
Matt Harbison <matt_harbison@yahoo.com>
parents: 16640
diff changeset
  1072
            rn = repo.changelog.rev(pm)
47b8ec0eb7fb revset: fix traceback for bogus revisions in id(rev)
Matt Harbison <matt_harbison@yahoo.com>
parents: 16640
diff changeset
  1073
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1074
    return baseset([r for r in subset if r == rn])
12716
c7e619e30ba3 revset: add id() and rev() to allow explicitly referring to changes by hash or rev
Augie Fackler <durin42@gmail.com>
parents: 12715
diff changeset
  1075
17170
63a4a3871607 revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17102
diff changeset
  1076
def obsolete(repo, subset, x):
63a4a3871607 revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17102
diff changeset
  1077
    """``obsolete()``
63a4a3871607 revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17102
diff changeset
  1078
    Mutable changeset with a newer version."""
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
  1079
    # i18n: "obsolete" is a keyword
17170
63a4a3871607 revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17102
diff changeset
  1080
    getargs(x, 0, 0, _("obsolete takes no arguments"))
17825
3cc06457f15e obsolete: rename `getobscache` into `getrevs`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17804
diff changeset
  1081
    obsoletes = obsmod.getrevs(repo, 'obsolete')
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  1082
    return subset & obsoletes
17170
63a4a3871607 revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17102
diff changeset
  1083
17185
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1084
def origin(repo, subset, x):
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1085
    """``origin([set])``
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1086
    Changesets that were specified as a source for the grafts, transplants or
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1087
    rebases that created the given revisions.  Omitting the optional set is the
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1088
    same as passing all().  If a changeset created by these operations is itself
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1089
    specified as a source for one of these operations, only the source changeset
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1090
    for the first operation is selected.
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1091
    """
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1092
    if x is not None:
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
  1093
        args = getset(repo, spanset(repo), x).set()
17185
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1094
    else:
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
  1095
        args = getall(repo, spanset(repo), x).set()
17185
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1096
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1097
    def _firstsrc(rev):
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1098
        src = _getrevsource(repo, rev)
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1099
        if src is None:
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1100
            return None
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1101
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1102
        while True:
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1103
            prev = _getrevsource(repo, src)
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1104
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1105
            if prev is None:
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1106
                return src
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1107
            src = prev
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1108
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1109
    o = set([_firstsrc(r) for r in args])
20393
b0638b5b004d revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20367
diff changeset
  1110
    return baseset([r for r in subset if r in o])
17185
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1111
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1112
def outgoing(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1113
    """``outgoing([path])``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1114
    Changesets not found in the specified destination repository, or the
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1115
    default push location.
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1116
    """
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1117
    import hg # avoid start-up nasties
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1118
    # i18n: "outgoing" is a keyword
14717
c8ee2729e89f revset and fileset: fix typos in parser error messages
Mads Kiilerich <mads@kiilerich.com>
parents: 14715
diff changeset
  1119
    l = getargs(x, 0, 1, _("outgoing takes one or no arguments"))
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1120
    # i18n: "outgoing" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1121
    dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1122
    dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1123
    dest, branches = hg.parseurl(dest)
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1124
    revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1125
    if revs:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1126
        revs = [repo.lookup(rev) for rev in revs]
14556
517e1d88bf7e hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents: 14509
diff changeset
  1127
    other = hg.peer(repo, {}, dest)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1128
    repo.ui.pushbuffer()
15837
cd956049fc14 discovery: introduce outgoing object for result of findcommonoutgoing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15819
diff changeset
  1129
    outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1130
    repo.ui.popbuffer()
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1131
    cl = repo.changelog
15837
cd956049fc14 discovery: introduce outgoing object for result of findcommonoutgoing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15819
diff changeset
  1132
    o = set([cl.rev(r) for r in outgoing.missing])
20393
b0638b5b004d revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20367
diff changeset
  1133
    return baseset([r for r in subset if r in o])
12716
c7e619e30ba3 revset: add id() and rev() to allow explicitly referring to changes by hash or rev
Augie Fackler <durin42@gmail.com>
parents: 12715
diff changeset
  1134
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1135
def p1(repo, subset, x):
12928
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1136
    """``p1([set])``
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1137
    First parent of changesets in set, or the working directory.
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1138
    """
12928
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1139
    if x is None:
13878
a8d13ee0ce68 misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents: 13873
diff changeset
  1140
        p = repo[x].p1().rev()
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1141
        return baseset([r for r in subset if r == p])
12928
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1142
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1143
    ps = set()
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1144
    cl = repo.changelog
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
  1145
    for r in getset(repo, spanset(repo), x):
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1146
        ps.add(cl.parentrevs(r)[0])
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  1147
    return subset & ps
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1148
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1149
def p2(repo, subset, x):
12928
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1150
    """``p2([set])``
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1151
    Second parent of changesets in set, or the working directory.
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1152
    """
12928
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1153
    if x is None:
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1154
        ps = repo[x].parents()
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1155
        try:
12935
98b79c892768 revset: fix p1, p2 and parents in dirstate case (a5f7f1e9340e)
Patrick Mezard <pmezard@gmail.com>
parents: 12929
diff changeset
  1156
            p = ps[1].rev()
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1157
            return baseset([r for r in subset if r == p])
12928
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1158
        except IndexError:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1159
            return baseset([])
12928
a5f7f1e9340e revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12859
diff changeset
  1160
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1161
    ps = set()
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1162
    cl = repo.changelog
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
  1163
    for r in getset(repo, spanset(repo), x):
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1164
        ps.add(cl.parentrevs(r)[1])
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  1165
    return subset & ps
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1166
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1167
def parents(repo, subset, x):
12929
515c2786e1cf revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12928
diff changeset
  1168
    """``parents([set])``
515c2786e1cf revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12928
diff changeset
  1169
    The set of all parents for all changesets in set, or the working directory.
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1170
    """
12929
515c2786e1cf revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12928
diff changeset
  1171
    if x is None:
12935
98b79c892768 revset: fix p1, p2 and parents in dirstate case (a5f7f1e9340e)
Patrick Mezard <pmezard@gmail.com>
parents: 12929
diff changeset
  1172
        ps = tuple(p.rev() for p in repo[x].parents())
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  1173
        return subset & ps
12929
515c2786e1cf revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents: 12928
diff changeset
  1174
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1175
    ps = set()
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1176
    cl = repo.changelog
20526
9ad6dae67845 revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20525
diff changeset
  1177
    for r in getset(repo, spanset(repo), x):
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1178
        ps.update(cl.parentrevs(r))
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  1179
    return subset & ps
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1180
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1181
def parentspec(repo, subset, x, n):
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1182
    """``set^0``
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1183
    The set.
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1184
    ``set^1`` (or ``set^``), ``set^2``
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1185
    First or second parent, respectively, of all changesets in set.
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1186
    """
12320
40c40c6f20b8 revset: handle re.compile() errors in grep()
Brodie Rao <brodie@bitheap.org>
parents: 11882
diff changeset
  1187
    try:
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1188
        n = int(n[1])
14072
2e4d79dcc0a0 revset: add missing whitespace
Kevin Gessner <kevin@kevingessner.com>
parents: 14070
diff changeset
  1189
        if n not in (0, 1, 2):
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1190
            raise ValueError
14851
f96c354493d7 revsets: actually catch type error on tip^p1(tip) (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14842
diff changeset
  1191
    except (TypeError, ValueError):
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1192
        raise error.ParseError(_("^ expects a number 0, 1, or 2"))
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1193
    ps = set()
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1194
    cl = repo.changelog
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1195
    for r in getset(repo, baseset(cl), x):
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1196
        if n == 0:
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1197
            ps.add(r)
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1198
        elif n == 1:
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1199
            ps.add(cl.parentrevs(r)[0])
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1200
        elif n == 2:
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1201
            parents = cl.parentrevs(r)
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1202
            if len(parents) > 1:
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1203
                ps.add(parents[1])
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  1204
    return subset & ps
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1205
11944
df52ff0980fe revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 11886
diff changeset
  1206
def present(repo, subset, x):
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1207
    """``present(set)``
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1208
    An empty set, if any revision in set isn't found; otherwise,
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1209
    all revisions in set.
16748
0a730d3c5aae doc: add detail explanation for 'present()' predicate of revsets
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16735
diff changeset
  1210
0a730d3c5aae doc: add detail explanation for 'present()' predicate of revsets
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16735
diff changeset
  1211
    If any of specified revisions is not present in the local repository,
0a730d3c5aae doc: add detail explanation for 'present()' predicate of revsets
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16735
diff changeset
  1212
    the query is normally aborted. But this predicate allows the query
0a730d3c5aae doc: add detail explanation for 'present()' predicate of revsets
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16735
diff changeset
  1213
    to continue even in such cases.
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1214
    """
11944
df52ff0980fe revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 11886
diff changeset
  1215
    try:
df52ff0980fe revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 11886
diff changeset
  1216
        return getset(repo, subset, x)
df52ff0980fe revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 11886
diff changeset
  1217
    except error.RepoLookupError:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1218
        return baseset([])
11944
df52ff0980fe revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 11886
diff changeset
  1219
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1220
def public(repo, subset, x):
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1221
    """``public()``
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1222
    Changeset in public phase."""
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
  1223
    # i18n: "public" is a keyword
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1224
    getargs(x, 0, 0, _("public takes no arguments"))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16647
diff changeset
  1225
    pc = repo._phasecache
20456
9a49feb408f3 revset: added lazyset implementation to public revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20454
diff changeset
  1226
    return lazyset(subset, lambda r: pc.phase(repo, r) == phases.public)
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1227
15936
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1228
def remote(repo, subset, x):
16007
f06c53ca59a9 revset: fix documentation for 'remote()' predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16006
diff changeset
  1229
    """``remote([id [,path]])``
15936
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1230
    Local revision that corresponds to the given identifier in a
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1231
    remote repository, if present. Here, the '.' identifier is a
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1232
    synonym for the current local branch.
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1233
    """
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1234
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1235
    import hg # avoid start-up nasties
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1236
    # i18n: "remote" is a keyword
16007
f06c53ca59a9 revset: fix documentation for 'remote()' predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16006
diff changeset
  1237
    l = getargs(x, 0, 2, _("remote takes one, two or no arguments"))
15936
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1238
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1239
    q = '.'
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1240
    if len(l) > 0:
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1241
    # i18n: "remote" is a keyword
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1242
        q = getstring(l[0], _("remote requires a string id"))
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1243
    if q == '.':
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1244
        q = repo['.'].branch()
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1245
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1246
    dest = ''
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1247
    if len(l) > 1:
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1248
        # i18n: "remote" is a keyword
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1249
        dest = getstring(l[1], _("remote requires a repository path"))
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1250
    dest = repo.ui.expandpath(dest or 'default')
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1251
    dest, branches = hg.parseurl(dest)
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1252
    revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1253
    if revs:
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1254
        revs = [repo.lookup(rev) for rev in revs]
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1255
    other = hg.peer(repo, {}, dest)
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1256
    n = other.lookup(q)
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1257
    if n in repo:
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1258
        r = repo[n].rev()
16006
39e60576ac98 revset: fix 'remote()' failure when remote repo has more revs than local
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15966
diff changeset
  1259
        if r in subset:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1260
            return baseset([r])
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1261
    return baseset([])
15936
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1262
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1263
def removes(repo, subset, x):
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1264
    """``removes(pattern)``
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1265
    Changesets which remove files matching pattern.
20289
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
  1266
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
  1267
    The pattern without explicit kind like ``glob:`` is expected to be
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
  1268
    relative to the current directory and match against a file or a
96be25f1da45 revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20288
diff changeset
  1269
    directory.
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1270
    """
12815
079a618ea89d revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents: 12786
diff changeset
  1271
    # i18n: "removes" is a keyword
12736
7e14e67e6622 revset: use 'requires' instead of 'wants' in error message
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12733
diff changeset
  1272
    pat = getstring(x, _("removes requires a pattern"))
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1273
    return checkstatus(repo, subset, pat, 2)
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1274
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1275
def rev(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1276
    """``rev(number)``
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1277
    Revision with the given numeric identifier.
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1278
    """
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1279
    # i18n: "rev" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1280
    l = getargs(x, 1, 1, _("rev requires one argument"))
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1281
    try:
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1282
        # i18n: "rev" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1283
        l = int(getstring(l[0], _("rev requires a number")))
14851
f96c354493d7 revsets: actually catch type error on tip^p1(tip) (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14842
diff changeset
  1284
    except (TypeError, ValueError):
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1285
        # i18n: "rev" is a keyword
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1286
        raise error.ParseError(_("rev expects a number"))
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1287
    return baseset([r for r in subset if r == l])
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1288
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1289
def matching(repo, subset, x):
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1290
    """``matching(revision [, field])``
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1291
    Changesets in which a given set of fields match the set of fields in the
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1292
    selected revision or set.
16528
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1293
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1294
    To match more than one field pass the list of fields to match separated
16528
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1295
    by spaces (e.g. ``author description``).
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1296
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1297
    Valid fields are most regular revision fields and some special fields.
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1298
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1299
    Regular revision fields are ``description``, ``author``, ``branch``,
17102
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1300
    ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user``
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1301
    and ``diff``.
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1302
    Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1303
    contents of the revision. Two revisions matching their ``diff`` will
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1304
    also match their ``files``.
16528
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1305
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1306
    Special fields are ``summary`` and ``metadata``:
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1307
    ``summary`` matches the first line of the description.
16639
00290bd359fe revset: documentation typo "metatadata"
Jesse Glick <jesse.glick@oracle.com>
parents: 16528
diff changeset
  1308
    ``metadata`` is equivalent to matching ``description user date``
16528
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1309
    (i.e. it matches the main metadata fields).
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1310
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1311
    ``metadata`` is the default field which is used when no fields are
5d803620ca05 doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16521
diff changeset
  1312
    specified. You can match more than one field at a time.
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1313
    """
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
  1314
    # i18n: "matching" is a keyword
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1315
    l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments"))
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1316
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1317
    revs = getset(repo, baseset(repo.changelog), l[0])
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1318
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1319
    fieldlist = ['metadata']
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1320
    if len(l) > 1:
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1321
            fieldlist = getstring(l[1],
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
  1322
                # i18n: "matching" is a keyword
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1323
                _("matching requires a string "
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1324
                "as its second argument")).split()
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1325
17102
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1326
    # Make sure that there are no repeated fields,
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1327
    # expand the 'special' 'metadata' field type
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1328
    # and check the 'files' whenever we check the 'diff'
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1329
    fields = []
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1330
    for field in fieldlist:
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1331
        if field == 'metadata':
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1332
            fields += ['user', 'description', 'date']
17102
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1333
        elif field == 'diff':
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1334
            # a revision matching the diff must also match the files
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1335
            # since matching the diff is very costly, make sure to
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1336
            # also match the files first
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1337
            fields += ['files', 'diff']
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1338
        else:
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1339
            if field == 'author':
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1340
                field = 'user'
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1341
            fields.append(field)
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1342
    fields = set(fields)
16444
432f198600c6 revset: make matching keyword not match summary when matching for description
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16417
diff changeset
  1343
    if 'summary' in fields and 'description' in fields:
432f198600c6 revset: make matching keyword not match summary when matching for description
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16417
diff changeset
  1344
        # If a revision matches its description it also matches its summary
432f198600c6 revset: make matching keyword not match summary when matching for description
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16417
diff changeset
  1345
        fields.discard('summary')
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1346
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1347
    # We may want to match more than one field
16446
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1348
    # Not all fields take the same amount of time to be matched
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1349
    # Sort the selected fields in order of increasing matching cost
16453
d2a865d4b963 revset: make matching() work on python 2.4
Patrick Mezard <patrick@mezard.eu>
parents: 16452
diff changeset
  1350
    fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary',
17102
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1351
        'files', 'description', 'substate', 'diff']
16446
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1352
    def fieldkeyfunc(f):
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1353
        try:
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1354
            return fieldorder.index(f)
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1355
        except ValueError:
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1356
            # assume an unknown field is very costly
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1357
            return len(fieldorder)
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1358
    fields = list(fields)
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1359
    fields.sort(key=fieldkeyfunc)
984e0412e82b revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16445
diff changeset
  1360
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1361
    # Each field will be matched with its own "getfield" function
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1362
    # which will be added to the getfieldfuncs array of functions
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1363
    getfieldfuncs = []
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1364
    _funcs = {
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1365
        'user': lambda r: repo[r].user(),
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1366
        'branch': lambda r: repo[r].branch(),
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1367
        'date': lambda r: repo[r].date(),
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1368
        'description': lambda r: repo[r].description(),
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1369
        'files': lambda r: repo[r].files(),
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1370
        'parents': lambda r: repo[r].parents(),
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1371
        'phase': lambda r: repo[r].phase(),
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1372
        'substate': lambda r: repo[r].substate,
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1373
        'summary': lambda r: repo[r].description().splitlines()[0],
17102
d9a046ae4d8e revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 17100
diff changeset
  1374
        'diff': lambda r: list(repo[r].diff(git=True),)
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1375
    }
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1376
    for info in fields:
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1377
        getfield = _funcs.get(info, None)
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1378
        if getfield is None:
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1379
            raise error.ParseError(
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
  1380
                # i18n: "matching" is a keyword
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1381
                _("unexpected field name passed to matching: %s") % info)
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1382
        getfieldfuncs.append(getfield)
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1383
    # convert the getfield array of functions into a "getinfo" function
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1384
    # which returns an array of field values (or a single value if there
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1385
    # is only one field to match)
16445
453c8670566c revset: speedup matching() by stopping the match early if a field does not match
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16444
diff changeset
  1386
    getinfo = lambda r: [f(r) for f in getfieldfuncs]
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1387
20459
51890507c6b3 revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20458
diff changeset
  1388
    def matches(x):
51890507c6b3 revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20458
diff changeset
  1389
        for rev in revs:
51890507c6b3 revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20458
diff changeset
  1390
            target = getinfo(rev)
16445
453c8670566c revset: speedup matching() by stopping the match early if a field does not match
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16444
diff changeset
  1391
            match = True
453c8670566c revset: speedup matching() by stopping the match early if a field does not match
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16444
diff changeset
  1392
            for n, f in enumerate(getfieldfuncs):
20459
51890507c6b3 revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20458
diff changeset
  1393
                if target[n] != f(x):
16445
453c8670566c revset: speedup matching() by stopping the match early if a field does not match
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16444
diff changeset
  1394
                    match = False
453c8670566c revset: speedup matching() by stopping the match early if a field does not match
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16444
diff changeset
  1395
            if match:
20459
51890507c6b3 revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20458
diff changeset
  1396
                return True
51890507c6b3 revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20458
diff changeset
  1397
        return False
51890507c6b3 revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20458
diff changeset
  1398
51890507c6b3 revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20458
diff changeset
  1399
    return lazyset(subset, matches)
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1400
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1401
def reverse(repo, subset, x):
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1402
    """``reverse(set)``
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1403
    Reverse order of set.
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1404
    """
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1405
    l = getset(repo, subset, x)
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1406
    l.reverse()
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1407
    return l
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1408
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1409
def roots(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1410
    """``roots(set)``
16394
f3df7d34791e revset: do not ignore input revisions in roots()
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1411
    Changesets in set with no parent changeset in set.
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1412
    """
20365
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  1413
    s = getset(repo, baseset(repo.changelog), x).set()
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1414
    subset = baseset([r for r in subset if r in s])
16394
f3df7d34791e revset: do not ignore input revisions in roots()
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1415
    cs = _children(repo, subset, s)
20366
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
  1416
    return subset - cs
11944
df52ff0980fe revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 11886
diff changeset
  1417
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1418
def secret(repo, subset, x):
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1419
    """``secret()``
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1420
    Changeset in secret phase."""
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
  1421
    # i18n: "secret" is a keyword
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1422
    getargs(x, 0, 0, _("secret takes no arguments"))
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16647
diff changeset
  1423
    pc = repo._phasecache
20460
3a88d0d0c6b6 revset: added lazyset implementation to secret revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20459
diff changeset
  1424
    return lazyset(subset, lambda x: pc.phase(repo, x) == phases.secret)
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1425
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1426
def sort(repo, subset, x):
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1427
    """``sort(set[, [-]key...])``
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1428
    Sort set by keys. The default sort order is ascending, specify a key
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1429
    as ``-key`` to sort in descending order.
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1430
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1431
    The keys can be:
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1432
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1433
    - ``rev`` for the revision number,
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1434
    - ``branch`` for the branch name,
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1435
    - ``desc`` for the commit message (description),
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1436
    - ``user`` for user name (``author`` can be used as an alias),
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1437
    - ``date`` for the commit date
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1438
    """
12815
079a618ea89d revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents: 12786
diff changeset
  1439
    # i18n: "sort" is a keyword
12736
7e14e67e6622 revset: use 'requires' instead of 'wants' in error message
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12733
diff changeset
  1440
    l = getargs(x, 1, 2, _("sort requires one or two arguments"))
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1441
    keys = "rev"
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1442
    if len(l) == 2:
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
  1443
        # i18n: "sort" is a keyword
11383
de544774ebea revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents: 11349
diff changeset
  1444
        keys = getstring(l[1], _("sort spec must be a string"))
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1445
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1446
    s = l[0]
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1447
    keys = keys.split()
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1448
    l = []
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1449
    def invert(s):
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1450
        return "".join(chr(255 - ord(c)) for c in s)
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1451
    for r in getset(repo, subset, s):
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1452
        c = repo[r]
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1453
        e = []
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1454
        for k in keys:
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1455
            if k == 'rev':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1456
                e.append(r)
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1457
            elif k == '-rev':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1458
                e.append(-r)
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1459
            elif k == 'branch':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1460
                e.append(c.branch())
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1461
            elif k == '-branch':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1462
                e.append(invert(c.branch()))
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1463
            elif k == 'desc':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1464
                e.append(c.description())
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1465
            elif k == '-desc':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1466
                e.append(invert(c.description()))
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1467
            elif k in 'user author':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1468
                e.append(c.user())
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1469
            elif k in '-user -author':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1470
                e.append(invert(c.user()))
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1471
            elif k == 'date':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1472
                e.append(c.date()[0])
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1473
            elif k == '-date':
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1474
                e.append(-c.date()[0])
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1475
            else:
11383
de544774ebea revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents: 11349
diff changeset
  1476
                raise error.ParseError(_("unknown sort key %r") % k)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1477
        e.append(r)
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1478
        l.append(e)
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1479
    l.sort()
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1480
    return baseset([e[-1] for e in l])
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1481
16819
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1482
def _stringmatcher(pattern):
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1483
    """
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1484
    accepts a string, possibly starting with 're:' or 'literal:' prefix.
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1485
    returns the matcher name, pattern, and matcher function.
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1486
    missing or unknown prefixes are treated as literal matches.
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1487
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1488
    helper for tests:
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1489
    >>> def test(pattern, *tests):
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1490
    ...     kind, pattern, matcher = _stringmatcher(pattern)
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1491
    ...     return (kind, pattern, [bool(matcher(t)) for t in tests])
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1492
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1493
    exact matching (no prefix):
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1494
    >>> test('abcdefg', 'abc', 'def', 'abcdefg')
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1495
    ('literal', 'abcdefg', [False, False, True])
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1496
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1497
    regex matching ('re:' prefix)
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1498
    >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar')
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1499
    ('re', 'a.+b', [False, False, True])
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1500
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1501
    force exact matches ('literal:' prefix)
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1502
    >>> test('literal:re:foobar', 'foobar', 're:foobar')
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1503
    ('literal', 're:foobar', [False, True])
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1504
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1505
    unknown prefixes are ignored and treated as literals
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1506
    >>> test('foo:bar', 'foo', 'bar', 'foo:bar')
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1507
    ('literal', 'foo:bar', [False, False, True])
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1508
    """
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1509
    if pattern.startswith('re:'):
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1510
        pattern = pattern[3:]
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1511
        try:
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1512
            regex = re.compile(pattern)
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1513
        except re.error, e:
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1514
            raise error.ParseError(_('invalid regular expression: %s')
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1515
                                   % e)
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1516
        return 're', pattern, regex.search
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1517
    elif pattern.startswith('literal:'):
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1518
        pattern = pattern[8:]
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1519
    return 'literal', pattern, pattern.__eq__
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1520
16823
b23bacb230c9 revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents: 16822
diff changeset
  1521
def _substringmatcher(pattern):
b23bacb230c9 revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents: 16822
diff changeset
  1522
    kind, pattern, matcher = _stringmatcher(pattern)
b23bacb230c9 revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents: 16822
diff changeset
  1523
    if kind == 'literal':
b23bacb230c9 revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents: 16822
diff changeset
  1524
        matcher = lambda s: pattern in s
b23bacb230c9 revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents: 16822
diff changeset
  1525
    return kind, pattern, matcher
16819
5260a9e93113 revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents: 16803
diff changeset
  1526
12715
33820dccbea4 revset: rename tagged() to tag() and allow it to take an optional tag name
Augie Fackler <durin42@gmail.com>
parents: 12616
diff changeset
  1527
def tag(repo, subset, x):
14356
02a5bebd0dc4 revset: the name is optional for the tag predicate
Martin Geisler <mg@aragost.com>
parents: 14355
diff changeset
  1528
    """``tag([name])``
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1529
    The specified tag by name, or all tagged revisions if no name is given.
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1530
    """
12815
079a618ea89d revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents: 12786
diff changeset
  1531
    # i18n: "tag" is a keyword
12715
33820dccbea4 revset: rename tagged() to tag() and allow it to take an optional tag name
Augie Fackler <durin42@gmail.com>
parents: 12616
diff changeset
  1532
    args = getargs(x, 0, 1, _("tag takes one or no arguments"))
11280
a5eb0bf7e158 revset: add tagged predicate
Matt Mackall <mpm@selenic.com>
parents: 11279
diff changeset
  1533
    cl = repo.changelog
12715
33820dccbea4 revset: rename tagged() to tag() and allow it to take an optional tag name
Augie Fackler <durin42@gmail.com>
parents: 12616
diff changeset
  1534
    if args:
16820
20f55613fb2a revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents: 16819
diff changeset
  1535
        pattern = getstring(args[0],
20f55613fb2a revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents: 16819
diff changeset
  1536
                            # i18n: "tag" is a keyword
20f55613fb2a revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents: 16819
diff changeset
  1537
                            _('the argument to tag must be a string'))
20f55613fb2a revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents: 16819
diff changeset
  1538
        kind, pattern, matcher = _stringmatcher(pattern)
20f55613fb2a revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents: 16819
diff changeset
  1539
        if kind == 'literal':
16825
b6ef1395d77f revset: avoid validating all tag nodes for tag(x)
Matt Mackall <mpm@selenic.com>
parents: 16824
diff changeset
  1540
            # avoid resolving all tags
b6ef1395d77f revset: avoid validating all tag nodes for tag(x)
Matt Mackall <mpm@selenic.com>
parents: 16824
diff changeset
  1541
            tn = repo._tagscache.tags.get(pattern, None)
b6ef1395d77f revset: avoid validating all tag nodes for tag(x)
Matt Mackall <mpm@selenic.com>
parents: 16824
diff changeset
  1542
            if tn is None:
16820
20f55613fb2a revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents: 16819
diff changeset
  1543
                raise util.Abort(_("tag '%s' does not exist") % pattern)
16825
b6ef1395d77f revset: avoid validating all tag nodes for tag(x)
Matt Mackall <mpm@selenic.com>
parents: 16824
diff changeset
  1544
            s = set([repo[tn].rev()])
16820
20f55613fb2a revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents: 16819
diff changeset
  1545
        else:
20f55613fb2a revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents: 16819
diff changeset
  1546
            s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
12715
33820dccbea4 revset: rename tagged() to tag() and allow it to take an optional tag name
Augie Fackler <durin42@gmail.com>
parents: 12616
diff changeset
  1547
    else:
33820dccbea4 revset: rename tagged() to tag() and allow it to take an optional tag name
Augie Fackler <durin42@gmail.com>
parents: 12616
diff changeset
  1548
        s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  1549
    return subset & s
11280
a5eb0bf7e158 revset: add tagged predicate
Matt Mackall <mpm@selenic.com>
parents: 11279
diff changeset
  1550
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1551
def tagged(repo, subset, x):
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1552
    return tag(repo, subset, x)
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1553
17171
9c750c3e4fac obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17170
diff changeset
  1554
def unstable(repo, subset, x):
9c750c3e4fac obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17170
diff changeset
  1555
    """``unstable()``
17291
2d6bbf87f7b4 revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents: 17272
diff changeset
  1556
    Non-obsolete changesets with obsolete ancestors.
2d6bbf87f7b4 revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents: 17272
diff changeset
  1557
    """
17259
e96ad092fb18 i18n: add/relocate "i18n keyword" comments for i18n messages in revset.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17258
diff changeset
  1558
    # i18n: "unstable" is a keyword
17258
5822345e9e46 revset: use appropriate predicate name in error messages
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17244
diff changeset
  1559
    getargs(x, 0, 0, _("unstable takes no arguments"))
17825
3cc06457f15e obsolete: rename `getobscache` into `getrevs`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17804
diff changeset
  1560
    unstables = obsmod.getrevs(repo, 'unstable')
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  1561
    return subset & unstables
17171
9c750c3e4fac obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17170
diff changeset
  1562
9c750c3e4fac obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17170
diff changeset
  1563
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1564
def user(repo, subset, x):
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1565
    """``user(string)``
14357
cb4ff8ef466b merge with stable
Martin Geisler <mg@aragost.com>
parents: 14343 14356
diff changeset
  1566
    User name contains string. The match is case-insensitive.
16823
b23bacb230c9 revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents: 16822
diff changeset
  1567
b23bacb230c9 revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents: 16822
diff changeset
  1568
    If `string` starts with `re:`, the remainder of the string is treated as
b23bacb230c9 revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents: 16822
diff changeset
  1569
    a regular expression. To match a user that actually contains `re:`, use
b23bacb230c9 revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents: 16822
diff changeset
  1570
    the prefix `literal:`.
13359
87f248e78173 bookmarks: move revset support to core
Matt Mackall <mpm@selenic.com>
parents: 13031
diff changeset
  1571
    """
13915
8f81d6f4047f revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents: 13914
diff changeset
  1572
    return author(repo, subset, x)
13359
87f248e78173 bookmarks: move revset support to core
Matt Mackall <mpm@selenic.com>
parents: 13031
diff changeset
  1573
15898
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  1574
# for internal use
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  1575
def _list(repo, subset, x):
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  1576
    s = getstring(x, "internal error")
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  1577
    if not s:
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  1578
        return baseset([])
15898
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  1579
    ls = [repo[r].rev() for r in s.split('\0')]
20365
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  1580
    s = subset.set()
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  1581
    return baseset([r for r in ls if r in s])
15898
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  1582
20566
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1583
# for internal use
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1584
def _intlist(repo, subset, x):
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1585
    s = getstring(x, "internal error")
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1586
    if not s:
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1587
        return baseset([])
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1588
    ls = [int(r) for r in s.split('\0')]
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1589
    s = subset.set()
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1590
    return baseset([r for r in ls if r in s])
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1591
20569
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1592
# for internal use
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1593
def _hexlist(repo, subset, x):
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1594
    s = getstring(x, "internal error")
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1595
    if not s:
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1596
        return baseset([])
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1597
    cl = repo.changelog
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1598
    ls = [cl.rev(node.bin(r)) for r in s.split('\0')]
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1599
    s = subset.set()
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1600
    return baseset([r for r in ls if r in s])
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1601
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1602
symbols = {
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1603
    "adds": adds,
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1604
    "all": getall,
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1605
    "ancestor": ancestor,
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1606
    "ancestors": ancestors,
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
  1607
    "_firstancestors": _firstancestors,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1608
    "author": author,
15134
81adf7777f8f revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15133
diff changeset
  1609
    "bisect": bisect,
13602
54b198fe9768 revset: add a revset command to get bisect state.
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 13593
diff changeset
  1610
    "bisected": bisected,
13359
87f248e78173 bookmarks: move revset support to core
Matt Mackall <mpm@selenic.com>
parents: 13031
diff changeset
  1611
    "bookmark": bookmark,
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1612
    "branch": branch,
17753
69d5078d760d revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents: 17675
diff changeset
  1613
    "branchpoint": branchpoint,
17829
c73f7a28953c revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
  1614
    "bumped": bumped,
17913
03e552aaae67 bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents: 17886
diff changeset
  1615
    "bundle": bundle,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1616
    "children": children,
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1617
    "closed": closed,
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1618
    "contains": contains,
17002
0eb522625eb2 revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 16862
diff changeset
  1619
    "converted": converted,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1620
    "date": date,
14650
93731b3efd0d revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14649
diff changeset
  1621
    "desc": desc,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1622
    "descendants": descendants,
16409
2cbd7dd0cc1f graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents: 16402
diff changeset
  1623
    "_firstdescendants": _firstdescendants,
17186
a3da6f298592 revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17185
diff changeset
  1624
    "destination": destination,
18071
bea754715961 obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18063
diff changeset
  1625
    "divergent": divergent,
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1626
    "draft": draft,
17173
c621f84dbb35 obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17171
diff changeset
  1627
    "extinct": extinct,
16661
de4b42daf396 revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents: 16657
diff changeset
  1628
    "extra": extra,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1629
    "file": hasfile,
14342
c0b6a734b4f3 revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
  1630
    "filelog": filelog,
15117
0ab1c3a1f3b2 revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents: 15116
diff changeset
  1631
    "first": first,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1632
    "follow": follow,
16174
0a73c4bd9f47 graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents: 16161
diff changeset
  1633
    "_followfirst": _followfirst,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1634
    "grep": grep,
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1635
    "head": head,
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1636
    "heads": heads,
17390
74b44f25b4b1 revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents: 17291
diff changeset
  1637
    "hidden": hidden,
16417
b4b0c6931e11 revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents: 16415
diff changeset
  1638
    "id": node_,
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1639
    "keyword": keyword,
14061
611d2f8a4ba2 revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents: 14057
diff changeset
  1640
    "last": last,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1641
    "limit": limit,
16161
5a627b49b4d9 graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents: 16096
diff changeset
  1642
    "_matchfiles": _matchfiles,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1643
    "max": maxrev,
14649
a6a8809c6e33 revset: update sorting of symbols
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14556
diff changeset
  1644
    "merge": merge,
11708
ba65d61f3158 revset: add min function
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11650
diff changeset
  1645
    "min": minrev,
20498
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1646
    "_missingancestors": _missingancestors,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1647
    "modifies": modifies,
17170
63a4a3871607 revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17102
diff changeset
  1648
    "obsolete": obsolete,
17185
2c7c4824969e revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents: 17173
diff changeset
  1649
    "origin": origin,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1650
    "outgoing": outgoing,
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1651
    "p1": p1,
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1652
    "p2": p2,
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1653
    "parents": parents,
11944
df52ff0980fe revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 11886
diff changeset
  1654
    "present": present,
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1655
    "public": public,
15936
878bc4a62a73 revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents: 15903
diff changeset
  1656
    "remote": remote,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1657
    "removes": removes,
14649
a6a8809c6e33 revset: update sorting of symbols
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14556
diff changeset
  1658
    "rev": rev,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1659
    "reverse": reverse,
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1660
    "roots": roots,
11284
0b5c2e82aeb5 revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents: 11283
diff changeset
  1661
    "sort": sort,
15819
33ca11b010e2 phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15791
diff changeset
  1662
    "secret": secret,
16402
1fb2f1400ea8 revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16218
diff changeset
  1663
    "matching": matching,
12715
33820dccbea4 revset: rename tagged() to tag() and allow it to take an optional tag name
Augie Fackler <durin42@gmail.com>
parents: 12616
diff changeset
  1664
    "tag": tag,
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1665
    "tagged": tagged,
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1666
    "user": user,
17171
9c750c3e4fac obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17170
diff changeset
  1667
    "unstable": unstable,
15898
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  1668
    "_list": _list,
20566
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1669
    "_intlist": _intlist,
20569
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1670
    "_hexlist": _hexlist,
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1671
}
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1672
19721
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1673
# symbols which can't be used for a DoS attack for any given input
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1674
# (e.g. those which accept regexes as plain strings shouldn't be included)
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1675
# functions that just return a lot of changesets (like all) don't count here
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1676
safesymbols = set([
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1677
    "adds",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1678
    "all",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1679
    "ancestor",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1680
    "ancestors",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1681
    "_firstancestors",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1682
    "author",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1683
    "bisect",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1684
    "bisected",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1685
    "bookmark",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1686
    "branch",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1687
    "branchpoint",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1688
    "bumped",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1689
    "bundle",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1690
    "children",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1691
    "closed",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1692
    "converted",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1693
    "date",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1694
    "desc",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1695
    "descendants",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1696
    "_firstdescendants",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1697
    "destination",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1698
    "divergent",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1699
    "draft",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1700
    "extinct",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1701
    "extra",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1702
    "file",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1703
    "filelog",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1704
    "first",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1705
    "follow",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1706
    "_followfirst",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1707
    "head",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1708
    "heads",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1709
    "hidden",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1710
    "id",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1711
    "keyword",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1712
    "last",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1713
    "limit",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1714
    "_matchfiles",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1715
    "max",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1716
    "merge",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1717
    "min",
20498
fb2df4506c87 revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents: 20484
diff changeset
  1718
    "_missingancestors",
19721
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1719
    "modifies",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1720
    "obsolete",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1721
    "origin",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1722
    "outgoing",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1723
    "p1",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1724
    "p2",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1725
    "parents",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1726
    "present",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1727
    "public",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1728
    "remote",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1729
    "removes",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1730
    "rev",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1731
    "reverse",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1732
    "roots",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1733
    "sort",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1734
    "secret",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1735
    "matching",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1736
    "tag",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1737
    "tagged",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1738
    "user",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1739
    "unstable",
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1740
    "_list",
20566
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  1741
    "_intlist",
20569
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  1742
    "_hexlist",
19721
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1743
])
d8ca6d965230 revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents: 19720
diff changeset
  1744
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1745
methods = {
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1746
    "range": rangeset,
16860
e1aa1ed30030 revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents: 16859
diff changeset
  1747
    "dagrange": dagrange,
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1748
    "string": stringset,
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1749
    "symbol": symbolset,
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1750
    "and": andset,
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1751
    "or": orset,
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1752
    "not": notset,
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1753
    "list": listset,
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1754
    "func": func,
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1755
    "ancestor": ancestorspec,
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1756
    "parent": parentspec,
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1757
    "parentpost": p1,
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1758
}
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1759
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1760
def optimize(x, small):
13031
3da456d0c885 code style: prefer 'is' and 'is not' tests with singletons
Martin Geisler <mg@aragost.com>
parents: 12936
diff changeset
  1761
    if x is None:
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1762
        return 0, x
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1763
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1764
    smallbonus = 1
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1765
    if small:
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1766
        smallbonus = .5
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1767
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1768
    op = x[0]
11283
a6356b2695a3 revset: fix - handling in the optimizer
Matt Mackall <mpm@selenic.com>
parents: 11282
diff changeset
  1769
    if op == 'minus':
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1770
        return optimize(('and', x[1], ('not', x[2])), small)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1771
    elif op == 'dagrangepre':
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1772
        return optimize(('func', ('symbol', 'ancestors'), x[1]), small)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1773
    elif op == 'dagrangepost':
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1774
        return optimize(('func', ('symbol', 'descendants'), x[1]), small)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1775
    elif op == 'rangepre':
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1776
        return optimize(('range', ('string', '0'), x[1]), small)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1777
    elif op == 'rangepost':
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1778
        return optimize(('range', x[1], ('string', 'tip')), small)
11467
6b836d5c8c9e revset: make negate work for sort specs
Matt Mackall <mpm@selenic.com>
parents: 11456
diff changeset
  1779
    elif op == 'negate':
6b836d5c8c9e revset: make negate work for sort specs
Matt Mackall <mpm@selenic.com>
parents: 11456
diff changeset
  1780
        return optimize(('string',
6b836d5c8c9e revset: make negate work for sort specs
Matt Mackall <mpm@selenic.com>
parents: 11456
diff changeset
  1781
                         '-' + getstring(x[1], _("can't negate that"))), small)
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1782
    elif op in 'string symbol negate':
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1783
        return smallbonus, x # single revisions are small
16859
eeb464ed7275 revset: drop unreachable code
Bryan O'Sullivan <bryano@fb.com>
parents: 16838
diff changeset
  1784
    elif op == 'and':
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1785
        wa, ta = optimize(x[1], True)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1786
        wb, tb = optimize(x[2], True)
20499
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1787
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1788
        # (::x and not ::y)/(not ::y and ::x) have a fast path
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1789
        def ismissingancestors(revs, bases):
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1790
            return (
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1791
                revs[0] == 'func'
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1792
                and getstring(revs[1], _('not a symbol')) == 'ancestors'
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1793
                and bases[0] == 'not'
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1794
                and bases[1][0] == 'func'
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1795
                and getstring(bases[1][1], _('not a symbol')) == 'ancestors')
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1796
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1797
        w = min(wa, wb)
20499
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1798
        if ismissingancestors(ta, tb):
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1799
            return w, ('func', ('symbol', '_missingancestors'),
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1800
                       ('list', ta[2], tb[1][2]))
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1801
        if ismissingancestors(tb, ta):
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1802
            return w, ('func', ('symbol', '_missingancestors'),
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1803
                       ('list', tb[2], ta[1][2]))
2efd608473fb revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents: 20498
diff changeset
  1804
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1805
        if wa > wb:
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1806
            return w, (op, tb, ta)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1807
        return w, (op, ta, tb)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1808
    elif op == 'or':
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1809
        wa, ta = optimize(x[1], False)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1810
        wb, tb = optimize(x[2], False)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1811
        if wb < wa:
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1812
            wb, wa = wa, wb
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1813
        return max(wa, wb), (op, ta, tb)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1814
    elif op == 'not':
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1815
        o = optimize(x[1], not small)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1816
        return o[0], (op, o[1])
14070
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1817
    elif op == 'parentpost':
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1818
        o = optimize(x[1], small)
305c97670d7a revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents: 14061
diff changeset
  1819
        return o[0], (op, o[1])
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1820
    elif op == 'group':
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1821
        return optimize(x[1], small)
16860
e1aa1ed30030 revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents: 16859
diff changeset
  1822
    elif op in 'dagrange range list parent ancestorspec':
14842
805651777188 revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14723
diff changeset
  1823
        if op == 'parent':
805651777188 revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14723
diff changeset
  1824
            # x^:y means (x^) : y, not x ^ (:y)
805651777188 revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14723
diff changeset
  1825
            post = ('parentpost', x[1])
805651777188 revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14723
diff changeset
  1826
            if x[2][0] == 'dagrangepre':
805651777188 revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14723
diff changeset
  1827
                return optimize(('dagrange', post, x[2][1]), small)
805651777188 revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14723
diff changeset
  1828
            elif x[2][0] == 'rangepre':
805651777188 revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14723
diff changeset
  1829
                return optimize(('range', post, x[2][1]), small)
805651777188 revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents: 14723
diff changeset
  1830
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1831
        wa, ta = optimize(x[1], small)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1832
        wb, tb = optimize(x[2], small)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1833
        return wa + wb, (op, ta, tb)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1834
    elif op == 'func':
11383
de544774ebea revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents: 11349
diff changeset
  1835
        f = getstring(x[1], _("not a symbol"))
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1836
        wa, ta = optimize(x[2], small)
14650
93731b3efd0d revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14649
diff changeset
  1837
        if f in ("author branch closed date desc file grep keyword "
93731b3efd0d revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14649
diff changeset
  1838
                 "outgoing user"):
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1839
            w = 10 # slow
12351
b913232d13c1 revsets: reduce cost of outgoing in the optimizer
Matt Mackall <mpm@selenic.com>
parents: 12321
diff changeset
  1840
        elif f in "modifies adds removes":
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1841
            w = 30 # slower
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1842
        elif f == "contains":
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1843
            w = 100 # very slow
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1844
        elif f == "ancestor":
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1845
            w = 1 * smallbonus
15117
0ab1c3a1f3b2 revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents: 15116
diff changeset
  1846
        elif f in "reverse limit first":
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1847
            w = 0
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1848
        elif f in "sort":
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1849
            w = 10 # assume most sorts look at changelog
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1850
        else:
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1851
            w = 1
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1852
        return w + wa, (op, x[1], ta)
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1853
    return 1, x
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1854
16771
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1855
_aliasarg = ('func', ('symbol', '_aliasarg'))
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1856
def _getaliasarg(tree):
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1857
    """If tree matches ('func', ('symbol', '_aliasarg'), ('string', X))
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1858
    return X, None otherwise.
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1859
    """
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1860
    if (len(tree) == 3 and tree[:2] == _aliasarg
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1861
        and tree[2][0] == 'string'):
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1862
        return tree[2][1]
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1863
    return None
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1864
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1865
def _checkaliasarg(tree, known=None):
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1866
    """Check tree contains no _aliasarg construct or only ones which
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1867
    value is in known. Used to avoid alias placeholders injection.
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1868
    """
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1869
    if isinstance(tree, tuple):
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1870
        arg = _getaliasarg(tree)
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1871
        if arg is not None and (not known or arg not in known):
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1872
            raise error.ParseError(_("not a function: %s") % '_aliasarg')
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1873
        for t in tree:
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1874
            _checkaliasarg(t, known)
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1875
14098
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1876
class revsetalias(object):
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1877
    funcre = re.compile('^([^(]+)\(([^)]+)\)$')
14723
b9faf94ee196 revset: fix aliases with 0 or more than 2 parameters
Mads Kiilerich <mads@kiilerich.com>
parents: 14717
diff changeset
  1878
    args = None
14098
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1879
14723
b9faf94ee196 revset: fix aliases with 0 or more than 2 parameters
Mads Kiilerich <mads@kiilerich.com>
parents: 14717
diff changeset
  1880
    def __init__(self, name, value):
14098
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1881
        '''Aliases like:
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1882
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1883
        h = heads(default)
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1884
        b($1) = ancestors($1) - ancestors(default)
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1885
        '''
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1886
        m = self.funcre.search(name)
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1887
        if m:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1888
            self.name = m.group(1)
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1889
            self.tree = ('func', ('symbol', m.group(1)))
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1890
            self.args = [x.strip() for x in m.group(2).split(',')]
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1891
            for arg in self.args:
16771
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1892
                # _aliasarg() is an unknown symbol only used separate
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1893
                # alias argument placeholders from regular strings.
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1894
                value = value.replace(arg, '_aliasarg(%r)' % (arg,))
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1895
        else:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1896
            self.name = name
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1897
            self.tree = ('symbol', name)
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1898
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1899
        self.replacement, pos = parse(value)
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1900
        if pos != len(value):
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1901
            raise error.ParseError(_('invalid token'), pos)
16771
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1902
        # Check for placeholder injection
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1903
        _checkaliasarg(self.replacement, self.args)
14098
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1904
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1905
def _getalias(aliases, tree):
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1906
    """If tree looks like an unexpanded alias, return it. Return None
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1907
    otherwise.
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1908
    """
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1909
    if isinstance(tree, tuple) and tree:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1910
        if tree[0] == 'symbol' and len(tree) == 2:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1911
            name = tree[1]
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1912
            alias = aliases.get(name)
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1913
            if alias and alias.args is None and alias.tree == tree:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1914
                return alias
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1915
        if tree[0] == 'func' and len(tree) > 1:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1916
            if tree[1][0] == 'symbol' and len(tree[1]) == 2:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1917
                name = tree[1][1]
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1918
                alias = aliases.get(name)
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1919
                if alias and alias.args is not None and alias.tree == tree[:2]:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1920
                    return alias
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1921
    return None
14098
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1922
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1923
def _expandargs(tree, args):
16771
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1924
    """Replace _aliasarg instances with the substitution value of the
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1925
    same name in args, recursively.
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1926
    """
16771
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1927
    if not tree or not isinstance(tree, tuple):
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1928
        return tree
16771
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1929
    arg = _getaliasarg(tree)
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1930
    if arg is not None:
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1931
        return args[arg]
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1932
    return tuple(_expandargs(t, args) for t in tree)
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1933
16838
d37d221334be revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents: 16834
diff changeset
  1934
def _expandaliases(aliases, tree, expanding, cache):
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1935
    """Expand aliases in tree, recursively.
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1936
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1937
    'aliases' is a dictionary mapping user defined aliases to
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1938
    revsetalias objects.
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1939
    """
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1940
    if not isinstance(tree, tuple):
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1941
        # Do not expand raw strings
14098
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1942
        return tree
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1943
    alias = _getalias(aliases, tree)
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1944
    if alias is not None:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1945
        if alias in expanding:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1946
            raise error.ParseError(_('infinite expansion of revset alias "%s" '
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1947
                                     'detected') % alias.name)
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1948
        expanding.append(alias)
16838
d37d221334be revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents: 16834
diff changeset
  1949
        if alias.name not in cache:
d37d221334be revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents: 16834
diff changeset
  1950
            cache[alias.name] = _expandaliases(aliases, alias.replacement,
d37d221334be revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents: 16834
diff changeset
  1951
                                               expanding, cache)
d37d221334be revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents: 16834
diff changeset
  1952
        result = cache[alias.name]
16772
30e46d7138de revset: fix infinite alias expansion detection
Patrick Mezard <patrick@mezard.eu>
parents: 16771
diff changeset
  1953
        expanding.pop()
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1954
        if alias.args is not None:
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1955
            l = getlist(tree[2])
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1956
            if len(l) != len(alias.args):
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1957
                raise error.ParseError(
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1958
                    _('invalid number of arguments: %s') % len(l))
16838
d37d221334be revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents: 16834
diff changeset
  1959
            l = [_expandaliases(aliases, a, [], cache) for a in l]
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1960
            result = _expandargs(result, dict(zip(alias.args, l)))
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1961
    else:
16838
d37d221334be revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents: 16834
diff changeset
  1962
        result = tuple(_expandaliases(aliases, t, expanding, cache)
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1963
                       for t in tree)
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1964
    return result
14098
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1965
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1966
def findaliases(ui, tree):
16771
2f3317d53d51 revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents: 16748
diff changeset
  1967
    _checkaliasarg(tree)
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1968
    aliases = {}
14098
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1969
    for k, v in ui.configitems('revsetalias'):
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1970
        alias = revsetalias(k, v)
16096
b8be450638f6 revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents: 16007
diff changeset
  1971
        aliases[alias.name] = alias
16838
d37d221334be revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents: 16834
diff changeset
  1972
    return _expandaliases(aliases, tree, [], {})
14098
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1973
20208
61a47fd64f30 fileset, revset: do not use global parser object for thread safety
Yuya Nishihara <yuya@tcha.org>
parents: 19721
diff changeset
  1974
def parse(spec):
61a47fd64f30 fileset, revset: do not use global parser object for thread safety
Yuya Nishihara <yuya@tcha.org>
parents: 19721
diff changeset
  1975
    p = parser.parser(tokenize, elements)
61a47fd64f30 fileset, revset: do not use global parser object for thread safety
Yuya Nishihara <yuya@tcha.org>
parents: 19721
diff changeset
  1976
    return p.parse(spec)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1977
14098
9f5a0acb0056 revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 14073
diff changeset
  1978
def match(ui, spec):
11385
e5a2134c083b revset: nicer exception for empty queries
Matt Mackall <mpm@selenic.com>
parents: 11383
diff changeset
  1979
    if not spec:
e5a2134c083b revset: nicer exception for empty queries
Matt Mackall <mpm@selenic.com>
parents: 11383
diff changeset
  1980
        raise error.ParseError(_("empty query"))
14496
ffcb7e4d719f revset: report a parse error if a revset is not parsed completely (issue2654)
Bernhard Leiner <bleiner@gmail.com>
parents: 14356
diff changeset
  1981
    tree, pos = parse(spec)
ffcb7e4d719f revset: report a parse error if a revset is not parsed completely (issue2654)
Bernhard Leiner <bleiner@gmail.com>
parents: 14356
diff changeset
  1982
    if (pos != len(spec)):
14701
4b93bd041772 parsers: fix localization markup of parser errors
Mads Kiilerich <mads@kiilerich.com>
parents: 14650
diff changeset
  1983
        raise error.ParseError(_("invalid token"), pos)
14900
fc3d6f300d7d revset: allow bypassing alias expansion
Matt Mackall <mpm@selenic.com>
parents: 14851
diff changeset
  1984
    if ui:
fc3d6f300d7d revset: allow bypassing alias expansion
Matt Mackall <mpm@selenic.com>
parents: 14851
diff changeset
  1985
        tree = findaliases(ui, tree)
11279
62ccf4cd6e7f revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents: 11278
diff changeset
  1986
    weight, tree = optimize(tree, True)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1987
    def mfunc(repo, subset):
20527
bde426f18e0a revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20526
diff changeset
  1988
        if util.safehasattr(subset, 'set'):
bde426f18e0a revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20526
diff changeset
  1989
            return getset(repo, subset, tree)
bde426f18e0a revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20526
diff changeset
  1990
        return getset(repo, baseset(subset), tree)
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1991
    return mfunc
12821
165079e564f0 revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 12815
diff changeset
  1992
14901
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  1993
def formatspec(expr, *args):
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  1994
    '''
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  1995
    This is a convenience function for using revsets internally, and
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  1996
    escapes arguments appropriately. Aliases are intentionally ignored
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  1997
    so that intended expression behavior isn't accidentally subverted.
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  1998
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  1999
    Supported arguments:
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2000
15266
8bea39ca9acb revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents: 15153
diff changeset
  2001
    %r = revset expression, parenthesized
14901
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2002
    %d = int(arg), no quoting
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2003
    %s = string(arg), escaped and single-quoted
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2004
    %b = arg.branch(), escaped and single-quoted
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2005
    %n = hex(arg), single-quoted
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2006
    %% = a literal '%'
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2007
15266
8bea39ca9acb revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents: 15153
diff changeset
  2008
    Prefixing the type with 'l' specifies a parenthesized list of that type.
15140
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2009
15268
bd5103819c2e revset: fix %r handling in formatspec
Matt Mackall <mpm@selenic.com>
parents: 15266
diff changeset
  2010
    >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()"))
bd5103819c2e revset: fix %r handling in formatspec
Matt Mackall <mpm@selenic.com>
parents: 15266
diff changeset
  2011
    '(10 or 11):: and ((this()) or (that()))'
14901
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2012
    >>> formatspec('%d:: and not %d::', 10, 20)
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2013
    '10:: and not 20::'
15325
cdf1daa3b83f revset: deal with empty lists in formatspec
Matt Mackall <mpm@selenic.com>
parents: 15268
diff changeset
  2014
    >>> formatspec('%ld or %ld', [], [1])
15898
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2015
    "_list('') or 1"
14901
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2016
    >>> formatspec('keyword(%s)', 'foo\\xe9')
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2017
    "keyword('foo\\\\xe9')"
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2018
    >>> b = lambda: 'default'
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2019
    >>> b.branch = b
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2020
    >>> formatspec('branch(%b)', b)
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2021
    "branch('default')"
15140
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2022
    >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd'])
15898
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2023
    "root(_list('a\\x00b\\x00c\\x00d'))"
14901
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2024
    '''
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2025
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2026
    def quote(s):
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2027
        return repr(str(s))
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2028
15140
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2029
    def argtype(c, arg):
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2030
        if c == 'd':
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2031
            return str(int(arg))
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2032
        elif c == 's':
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2033
            return quote(arg)
15266
8bea39ca9acb revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents: 15153
diff changeset
  2034
        elif c == 'r':
8bea39ca9acb revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents: 15153
diff changeset
  2035
            parse(arg) # make sure syntax errors are confined
8bea39ca9acb revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents: 15153
diff changeset
  2036
            return '(%s)' % arg
15140
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2037
        elif c == 'n':
16417
b4b0c6931e11 revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents: 16415
diff changeset
  2038
            return quote(node.hex(arg))
15140
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2039
        elif c == 'b':
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2040
            return quote(arg.branch())
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2041
15595
a585d78e7b2f revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents: 15532
diff changeset
  2042
    def listexp(s, t):
a585d78e7b2f revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents: 15532
diff changeset
  2043
        l = len(s)
a585d78e7b2f revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents: 15532
diff changeset
  2044
        if l == 0:
15898
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2045
            return "_list('')"
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2046
        elif l == 1:
15595
a585d78e7b2f revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents: 15532
diff changeset
  2047
            return argtype(t, s[0])
15898
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2048
        elif t == 'd':
20566
98024950ade0 revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20552
diff changeset
  2049
            return "_intlist('%s')" % "\0".join(str(int(a)) for a in s)
15898
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2050
        elif t == 's':
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2051
            return "_list('%s')" % "\0".join(s)
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2052
        elif t == 'n':
20569
0d4be103c734 revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20566
diff changeset
  2053
            return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s)
15898
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2054
        elif t == 'b':
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2055
            return "_list('%s')" % "\0".join(a.branch() for a in s)
6902e13ddd03 revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents: 15837
diff changeset
  2056
15791
a814f8fcc65a Use explicit integer division
Martin Geisler <mg@aragost.com>
parents: 15726
diff changeset
  2057
        m = l // 2
15595
a585d78e7b2f revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents: 15532
diff changeset
  2058
        return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))
a585d78e7b2f revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents: 15532
diff changeset
  2059
14901
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2060
    ret = ''
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2061
    pos = 0
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2062
    arg = 0
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2063
    while pos < len(expr):
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2064
        c = expr[pos]
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2065
        if c == '%':
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2066
            pos += 1
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2067
            d = expr[pos]
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2068
            if d == '%':
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2069
                ret += d
15268
bd5103819c2e revset: fix %r handling in formatspec
Matt Mackall <mpm@selenic.com>
parents: 15266
diff changeset
  2070
            elif d in 'dsnbr':
15140
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2071
                ret += argtype(d, args[arg])
14901
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2072
                arg += 1
15140
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2073
            elif d == 'l':
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2074
                # a list of some type
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2075
                pos += 1
353a1ba928f6 revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents: 15138
diff changeset
  2076
                d = expr[pos]
15596
2555f441a32f merge with stable
Matt Mackall <mpm@selenic.com>
parents: 15595
diff changeset
  2077
                ret += listexp(list(args[arg]), d)
14901
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2078
                arg += 1
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2079
            else:
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2080
                raise util.Abort('unexpected revspec format character %s' % d)
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2081
        else:
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2082
            ret += c
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2083
        pos += 1
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2084
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2085
    return ret
a773119f30ba revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents: 14900
diff changeset
  2086
16218
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2087
def prettyformat(tree):
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2088
    def _prettyformat(tree, level, lines):
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2089
        if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2090
            lines.append((level, str(tree)))
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2091
        else:
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2092
            lines.append((level, '(%s' % tree[0]))
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2093
            for s in tree[1:]:
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2094
                _prettyformat(s, level + 1, lines)
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2095
            lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')]
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2096
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2097
    lines = []
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2098
    _prettyformat(tree, 0, lines)
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2099
    output = '\n'.join(('  '*l + s) for l, s in lines)
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2100
    return output
81a1a00f5738 debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents: 16185
diff changeset
  2101
19719
2f9d5c5256ea revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents: 19706
diff changeset
  2102
def depth(tree):
2f9d5c5256ea revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents: 19706
diff changeset
  2103
    if isinstance(tree, tuple):
2f9d5c5256ea revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents: 19706
diff changeset
  2104
        return max(map(depth, tree)) + 1
2f9d5c5256ea revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents: 19706
diff changeset
  2105
    else:
2f9d5c5256ea revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents: 19706
diff changeset
  2106
        return 0
2f9d5c5256ea revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents: 19706
diff changeset
  2107
19720
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2108
def funcsused(tree):
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2109
    if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2110
        return set()
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2111
    else:
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2112
        funcs = set()
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2113
        for s in tree[1:]:
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2114
            funcs |= funcsused(s)
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2115
        if tree[0] == 'func':
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2116
            funcs.add(tree[1][1])
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2117
        return funcs
f0b992a9be9c revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents: 19719
diff changeset
  2118
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  2119
class baseset(list):
20416
e72bcc245ecb revset: added docstring to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20393
diff changeset
  2120
    """Basic data structure that represents a revset and contains the basic
e72bcc245ecb revset: added docstring to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20393
diff changeset
  2121
    operation that it should be able to perform.
e72bcc245ecb revset: added docstring to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20393
diff changeset
  2122
    """
20365
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  2123
    def __init__(self, data):
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  2124
        super(baseset, self).__init__(data)
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  2125
        self._set = None
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  2126
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  2127
    def set(self):
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  2128
        if not self._set:
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  2129
            self._set = set(self)
bc770ee6a351 revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20364
diff changeset
  2130
        return self._set
20364
a6cf48b2880d revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20289
diff changeset
  2131
20366
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
  2132
    def __sub__(self, x):
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
  2133
        if isinstance(x, baseset):
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
  2134
            s = x.set()
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
  2135
        else:
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
  2136
            s = set(x)
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
  2137
        return baseset(self.set() - s)
5ec6321f49a9 revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20365
diff changeset
  2138
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  2139
    def __and__(self, x):
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  2140
        if isinstance(x, baseset):
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  2141
            x = x.set()
20393
b0638b5b004d revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20367
diff changeset
  2142
        return baseset([y for y in self if y in x])
20367
2ac278aab2b4 revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20366
diff changeset
  2143
20417
827561a99569 revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20416
diff changeset
  2144
    def __add__(self, x):
827561a99569 revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20416
diff changeset
  2145
        s = self.set()
827561a99569 revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20416
diff changeset
  2146
        l = [r for r in x if r not in s]
827561a99569 revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20416
diff changeset
  2147
        return baseset(list(self) + l)
827561a99569 revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20416
diff changeset
  2148
20610
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2149
    def filter(self, l):
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2150
        return lazyset(self, l)
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2151
20427
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2152
class lazyset(object):
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2153
    """Duck type for baseset class which iterates lazily over the revisions in
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2154
    the subset and contains a function which tests for membership in the
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2155
    revset
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2156
    """
20586
2d52f37937b0 revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20569
diff changeset
  2157
    def __init__(self, subset, condition=lambda x: True):
20427
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2158
        self._subset = subset
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2159
        self._condition = condition
20512
659b8d8ddf19 revset: added cache to lazysets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20499
diff changeset
  2160
        self._cache = {}
20427
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2161
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2162
    def __contains__(self, x):
20512
659b8d8ddf19 revset: added cache to lazysets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20499
diff changeset
  2163
        c = self._cache
659b8d8ddf19 revset: added cache to lazysets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20499
diff changeset
  2164
        if x not in c:
659b8d8ddf19 revset: added cache to lazysets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20499
diff changeset
  2165
            c[x] = x in self._subset and self._condition(x)
659b8d8ddf19 revset: added cache to lazysets
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20499
diff changeset
  2166
        return c[x]
20427
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2167
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2168
    def __iter__(self):
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2169
        cond = self._condition
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2170
        for x in self._subset:
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2171
            if cond(x):
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2172
                yield x
4a9191ca848e revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20424
diff changeset
  2173
20428
2e33cda452f6 revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20427
diff changeset
  2174
    def __and__(self, x):
2e33cda452f6 revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20427
diff changeset
  2175
        return lazyset(self, lambda r: r in x)
2e33cda452f6 revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20427
diff changeset
  2176
2e33cda452f6 revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20427
diff changeset
  2177
    def __sub__(self, x):
2e33cda452f6 revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20427
diff changeset
  2178
        return lazyset(self, lambda r: r not in x)
2e33cda452f6 revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20427
diff changeset
  2179
2e33cda452f6 revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20427
diff changeset
  2180
    def __add__(self, x):
20586
2d52f37937b0 revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20569
diff changeset
  2181
        def iterates():
2d52f37937b0 revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20569
diff changeset
  2182
            for r in self:
2d52f37937b0 revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20569
diff changeset
  2183
                yield r
2d52f37937b0 revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20569
diff changeset
  2184
            for r in x:
2d52f37937b0 revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20569
diff changeset
  2185
                if r not in self:
2d52f37937b0 revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20569
diff changeset
  2186
                    yield r
2d52f37937b0 revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20569
diff changeset
  2187
2d52f37937b0 revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20569
diff changeset
  2188
        return lazyset(generatorset(iterates()))
20428
2e33cda452f6 revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20427
diff changeset
  2189
20552
0e99a66eb7bc revset: added __nonzero__ method to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20540
diff changeset
  2190
    def __nonzero__(self):
0e99a66eb7bc revset: added __nonzero__ method to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20540
diff changeset
  2191
        for r in self:
0e99a66eb7bc revset: added __nonzero__ method to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20540
diff changeset
  2192
            return True
0e99a66eb7bc revset: added __nonzero__ method to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20540
diff changeset
  2193
        return False
0e99a66eb7bc revset: added __nonzero__ method to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20540
diff changeset
  2194
20429
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2195
    def __len__(self):
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2196
        # Basic implementation to be changed in future patches.
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2197
        l = baseset([r for r in self])
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2198
        return len(l)
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2199
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2200
    def __getitem__(self, x):
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2201
        # Basic implementation to be changed in future patches.
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2202
        l = baseset([r for r in self])
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2203
        return l[x]
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2204
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2205
    def sort(self, reverse=False):
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2206
        # Basic implementation to be changed in future patches.
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2207
        self._subset = baseset(self._subset)
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2208
        self._subset.sort(reverse=reverse)
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2209
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2210
    def reverse(self):
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2211
        self._subset.reverse()
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2212
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2213
    def set(self):
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2214
        return set([r for r in self])
f5b560c60bcd revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20428
diff changeset
  2215
20610
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2216
    def filter(self, l):
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2217
        return lazyset(self, l)
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2218
20609
56ecc82fcd67 revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20587
diff changeset
  2219
class orderedlazyset(lazyset):
56ecc82fcd67 revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20587
diff changeset
  2220
    """Subclass of lazyset which subset can be ordered either ascending or
56ecc82fcd67 revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20587
diff changeset
  2221
    descendingly
56ecc82fcd67 revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20587
diff changeset
  2222
    """
56ecc82fcd67 revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20587
diff changeset
  2223
    def __init__(self, subset, condition, ascending=True):
56ecc82fcd67 revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20587
diff changeset
  2224
        super(orderedlazyset, self).__init__(subset, condition)
56ecc82fcd67 revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20587
diff changeset
  2225
        self._ascending = ascending
56ecc82fcd67 revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20587
diff changeset
  2226
20610
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2227
    def filter(self, l):
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2228
        return orderedlazyset(self, l, ascending=self._ascending)
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2229
20536
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2230
class generatorset(object):
20540
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2231
    """Wrapper structure for generators that provides lazy membership and can
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2232
    be iterated more than once.
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2233
    When asked for membership it generates values until either it finds the
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2234
    requested one or has gone through all the elements in the generator
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2235
    """
20536
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2236
    def __init__(self, gen):
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2237
        self._gen = gen
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2238
        self._iter = iter(gen)
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2239
        self._cache = {}
20540
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2240
        self._genlist = baseset([])
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2241
        self._iterated = False
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2242
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2243
    def _nextitem(self):
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2244
        l = self._iter.next()
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2245
        self._cache[l] = True
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2246
        self._genlist.append(l)
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2247
        return l
20536
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2248
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2249
    def __contains__(self, x):
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2250
        if x in self._cache:
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2251
            return self._cache[x]
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2252
20540
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2253
        self._iterated = True
20536
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2254
        while True:
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2255
            try:
20540
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2256
                l = self._nextitem()
20536
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2257
                if l == x:
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2258
                    return True
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2259
            except (StopIteration):
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2260
                break
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2261
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2262
        self._cache[x] = False
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2263
        return False
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2264
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2265
    def __iter__(self):
20540
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2266
        if self._iterated:
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2267
            for l in self._genlist:
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2268
                yield l
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2269
            while True:
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2270
                try:
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2271
                    item = self._nextitem()
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2272
                    yield item
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2273
                except (StopIteration):
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2274
                    break
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2275
        else:
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2276
            self._iterated = True
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2277
            for item in self._gen:
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2278
                self._cache[item] = True
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2279
                self._genlist.append(item)
fa16c710a3d8 revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20538
diff changeset
  2280
                yield item
20536
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2281
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2282
    def set(self):
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2283
        return self
532b114a6e02 revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20534
diff changeset
  2284
20482
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2285
class spanset(object):
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2286
    """Duck type for baseset class which represents a range of revisions and
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2287
    can work lazily and without having all the range in memory
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2288
    """
20525
aa73a6327df4 revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20521
diff changeset
  2289
    def __init__(self, repo, start=0, end=None):
20482
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2290
        self._start = start
20525
aa73a6327df4 revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20521
diff changeset
  2291
        if end is not None:
aa73a6327df4 revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20521
diff changeset
  2292
            self._end = end
aa73a6327df4 revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20521
diff changeset
  2293
        else:
aa73a6327df4 revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20521
diff changeset
  2294
            self._end = len(repo)
aa73a6327df4 revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20521
diff changeset
  2295
        self._hiddenrevs = repo.changelog.filteredrevs
20521
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2296
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2297
    def _contained(self, rev):
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2298
        return (rev <= self._start and rev > self._end) or (rev >= self._start
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2299
                and rev < self._end)
20482
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2300
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2301
    def __iter__(self):
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2302
        if self._start <= self._end:
20521
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2303
            iterrange = xrange(self._start, self._end)
20482
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2304
        else:
20521
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2305
            iterrange = xrange(self._start, self._end, -1)
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2306
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2307
        if self._hiddenrevs:
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2308
            s = self._hiddenrevs
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2309
            for r in iterrange:
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2310
                if r not in s:
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2311
                    yield r
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2312
        else:
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2313
            for r in iterrange:
20482
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2314
                yield r
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2315
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2316
    def __contains__(self, x):
20521
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2317
        return self._contained(x) and not (self._hiddenrevs and rev in
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2318
                self._hiddenrevs)
20482
a979078bd788 revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20481
diff changeset
  2319
20483
ed57358398af revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20482
diff changeset
  2320
    def __and__(self, x):
20538
fe220013e4db revset: fixed bug where log -f was taking too long to return
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20536
diff changeset
  2321
        if isinstance(x, baseset):
fe220013e4db revset: fixed bug where log -f was taking too long to return
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20536
diff changeset
  2322
            x = x.set()
20483
ed57358398af revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20482
diff changeset
  2323
        return lazyset(self, lambda r: r in x)
ed57358398af revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20482
diff changeset
  2324
ed57358398af revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20482
diff changeset
  2325
    def __sub__(self, x):
20538
fe220013e4db revset: fixed bug where log -f was taking too long to return
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20536
diff changeset
  2326
        if isinstance(x, baseset):
fe220013e4db revset: fixed bug where log -f was taking too long to return
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20536
diff changeset
  2327
            x = x.set()
20483
ed57358398af revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20482
diff changeset
  2328
        return lazyset(self, lambda r: r not in x)
ed57358398af revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20482
diff changeset
  2329
ed57358398af revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20482
diff changeset
  2330
    def __add__(self, x):
20587
cb18fe3461b1 revset: changed spanset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20586
diff changeset
  2331
        def iterates():
cb18fe3461b1 revset: changed spanset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20586
diff changeset
  2332
            for r in self:
cb18fe3461b1 revset: changed spanset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20586
diff changeset
  2333
                yield r
cb18fe3461b1 revset: changed spanset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20586
diff changeset
  2334
            for r in x:
cb18fe3461b1 revset: changed spanset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20586
diff changeset
  2335
                if r not in self:
cb18fe3461b1 revset: changed spanset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20586
diff changeset
  2336
                    yield r
cb18fe3461b1 revset: changed spanset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20586
diff changeset
  2337
cb18fe3461b1 revset: changed spanset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20586
diff changeset
  2338
        return lazyset(generatorset(iterates()))
20483
ed57358398af revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20482
diff changeset
  2339
20484
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2340
    def __len__(self):
20521
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2341
        if not self._hiddenrevs:
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2342
            return abs(self._end - self._start)
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2343
        else:
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2344
            count = 0
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2345
            for rev in self._hiddenrevs:
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2346
                if self._contained(rev):
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2347
                    count += 1
1850a7f5fb66 revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20512
diff changeset
  2348
            return abs(self._end - self._start) - count
20484
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2349
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2350
    def __getitem__(self, x):
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2351
        # Basic implementation to be changed in future patches.
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2352
        l = baseset([r for r in self])
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2353
        return l[x]
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2354
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2355
    def sort(self, reverse=False):
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2356
        # Basic implementation to be changed in future patches.
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2357
        if reverse:
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2358
            self.reverse()
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2359
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2360
    def reverse(self):
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2361
        if self._start <= self._end:
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2362
            self._start, self._end = self._end - 1, self._start - 1
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2363
        else:
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2364
            self._start, self._end = self._end + 1, self._start + 1
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2365
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2366
    def set(self):
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2367
        return self
0f1ef9e9e904 revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20483
diff changeset
  2368
20610
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2369
    def filter(self, l):
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2370
        if self._start <= self._end:
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2371
            return orderedlazyset(self, l)
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2372
        else:
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2373
            return orderedlazyset(self, l, ascending=False)
34bb07e70c68 revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20609
diff changeset
  2374
12823
80deae3bc5ea hggettext: handle i18nfunctions declaration for docstrings translations
Patrick Mezard <pmezard@gmail.com>
parents: 12821
diff changeset
  2375
# tell hggettext to extract docstrings from these functions:
80deae3bc5ea hggettext: handle i18nfunctions declaration for docstrings translations
Patrick Mezard <pmezard@gmail.com>
parents: 12821
diff changeset
  2376
i18nfunctions = symbols.values()