author | Siddharth Agarwal <sid0@fb.com> |
Thu, 13 Feb 2014 13:52:45 -0800 | |
changeset 20497 | 19b1c62cee1c |
parent 20484 | 0f1ef9e9e904 |
child 20498 | fb2df4506c87 |
permissions | -rw-r--r-- |
11275 | 1 |
# revset.py - revision set queries for mercurial |
2 |
# |
|
3 |
# Copyright 2010 Matt Mackall <mpm@selenic.com> |
|
4 |
# |
|
5 |
# This software may be used and distributed according to the terms of the |
|
6 |
# GNU General Public License version 2 or any later version. |
|
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 | 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 | 82 |
elements = { |
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 | 92 |
"not": (10, ("not", 10)), |
93 |
"!": (10, ("not", 10)), |
|
94 |
"and": (5, None, ("and", 5)), |
|
95 |
"&": (5, None, ("and", 5)), |
|
96 |
"or": (4, None, ("or", 4)), |
|
97 |
"|": (4, None, ("or", 4)), |
|
98 |
"+": (4, None, ("or", 4)), |
|
99 |
",": (2, None, ("list", 2)), |
|
100 |
")": (0, None, None), |
|
101 |
"symbol": (0, ("symbol",), None), |
|
102 |
"string": (0, ("string",), None), |
|
103 |
"end": (0, None, None), |
|
104 |
} |
|
105 |
||
106 |
keywords = set(['and', 'or', 'not']) |
|
107 |
||
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 | 118 |
pos, l = 0, len(program) |
119 |
while pos < l: |
|
120 |
c = program[pos] |
|
121 |
if c.isspace(): # skip inter-token whitespace |
|
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 | 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 | 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 | 139 |
pos += 1 |
140 |
s = pos |
|
141 |
while pos < l: # find closing quote |
|
142 |
d = program[pos] |
|
143 |
if d == '\\': # skip over escaped characters |
|
144 |
pos += 2 |
|
145 |
continue |
|
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 | 148 |
break |
149 |
pos += 1 |
|
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 | 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 | 154 |
s = pos |
155 |
pos += 1 |
|
156 |
while pos < l: # find end of symbol |
|
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 | 159 |
break |
160 |
if d == '.' and program[pos - 1] == '.': # special case for .. |
|
161 |
pos -= 1 |
|
162 |
break |
|
163 |
pos += 1 |
|
164 |
sym = program[s:pos] |
|
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 | 167 |
else: |
11289
4215ce511134
revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents:
11284
diff
changeset
|
168 |
yield ('symbol', sym, s) |
11275 | 169 |
pos -= 1 |
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 | 172 |
pos += 1 |
11289
4215ce511134
revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents:
11284
diff
changeset
|
173 |
yield ('end', None, pos) |
11275 | 174 |
|
175 |
# helpers |
|
176 |
||
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 | 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 | 181 |
|
182 |
def getlist(x): |
|
183 |
if not x: |
|
184 |
return [] |
|
185 |
if x[0] == 'list': |
|
186 |
return getlist(x[1]) + [x[2]] |
|
187 |
return [x] |
|
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 | 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 | 193 |
return l |
194 |
||
195 |
def getset(repo, subset, x): |
|
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")) |
20443
b68984d288d4
revset: changed getset so that it can return a lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20429
diff
changeset
|
198 |
return methods[x[0]](repo, subset, *x[1:]) |
11275 | 199 |
|
17003
42c472877825
revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents:
17002
diff
changeset
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
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
|
204 |
try: |
42c472877825
revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents:
17002
diff
changeset
|
205 |
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
|
206 |
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
|
207 |
pass |
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 None |
42c472877825
revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents:
17002
diff
changeset
|
209 |
|
11275 | 210 |
# operator methods |
211 |
||
212 |
def stringset(repo, subset, x): |
|
213 |
x = repo[x].rev() |
|
11282 | 214 |
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
|
215 |
return baseset([-1]) |
13938
e44ebd2a142a
revset: optimize stringset when subset == entire repo
Idan Kamara <idankk86@gmail.com>
parents:
13932
diff
changeset
|
216 |
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
|
217 |
return baseset([x]) |
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
218 |
return baseset([]) |
11275 | 219 |
|
220 |
def symbolset(repo, subset, x): |
|
221 |
if x in symbols: |
|
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
222 |
raise error.ParseError(_("can't use %s here") % x) |
11275 | 223 |
return stringset(repo, subset, x) |
224 |
||
225 |
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
|
226 |
cl = baseset(repo.changelog) |
18473
692cbda1eb50
revset: evaluate sub expressions correctly (issue3775)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18411
diff
changeset
|
227 |
m = getset(repo, cl, x) |
692cbda1eb50
revset: evaluate sub expressions correctly (issue3775)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18411
diff
changeset
|
228 |
n = getset(repo, cl, y) |
11456
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
229 |
|
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
230 |
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
|
231 |
return baseset([]) |
11456
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
232 |
m, n = m[0], n[-1] |
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
233 |
|
11275 | 234 |
if m < n: |
11456
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
235 |
r = range(m, n + 1) |
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
236 |
else: |
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
237 |
r = range(m, n - 1, -1) |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
238 |
s = subset.set() |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
239 |
return baseset([x for x in r if x in s]) |
11275 | 240 |
|
16860
e1aa1ed30030
revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents:
16859
diff
changeset
|
241 |
def dagrange(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
|
242 |
r = baseset(repo) |
18991
c1af1fb314bc
log: fix behavior with empty repositories (issue3497)
Alexander Plavin <me@aplavin.ru>
parents:
18779
diff
changeset
|
243 |
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
|
244 |
s = subset.set() |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
245 |
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
|
246 |
|
11275 | 247 |
def andset(repo, subset, x, y): |
248 |
return getset(repo, getset(repo, subset, x), y) |
|
249 |
||
250 |
def orset(repo, subset, x, y): |
|
13932
34f577007ffe
revsets: preserve ordering with the or operator
Augie Fackler <durin42@gmail.com>
parents:
13915
diff
changeset
|
251 |
xl = getset(repo, subset, x) |
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
252 |
yl = getset(repo, subset - xl, y) |
20418
454c143b9955
revset: minor changes adding baseset to revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20417
diff
changeset
|
253 |
return xl + yl |
11275 | 254 |
|
255 |
def notset(repo, subset, x): |
|
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
256 |
return subset - getset(repo, subset, x) |
11275 | 257 |
|
258 |
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
|
259 |
raise error.ParseError(_("can't use a list in this context")) |
11275 | 260 |
|
261 |
def func(repo, subset, a, b): |
|
262 |
if a[0] == 'symbol' and a[1] in symbols: |
|
263 |
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
|
264 |
raise error.ParseError(_("not a function: %s") % a[1]) |
11275 | 265 |
|
266 |
# functions |
|
267 |
||
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
268 |
def adds(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
269 |
"""``adds(pattern)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
270 |
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
|
271 |
|
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
272 |
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
|
273 |
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
|
274 |
directory. |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
275 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
276 |
# i18n: "adds" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
277 |
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
|
278 |
return checkstatus(repo, subset, pat, 1) |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
279 |
|
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
280 |
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
|
281 |
"""``ancestor(*changeset)`` |
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
282 |
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
|
283 |
|
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
288 |
# 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
|
289 |
l = getlist(x) |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
290 |
rl = baseset(repo) |
18536
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
291 |
anc = None |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
292 |
|
18536
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
293 |
# (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
|
294 |
rev = repo.changelog.rev |
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
295 |
ancestor = repo.changelog.ancestor |
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
296 |
node = repo.changelog.node |
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
297 |
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
|
298 |
for r in revs: |
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
299 |
if anc is None: |
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
300 |
anc = r |
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
301 |
else: |
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
302 |
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
|
303 |
|
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
304 |
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
|
305 |
return baseset([anc]) |
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
306 |
return baseset([]) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
307 |
|
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
308 |
def _ancestors(repo, subset, x, followfirst=False): |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
309 |
args = getset(repo, baseset(repo), x) |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
310 |
if not args: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
311 |
return baseset([]) |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
312 |
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
|
313 |
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
|
314 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
315 |
def ancestors(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
316 |
"""``ancestors(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
317 |
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
|
318 |
""" |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
319 |
return _ancestors(repo, subset, x) |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
320 |
|
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
321 |
def _firstancestors(repo, subset, x): |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
322 |
# ``_firstancestors(set)`` |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
323 |
# 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
|
324 |
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
|
325 |
|
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
326 |
def ancestorspec(repo, subset, x, n): |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
327 |
"""``set~n`` |
16683 | 328 |
Changesets that are the Nth ancestor (first parents only) of a changeset |
329 |
in set. |
|
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
330 |
""" |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
331 |
try: |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
332 |
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
|
333 |
except (TypeError, ValueError): |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
334 |
raise error.ParseError(_("~ expects a number")) |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
335 |
ps = set() |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
336 |
cl = repo.changelog |
20424
1da346bad3d8
revset: minor changes adding baseset to revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20418
diff
changeset
|
337 |
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
|
338 |
for i in range(n): |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
339 |
r = cl.parentrevs(r)[0] |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
340 |
ps.add(r) |
20393
b0638b5b004d
revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20367
diff
changeset
|
341 |
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
|
342 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
343 |
def author(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
344 |
"""``author(string)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
345 |
Alias for ``user(string)``. |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
346 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
347 |
# 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
|
348 |
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
|
349 |
kind, pattern, matcher = _substringmatcher(n) |
20448
92f6f2db3cf4
revset: added lazyset implementation to author revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20447
diff
changeset
|
350 |
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
|
351 |
|
15134
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
352 |
def bisect(repo, subset, x): |
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
353 |
"""``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
|
354 |
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
|
355 |
|
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 |
- ``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
|
357 |
- ``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
|
358 |
- ``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
|
359 |
- ``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
|
360 |
- ``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
|
361 |
- ``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
|
362 |
- ``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
|
363 |
""" |
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
|
364 |
# 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
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
|
15134
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
369 |
# Backward-compatibility |
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
370 |
# - 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
|
371 |
def bisected(repo, subset, x): |
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
372 |
return bisect(repo, subset, x) |
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
373 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
374 |
def bookmark(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
375 |
"""``bookmark([name])`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
376 |
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
|
377 |
|
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
378 |
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
|
379 |
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
|
380 |
use the prefix `literal:`. |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
381 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
382 |
# i18n: "bookmark" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
383 |
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
|
384 |
if args: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
385 |
bm = getstring(args[0], |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
386 |
# i18n: "bookmark" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
387 |
_('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
|
388 |
kind, pattern, matcher = _stringmatcher(bm) |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
389 |
if kind == 'literal': |
18495
8260fa9f30b9
bookmarks: don't use bookmarks.listbookmarks in local computations
Kevin Bullock <kbullock@ringworld.org>
parents:
18473
diff
changeset
|
390 |
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
|
391 |
if not bmrev: |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
392 |
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
|
393 |
bmrev = repo[bmrev].rev() |
20450
4f1aed2c7a7e
revset: added lazyset implementation bookmark revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20449
diff
changeset
|
394 |
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
|
395 |
else: |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
396 |
matchrevs = set() |
18495
8260fa9f30b9
bookmarks: don't use bookmarks.listbookmarks in local computations
Kevin Bullock <kbullock@ringworld.org>
parents:
18473
diff
changeset
|
397 |
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
|
398 |
if matcher(name): |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
399 |
matchrevs.add(bmrev) |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
400 |
if not matchrevs: |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
401 |
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
|
402 |
% pattern) |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
403 |
bmrevs = set() |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
404 |
for bmrev in matchrevs: |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
405 |
bmrevs.add(repo[bmrev].rev()) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
406 |
return subset & bmrevs |
16822
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
407 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
408 |
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
|
409 |
for r in repo._bookmarks.values()]) |
20450
4f1aed2c7a7e
revset: added lazyset implementation bookmark revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20449
diff
changeset
|
410 |
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
|
411 |
|
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
412 |
def branch(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
413 |
"""``branch(string or set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
414 |
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
|
415 |
changesets. |
16821
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
416 |
|
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
417 |
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
|
418 |
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
|
419 |
use the prefix `literal:`. |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
420 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
421 |
try: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
422 |
b = getstring(x, '') |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
423 |
except error.ParseError: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
424 |
# 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
|
425 |
pass |
16821
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
426 |
else: |
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
427 |
kind, pattern, matcher = _stringmatcher(b) |
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
428 |
if kind == 'literal': |
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
429 |
# 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
|
430 |
# this name exists |
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
431 |
if pattern in repo.branchmap(): |
20445
507261c0914f
revset: added lazyset implementation to branch revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20443
diff
changeset
|
432 |
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
|
433 |
else: |
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())) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
435 |
|
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
436 |
s = getset(repo, baseset(repo), x) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
437 |
b = set() |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
438 |
for r in s: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
439 |
b.add(repo[r].branch()) |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
440 |
s = s.set() |
20445
507261c0914f
revset: added lazyset implementation to branch revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20443
diff
changeset
|
441 |
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
|
442 |
|
17829
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
443 |
def bumped(repo, subset, x): |
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
444 |
"""``bumped()`` |
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
445 |
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
|
446 |
|
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
447 |
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
|
448 |
""" |
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
449 |
# i18n: "bumped" is a keyword |
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
450 |
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
|
451 |
bumped = obsmod.getrevs(repo, 'bumped') |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
452 |
return subset & bumped |
17829
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
453 |
|
17913
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
454 |
def bundle(repo, subset, x): |
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
455 |
"""``bundle()`` |
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
456 |
Changesets in the bundle. |
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
457 |
|
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
458 |
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
|
459 |
|
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
460 |
try: |
18411
8b0f0dd56cec
bundlerepo: improve performance for bundle() revset expression
Mads Kiilerich <madski@unity3d.com>
parents:
18382
diff
changeset
|
461 |
bundlerevs = repo.changelog.bundlerevs |
17913
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
462 |
except AttributeError: |
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
463 |
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
|
464 |
return subset & bundlerevs |
17913
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
465 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
466 |
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
|
467 |
hasset = matchmod.patkind(pat) == 'set' |
20457
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
468 |
|
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
469 |
def matches(x): |
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
470 |
m = None |
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
471 |
fname = None |
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
472 |
c = repo[x] |
16521
592701c8eac6
revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents:
16467
diff
changeset
|
473 |
if not m or hasset: |
592701c8eac6
revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents:
16467
diff
changeset
|
474 |
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
|
475 |
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
|
476 |
fname = m.files()[0] |
592701c8eac6
revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents:
16467
diff
changeset
|
477 |
if fname is not None: |
592701c8eac6
revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents:
16467
diff
changeset
|
478 |
if fname not in c.files(): |
20457
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
479 |
return False |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
480 |
else: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
481 |
for f in c.files(): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
482 |
if m(f): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
483 |
break |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
484 |
else: |
20457
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
485 |
return False |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
486 |
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
|
487 |
if fname is not None: |
592701c8eac6
revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents:
16467
diff
changeset
|
488 |
if fname in files: |
20457
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
489 |
return True |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
490 |
else: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
491 |
for f in files: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
492 |
if m(f): |
20457
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
493 |
return True |
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
494 |
|
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
495 |
return lazyset(subset, matches) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
496 |
|
16396
03e408a122c4
revset: avoid set duplication in roots()
Patrick Mezard <patrick@mezard.eu>
parents:
16395
diff
changeset
|
497 |
def _children(repo, narrow, parentset): |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
498 |
cs = set() |
18063
34a1a639d835
revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents:
17980
diff
changeset
|
499 |
if not parentset: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
500 |
return baseset(cs) |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
501 |
pr = repo.changelog.parentrevs |
18063
34a1a639d835
revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents:
17980
diff
changeset
|
502 |
minrev = min(parentset) |
16394
f3df7d34791e
revset: do not ignore input revisions in roots()
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
503 |
for r in narrow: |
18063
34a1a639d835
revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents:
17980
diff
changeset
|
504 |
if r <= minrev: |
34a1a639d835
revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents:
17980
diff
changeset
|
505 |
continue |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
506 |
for p in pr(r): |
16396
03e408a122c4
revset: avoid set duplication in roots()
Patrick Mezard <patrick@mezard.eu>
parents:
16395
diff
changeset
|
507 |
if p in parentset: |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
508 |
cs.add(r) |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
509 |
return baseset(cs) |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
510 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
511 |
def children(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
512 |
"""``children(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
513 |
Child changesets of changesets in set. |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
514 |
""" |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
515 |
s = getset(repo, baseset(repo), x).set() |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
516 |
cs = _children(repo, subset, s) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
517 |
return subset & cs |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
518 |
|
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
519 |
def closed(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
520 |
"""``closed()`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
521 |
Changeset is closed. |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
522 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
523 |
# i18n: "closed" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
524 |
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
|
525 |
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
|
526 |
|
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
527 |
def contains(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
528 |
"""``contains(pattern)`` |
14357 | 529 |
Revision contains a file matching pattern. See :hg:`help patterns` |
530 |
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
|
531 |
|
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
532 |
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
|
533 |
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
|
534 |
for efficiency. |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
535 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
536 |
# i18n: "contains" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
537 |
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
|
538 |
|
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
539 |
def matches(x): |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
540 |
if not matchmod.patkind(pat): |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
541 |
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
|
542 |
if pats in repo[x]: |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
543 |
return True |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
544 |
else: |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
545 |
c = repo[x] |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
546 |
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
|
547 |
for f in c.manifest(): |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
548 |
if m(f): |
20461
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
549 |
return True |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
550 |
return False |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
551 |
|
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
552 |
return lazyset(subset, matches) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
553 |
|
17002
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
554 |
def converted(repo, subset, x): |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
555 |
"""``converted([id])`` |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
556 |
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
|
557 |
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
|
558 |
""" |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
559 |
|
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
560 |
# 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
|
561 |
# 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
|
562 |
|
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
|
563 |
rev = None |
17002
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
564 |
# i18n: "converted" is a keyword |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
565 |
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
|
566 |
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
|
567 |
# 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
|
568 |
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
|
569 |
|
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
570 |
def _matchvalue(r): |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
571 |
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
|
572 |
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
|
573 |
|
20480
ada89e5b5b0c
revset: added lazyset implementation to converted revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20479
diff
changeset
|
574 |
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
|
575 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
576 |
def date(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
577 |
"""``date(interval)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
578 |
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
|
579 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
580 |
# i18n: "date" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
581 |
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
|
582 |
dm = util.matchdate(ds) |
20449
ad2f1512eaa6
revset: added lazyset implementation to date revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20448
diff
changeset
|
583 |
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
|
584 |
|
14650
93731b3efd0d
revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14649
diff
changeset
|
585 |
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
|
586 |
"""``desc(string)`` |
93731b3efd0d
revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14649
diff
changeset
|
587 |
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
|
588 |
""" |
93731b3efd0d
revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14649
diff
changeset
|
589 |
# 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
|
590 |
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
|
591 |
|
a685d9870eb5
revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20451
diff
changeset
|
592 |
def matches(x): |
a685d9870eb5
revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20451
diff
changeset
|
593 |
c = repo[x] |
a685d9870eb5
revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20451
diff
changeset
|
594 |
return ds in encoding.lower(c.description()) |
a685d9870eb5
revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20451
diff
changeset
|
595 |
|
a685d9870eb5
revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20451
diff
changeset
|
596 |
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
|
597 |
|
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
598 |
def _descendants(repo, subset, x, followfirst=False): |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
599 |
args = getset(repo, baseset(repo), x) |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
600 |
if not args: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
601 |
return baseset([]) |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
602 |
s = set(_revdescendants(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
|
603 |
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
|
604 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
605 |
def descendants(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
606 |
"""``descendants(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
607 |
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
|
608 |
""" |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
609 |
return _descendants(repo, subset, x) |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
610 |
|
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
611 |
def _firstdescendants(repo, subset, x): |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
612 |
# ``_firstdescendants(set)`` |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
613 |
# 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
|
614 |
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
|
615 |
|
17186
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
616 |
def destination(repo, subset, x): |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
617 |
"""``destination([set])`` |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
618 |
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
|
619 |
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
|
620 |
is the same as passing all(). |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
621 |
""" |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
622 |
if x is not None: |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
623 |
args = getset(repo, baseset(repo), x).set() |
17186
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
624 |
else: |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
625 |
args = getall(repo, baseset(repo), x).set() |
17186
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
626 |
|
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
627 |
dests = set() |
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 |
# 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
|
630 |
# 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
|
631 |
# 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
|
632 |
# 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
|
633 |
# 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
|
634 |
# grafts. |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
635 |
for r in subset: |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
636 |
src = _getrevsource(repo, r) |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
637 |
lineage = None |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
638 |
|
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
639 |
while src is not None: |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
640 |
if lineage is None: |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
641 |
lineage = list() |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
642 |
|
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
643 |
lineage.append(r) |
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 |
# 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
|
646 |
# set. Since every candidate dest is visited by way of iterating |
17494 | 647 |
# 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
|
648 |
# 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
|
649 |
# 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
|
650 |
# further. |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
651 |
if src in args or src in dests: |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
652 |
dests.update(lineage) |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
653 |
break |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
654 |
|
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
655 |
r = src |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
656 |
src = _getrevsource(repo, r) |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
657 |
|
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
658 |
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
|
659 |
|
18071
bea754715961
obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18063
diff
changeset
|
660 |
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
|
661 |
"""``divergent()`` |
bea754715961
obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18063
diff
changeset
|
662 |
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
|
663 |
""" |
bea754715961
obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18063
diff
changeset
|
664 |
# 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
|
665 |
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
|
666 |
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
|
667 |
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
|
668 |
|
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
669 |
def draft(repo, subset, x): |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
670 |
"""``draft()`` |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
671 |
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
|
672 |
# 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
|
673 |
getargs(x, 0, 0, _("draft takes no arguments")) |
16657
b6081c2c4647
phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents:
16647
diff
changeset
|
674 |
pc = repo._phasecache |
20451
ac7cebf45eb4
revset: added lazyset implementation to draft revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20450
diff
changeset
|
675 |
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
|
676 |
|
17173
c621f84dbb35
obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17171
diff
changeset
|
677 |
def extinct(repo, subset, x): |
c621f84dbb35
obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17171
diff
changeset
|
678 |
"""``extinct()`` |
17291
2d6bbf87f7b4
revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents:
17272
diff
changeset
|
679 |
Obsolete changesets with obsolete descendants only. |
2d6bbf87f7b4
revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents:
17272
diff
changeset
|
680 |
""" |
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
|
681 |
# 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
|
682 |
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
|
683 |
extincts = obsmod.getrevs(repo, 'extinct') |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
684 |
return subset & extincts |
17173
c621f84dbb35
obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17171
diff
changeset
|
685 |
|
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
686 |
def extra(repo, subset, x): |
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
687 |
"""``extra(label, [value])`` |
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
688 |
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
|
689 |
optional value. |
f3b8c82a559c
revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents:
16823
diff
changeset
|
690 |
|
f3b8c82a559c
revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents:
16823
diff
changeset
|
691 |
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
|
692 |
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
|
693 |
use the prefix `literal:`. |
f3b8c82a559c
revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents:
16823
diff
changeset
|
694 |
""" |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
695 |
|
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
|
696 |
# i18n: "extra" is a keyword |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
697 |
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
|
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 |
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
|
700 |
value = None |
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
701 |
|
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
702 |
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
|
703 |
# i18n: "extra" is a keyword |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
704 |
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
|
705 |
kind, value, matcher = _stringmatcher(value) |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
706 |
|
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
707 |
def _matchvalue(r): |
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
708 |
extra = repo[r].extra() |
16824
f3b8c82a559c
revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents:
16823
diff
changeset
|
709 |
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
|
710 |
|
20481
a5d7081a4c34
revset: added lazyset implementation to extra revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20480
diff
changeset
|
711 |
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
|
712 |
|
14342
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
713 |
def filelog(repo, subset, x): |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
714 |
"""``filelog(pattern)`` |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
715 |
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
|
716 |
|
17265
c30307eeec4b
revset: polish explanation of the difference between file() and filelog()
Greg Ward <greg@gerg.ca>
parents:
17259
diff
changeset
|
717 |
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
|
718 |
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
|
719 |
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
|
720 |
|
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
721 |
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
|
722 |
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
|
723 |
for efficiency. |
14342
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
724 |
""" |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
725 |
|
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
|
726 |
# 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
|
727 |
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
|
728 |
s = set() |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
729 |
|
15964
6e37b8282aa2
revsets: provide contexts for filesets
Matt Mackall <mpm@selenic.com>
parents:
15949
diff
changeset
|
730 |
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
|
731 |
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
|
732 |
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
|
733 |
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
|
734 |
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
|
735 |
else: |
20288
b61ad01c4e73
revset: use "canonpath()" for "filelog()" pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20287
diff
changeset
|
736 |
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
|
737 |
for f in repo[None]: |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
738 |
if m(f): |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
739 |
fl = repo.file(f) |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
740 |
for fr in fl: |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
741 |
s.add(fl.linkrev(fr)) |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
742 |
|
20393
b0638b5b004d
revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20367
diff
changeset
|
743 |
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
|
744 |
|
15117
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
745 |
def first(repo, subset, x): |
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
746 |
"""``first(set, [n])`` |
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
747 |
An alias for limit(). |
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
748 |
""" |
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
749 |
return limit(repo, subset, x) |
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
750 |
|
16185
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
751 |
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
|
752 |
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
|
753 |
c = repo['.'] |
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
754 |
if l: |
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
755 |
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
|
756 |
if x in c: |
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
757 |
cx = c[x] |
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
758 |
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
|
759 |
# 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
|
760 |
s.add(cx.linkrev()) |
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
761 |
else: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
762 |
return baseset([]) |
16185
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
763 |
else: |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
764 |
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
|
765 |
|
20393
b0638b5b004d
revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20367
diff
changeset
|
766 |
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
|
767 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
768 |
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
|
769 |
"""``follow([file])`` |
9ed227f79e47
revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents:
14342
diff
changeset
|
770 |
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
|
771 |
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
|
772 |
including copies. |
9ed227f79e47
revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents:
14342
diff
changeset
|
773 |
""" |
16185
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
774 |
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
|
775 |
|
16174
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
776 |
def _followfirst(repo, subset, x): |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
777 |
# ``followfirst([file])`` |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
778 |
# Like ``follow([file])`` but follows only the first parent of |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
779 |
# every revision or file revision. |
16185
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
780 |
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
|
781 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
782 |
def getall(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
783 |
"""``all()`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
784 |
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
|
785 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
786 |
# i18n: "all" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
787 |
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
|
788 |
return subset |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
789 |
|
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
790 |
def grep(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
791 |
"""``grep(regex)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
792 |
Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` |
14357 | 793 |
to ensure special escape characters are handled correctly. Unlike |
794 |
``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
|
795 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
796 |
try: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
797 |
# i18n: "grep" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
798 |
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
|
799 |
except re.error, e: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
800 |
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
|
801 |
|
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
802 |
def matches(x): |
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
803 |
c = repo[x] |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
804 |
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
|
805 |
if gr.search(e): |
20453
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
806 |
return True |
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
807 |
return False |
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
808 |
|
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
809 |
return lazyset(subset, matches) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
810 |
|
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
811 |
def _matchfiles(repo, subset, x): |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
812 |
# _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
|
813 |
# |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
814 |
# [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
|
815 |
# |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
816 |
# 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
|
817 |
# 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
|
818 |
# 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
|
819 |
# 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
|
820 |
# 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
|
821 |
# 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
|
822 |
# 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
|
823 |
|
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
824 |
# i18n: "_matchfiles" is a keyword |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
825 |
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
|
826 |
pats, inc, exc = [], [], [] |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
827 |
hasset = False |
16411
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
828 |
rev, default = None, None |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
829 |
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
|
830 |
# 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
|
831 |
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
|
832 |
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
|
833 |
if prefix == 'p:': |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
834 |
pats.append(value) |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
835 |
elif prefix == 'i:': |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
836 |
inc.append(value) |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
837 |
elif prefix == 'x:': |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
838 |
exc.append(value) |
16181
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
839 |
elif prefix == 'r:': |
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
840 |
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
|
841 |
# 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
|
842 |
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
|
843 |
'revision')) |
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
844 |
rev = value |
16411
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
845 |
elif prefix == 'd:': |
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
846 |
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
|
847 |
# i18n: "_matchfiles" is a keyword |
16411
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
848 |
raise error.ParseError(_('_matchfiles expected at most one ' |
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
849 |
'default mode')) |
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
850 |
default = value |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
851 |
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
|
852 |
# 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
|
853 |
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
|
854 |
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
|
855 |
hasset = True |
16411
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
856 |
if not default: |
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
857 |
default = 'glob' |
20458
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
858 |
|
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
859 |
def matches(x): |
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
860 |
m = None |
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
861 |
c = repo[x] |
16181
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
862 |
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
|
863 |
ctx = c |
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
864 |
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
|
865 |
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
|
866 |
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
|
867 |
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
|
868 |
for f in c.files(): |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
869 |
if m(f): |
20458
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
870 |
return True |
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
871 |
return False |
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
872 |
|
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
873 |
return lazyset(subset, matches) |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
874 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
875 |
def hasfile(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
876 |
"""``file(pattern)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
877 |
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
|
878 |
|
17265
c30307eeec4b
revset: polish explanation of the difference between file() and filelog()
Greg Ward <greg@gerg.ca>
parents:
17259
diff
changeset
|
879 |
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
|
880 |
instead. |
20289
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
881 |
|
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
882 |
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
|
883 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
884 |
# i18n: "file" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
885 |
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
|
886 |
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
|
887 |
|
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
888 |
def head(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
889 |
"""``head()`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
890 |
Changeset is a named branch head. |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
891 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
892 |
# i18n: "head" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
893 |
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
|
894 |
hs = set() |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
895 |
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
|
896 |
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
|
897 |
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
|
898 |
|
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
899 |
def heads(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
900 |
"""``heads(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
901 |
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
|
902 |
""" |
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
903 |
s = getset(repo, subset, x) |
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
904 |
ps = parents(repo, subset, x) |
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
905 |
return s - ps |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
906 |
|
17390
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
907 |
def hidden(repo, subset, x): |
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
908 |
"""``hidden()`` |
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
909 |
Hidden changesets. |
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
910 |
""" |
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
911 |
# i18n: "hidden" is a keyword |
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
912 |
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
|
913 |
hiddenrevs = repoview.filterrevs(repo, 'visible') |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
914 |
return subset & hiddenrevs |
17390
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
915 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
916 |
def keyword(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
917 |
"""``keyword(string)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
918 |
Search commit message, user name, and names of changed files for |
14357 | 919 |
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
|
920 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
921 |
# 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
|
922 |
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
|
923 |
|
abb91b74f758
revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20446
diff
changeset
|
924 |
def matches(r): |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
925 |
c = repo[r] |
20447
abb91b74f758
revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20446
diff
changeset
|
926 |
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
|
927 |
c.description()]) |
abb91b74f758
revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20446
diff
changeset
|
928 |
|
abb91b74f758
revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20446
diff
changeset
|
929 |
return lazyset(subset, matches) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
930 |
|
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
931 |
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
|
932 |
"""``limit(set, [n])`` |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
933 |
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
|
934 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
935 |
# 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
|
936 |
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
|
937 |
try: |
15116
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
938 |
lim = 1 |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
939 |
if len(l) == 2: |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
940 |
# 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
|
941 |
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
|
942 |
except (TypeError, ValueError): |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
943 |
# i18n: "limit" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
944 |
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
|
945 |
ss = subset.set() |
20446
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
946 |
os = getset(repo, baseset(repo), l[0]) |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
947 |
bs = baseset([]) |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
948 |
it = iter(os) |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
949 |
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
|
950 |
try: |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
951 |
y = it.next() |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
952 |
if y in ss: |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
953 |
bs.append(y) |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
954 |
except (StopIteration): |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
955 |
break |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
956 |
return bs |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
957 |
|
14061
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
958 |
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
|
959 |
"""``last(set, [n])`` |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
960 |
Last n members of set, defaulting to 1. |
14061
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
961 |
""" |
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
962 |
# 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
|
963 |
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
|
964 |
try: |
15116
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
965 |
lim = 1 |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
966 |
if len(l) == 2: |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
967 |
# 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
|
968 |
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
|
969 |
except (TypeError, ValueError): |
14061
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
970 |
# i18n: "last" is a keyword |
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
971 |
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
|
972 |
ss = subset.set() |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
973 |
os = getset(repo, baseset(repo), l[0])[-lim:] |
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
974 |
return baseset([r for r in os if r in ss]) |
14061
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
975 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
976 |
def maxrev(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
977 |
"""``max(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
978 |
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
|
979 |
""" |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
980 |
os = getset(repo, baseset(repo), x) |
14153
f8047a059ca0
revset: avoid over-aggresive optimizations of non-filtering functions (issue2549)
Mads Kiilerich <mads@kiilerich.com>
parents:
14098
diff
changeset
|
981 |
if os: |
f8047a059ca0
revset: avoid over-aggresive optimizations of non-filtering functions (issue2549)
Mads Kiilerich <mads@kiilerich.com>
parents:
14098
diff
changeset
|
982 |
m = max(os) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
983 |
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
|
984 |
return baseset([m]) |
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
985 |
return baseset([]) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
986 |
|
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
987 |
def merge(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
988 |
"""``merge()`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
989 |
Changeset is a merge changeset. |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
990 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
991 |
# i18n: "merge" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
992 |
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
|
993 |
cl = repo.changelog |
20454
47fd57f650e5
revset: added lazyset implementation to merge revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20453
diff
changeset
|
994 |
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
|
995 |
|
17753
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
996 |
def branchpoint(repo, subset, x): |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
997 |
"""``branchpoint()`` |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
998 |
Changesets with more than one child. |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
999 |
""" |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1000 |
# i18n: "branchpoint" is a keyword |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1001 |
getargs(x, 0, 0, _("branchpoint takes no arguments")) |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1002 |
cl = repo.changelog |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1003 |
if not subset: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1004 |
return baseset([]) |
17753
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1005 |
baserev = min(subset) |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1006 |
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
|
1007 |
for r in cl.revs(start=baserev + 1): |
17753
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1008 |
for p in cl.parentrevs(r): |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1009 |
if p >= baserev: |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1010 |
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
|
1011 |
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
|
1012 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1013 |
def minrev(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1014 |
"""``min(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1015 |
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
|
1016 |
""" |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1017 |
os = getset(repo, baseset(repo), x) |
14153
f8047a059ca0
revset: avoid over-aggresive optimizations of non-filtering functions (issue2549)
Mads Kiilerich <mads@kiilerich.com>
parents:
14098
diff
changeset
|
1018 |
if os: |
f8047a059ca0
revset: avoid over-aggresive optimizations of non-filtering functions (issue2549)
Mads Kiilerich <mads@kiilerich.com>
parents:
14098
diff
changeset
|
1019 |
m = min(os) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1020 |
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
|
1021 |
return baseset([m]) |
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1022 |
return baseset([]) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1023 |
|
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1024 |
def modifies(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1025 |
"""``modifies(pattern)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1026 |
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
|
1027 |
|
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
1028 |
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
|
1029 |
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
|
1030 |
directory. |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1031 |
""" |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1032 |
# i18n: "modifies" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1033 |
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
|
1034 |
return checkstatus(repo, subset, pat, 0) |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1035 |
|
16417
b4b0c6931e11
revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents:
16415
diff
changeset
|
1036 |
def node_(repo, subset, x): |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1037 |
"""``id(string)`` |
12859
76066903ae08
revset: fix missing dot in docstring
Wagner Bruna <wbruna@yahoo.com>
parents:
12855
diff
changeset
|
1038 |
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
|
1039 |
""" |
12815
079a618ea89d
revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents:
12786
diff
changeset
|
1040 |
# 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
|
1041 |
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
|
1042 |
# 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
|
1043 |
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
|
1044 |
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
|
1045 |
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
|
1046 |
else: |
16735
47b8ec0eb7fb
revset: fix traceback for bogus revisions in id(rev)
Matt Harbison <matt_harbison@yahoo.com>
parents:
16640
diff
changeset
|
1047 |
rn = None |
47b8ec0eb7fb
revset: fix traceback for bogus revisions in id(rev)
Matt Harbison <matt_harbison@yahoo.com>
parents:
16640
diff
changeset
|
1048 |
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
|
1049 |
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
|
1050 |
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
|
1051 |
|
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1052 |
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
|
1053 |
|
17170
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1054 |
def obsolete(repo, subset, x): |
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1055 |
"""``obsolete()`` |
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1056 |
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
|
1057 |
# i18n: "obsolete" is a keyword |
17170
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1058 |
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
|
1059 |
obsoletes = obsmod.getrevs(repo, 'obsolete') |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1060 |
return subset & obsoletes |
17170
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1061 |
|
17185
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1062 |
def origin(repo, subset, x): |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1063 |
"""``origin([set])`` |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1064 |
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
|
1065 |
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
|
1066 |
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
|
1067 |
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
|
1068 |
for the first operation is selected. |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1069 |
""" |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1070 |
if x is not None: |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
1071 |
args = getset(repo, baseset(repo), x).set() |
17185
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1072 |
else: |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
1073 |
args = getall(repo, baseset(repo), x).set() |
17185
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1074 |
|
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1075 |
def _firstsrc(rev): |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1076 |
src = _getrevsource(repo, rev) |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1077 |
if src is None: |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1078 |
return None |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1079 |
|
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1080 |
while True: |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1081 |
prev = _getrevsource(repo, src) |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1082 |
|
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1083 |
if prev is None: |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1084 |
return src |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1085 |
src = prev |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1086 |
|
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1087 |
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
|
1088 |
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
|
1089 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1090 |
def outgoing(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1091 |
"""``outgoing([path])`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1092 |
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
|
1093 |
default push location. |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1094 |
""" |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1095 |
import hg # avoid start-up nasties |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1096 |
# 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
|
1097 |
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
|
1098 |
# i18n: "outgoing" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1099 |
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
|
1100 |
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
|
1101 |
dest, branches = hg.parseurl(dest) |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1102 |
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
|
1103 |
if revs: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1104 |
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
|
1105 |
other = hg.peer(repo, {}, dest) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1106 |
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
|
1107 |
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
|
1108 |
repo.ui.popbuffer() |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1109 |
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
|
1110 |
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
|
1111 |
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
|
1112 |
|
11275 | 1113 |
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
|
1114 |
"""``p1([set])`` |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1115 |
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
|
1116 |
""" |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1117 |
if x is None: |
13878
a8d13ee0ce68
misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents:
13873
diff
changeset
|
1118 |
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
|
1119 |
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
|
1120 |
|
11275 | 1121 |
ps = set() |
1122 |
cl = repo.changelog |
|
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1123 |
for r in getset(repo, baseset(repo), x): |
11275 | 1124 |
ps.add(cl.parentrevs(r)[0]) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1125 |
return subset & ps |
11275 | 1126 |
|
1127 |
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
|
1128 |
"""``p2([set])`` |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1129 |
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
|
1130 |
""" |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1131 |
if x is None: |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1132 |
ps = repo[x].parents() |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1133 |
try: |
12935
98b79c892768
revset: fix p1, p2 and parents in dirstate case (a5f7f1e9340e)
Patrick Mezard <pmezard@gmail.com>
parents:
12929
diff
changeset
|
1134 |
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
|
1135 |
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
|
1136 |
except IndexError: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1137 |
return baseset([]) |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1138 |
|
11275 | 1139 |
ps = set() |
1140 |
cl = repo.changelog |
|
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1141 |
for r in getset(repo, baseset(repo), x): |
11275 | 1142 |
ps.add(cl.parentrevs(r)[1]) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1143 |
return subset & ps |
11275 | 1144 |
|
1145 |
def parents(repo, subset, x): |
|
12929
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
1146 |
"""``parents([set])`` |
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
1147 |
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
|
1148 |
""" |
12929
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
1149 |
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
|
1150 |
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
|
1151 |
return subset & ps |
12929
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
1152 |
|
11275 | 1153 |
ps = set() |
1154 |
cl = repo.changelog |
|
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1155 |
for r in getset(repo, baseset(repo), x): |
11275 | 1156 |
ps.update(cl.parentrevs(r)) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1157 |
return subset & ps |
11275 | 1158 |
|
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1159 |
def parentspec(repo, subset, x, n): |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1160 |
"""``set^0`` |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1161 |
The set. |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1162 |
``set^1`` (or ``set^``), ``set^2`` |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1163 |
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
|
1164 |
""" |
12320
40c40c6f20b8
revset: handle re.compile() errors in grep()
Brodie Rao <brodie@bitheap.org>
parents:
11882
diff
changeset
|
1165 |
try: |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1166 |
n = int(n[1]) |
14072
2e4d79dcc0a0
revset: add missing whitespace
Kevin Gessner <kevin@kevingessner.com>
parents:
14070
diff
changeset
|
1167 |
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
|
1168 |
raise ValueError |
14851
f96c354493d7
revsets: actually catch type error on tip^p1(tip) (issue2884)
Matt Mackall <mpm@selenic.com>
parents:
14842
diff
changeset
|
1169 |
except (TypeError, ValueError): |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1170 |
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
|
1171 |
ps = set() |
11275 | 1172 |
cl = repo.changelog |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1173 |
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
|
1174 |
if n == 0: |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1175 |
ps.add(r) |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1176 |
elif n == 1: |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1177 |
ps.add(cl.parentrevs(r)[0]) |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1178 |
elif n == 2: |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1179 |
parents = cl.parentrevs(r) |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1180 |
if len(parents) > 1: |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1181 |
ps.add(parents[1]) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1182 |
return subset & ps |
11275 | 1183 |
|
11944
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1184 |
def present(repo, subset, x): |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1185 |
"""``present(set)`` |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1186 |
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
|
1187 |
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
|
1188 |
|
0a730d3c5aae
doc: add detail explanation for 'present()' predicate of revsets
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16735
diff
changeset
|
1189 |
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
|
1190 |
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
|
1191 |
to continue even in such cases. |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1192 |
""" |
11944
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1193 |
try: |
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1194 |
return getset(repo, subset, x) |
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1195 |
except error.RepoLookupError: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1196 |
return baseset([]) |
11944
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1197 |
|
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1198 |
def public(repo, subset, x): |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1199 |
"""``public()`` |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1200 |
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
|
1201 |
# 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
|
1202 |
getargs(x, 0, 0, _("public takes no arguments")) |
16657
b6081c2c4647
phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents:
16647
diff
changeset
|
1203 |
pc = repo._phasecache |
20456
9a49feb408f3
revset: added lazyset implementation to public revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20454
diff
changeset
|
1204 |
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
|
1205 |
|
15936
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1206 |
def remote(repo, subset, x): |
16007
f06c53ca59a9
revset: fix documentation for 'remote()' predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16006
diff
changeset
|
1207 |
"""``remote([id [,path]])`` |
15936
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1208 |
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
|
1209 |
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
|
1210 |
synonym for the current local branch. |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1211 |
""" |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1212 |
|
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1213 |
import hg # avoid start-up nasties |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1214 |
# i18n: "remote" is a keyword |
16007
f06c53ca59a9
revset: fix documentation for 'remote()' predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16006
diff
changeset
|
1215 |
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
|
1216 |
|
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1217 |
q = '.' |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1218 |
if len(l) > 0: |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1219 |
# i18n: "remote" is a keyword |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1220 |
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
|
1221 |
if q == '.': |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1222 |
q = repo['.'].branch() |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1223 |
|
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1224 |
dest = '' |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1225 |
if len(l) > 1: |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1226 |
# i18n: "remote" is a keyword |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1227 |
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
|
1228 |
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
|
1229 |
dest, branches = hg.parseurl(dest) |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1230 |
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
|
1231 |
if revs: |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1232 |
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
|
1233 |
other = hg.peer(repo, {}, dest) |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1234 |
n = other.lookup(q) |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1235 |
if n in repo: |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1236 |
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
|
1237 |
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
|
1238 |
return baseset([r]) |
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1239 |
return baseset([]) |
15936
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1240 |
|
11275 | 1241 |
def removes(repo, subset, x): |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1242 |
"""``removes(pattern)`` |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1243 |
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
|
1244 |
|
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
1245 |
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
|
1246 |
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
|
1247 |
directory. |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1248 |
""" |
12815
079a618ea89d
revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents:
12786
diff
changeset
|
1249 |
# 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
|
1250 |
pat = getstring(x, _("removes requires a pattern")) |
11275 | 1251 |
return checkstatus(repo, subset, pat, 2) |
1252 |
||
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1253 |
def rev(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1254 |
"""``rev(number)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1255 |
Revision with the given numeric identifier. |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1256 |
""" |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1257 |
# i18n: "rev" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1258 |
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
|
1259 |
try: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1260 |
# i18n: "rev" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1261 |
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
|
1262 |
except (TypeError, ValueError): |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1263 |
# i18n: "rev" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1264 |
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
|
1265 |
return baseset([r for r in subset if r == l]) |
11275 | 1266 |
|
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1267 |
def matching(repo, subset, x): |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1268 |
"""``matching(revision [, field])`` |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1269 |
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
|
1270 |
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
|
1271 |
|
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1272 |
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
|
1273 |
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
|
1274 |
|
5d803620ca05
doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16521
diff
changeset
|
1275 |
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
|
1276 |
|
5d803620ca05
doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16521
diff
changeset
|
1277 |
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
|
1278 |
``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` |
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1279 |
and ``diff``. |
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1280 |
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
|
1281 |
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
|
1282 |
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
|
1283 |
|
5d803620ca05
doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16521
diff
changeset
|
1284 |
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
|
1285 |
``summary`` matches the first line of the description. |
16639
00290bd359fe
revset: documentation typo "metatadata"
Jesse Glick <jesse.glick@oracle.com>
parents:
16528
diff
changeset
|
1286 |
``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
|
1287 |
(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
|
1288 |
|
5d803620ca05
doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16521
diff
changeset
|
1289 |
``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
|
1290 |
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
|
1291 |
""" |
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
|
1292 |
# i18n: "matching" is a keyword |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1293 |
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
|
1294 |
|
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1295 |
revs = getset(repo, baseset(repo.changelog), l[0]) |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1296 |
|
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1297 |
fieldlist = ['metadata'] |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1298 |
if len(l) > 1: |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1299 |
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
|
1300 |
# i18n: "matching" is a keyword |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1301 |
_("matching requires a string " |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1302 |
"as its second argument")).split() |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1303 |
|
17102
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1304 |
# 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
|
1305 |
# expand the 'special' 'metadata' field type |
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1306 |
# 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
|
1307 |
fields = [] |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1308 |
for field in fieldlist: |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1309 |
if field == 'metadata': |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1310 |
fields += ['user', 'description', 'date'] |
17102
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1311 |
elif field == 'diff': |
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1312 |
# 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
|
1313 |
# 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
|
1314 |
# also match the files first |
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1315 |
fields += ['files', 'diff'] |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1316 |
else: |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1317 |
if field == 'author': |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1318 |
field = 'user' |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1319 |
fields.append(field) |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1320 |
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
|
1321 |
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
|
1322 |
# 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
|
1323 |
fields.discard('summary') |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1324 |
|
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1325 |
# 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
|
1326 |
# 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
|
1327 |
# 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
|
1328 |
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
|
1329 |
'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
|
1330 |
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
|
1331 |
try: |
984e0412e82b
revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16445
diff
changeset
|
1332 |
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
|
1333 |
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
|
1334 |
# 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
|
1335 |
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
|
1336 |
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
|
1337 |
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
|
1338 |
|
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1339 |
# 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
|
1340 |
# 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
|
1341 |
getfieldfuncs = [] |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1342 |
_funcs = { |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1343 |
'user': lambda r: repo[r].user(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1344 |
'branch': lambda r: repo[r].branch(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1345 |
'date': lambda r: repo[r].date(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1346 |
'description': lambda r: repo[r].description(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1347 |
'files': lambda r: repo[r].files(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1348 |
'parents': lambda r: repo[r].parents(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1349 |
'phase': lambda r: repo[r].phase(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1350 |
'substate': lambda r: repo[r].substate, |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1351 |
'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
|
1352 |
'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
|
1353 |
} |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1354 |
for info in fields: |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1355 |
getfield = _funcs.get(info, None) |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1356 |
if getfield is None: |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1357 |
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
|
1358 |
# i18n: "matching" is a keyword |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1359 |
_("unexpected field name passed to matching: %s") % info) |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1360 |
getfieldfuncs.append(getfield) |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1361 |
# 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
|
1362 |
# 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
|
1363 |
# 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
|
1364 |
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
|
1365 |
|
20459
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1366 |
def matches(x): |
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1367 |
for rev in revs: |
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1368 |
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
|
1369 |
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
|
1370 |
for n, f in enumerate(getfieldfuncs): |
20459
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1371 |
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
|
1372 |
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
|
1373 |
if match: |
20459
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1374 |
return True |
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1375 |
return False |
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1376 |
|
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1377 |
return lazyset(subset, matches) |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1378 |
|
11275 | 1379 |
def reverse(repo, subset, x): |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1380 |
"""``reverse(set)`` |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1381 |
Reverse order of set. |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1382 |
""" |
11275 | 1383 |
l = getset(repo, subset, x) |
1384 |
l.reverse() |
|
1385 |
return l |
|
1386 |
||
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1387 |
def roots(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1388 |
"""``roots(set)`` |
16394
f3df7d34791e
revset: do not ignore input revisions in roots()
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1389 |
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
|
1390 |
""" |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
1391 |
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
|
1392 |
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
|
1393 |
cs = _children(repo, subset, s) |
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
1394 |
return subset - cs |
11944
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1395 |
|
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1396 |
def secret(repo, subset, x): |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1397 |
"""``secret()`` |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1398 |
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
|
1399 |
# 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
|
1400 |
getargs(x, 0, 0, _("secret takes no arguments")) |
16657
b6081c2c4647
phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents:
16647
diff
changeset
|
1401 |
pc = repo._phasecache |
20460
3a88d0d0c6b6
revset: added lazyset implementation to secret revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20459
diff
changeset
|
1402 |
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
|
1403 |
|
11275 | 1404 |
def sort(repo, subset, x): |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1405 |
"""``sort(set[, [-]key...])`` |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1406 |
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
|
1407 |
as ``-key`` to sort in descending order. |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1408 |
|
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1409 |
The keys can be: |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1410 |
|
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1411 |
- ``rev`` for the revision number, |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1412 |
- ``branch`` for the branch name, |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1413 |
- ``desc`` for the commit message (description), |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1414 |
- ``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
|
1415 |
- ``date`` for the commit date |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1416 |
""" |
12815
079a618ea89d
revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents:
12786
diff
changeset
|
1417 |
# 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
|
1418 |
l = getargs(x, 1, 2, _("sort requires one or two arguments")) |
11275 | 1419 |
keys = "rev" |
1420 |
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
|
1421 |
# i18n: "sort" is a keyword |
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
1422 |
keys = getstring(l[1], _("sort spec must be a string")) |
11275 | 1423 |
|
1424 |
s = l[0] |
|
1425 |
keys = keys.split() |
|
1426 |
l = [] |
|
1427 |
def invert(s): |
|
1428 |
return "".join(chr(255 - ord(c)) for c in s) |
|
1429 |
for r in getset(repo, subset, s): |
|
1430 |
c = repo[r] |
|
1431 |
e = [] |
|
1432 |
for k in keys: |
|
1433 |
if k == 'rev': |
|
1434 |
e.append(r) |
|
1435 |
elif k == '-rev': |
|
1436 |
e.append(-r) |
|
1437 |
elif k == 'branch': |
|
1438 |
e.append(c.branch()) |
|
1439 |
elif k == '-branch': |
|
1440 |
e.append(invert(c.branch())) |
|
1441 |
elif k == 'desc': |
|
1442 |
e.append(c.description()) |
|
1443 |
elif k == '-desc': |
|
1444 |
e.append(invert(c.description())) |
|
1445 |
elif k in 'user author': |
|
1446 |
e.append(c.user()) |
|
1447 |
elif k in '-user -author': |
|
1448 |
e.append(invert(c.user())) |
|
1449 |
elif k == 'date': |
|
1450 |
e.append(c.date()[0]) |
|
1451 |
elif k == '-date': |
|
1452 |
e.append(-c.date()[0]) |
|
1453 |
else: |
|
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
1454 |
raise error.ParseError(_("unknown sort key %r") % k) |
11275 | 1455 |
e.append(r) |
1456 |
l.append(e) |
|
1457 |
l.sort() |
|
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1458 |
return baseset([e[-1] for e in l]) |
11275 | 1459 |
|
16819
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1460 |
def _stringmatcher(pattern): |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1461 |
""" |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1462 |
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
|
1463 |
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
|
1464 |
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
|
1465 |
|
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1466 |
helper for tests: |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1467 |
>>> def test(pattern, *tests): |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1468 |
... 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
|
1469 |
... 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
|
1470 |
|
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1471 |
exact matching (no prefix): |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1472 |
>>> 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
|
1473 |
('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
|
1474 |
|
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1475 |
regex matching ('re:' prefix) |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1476 |
>>> 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
|
1477 |
('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
|
1478 |
|
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1479 |
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
|
1480 |
>>> 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
|
1481 |
('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
|
1482 |
|
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1483 |
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
|
1484 |
>>> 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
|
1485 |
('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
|
1486 |
""" |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1487 |
if pattern.startswith('re:'): |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1488 |
pattern = pattern[3:] |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1489 |
try: |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1490 |
regex = re.compile(pattern) |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1491 |
except re.error, e: |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1492 |
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
|
1493 |
% e) |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1494 |
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
|
1495 |
elif pattern.startswith('literal:'): |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1496 |
pattern = pattern[8:] |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1497 |
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
|
1498 |
|
16823
b23bacb230c9
revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents:
16822
diff
changeset
|
1499 |
def _substringmatcher(pattern): |
b23bacb230c9
revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents:
16822
diff
changeset
|
1500 |
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
|
1501 |
if kind == 'literal': |
b23bacb230c9
revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents:
16822
diff
changeset
|
1502 |
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
|
1503 |
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
|
1504 |
|
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
|
1505 |
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
|
1506 |
"""``tag([name])`` |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1507 |
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
|
1508 |
""" |
12815
079a618ea89d
revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents:
12786
diff
changeset
|
1509 |
# 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
|
1510 |
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
|
1511 |
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
|
1512 |
if args: |
16820
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1513 |
pattern = getstring(args[0], |
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1514 |
# i18n: "tag" is a keyword |
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1515 |
_('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
|
1516 |
kind, pattern, matcher = _stringmatcher(pattern) |
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1517 |
if kind == 'literal': |
16825
b6ef1395d77f
revset: avoid validating all tag nodes for tag(x)
Matt Mackall <mpm@selenic.com>
parents:
16824
diff
changeset
|
1518 |
# avoid resolving all tags |
b6ef1395d77f
revset: avoid validating all tag nodes for tag(x)
Matt Mackall <mpm@selenic.com>
parents:
16824
diff
changeset
|
1519 |
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
|
1520 |
if tn is None: |
16820
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1521 |
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
|
1522 |
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
|
1523 |
else: |
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1524 |
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
|
1525 |
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
|
1526 |
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
|
1527 |
return subset & s |
11280
a5eb0bf7e158
revset: add tagged predicate
Matt Mackall <mpm@selenic.com>
parents:
11279
diff
changeset
|
1528 |
|
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1529 |
def tagged(repo, subset, x): |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1530 |
return tag(repo, subset, x) |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1531 |
|
17171
9c750c3e4fac
obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17170
diff
changeset
|
1532 |
def unstable(repo, subset, x): |
9c750c3e4fac
obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17170
diff
changeset
|
1533 |
"""``unstable()`` |
17291
2d6bbf87f7b4
revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents:
17272
diff
changeset
|
1534 |
Non-obsolete changesets with obsolete ancestors. |
2d6bbf87f7b4
revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents:
17272
diff
changeset
|
1535 |
""" |
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
|
1536 |
# 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
|
1537 |
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
|
1538 |
unstables = obsmod.getrevs(repo, 'unstable') |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1539 |
return subset & unstables |
17171
9c750c3e4fac
obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17170
diff
changeset
|
1540 |
|
9c750c3e4fac
obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17170
diff
changeset
|
1541 |
|
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1542 |
def user(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1543 |
"""``user(string)`` |
14357 | 1544 |
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
|
1545 |
|
b23bacb230c9
revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents:
16822
diff
changeset
|
1546 |
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
|
1547 |
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
|
1548 |
the prefix `literal:`. |
13359
87f248e78173
bookmarks: move revset support to core
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
1549 |
""" |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1550 |
return author(repo, subset, x) |
13359
87f248e78173
bookmarks: move revset support to core
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
1551 |
|
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1552 |
# for internal use |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1553 |
def _list(repo, subset, x): |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1554 |
s = getstring(x, "internal error") |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1555 |
if not s: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1556 |
return baseset([]) |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1557 |
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
|
1558 |
s = subset.set() |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
1559 |
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
|
1560 |
|
11275 | 1561 |
symbols = { |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1562 |
"adds": adds, |
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1563 |
"all": getall, |
11275 | 1564 |
"ancestor": ancestor, |
1565 |
"ancestors": ancestors, |
|
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
1566 |
"_firstancestors": _firstancestors, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1567 |
"author": author, |
15134
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
1568 |
"bisect": bisect, |
13602
54b198fe9768
revset: add a revset command to get bisect state.
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13593
diff
changeset
|
1569 |
"bisected": bisected, |
13359
87f248e78173
bookmarks: move revset support to core
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
1570 |
"bookmark": bookmark, |
11275 | 1571 |
"branch": branch, |
17753
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1572 |
"branchpoint": branchpoint, |
17829
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
1573 |
"bumped": bumped, |
17913
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
1574 |
"bundle": bundle, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1575 |
"children": children, |
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1576 |
"closed": closed, |
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1577 |
"contains": contains, |
17002
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
1578 |
"converted": converted, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1579 |
"date": date, |
14650
93731b3efd0d
revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14649
diff
changeset
|
1580 |
"desc": desc, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1581 |
"descendants": descendants, |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
1582 |
"_firstdescendants": _firstdescendants, |
17186
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
1583 |
"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
|
1584 |
"divergent": divergent, |
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1585 |
"draft": draft, |
17173
c621f84dbb35
obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17171
diff
changeset
|
1586 |
"extinct": extinct, |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
1587 |
"extra": extra, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1588 |
"file": hasfile, |
14342
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
1589 |
"filelog": filelog, |
15117
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
1590 |
"first": first, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1591 |
"follow": follow, |
16174
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
1592 |
"_followfirst": _followfirst, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1593 |
"grep": grep, |
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1594 |
"head": head, |
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1595 |
"heads": heads, |
17390
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
1596 |
"hidden": hidden, |
16417
b4b0c6931e11
revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents:
16415
diff
changeset
|
1597 |
"id": node_, |
11275 | 1598 |
"keyword": keyword, |
14061
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
1599 |
"last": last, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1600 |
"limit": limit, |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
1601 |
"_matchfiles": _matchfiles, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1602 |
"max": maxrev, |
14649
a6a8809c6e33
revset: update sorting of symbols
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14556
diff
changeset
|
1603 |
"merge": merge, |
11708
ba65d61f3158
revset: add min function
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11650
diff
changeset
|
1604 |
"min": minrev, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1605 |
"modifies": modifies, |
17170
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1606 |
"obsolete": obsolete, |
17185
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1607 |
"origin": origin, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1608 |
"outgoing": outgoing, |
11275 | 1609 |
"p1": p1, |
1610 |
"p2": p2, |
|
1611 |
"parents": parents, |
|
11944
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1612 |
"present": present, |
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1613 |
"public": public, |
15936
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1614 |
"remote": remote, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1615 |
"removes": removes, |
14649
a6a8809c6e33
revset: update sorting of symbols
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14556
diff
changeset
|
1616 |
"rev": rev, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1617 |
"reverse": reverse, |
11275 | 1618 |
"roots": roots, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1619 |
"sort": sort, |
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1620 |
"secret": secret, |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1621 |
"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
|
1622 |
"tag": tag, |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1623 |
"tagged": tagged, |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1624 |
"user": user, |
17171
9c750c3e4fac
obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17170
diff
changeset
|
1625 |
"unstable": unstable, |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1626 |
"_list": _list, |
11275 | 1627 |
} |
1628 |
||
19721
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1629 |
# 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
|
1630 |
# (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
|
1631 |
# 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
|
1632 |
safesymbols = set([ |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1633 |
"adds", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1634 |
"all", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1635 |
"ancestor", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1636 |
"ancestors", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1637 |
"_firstancestors", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1638 |
"author", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1639 |
"bisect", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1640 |
"bisected", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1641 |
"bookmark", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1642 |
"branch", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1643 |
"branchpoint", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1644 |
"bumped", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1645 |
"bundle", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1646 |
"children", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1647 |
"closed", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1648 |
"converted", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1649 |
"date", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1650 |
"desc", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1651 |
"descendants", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1652 |
"_firstdescendants", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1653 |
"destination", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1654 |
"divergent", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1655 |
"draft", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1656 |
"extinct", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1657 |
"extra", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1658 |
"file", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1659 |
"filelog", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1660 |
"first", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1661 |
"follow", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1662 |
"_followfirst", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1663 |
"head", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1664 |
"heads", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1665 |
"hidden", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1666 |
"id", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1667 |
"keyword", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1668 |
"last", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1669 |
"limit", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1670 |
"_matchfiles", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1671 |
"max", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1672 |
"merge", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1673 |
"min", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1674 |
"modifies", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1675 |
"obsolete", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1676 |
"origin", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1677 |
"outgoing", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1678 |
"p1", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1679 |
"p2", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1680 |
"parents", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1681 |
"present", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1682 |
"public", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1683 |
"remote", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1684 |
"removes", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1685 |
"rev", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1686 |
"reverse", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1687 |
"roots", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1688 |
"sort", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1689 |
"secret", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1690 |
"matching", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1691 |
"tag", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1692 |
"tagged", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1693 |
"user", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1694 |
"unstable", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1695 |
"_list", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1696 |
]) |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1697 |
|
11275 | 1698 |
methods = { |
1699 |
"range": rangeset, |
|
16860
e1aa1ed30030
revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents:
16859
diff
changeset
|
1700 |
"dagrange": dagrange, |
11275 | 1701 |
"string": stringset, |
1702 |
"symbol": symbolset, |
|
1703 |
"and": andset, |
|
1704 |
"or": orset, |
|
1705 |
"not": notset, |
|
1706 |
"list": listset, |
|
1707 |
"func": func, |
|
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1708 |
"ancestor": ancestorspec, |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1709 |
"parent": parentspec, |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1710 |
"parentpost": p1, |
11275 | 1711 |
} |
1712 |
||
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1713 |
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
|
1714 |
if x is None: |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1715 |
return 0, x |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1716 |
|
11275 | 1717 |
smallbonus = 1 |
1718 |
if small: |
|
1719 |
smallbonus = .5 |
|
1720 |
||
1721 |
op = x[0] |
|
11283
a6356b2695a3
revset: fix - handling in the optimizer
Matt Mackall <mpm@selenic.com>
parents:
11282
diff
changeset
|
1722 |
if op == 'minus': |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1723 |
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
|
1724 |
elif op == 'dagrangepre': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1725 |
return optimize(('func', ('symbol', 'ancestors'), x[1]), small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1726 |
elif op == 'dagrangepost': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1727 |
return optimize(('func', ('symbol', 'descendants'), x[1]), small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1728 |
elif op == 'rangepre': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1729 |
return optimize(('range', ('string', '0'), x[1]), small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1730 |
elif op == 'rangepost': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1731 |
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
|
1732 |
elif op == 'negate': |
6b836d5c8c9e
revset: make negate work for sort specs
Matt Mackall <mpm@selenic.com>
parents:
11456
diff
changeset
|
1733 |
return optimize(('string', |
6b836d5c8c9e
revset: make negate work for sort specs
Matt Mackall <mpm@selenic.com>
parents:
11456
diff
changeset
|
1734 |
'-' + 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
|
1735 |
elif op in 'string symbol negate': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1736 |
return smallbonus, x # single revisions are small |
16859
eeb464ed7275
revset: drop unreachable code
Bryan O'Sullivan <bryano@fb.com>
parents:
16838
diff
changeset
|
1737 |
elif op == 'and': |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1738 |
wa, ta = optimize(x[1], True) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1739 |
wb, tb = optimize(x[2], True) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1740 |
w = min(wa, wb) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1741 |
if wa > wb: |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1742 |
return w, (op, tb, ta) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1743 |
return w, (op, ta, tb) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1744 |
elif op == 'or': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1745 |
wa, ta = optimize(x[1], False) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1746 |
wb, tb = optimize(x[2], False) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1747 |
if wb < wa: |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1748 |
wb, wa = wa, wb |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1749 |
return max(wa, wb), (op, ta, tb) |
11275 | 1750 |
elif op == 'not': |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1751 |
o = optimize(x[1], not small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1752 |
return o[0], (op, o[1]) |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1753 |
elif op == 'parentpost': |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1754 |
o = optimize(x[1], small) |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1755 |
return o[0], (op, o[1]) |
11275 | 1756 |
elif op == 'group': |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1757 |
return optimize(x[1], small) |
16860
e1aa1ed30030
revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents:
16859
diff
changeset
|
1758 |
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
|
1759 |
if op == 'parent': |
805651777188
revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents:
14723
diff
changeset
|
1760 |
# 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
|
1761 |
post = ('parentpost', x[1]) |
805651777188
revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents:
14723
diff
changeset
|
1762 |
if x[2][0] == 'dagrangepre': |
805651777188
revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents:
14723
diff
changeset
|
1763 |
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
|
1764 |
elif x[2][0] == 'rangepre': |
805651777188
revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents:
14723
diff
changeset
|
1765 |
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
|
1766 |
|
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1767 |
wa, ta = optimize(x[1], small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1768 |
wb, tb = optimize(x[2], small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1769 |
return wa + wb, (op, ta, tb) |
11275 | 1770 |
elif op == 'func': |
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
1771 |
f = getstring(x[1], _("not a symbol")) |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1772 |
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
|
1773 |
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
|
1774 |
"outgoing user"): |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1775 |
w = 10 # slow |
12351
b913232d13c1
revsets: reduce cost of outgoing in the optimizer
Matt Mackall <mpm@selenic.com>
parents:
12321
diff
changeset
|
1776 |
elif f in "modifies adds removes": |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1777 |
w = 30 # slower |
11275 | 1778 |
elif f == "contains": |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1779 |
w = 100 # very slow |
11275 | 1780 |
elif f == "ancestor": |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1781 |
w = 1 * smallbonus |
15117
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
1782 |
elif f in "reverse limit first": |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1783 |
w = 0 |
11275 | 1784 |
elif f in "sort": |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1785 |
w = 10 # assume most sorts look at changelog |
11275 | 1786 |
else: |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1787 |
w = 1 |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1788 |
return w + wa, (op, x[1], ta) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1789 |
return 1, x |
11275 | 1790 |
|
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1791 |
_aliasarg = ('func', ('symbol', '_aliasarg')) |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1792 |
def _getaliasarg(tree): |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1793 |
"""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
|
1794 |
return X, None otherwise. |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1795 |
""" |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1796 |
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
|
1797 |
and tree[2][0] == 'string'): |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1798 |
return tree[2][1] |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1799 |
return None |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1800 |
|
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1801 |
def _checkaliasarg(tree, known=None): |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1802 |
"""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
|
1803 |
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
|
1804 |
""" |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1805 |
if isinstance(tree, tuple): |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1806 |
arg = _getaliasarg(tree) |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1807 |
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
|
1808 |
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
|
1809 |
for t in tree: |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1810 |
_checkaliasarg(t, known) |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1811 |
|
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1812 |
class revsetalias(object): |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1813 |
funcre = re.compile('^([^(]+)\(([^)]+)\)$') |
14723
b9faf94ee196
revset: fix aliases with 0 or more than 2 parameters
Mads Kiilerich <mads@kiilerich.com>
parents:
14717
diff
changeset
|
1814 |
args = None |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1815 |
|
14723
b9faf94ee196
revset: fix aliases with 0 or more than 2 parameters
Mads Kiilerich <mads@kiilerich.com>
parents:
14717
diff
changeset
|
1816 |
def __init__(self, name, value): |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1817 |
'''Aliases like: |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1818 |
|
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1819 |
h = heads(default) |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1820 |
b($1) = ancestors($1) - ancestors(default) |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1821 |
''' |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1822 |
m = self.funcre.search(name) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1823 |
if m: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1824 |
self.name = m.group(1) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1825 |
self.tree = ('func', ('symbol', m.group(1))) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1826 |
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
|
1827 |
for arg in self.args: |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1828 |
# _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
|
1829 |
# alias argument placeholders from regular strings. |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1830 |
value = value.replace(arg, '_aliasarg(%r)' % (arg,)) |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1831 |
else: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1832 |
self.name = name |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1833 |
self.tree = ('symbol', name) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1834 |
|
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1835 |
self.replacement, pos = parse(value) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1836 |
if pos != len(value): |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1837 |
raise error.ParseError(_('invalid token'), pos) |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1838 |
# Check for placeholder injection |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1839 |
_checkaliasarg(self.replacement, self.args) |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1840 |
|
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1841 |
def _getalias(aliases, tree): |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1842 |
"""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
|
1843 |
otherwise. |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1844 |
""" |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1845 |
if isinstance(tree, tuple) and tree: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1846 |
if tree[0] == 'symbol' and len(tree) == 2: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1847 |
name = tree[1] |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1848 |
alias = aliases.get(name) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1849 |
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
|
1850 |
return alias |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1851 |
if tree[0] == 'func' and len(tree) > 1: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1852 |
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
|
1853 |
name = tree[1][1] |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1854 |
alias = aliases.get(name) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1855 |
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
|
1856 |
return alias |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1857 |
return None |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1858 |
|
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1859 |
def _expandargs(tree, args): |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1860 |
"""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
|
1861 |
same name in args, recursively. |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1862 |
""" |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1863 |
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
|
1864 |
return tree |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1865 |
arg = _getaliasarg(tree) |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1866 |
if arg is not None: |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1867 |
return args[arg] |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1868 |
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
|
1869 |
|
16838
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
1870 |
def _expandaliases(aliases, tree, expanding, cache): |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1871 |
"""Expand aliases in tree, recursively. |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1872 |
|
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1873 |
'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
|
1874 |
revsetalias objects. |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1875 |
""" |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1876 |
if not isinstance(tree, tuple): |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1877 |
# Do not expand raw strings |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1878 |
return tree |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1879 |
alias = _getalias(aliases, tree) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1880 |
if alias is not None: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1881 |
if alias in expanding: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1882 |
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
|
1883 |
'detected') % alias.name) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1884 |
expanding.append(alias) |
16838
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
1885 |
if alias.name not in cache: |
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
1886 |
cache[alias.name] = _expandaliases(aliases, alias.replacement, |
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
1887 |
expanding, cache) |
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
1888 |
result = cache[alias.name] |
16772
30e46d7138de
revset: fix infinite alias expansion detection
Patrick Mezard <patrick@mezard.eu>
parents:
16771
diff
changeset
|
1889 |
expanding.pop() |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1890 |
if alias.args is not None: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1891 |
l = getlist(tree[2]) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1892 |
if len(l) != len(alias.args): |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1893 |
raise error.ParseError( |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1894 |
_('invalid number of arguments: %s') % len(l)) |
16838
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
1895 |
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
|
1896 |
result = _expandargs(result, dict(zip(alias.args, l))) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1897 |
else: |
16838
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
1898 |
result = tuple(_expandaliases(aliases, t, expanding, cache) |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1899 |
for t in tree) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1900 |
return result |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1901 |
|
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1902 |
def findaliases(ui, tree): |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1903 |
_checkaliasarg(tree) |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1904 |
aliases = {} |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1905 |
for k, v in ui.configitems('revsetalias'): |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1906 |
alias = revsetalias(k, v) |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1907 |
aliases[alias.name] = alias |
16838
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
1908 |
return _expandaliases(aliases, tree, [], {}) |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1909 |
|
20208
61a47fd64f30
fileset, revset: do not use global parser object for thread safety
Yuya Nishihara <yuya@tcha.org>
parents:
19721
diff
changeset
|
1910 |
def parse(spec): |
61a47fd64f30
fileset, revset: do not use global parser object for thread safety
Yuya Nishihara <yuya@tcha.org>
parents:
19721
diff
changeset
|
1911 |
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
|
1912 |
return p.parse(spec) |
11275 | 1913 |
|
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1914 |
def match(ui, spec): |
11385
e5a2134c083b
revset: nicer exception for empty queries
Matt Mackall <mpm@selenic.com>
parents:
11383
diff
changeset
|
1915 |
if not spec: |
e5a2134c083b
revset: nicer exception for empty queries
Matt Mackall <mpm@selenic.com>
parents:
11383
diff
changeset
|
1916 |
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
|
1917 |
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
|
1918 |
if (pos != len(spec)): |
14701
4b93bd041772
parsers: fix localization markup of parser errors
Mads Kiilerich <mads@kiilerich.com>
parents:
14650
diff
changeset
|
1919 |
raise error.ParseError(_("invalid token"), pos) |
14900
fc3d6f300d7d
revset: allow bypassing alias expansion
Matt Mackall <mpm@selenic.com>
parents:
14851
diff
changeset
|
1920 |
if ui: |
fc3d6f300d7d
revset: allow bypassing alias expansion
Matt Mackall <mpm@selenic.com>
parents:
14851
diff
changeset
|
1921 |
tree = findaliases(ui, tree) |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1922 |
weight, tree = optimize(tree, True) |
11275 | 1923 |
def mfunc(repo, subset): |
1924 |
return getset(repo, subset, tree) |
|
1925 |
return mfunc |
|
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1926 |
|
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1927 |
def formatspec(expr, *args): |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1928 |
''' |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1929 |
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
|
1930 |
escapes arguments appropriately. Aliases are intentionally ignored |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1931 |
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
|
1932 |
|
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1933 |
Supported arguments: |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1934 |
|
15266
8bea39ca9acb
revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents:
15153
diff
changeset
|
1935 |
%r = revset expression, parenthesized |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1936 |
%d = int(arg), no quoting |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1937 |
%s = string(arg), escaped and single-quoted |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1938 |
%b = arg.branch(), escaped and single-quoted |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1939 |
%n = hex(arg), single-quoted |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1940 |
%% = a literal '%' |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1941 |
|
15266
8bea39ca9acb
revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents:
15153
diff
changeset
|
1942 |
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
|
1943 |
|
15268
bd5103819c2e
revset: fix %r handling in formatspec
Matt Mackall <mpm@selenic.com>
parents:
15266
diff
changeset
|
1944 |
>>> 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
|
1945 |
'(10 or 11):: and ((this()) or (that()))' |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1946 |
>>> formatspec('%d:: and not %d::', 10, 20) |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1947 |
'10:: and not 20::' |
15325
cdf1daa3b83f
revset: deal with empty lists in formatspec
Matt Mackall <mpm@selenic.com>
parents:
15268
diff
changeset
|
1948 |
>>> formatspec('%ld or %ld', [], [1]) |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1949 |
"_list('') or 1" |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1950 |
>>> formatspec('keyword(%s)', 'foo\\xe9') |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1951 |
"keyword('foo\\\\xe9')" |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1952 |
>>> b = lambda: 'default' |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1953 |
>>> b.branch = b |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1954 |
>>> formatspec('branch(%b)', b) |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1955 |
"branch('default')" |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
1956 |
>>> 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
|
1957 |
"root(_list('a\\x00b\\x00c\\x00d'))" |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1958 |
''' |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1959 |
|
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1960 |
def quote(s): |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1961 |
return repr(str(s)) |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1962 |
|
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
1963 |
def argtype(c, arg): |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
1964 |
if c == 'd': |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
1965 |
return str(int(arg)) |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
1966 |
elif c == 's': |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
1967 |
return quote(arg) |
15266
8bea39ca9acb
revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents:
15153
diff
changeset
|
1968 |
elif c == 'r': |
8bea39ca9acb
revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents:
15153
diff
changeset
|
1969 |
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
|
1970 |
return '(%s)' % arg |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
1971 |
elif c == 'n': |
16417
b4b0c6931e11
revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents:
16415
diff
changeset
|
1972 |
return quote(node.hex(arg)) |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
1973 |
elif c == 'b': |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
1974 |
return quote(arg.branch()) |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
1975 |
|
15595
a585d78e7b2f
revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents:
15532
diff
changeset
|
1976 |
def listexp(s, t): |
a585d78e7b2f
revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents:
15532
diff
changeset
|
1977 |
l = len(s) |
a585d78e7b2f
revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents:
15532
diff
changeset
|
1978 |
if l == 0: |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1979 |
return "_list('')" |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1980 |
elif l == 1: |
15595
a585d78e7b2f
revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents:
15532
diff
changeset
|
1981 |
return argtype(t, s[0]) |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1982 |
elif t == 'd': |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1983 |
return "_list('%s')" % "\0".join(str(int(a)) for a in s) |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1984 |
elif t == 's': |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1985 |
return "_list('%s')" % "\0".join(s) |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1986 |
elif t == 'n': |
16417
b4b0c6931e11
revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents:
16415
diff
changeset
|
1987 |
return "_list('%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
|
1988 |
elif t == 'b': |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1989 |
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
|
1990 |
|
15791
a814f8fcc65a
Use explicit integer division
Martin Geisler <mg@aragost.com>
parents:
15726
diff
changeset
|
1991 |
m = l // 2 |
15595
a585d78e7b2f
revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents:
15532
diff
changeset
|
1992 |
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
|
1993 |
|
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1994 |
ret = '' |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1995 |
pos = 0 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1996 |
arg = 0 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1997 |
while pos < len(expr): |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1998 |
c = expr[pos] |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
1999 |
if c == '%': |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2000 |
pos += 1 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2001 |
d = expr[pos] |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2002 |
if d == '%': |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2003 |
ret += d |
15268
bd5103819c2e
revset: fix %r handling in formatspec
Matt Mackall <mpm@selenic.com>
parents:
15266
diff
changeset
|
2004 |
elif d in 'dsnbr': |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2005 |
ret += argtype(d, args[arg]) |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2006 |
arg += 1 |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2007 |
elif d == 'l': |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2008 |
# a list of some type |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2009 |
pos += 1 |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2010 |
d = expr[pos] |
15596 | 2011 |
ret += listexp(list(args[arg]), d) |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2012 |
arg += 1 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2013 |
else: |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2014 |
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
|
2015 |
else: |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2016 |
ret += c |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2017 |
pos += 1 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2018 |
|
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2019 |
return ret |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2020 |
|
16218
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2021 |
def prettyformat(tree): |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2022 |
def _prettyformat(tree, level, lines): |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2023 |
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
|
2024 |
lines.append((level, str(tree))) |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2025 |
else: |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2026 |
lines.append((level, '(%s' % tree[0])) |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2027 |
for s in tree[1:]: |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2028 |
_prettyformat(s, level + 1, lines) |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2029 |
lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2030 |
|
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2031 |
lines = [] |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2032 |
_prettyformat(tree, 0, lines) |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2033 |
output = '\n'.join((' '*l + s) for l, s in lines) |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2034 |
return output |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2035 |
|
19719
2f9d5c5256ea
revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents:
19706
diff
changeset
|
2036 |
def depth(tree): |
2f9d5c5256ea
revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents:
19706
diff
changeset
|
2037 |
if isinstance(tree, tuple): |
2f9d5c5256ea
revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents:
19706
diff
changeset
|
2038 |
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
|
2039 |
else: |
2f9d5c5256ea
revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents:
19706
diff
changeset
|
2040 |
return 0 |
2f9d5c5256ea
revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents:
19706
diff
changeset
|
2041 |
|
19720
f0b992a9be9c
revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents:
19719
diff
changeset
|
2042 |
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
|
2043 |
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
|
2044 |
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
|
2045 |
else: |
f0b992a9be9c
revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents:
19719
diff
changeset
|
2046 |
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
|
2047 |
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
|
2048 |
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
|
2049 |
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
|
2050 |
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
|
2051 |
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
|
2052 |
|
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
2053 |
class baseset(list): |
20416
e72bcc245ecb
revset: added docstring to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20393
diff
changeset
|
2054 |
"""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
|
2055 |
operation that it should be able to perform. |
e72bcc245ecb
revset: added docstring to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20393
diff
changeset
|
2056 |
""" |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2057 |
def __init__(self, data): |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2058 |
super(baseset, self).__init__(data) |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2059 |
self._set = None |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2060 |
|
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2061 |
def set(self): |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2062 |
if not self._set: |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2063 |
self._set = set(self) |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2064 |
return self._set |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
2065 |
|
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
2066 |
def __sub__(self, x): |
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
2067 |
if isinstance(x, baseset): |
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
2068 |
s = x.set() |
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
2069 |
else: |
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
2070 |
s = set(x) |
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
2071 |
return baseset(self.set() - s) |
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
2072 |
|
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
2073 |
def __and__(self, x): |
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
2074 |
if isinstance(x, baseset): |
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
2075 |
x = x.set() |
20393
b0638b5b004d
revset: fixed bug where revset returning order was being changed
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20367
diff
changeset
|
2076 |
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
|
2077 |
|
20417
827561a99569
revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20416
diff
changeset
|
2078 |
def __add__(self, x): |
827561a99569
revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20416
diff
changeset
|
2079 |
s = self.set() |
827561a99569
revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20416
diff
changeset
|
2080 |
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
|
2081 |
return baseset(list(self) + l) |
827561a99569
revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20416
diff
changeset
|
2082 |
|
20427
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2083 |
class lazyset(object): |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2084 |
"""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
|
2085 |
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
|
2086 |
revset |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2087 |
""" |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2088 |
def __init__(self, subset, condition): |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2089 |
self._subset = subset |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2090 |
self._condition = condition |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2091 |
|
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2092 |
def __contains__(self, x): |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2093 |
return x in self._subset and self._condition(x) |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2094 |
|
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2095 |
def __iter__(self): |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2096 |
cond = self._condition |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2097 |
for x in self._subset: |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2098 |
if cond(x): |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2099 |
yield x |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2100 |
|
20428
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2101 |
def __and__(self, x): |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2102 |
return lazyset(self, lambda r: r in x) |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2103 |
|
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2104 |
def __sub__(self, x): |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2105 |
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
|
2106 |
|
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2107 |
def __add__(self, x): |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2108 |
l = baseset([r for r in self]) |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2109 |
return l + baseset(x) |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2110 |
|
20429
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2111 |
def __len__(self): |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2112 |
# 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
|
2113 |
l = baseset([r for r in self]) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2114 |
return len(l) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2115 |
|
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2116 |
def __getitem__(self, x): |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2117 |
# 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
|
2118 |
l = baseset([r for r in self]) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2119 |
return l[x] |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2120 |
|
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2121 |
def sort(self, reverse=False): |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2122 |
# 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
|
2123 |
self._subset = baseset(self._subset) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2124 |
self._subset.sort(reverse=reverse) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2125 |
|
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2126 |
def reverse(self): |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2127 |
self._subset.reverse() |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2128 |
|
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2129 |
def set(self): |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2130 |
return set([r for r in self]) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2131 |
|
20482
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2132 |
class spanset(object): |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2133 |
"""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
|
2134 |
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
|
2135 |
""" |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2136 |
def __init__(self, start, end): |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2137 |
self._start = start |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2138 |
self._end = end |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2139 |
|
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2140 |
def __iter__(self): |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2141 |
if self._start <= self._end: |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2142 |
for r in xrange(self._start, self._end): |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2143 |
yield r |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2144 |
else: |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2145 |
for r in xrange(self._start, self._end, -1): |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2146 |
yield r |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2147 |
|
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2148 |
def __contains__(self, x): |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2149 |
return (x <= self._start and x > self._end) or (x >= self._start and x< |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2150 |
self._end) |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2151 |
|
20483
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2152 |
def __and__(self, x): |
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2153 |
return lazyset(self, lambda r: r in x) |
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2154 |
|
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2155 |
def __sub__(self, x): |
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2156 |
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
|
2157 |
|
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2158 |
def __add__(self, x): |
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2159 |
l = baseset(self) |
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2160 |
return l + baseset(x) |
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2161 |
|
20484
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2162 |
def __len__(self): |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2163 |
return abs(self._end - self._start) |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2164 |
|
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2165 |
def __getitem__(self, x): |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2166 |
# 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
|
2167 |
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
|
2168 |
return l[x] |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2169 |
|
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2170 |
def sort(self, reverse=False): |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2171 |
# 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
|
2172 |
if reverse: |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2173 |
self.reverse() |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2174 |
|
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2175 |
def reverse(self): |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2176 |
if self._start <= self._end: |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2177 |
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
|
2178 |
else: |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2179 |
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
|
2180 |
|
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2181 |
def set(self): |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2182 |
return self |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2183 |
|
12823
80deae3bc5ea
hggettext: handle i18nfunctions declaration for docstrings translations
Patrick Mezard <pmezard@gmail.com>
parents:
12821
diff
changeset
|
2184 |
# 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
|
2185 |
i18nfunctions = symbols.values() |