Mercurial > hg
annotate mercurial/revset.py @ 21177:952af771bc17 stable
bundle2: gracefully handle abort during unbundle
Clients expect a bundle2 reply to their bundle2 submission. So we
catch the Abort error and turn it into a bundle2 containing a part
transporting the exception data. The unbundling of this reply will
raise the error again.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Mon, 21 Apr 2014 15:48:52 -0700 |
parents | d4daebb21cf6 |
children | e9c2f76be74b |
rev | line source |
---|---|
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 |
20690
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
11 import heapq |
12085
6f833fc3ccab
Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents:
11944
diff
changeset
|
12 import match as matchmod |
20613 | 13 import ancestor as ancestormod |
13593
cc4721ed7a2a
help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents:
13506
diff
changeset
|
14 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
|
15 import encoding |
17469
fb72eec7efd8
obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17424
diff
changeset
|
16 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
|
17 import pathutil |
18251
a6483f827512
revset: retrieve hidden from filteredrevs
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18071
diff
changeset
|
18 import repoview |
11275 | 19 |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
20 def _revancestors(repo, revs, followfirst): |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
21 """Like revlog.ancestors(), but supports followfirst.""" |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
22 cut = followfirst and 1 or None |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
23 cl = repo.changelog |
20690
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
24 |
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
25 def iterate(): |
20691
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
26 revqueue, revsnode = None, None |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
27 h = [] |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
28 |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
29 revs.descending() |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
30 revqueue = util.deque(revs) |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
31 if revqueue: |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
32 revsnode = revqueue.popleft() |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
33 heapq.heappush(h, -revsnode) |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
34 |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
35 seen = set([node.nullrev]) |
20690
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
36 while h: |
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
37 current = -heapq.heappop(h) |
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
38 if current not in seen: |
20691
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
39 if revsnode and current == revsnode: |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
40 if revqueue: |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
41 revsnode = revqueue.popleft() |
c1f666e27345
revset: optimized _revancestors method based on order of revisions
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20690
diff
changeset
|
42 heapq.heappush(h, -revsnode) |
20690
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
43 seen.add(current) |
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
44 yield current |
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
45 for parent in cl.parentrevs(current)[:cut]: |
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
46 if parent != node.nullrev: |
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
47 heapq.heappush(h, -parent) |
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
48 |
20707
1d5d6f622b94
revset: made descgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20706
diff
changeset
|
49 return _descgeneratorset(iterate()) |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
50 |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
51 def _revdescendants(repo, revs, followfirst): |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
52 """Like revlog.descendants() but supports followfirst.""" |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
53 cut = followfirst and 1 or None |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
54 |
20692
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
55 def iterate(): |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
56 cl = repo.changelog |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
57 first = min(revs) |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
58 nullrev = node.nullrev |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
59 if first == nullrev: |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
60 # Are there nodes with a null first parent and a non-null |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
61 # second one? Maybe. Do we care? Probably not. |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
62 for i in cl: |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
63 yield i |
20692
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
64 else: |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
65 seen = set(revs) |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
66 for i in cl.revs(first + 1): |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
67 for x in cl.parentrevs(i)[:cut]: |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
68 if x != nullrev and x in seen: |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
69 seen.add(i) |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
70 yield i |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
71 break |
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
72 |
20706
efb34b066e7a
revset: made ascgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20705
diff
changeset
|
73 return _ascgeneratorset(iterate()) |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
74 |
16862
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
75 def _revsbetween(repo, roots, heads): |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
76 """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
|
77 sets.""" |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
78 if not roots: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
79 return baseset([]) |
16862
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
80 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
|
81 visit = baseset(heads) |
16862
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
82 reachable = set() |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
83 seen = {} |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
84 minroot = min(roots) |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
85 roots = set(roots) |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
86 # 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
|
87 # sys.getrecursionlimit() |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
88 while visit: |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
89 rev = visit.pop() |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
90 if rev in roots: |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
91 reachable.add(rev) |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
92 parents = parentrevs(rev) |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
93 seen[rev] = parents |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
94 for parent in parents: |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
95 if parent >= minroot and parent not in seen: |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
96 visit.append(parent) |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
97 if not reachable: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
98 return baseset([]) |
16862
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
99 for rev in sorted(seen): |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
100 for parent in seen[rev]: |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
101 if parent in reachable: |
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
102 reachable.add(rev) |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
103 return baseset(sorted(reachable)) |
16862
b6efeb27e733
revset: introduce and use _revsbetween
Bryan O'Sullivan <bryano@fb.com>
parents:
16861
diff
changeset
|
104 |
11275 | 105 elements = { |
106 "(": (20, ("group", 1, ")"), ("func", 1, ")")), | |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
107 "~": (18, None, ("ancestor", 18)), |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
108 "^": (18, None, ("parent", 18), ("parentpost", 18)), |
12616
e797fdf91df4
revset: lower precedence of minus infix (issue2361)
Matt Mackall <mpm@selenic.com>
parents:
12615
diff
changeset
|
109 "-": (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
|
110 "::": (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
|
111 ("dagrangepost", 17)), |
7df88cdf47fd
revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents:
11275
diff
changeset
|
112 "..": (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
|
113 ("dagrangepost", 17)), |
7df88cdf47fd
revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents:
11275
diff
changeset
|
114 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)), |
11275 | 115 "not": (10, ("not", 10)), |
116 "!": (10, ("not", 10)), | |
117 "and": (5, None, ("and", 5)), | |
118 "&": (5, None, ("and", 5)), | |
119 "or": (4, None, ("or", 4)), | |
120 "|": (4, None, ("or", 4)), | |
121 "+": (4, None, ("or", 4)), | |
122 ",": (2, None, ("list", 2)), | |
123 ")": (0, None, None), | |
124 "symbol": (0, ("symbol",), None), | |
125 "string": (0, ("string",), None), | |
126 "end": (0, None, None), | |
127 } | |
128 | |
129 keywords = set(['and', 'or', 'not']) | |
130 | |
20779
ffc2295c6b80
revset: pass a lookup function to the tokenizer
Matt Mackall <mpm@selenic.com>
parents:
20754
diff
changeset
|
131 def tokenize(program, lookup=None): |
17886
d8905e2c1301
revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents:
17829
diff
changeset
|
132 ''' |
d8905e2c1301
revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents:
17829
diff
changeset
|
133 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
|
134 |
d8905e2c1301
revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents:
17829
diff
changeset
|
135 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
|
136 >>> list(tokenize("@::")) |
d8905e2c1301
revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents:
17829
diff
changeset
|
137 [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)] |
d8905e2c1301
revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents:
17829
diff
changeset
|
138 |
d8905e2c1301
revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents:
17829
diff
changeset
|
139 ''' |
d8905e2c1301
revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents:
17829
diff
changeset
|
140 |
11275 | 141 pos, l = 0, len(program) |
142 while pos < l: | |
143 c = program[pos] | |
144 if c.isspace(): # skip inter-token whitespace | |
145 pass | |
11278
7df88cdf47fd
revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents:
11275
diff
changeset
|
146 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
|
147 yield ('::', None, pos) |
11278
7df88cdf47fd
revset: add support for prefix and suffix versions of : and ::
Matt Mackall <mpm@selenic.com>
parents:
11275
diff
changeset
|
148 pos += 1 # skip ahead |
11275 | 149 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
|
150 yield ('..', None, pos) |
11275 | 151 pos += 1 # skip ahead |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
152 elif c in "():,-|&+!~^": # handle simple operators |
11289
4215ce511134
revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents:
11284
diff
changeset
|
153 yield (c, None, pos) |
12408
78a97859b90d
revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents:
12401
diff
changeset
|
154 elif (c in '"\'' or c == 'r' and |
78a97859b90d
revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents:
12401
diff
changeset
|
155 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
|
156 if c == 'r': |
78a97859b90d
revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents:
12401
diff
changeset
|
157 pos += 1 |
78a97859b90d
revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents:
12401
diff
changeset
|
158 c = program[pos] |
78a97859b90d
revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents:
12401
diff
changeset
|
159 decode = lambda x: x |
78a97859b90d
revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents:
12401
diff
changeset
|
160 else: |
78a97859b90d
revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents:
12401
diff
changeset
|
161 decode = lambda x: x.decode('string-escape') |
11275 | 162 pos += 1 |
163 s = pos | |
164 while pos < l: # find closing quote | |
165 d = program[pos] | |
166 if d == '\\': # skip over escaped characters | |
167 pos += 2 | |
168 continue | |
169 if d == c: | |
12408
78a97859b90d
revset: support raw string literals
Brodie Rao <brodie@bitheap.org>
parents:
12401
diff
changeset
|
170 yield ('string', decode(program[s:pos]), s) |
11275 | 171 break |
172 pos += 1 | |
173 else: | |
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
174 raise error.ParseError(_("unterminated string"), s) |
16683 | 175 # gather up a symbol/keyword |
17886
d8905e2c1301
revset: accept @ in unquoted symbols (issue3686)
Matt Mackall <mpm@selenic.com>
parents:
17829
diff
changeset
|
176 elif c.isalnum() or c in '._@' or ord(c) > 127: |
11275 | 177 s = pos |
178 pos += 1 | |
179 while pos < l: # find end of symbol | |
180 d = program[pos] | |
20780
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
181 if not (d.isalnum() or d in "-._/@" or ord(d) > 127): |
11275 | 182 break |
183 if d == '.' and program[pos - 1] == '.': # special case for .. | |
184 pos -= 1 | |
185 break | |
186 pos += 1 | |
187 sym = program[s:pos] | |
188 if sym in keywords: # operator keywords | |
11289
4215ce511134
revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents:
11284
diff
changeset
|
189 yield (sym, None, s) |
20780
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
190 elif '-' in sym: |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
191 # some jerk gave us foo-bar-baz, try to check if it's a symbol |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
192 if lookup and lookup(sym): |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
193 # looks like a real symbol |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
194 yield ('symbol', sym, s) |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
195 else: |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
196 # looks like an expression |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
197 parts = sym.split('-') |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
198 for p in parts[:-1]: |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
199 if p: # possible consecutive - |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
200 yield ('symbol', p, s) |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
201 s += len(p) |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
202 yield ('-', None, pos) |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
203 s += 1 |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
204 if parts[-1]: # possible trailing - |
403f1f73d30f
revset: try to handle hyphenated symbols if lookup callback is available
Matt Mackall <mpm@selenic.com>
parents:
20779
diff
changeset
|
205 yield ('symbol', parts[-1], s) |
11275 | 206 else: |
11289
4215ce511134
revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents:
11284
diff
changeset
|
207 yield ('symbol', sym, s) |
11275 | 208 pos -= 1 |
209 else: | |
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
210 raise error.ParseError(_("syntax error"), pos) |
11275 | 211 pos += 1 |
11289
4215ce511134
revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents:
11284
diff
changeset
|
212 yield ('end', None, pos) |
11275 | 213 |
214 # helpers | |
215 | |
216 def getstring(x, err): | |
11406
42408cd43f55
revset: fix up contains/getstring when no args passed
Matt Mackall <mpm@selenic.com>
parents:
11404
diff
changeset
|
217 if x and (x[0] == 'string' or x[0] == 'symbol'): |
11275 | 218 return x[1] |
11289
4215ce511134
revset: raise ParseError exceptions
Matt Mackall <mpm@selenic.com>
parents:
11284
diff
changeset
|
219 raise error.ParseError(err) |
11275 | 220 |
221 def getlist(x): | |
222 if not x: | |
223 return [] | |
224 if x[0] == 'list': | |
225 return getlist(x[1]) + [x[2]] | |
226 return [x] | |
227 | |
11339
744d5b73f776
revset: improve filter argument handling
Matt Mackall <mpm@selenic.com>
parents:
11304
diff
changeset
|
228 def getargs(x, min, max, err): |
11275 | 229 l = getlist(x) |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
230 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
|
231 raise error.ParseError(err) |
11275 | 232 return l |
233 | |
234 def getset(repo, subset, x): | |
235 if not x: | |
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
236 raise error.ParseError(_("missing argument")) |
20527
bde426f18e0a
revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20526
diff
changeset
|
237 s = methods[x[0]](repo, subset, *x[1:]) |
bde426f18e0a
revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20526
diff
changeset
|
238 if util.safehasattr(s, 'set'): |
bde426f18e0a
revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20526
diff
changeset
|
239 return s |
bde426f18e0a
revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20526
diff
changeset
|
240 return baseset(s) |
11275 | 241 |
17003
42c472877825
revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents:
17002
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 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
|
246 try: |
42c472877825
revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents:
17002
diff
changeset
|
247 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
|
248 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
|
249 pass |
42c472877825
revset: add a utility for obtaining the source of a given rev
Matt Harbison <matt_harbison@yahoo.com>
parents:
17002
diff
changeset
|
250 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
|
251 |
11275 | 252 # operator methods |
253 | |
254 def stringset(repo, subset, x): | |
255 x = repo[x].rev() | |
11282 | 256 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
|
257 return baseset([-1]) |
13938
e44ebd2a142a
revset: optimize stringset when subset == entire repo
Idan Kamara <idankk86@gmail.com>
parents:
13932
diff
changeset
|
258 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
|
259 return baseset([x]) |
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
260 return baseset([]) |
11275 | 261 |
262 def symbolset(repo, subset, x): | |
263 if x in symbols: | |
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
264 raise error.ParseError(_("can't use %s here") % x) |
11275 | 265 return stringset(repo, subset, x) |
266 | |
267 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
|
268 cl = baseset(repo.changelog) |
18473
692cbda1eb50
revset: evaluate sub expressions correctly (issue3775)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18411
diff
changeset
|
269 m = getset(repo, cl, x) |
692cbda1eb50
revset: evaluate sub expressions correctly (issue3775)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18411
diff
changeset
|
270 n = getset(repo, cl, y) |
11456
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
271 |
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
272 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
|
273 return baseset([]) |
11456
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
274 m, n = m[0], n[-1] |
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
275 |
11275 | 276 if m < n: |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
277 r = spanset(repo, m, n + 1) |
11456
88abbb046e66
revset: deal with empty sets in range endpoints
Matt Mackall <mpm@selenic.com>
parents:
11446
diff
changeset
|
278 else: |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
279 r = spanset(repo, m, n - 1) |
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
280 return r & subset |
11275 | 281 |
16860
e1aa1ed30030
revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents:
16859
diff
changeset
|
282 def dagrange(repo, subset, x, y): |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
283 r = spanset(repo) |
18991
c1af1fb314bc
log: fix behavior with empty repositories (issue3497)
Alexander Plavin <me@aplavin.ru>
parents:
18779
diff
changeset
|
284 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
|
285 s = subset.set() |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
286 return xs.filter(lambda r: r in s) |
16860
e1aa1ed30030
revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents:
16859
diff
changeset
|
287 |
11275 | 288 def andset(repo, subset, x, y): |
289 return getset(repo, getset(repo, subset, x), y) | |
290 | |
291 def orset(repo, subset, x, y): | |
13932
34f577007ffe
revsets: preserve ordering with the or operator
Augie Fackler <durin42@gmail.com>
parents:
13915
diff
changeset
|
292 xl = getset(repo, subset, x) |
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
293 yl = getset(repo, subset - xl, y) |
13932
34f577007ffe
revsets: preserve ordering with the or operator
Augie Fackler <durin42@gmail.com>
parents:
13915
diff
changeset
|
294 return xl + yl |
11275 | 295 |
296 def notset(repo, subset, x): | |
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
297 return subset - getset(repo, subset, x) |
11275 | 298 |
299 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
|
300 raise error.ParseError(_("can't use a list in this context")) |
11275 | 301 |
302 def func(repo, subset, a, b): | |
303 if a[0] == 'symbol' and a[1] in symbols: | |
304 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
|
305 raise error.ParseError(_("not a function: %s") % a[1]) |
11275 | 306 |
307 # functions | |
308 | |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
309 def adds(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
310 """``adds(pattern)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
311 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
|
312 |
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
313 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
|
314 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
|
315 directory. |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
316 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
317 # i18n: "adds" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
318 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
|
319 return checkstatus(repo, subset, pat, 1) |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
320 |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
321 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
|
322 """``ancestor(*changeset)`` |
20991
a05d694599f9
revlog: use context ancestor instead of changelog ancestor
Mads Kiilerich <madski@unity3d.com>
parents:
20895
diff
changeset
|
323 A greatest common ancestor of the changesets. |
18536
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
324 |
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
329 # 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
|
330 l = getlist(x) |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
331 rl = spanset(repo) |
18536
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
332 anc = None |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
333 |
18536
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
334 # (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
|
335 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
|
336 for r in revs: |
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
337 if anc is None: |
20991
a05d694599f9
revlog: use context ancestor instead of changelog ancestor
Mads Kiilerich <madski@unity3d.com>
parents:
20895
diff
changeset
|
338 anc = repo[r] |
18536
ae645d4f084c
revset: change ancestor to accept 0 or more arguments (issue3750)
Paul Cavallaro <ptc@fb.com>
parents:
18495
diff
changeset
|
339 else: |
20991
a05d694599f9
revlog: use context ancestor instead of changelog ancestor
Mads Kiilerich <madski@unity3d.com>
parents:
20895
diff
changeset
|
340 anc = anc.ancestor(repo[r]) |
a05d694599f9
revlog: use context ancestor instead of changelog ancestor
Mads Kiilerich <madski@unity3d.com>
parents:
20895
diff
changeset
|
341 |
a05d694599f9
revlog: use context ancestor instead of changelog ancestor
Mads Kiilerich <madski@unity3d.com>
parents:
20895
diff
changeset
|
342 if anc is not None and anc.rev() in subset: |
a05d694599f9
revlog: use context ancestor instead of changelog ancestor
Mads Kiilerich <madski@unity3d.com>
parents:
20895
diff
changeset
|
343 return baseset([anc.rev()]) |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
344 return baseset([]) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
345 |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
346 def _ancestors(repo, subset, x, followfirst=False): |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
347 args = getset(repo, spanset(repo), x) |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
348 if not args: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
349 return baseset([]) |
20690
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
350 s = _revancestors(repo, args, followfirst) |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
351 return subset.filter(lambda r: r in s) |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
352 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
353 def ancestors(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
354 """``ancestors(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
355 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
|
356 """ |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
357 return _ancestors(repo, subset, x) |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
358 |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
359 def _firstancestors(repo, subset, x): |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
360 # ``_firstancestors(set)`` |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
361 # 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
|
362 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
|
363 |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
364 def ancestorspec(repo, subset, x, n): |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
365 """``set~n`` |
16683 | 366 Changesets that are the Nth ancestor (first parents only) of a changeset |
367 in set. | |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
368 """ |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
369 try: |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
370 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
|
371 except (TypeError, ValueError): |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
372 raise error.ParseError(_("~ expects a number")) |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
373 ps = set() |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
374 cl = repo.changelog |
20424
1da346bad3d8
revset: minor changes adding baseset to revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20418
diff
changeset
|
375 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
|
376 for i in range(n): |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
377 r = cl.parentrevs(r)[0] |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
378 ps.add(r) |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
379 return subset.filter(lambda r: r in ps) |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
380 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
381 def author(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
382 """``author(string)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
383 Alias for ``user(string)``. |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
384 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
385 # 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
|
386 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
|
387 kind, pattern, matcher = _substringmatcher(n) |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
388 return subset.filter(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
|
389 |
20613 | 390 def only(repo, subset, x): |
391 """``only(set, [set])`` | |
392 Changesets that are ancestors of the first set that are not ancestors | |
393 of any other head in the repo. If a second set is specified, the result | |
394 is ancestors of the first set that are not ancestors of the second set | |
395 (i.e. ::<set1> - ::<set2>). | |
396 """ | |
397 cl = repo.changelog | |
21173
d4daebb21cf6
revset, i18n: add translator comment to "only"
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
21024
diff
changeset
|
398 # i18n: "only" is a keyword |
20613 | 399 args = getargs(x, 1, 2, _('only takes one or two arguments')) |
400 include = getset(repo, spanset(repo), args[0]).set() | |
401 if len(args) == 1: | |
402 descendants = set(_revdescendants(repo, include, False)) | |
403 exclude = [rev for rev in cl.headrevs() | |
404 if not rev in descendants and not rev in include] | |
405 else: | |
406 exclude = getset(repo, spanset(repo), args[1]) | |
407 | |
408 results = set(ancestormod.missingancestors(include, exclude, cl.parentrevs)) | |
409 return lazyset(subset, lambda x: x in results) | |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
410 |
15134
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
411 def bisect(repo, subset, x): |
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
412 """``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
|
413 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
|
414 |
15153
fa0a464e4ca5
hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15147
diff
changeset
|
415 - ``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
|
416 - ``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
|
417 - ``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
|
418 - ``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
|
419 - ``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
|
420 - ``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
|
421 - ``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
|
422 """ |
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
|
423 # 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
|
424 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
|
425 state = set(hbisect.get(repo, status)) |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
426 return subset.filter(lambda r: r in state) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
427 |
15134
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
428 # Backward-compatibility |
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
429 # - 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
|
430 def bisected(repo, subset, x): |
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
431 return bisect(repo, subset, x) |
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
432 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
433 def bookmark(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
434 """``bookmark([name])`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
435 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
|
436 |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
437 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
|
438 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
|
439 use the prefix `literal:`. |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
440 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
441 # i18n: "bookmark" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
442 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
|
443 if args: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
444 bm = getstring(args[0], |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
445 # i18n: "bookmark" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
446 _('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
|
447 kind, pattern, matcher = _stringmatcher(bm) |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
448 if kind == 'literal': |
18495
8260fa9f30b9
bookmarks: don't use bookmarks.listbookmarks in local computations
Kevin Bullock <kbullock@ringworld.org>
parents:
18473
diff
changeset
|
449 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
|
450 if not bmrev: |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
451 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
|
452 bmrev = repo[bmrev].rev() |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
453 return subset.filter(lambda r: r == bmrev) |
16822
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
454 else: |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
455 matchrevs = set() |
18495
8260fa9f30b9
bookmarks: don't use bookmarks.listbookmarks in local computations
Kevin Bullock <kbullock@ringworld.org>
parents:
18473
diff
changeset
|
456 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
|
457 if matcher(name): |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
458 matchrevs.add(bmrev) |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
459 if not matchrevs: |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
460 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
|
461 % pattern) |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
462 bmrevs = set() |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
463 for bmrev in matchrevs: |
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
464 bmrevs.add(repo[bmrev].rev()) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
465 return subset & bmrevs |
16822
da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
Simon King <simon@simonking.org.uk>
parents:
16821
diff
changeset
|
466 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
467 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
|
468 for r in repo._bookmarks.values()]) |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
469 return subset.filter(lambda r: r in bms) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
470 |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
471 def branch(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
472 """``branch(string or set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
473 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
|
474 changesets. |
16821
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
475 |
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
476 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
|
477 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
|
478 use the prefix `literal:`. |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
479 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
480 try: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
481 b = getstring(x, '') |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
482 except error.ParseError: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
483 # 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
|
484 pass |
16821
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
485 else: |
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
486 kind, pattern, matcher = _stringmatcher(b) |
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
487 if kind == 'literal': |
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
488 # 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
|
489 # this name exists |
0946502fd3d5
revset: add pattern matching to 'branch' revset expression
Simon King <simon@simonking.org.uk>
parents:
16820
diff
changeset
|
490 if pattern in repo.branchmap(): |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
491 return subset.filter(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
|
492 else: |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
493 return subset.filter(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
|
494 |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
495 s = getset(repo, spanset(repo), x) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
496 b = set() |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
497 for r in s: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
498 b.add(repo[r].branch()) |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
499 s = s.set() |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
500 return subset.filter(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
|
501 |
17829
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
502 def bumped(repo, subset, x): |
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
503 """``bumped()`` |
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
504 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
|
505 |
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
506 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
|
507 """ |
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
508 # i18n: "bumped" is a keyword |
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
509 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
|
510 bumped = obsmod.getrevs(repo, 'bumped') |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
511 return subset & bumped |
17829
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
512 |
17913
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
513 def bundle(repo, subset, x): |
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
514 """``bundle()`` |
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
515 Changesets in the bundle. |
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
516 |
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
517 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
|
518 |
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
519 try: |
18411
8b0f0dd56cec
bundlerepo: improve performance for bundle() revset expression
Mads Kiilerich <madski@unity3d.com>
parents:
18382
diff
changeset
|
520 bundlerevs = repo.changelog.bundlerevs |
17913
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
521 except AttributeError: |
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
522 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
|
523 return subset & bundlerevs |
17913
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
524 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
525 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
|
526 hasset = matchmod.patkind(pat) == 'set' |
20457
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
527 |
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
528 def matches(x): |
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
529 m = None |
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
530 fname = None |
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
531 c = repo[x] |
16521
592701c8eac6
revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents:
16467
diff
changeset
|
532 if not m or hasset: |
592701c8eac6
revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents:
16467
diff
changeset
|
533 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
|
534 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
|
535 fname = m.files()[0] |
592701c8eac6
revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents:
16467
diff
changeset
|
536 if fname is not None: |
592701c8eac6
revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents:
16467
diff
changeset
|
537 if fname not in c.files(): |
20457
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
538 return False |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
539 else: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
540 for f in c.files(): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
541 if m(f): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
542 break |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
543 else: |
20457
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
544 return False |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
545 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
|
546 if fname is not None: |
592701c8eac6
revset: fix adds/modifies/removes and patterns (issue3403)
Patrick Mezard <patrick@mezard.eu>
parents:
16467
diff
changeset
|
547 if fname in files: |
20457
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
548 return True |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
549 else: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
550 for f in files: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
551 if m(f): |
20457
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
552 return True |
ed7b674824a3
revset: added lazyset implementation to checkstatus
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20456
diff
changeset
|
553 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
554 return subset.filter(matches) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
555 |
16396
03e408a122c4
revset: avoid set duplication in roots()
Patrick Mezard <patrick@mezard.eu>
parents:
16395
diff
changeset
|
556 def _children(repo, narrow, parentset): |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
557 cs = set() |
18063
34a1a639d835
revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents:
17980
diff
changeset
|
558 if not parentset: |
20709
71df845d86cf
revsets: backout d04aac468bf4 due to performance regressions
Matt Mackall <mpm@selenic.com>
parents:
20708
diff
changeset
|
559 return baseset(cs) |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
560 pr = repo.changelog.parentrevs |
18063
34a1a639d835
revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents:
17980
diff
changeset
|
561 minrev = min(parentset) |
16394
f3df7d34791e
revset: do not ignore input revisions in roots()
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
562 for r in narrow: |
18063
34a1a639d835
revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents:
17980
diff
changeset
|
563 if r <= minrev: |
34a1a639d835
revset.children: ignore rev numbers that are too low
Siddharth Agarwal <sid0@fb.com>
parents:
17980
diff
changeset
|
564 continue |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
565 for p in pr(r): |
16396
03e408a122c4
revset: avoid set duplication in roots()
Patrick Mezard <patrick@mezard.eu>
parents:
16395
diff
changeset
|
566 if p in parentset: |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
567 cs.add(r) |
20709
71df845d86cf
revsets: backout d04aac468bf4 due to performance regressions
Matt Mackall <mpm@selenic.com>
parents:
20708
diff
changeset
|
568 return baseset(cs) |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
569 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
570 def children(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
571 """``children(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
572 Child changesets of changesets in set. |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
573 """ |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
574 s = getset(repo, baseset(repo), x).set() |
15899
476a981fdf34
revset: optimize roots and children
Matt Mackall <mpm@selenic.com>
parents:
15898
diff
changeset
|
575 cs = _children(repo, subset, s) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
576 return subset & cs |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
577 |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
578 def closed(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
579 """``closed()`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
580 Changeset is closed. |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
581 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
582 # i18n: "closed" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
583 getargs(x, 0, 0, _("closed takes no arguments")) |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
584 return subset.filter(lambda r: repo[r].closesbranch()) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
585 |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
586 def contains(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
587 """``contains(pattern)`` |
14357 | 588 Revision contains a file matching pattern. See :hg:`help patterns` |
589 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
|
590 |
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
591 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
|
592 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
|
593 for efficiency. |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
594 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
595 # i18n: "contains" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
596 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
|
597 |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
598 def matches(x): |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
599 if not matchmod.patkind(pat): |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
600 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
|
601 if pats in repo[x]: |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
602 return True |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
603 else: |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
604 c = repo[x] |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
605 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
|
606 for f in c.manifest(): |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
607 if m(f): |
20461
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
608 return True |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
609 return False |
abd8e56a1038
revset: added lazyset implementation to contains revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20460
diff
changeset
|
610 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
611 return subset.filter(matches) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
612 |
17002
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
613 def converted(repo, subset, x): |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
614 """``converted([id])`` |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
615 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
|
616 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
|
617 """ |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
618 |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
619 # 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
|
620 # 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
|
621 |
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
|
622 rev = None |
17002
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
623 # i18n: "converted" is a keyword |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
624 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
|
625 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
|
626 # 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
|
627 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
|
628 |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
629 def _matchvalue(r): |
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
630 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
|
631 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
|
632 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
633 return subset.filter(lambda r: _matchvalue(r)) |
17002
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
634 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
635 def date(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
636 """``date(interval)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
637 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
|
638 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
639 # i18n: "date" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
640 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
|
641 dm = util.matchdate(ds) |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
642 return subset.filter(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
|
643 |
14650
93731b3efd0d
revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14649
diff
changeset
|
644 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
|
645 """``desc(string)`` |
93731b3efd0d
revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14649
diff
changeset
|
646 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
|
647 """ |
93731b3efd0d
revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14649
diff
changeset
|
648 # 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
|
649 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
|
650 |
a685d9870eb5
revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20451
diff
changeset
|
651 def matches(x): |
a685d9870eb5
revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20451
diff
changeset
|
652 c = repo[x] |
a685d9870eb5
revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20451
diff
changeset
|
653 return ds in encoding.lower(c.description()) |
a685d9870eb5
revset: added lazyset implementation to desc revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20451
diff
changeset
|
654 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
655 return subset.filter(matches) |
14650
93731b3efd0d
revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14649
diff
changeset
|
656 |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
657 def _descendants(repo, subset, x, followfirst=False): |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
658 args = getset(repo, spanset(repo), x) |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
659 if not args: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
660 return baseset([]) |
20692
7af341082b76
revset: changed descendants revset to use lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20691
diff
changeset
|
661 s = _revdescendants(repo, args, followfirst) |
20894
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
662 |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
663 # Both sets need to be ascending in order to lazily return the union |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
664 # in the correct order. |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
665 args.ascending() |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
666 |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
667 subsetset = subset.set() |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
668 result = (orderedlazyset(s, subsetset.__contains__, ascending=True) + |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
669 orderedlazyset(args, subsetset.__contains__, ascending=True)) |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
670 |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
671 # Wrap result in a lazyset since it's an _addset, which doesn't implement |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
672 # all the necessary functions to be consumed by callers. |
04e1596d5dbd
revset: improve _descendants performance
Durham Goode <durham@fb.com>
parents:
20863
diff
changeset
|
673 return orderedlazyset(result, lambda r: True, ascending=True) |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
674 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
675 def descendants(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
676 """``descendants(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
677 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
|
678 """ |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
679 return _descendants(repo, subset, x) |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
680 |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
681 def _firstdescendants(repo, subset, x): |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
682 # ``_firstdescendants(set)`` |
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
683 # 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
|
684 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
|
685 |
17186
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
686 def destination(repo, subset, x): |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
687 """``destination([set])`` |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
688 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
|
689 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
|
690 is the same as passing all(). |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
691 """ |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
692 if x is not None: |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
693 args = getset(repo, spanset(repo), x).set() |
17186
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
694 else: |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
695 args = getall(repo, spanset(repo), x).set() |
17186
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
696 |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
697 dests = set() |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
698 |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
699 # 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
|
700 # 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
|
701 # 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
|
702 # 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
|
703 # 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
|
704 # grafts. |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
705 for r in subset: |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
706 src = _getrevsource(repo, r) |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
707 lineage = None |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
708 |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
709 while src is not None: |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
710 if lineage is None: |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
711 lineage = list() |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
712 |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
713 lineage.append(r) |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
714 |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
715 # 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
|
716 # set. Since every candidate dest is visited by way of iterating |
17494 | 717 # 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
|
718 # 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
|
719 # 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
|
720 # further. |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
721 if src in args or src in dests: |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
722 dests.update(lineage) |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
723 break |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
724 |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
725 r = src |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
726 src = _getrevsource(repo, r) |
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
727 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
728 return subset.filter(lambda r: r in dests) |
17186
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
729 |
18071
bea754715961
obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18063
diff
changeset
|
730 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
|
731 """``divergent()`` |
bea754715961
obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18063
diff
changeset
|
732 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
|
733 """ |
bea754715961
obsolete: add revset and test for divergent changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18063
diff
changeset
|
734 # 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
|
735 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
|
736 divergent = obsmod.getrevs(repo, 'divergent') |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
737 return subset.filter(lambda r: 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
|
738 |
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
739 def draft(repo, subset, x): |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
740 """``draft()`` |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
741 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
|
742 # 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
|
743 getargs(x, 0, 0, _("draft takes no arguments")) |
16657
b6081c2c4647
phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents:
16647
diff
changeset
|
744 pc = repo._phasecache |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
745 return subset.filter(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
|
746 |
17173
c621f84dbb35
obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17171
diff
changeset
|
747 def extinct(repo, subset, x): |
c621f84dbb35
obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17171
diff
changeset
|
748 """``extinct()`` |
17291
2d6bbf87f7b4
revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents:
17272
diff
changeset
|
749 Obsolete changesets with obsolete descendants only. |
2d6bbf87f7b4
revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents:
17272
diff
changeset
|
750 """ |
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
|
751 # 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
|
752 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
|
753 extincts = obsmod.getrevs(repo, 'extinct') |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
754 return subset & extincts |
17173
c621f84dbb35
obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17171
diff
changeset
|
755 |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
756 def extra(repo, subset, x): |
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
757 """``extra(label, [value])`` |
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
758 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
|
759 optional value. |
f3b8c82a559c
revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents:
16823
diff
changeset
|
760 |
f3b8c82a559c
revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents:
16823
diff
changeset
|
761 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
|
762 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
|
763 use the prefix `literal:`. |
f3b8c82a559c
revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents:
16823
diff
changeset
|
764 """ |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
765 |
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
|
766 # i18n: "extra" is a keyword |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
767 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
|
768 # i18n: "extra" is a keyword |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
769 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
|
770 value = None |
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
771 |
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
772 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
|
773 # i18n: "extra" is a keyword |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
774 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
|
775 kind, value, matcher = _stringmatcher(value) |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
776 |
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
777 def _matchvalue(r): |
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
778 extra = repo[r].extra() |
16824
f3b8c82a559c
revset: add pattern matching to 'extra' revset expression
Simon King <simon@simonking.org.uk>
parents:
16823
diff
changeset
|
779 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
|
780 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
781 return subset.filter(lambda r: _matchvalue(r)) |
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
782 |
14342
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
783 def filelog(repo, subset, x): |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
784 """``filelog(pattern)`` |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
785 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
|
786 |
17265
c30307eeec4b
revset: polish explanation of the difference between file() and filelog()
Greg Ward <greg@gerg.ca>
parents:
17259
diff
changeset
|
787 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
|
788 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
|
789 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
|
790 |
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
791 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
|
792 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
|
793 for efficiency. |
14342
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
794 """ |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
795 |
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
|
796 # 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
|
797 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
|
798 s = set() |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
799 |
15964
6e37b8282aa2
revsets: provide contexts for filesets
Matt Mackall <mpm@selenic.com>
parents:
15949
diff
changeset
|
800 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
|
801 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
|
802 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
|
803 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
|
804 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
|
805 else: |
20288
b61ad01c4e73
revset: use "canonpath()" for "filelog()" pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20287
diff
changeset
|
806 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
|
807 for f in repo[None]: |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
808 if m(f): |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
809 fl = repo.file(f) |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
810 for fr in fl: |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
811 s.add(fl.linkrev(fr)) |
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
812 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
813 return subset.filter(lambda r: r in s) |
14342
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
814 |
15117
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
815 def first(repo, subset, x): |
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
816 """``first(set, [n])`` |
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
817 An alias for limit(). |
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
818 """ |
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
819 return limit(repo, subset, x) |
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
820 |
16185
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
821 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
|
822 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
|
823 c = repo['.'] |
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
824 if l: |
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
825 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
|
826 if x in c: |
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
827 cx = c[x] |
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
828 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
|
829 # 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
|
830 s.add(cx.linkrev()) |
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
831 else: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
832 return baseset([]) |
16185
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
833 else: |
20690
13c0327eeb6f
revset: changed ancestors revset to return lazy generators
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20659
diff
changeset
|
834 s = _revancestors(repo, baseset([c.rev()]), followfirst) |
16185
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
835 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
836 return subset.filter(lambda r: r in s) |
16185
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
837 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
838 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
|
839 """``follow([file])`` |
9ed227f79e47
revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents:
14342
diff
changeset
|
840 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
|
841 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
|
842 including copies. |
9ed227f79e47
revset: add follow(filename) to follow a filename's history across copies
Matt Mackall <mpm@selenic.com>
parents:
14342
diff
changeset
|
843 """ |
16185
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
844 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
|
845 |
16174
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
846 def _followfirst(repo, subset, x): |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
847 # ``followfirst([file])`` |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
848 # Like ``follow([file])`` but follows only the first parent of |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
849 # every revision or file revision. |
16185
352053e6cd8e
context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents:
16181
diff
changeset
|
850 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
|
851 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
852 def getall(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
853 """``all()`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
854 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
|
855 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
856 # i18n: "all" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
857 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
|
858 return subset |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
859 |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
860 def grep(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
861 """``grep(regex)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
862 Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` |
14357 | 863 to ensure special escape characters are handled correctly. Unlike |
864 ``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
|
865 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
866 try: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
867 # i18n: "grep" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
868 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
|
869 except re.error, e: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
870 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
|
871 |
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
872 def matches(x): |
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
873 c = repo[x] |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
874 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
|
875 if gr.search(e): |
20453
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
876 return True |
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
877 return False |
6aa7dcae6bd8
revset: added lazyset implementation to grep revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20452
diff
changeset
|
878 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
879 return subset.filter(matches) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
880 |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
881 def _matchfiles(repo, subset, x): |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
882 # _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
|
883 # |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
884 # [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
|
885 # |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
886 # 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
|
887 # 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
|
888 # 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
|
889 # 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
|
890 # 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
|
891 # 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
|
892 # 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
|
893 |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
894 # i18n: "_matchfiles" is a keyword |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
895 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
|
896 pats, inc, exc = [], [], [] |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
897 hasset = False |
16411
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
898 rev, default = None, None |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
899 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
|
900 # 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
|
901 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
|
902 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
|
903 if prefix == 'p:': |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
904 pats.append(value) |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
905 elif prefix == 'i:': |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
906 inc.append(value) |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
907 elif prefix == 'x:': |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
908 exc.append(value) |
16181
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
909 elif prefix == 'r:': |
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
910 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
|
911 # 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
|
912 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
|
913 'revision')) |
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
914 rev = value |
16411
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
915 elif prefix == 'd:': |
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
916 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
|
917 # i18n: "_matchfiles" is a keyword |
16411
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
918 raise error.ParseError(_('_matchfiles expected at most one ' |
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
919 'default mode')) |
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
920 default = value |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
921 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
|
922 # 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
|
923 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
|
924 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
|
925 hasset = True |
16411
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
926 if not default: |
4c2edcd84175
graphlog: correctly handle calls in subdirectories
Patrick Mezard <patrick@mezard.eu>
parents:
16409
diff
changeset
|
927 default = 'glob' |
20458
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
928 |
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
929 def matches(x): |
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
930 m = None |
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
931 c = repo[x] |
16181
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
932 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
|
933 ctx = c |
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
934 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
|
935 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
|
936 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
|
937 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
|
938 for f in c.files(): |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
939 if m(f): |
20458
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
940 return True |
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
941 return False |
8dabcc889e33
revset: added lazyset implementation to _matchfiles
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20457
diff
changeset
|
942 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
943 return subset.filter(matches) |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
944 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
945 def hasfile(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
946 """``file(pattern)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
947 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
|
948 |
17265
c30307eeec4b
revset: polish explanation of the difference between file() and filelog()
Greg Ward <greg@gerg.ca>
parents:
17259
diff
changeset
|
949 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
|
950 instead. |
20289
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
951 |
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
952 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
|
953 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
954 # i18n: "file" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
955 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
|
956 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
|
957 |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
958 def head(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
959 """``head()`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
960 Changeset is a named branch head. |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
961 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
962 # i18n: "head" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
963 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
|
964 hs = set() |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
965 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
|
966 hs.update(repo[h].rev() for h in ls) |
20713
6a1a4c212d50
revset: improve head revset performance
Durham Goode <durham@fb.com>
parents:
20712
diff
changeset
|
967 return baseset(hs).filter(subset.__contains__) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
968 |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
969 def heads(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
970 """``heads(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
971 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
|
972 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
973 s = getset(repo, subset, x) |
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
974 ps = parents(repo, subset, x) |
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
975 return s - ps |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
976 |
17390
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
977 def hidden(repo, subset, x): |
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
978 """``hidden()`` |
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
979 Hidden changesets. |
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
980 """ |
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
981 # i18n: "hidden" is a keyword |
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
982 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
|
983 hiddenrevs = repoview.filterrevs(repo, 'visible') |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
984 return subset & hiddenrevs |
17390
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
985 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
986 def keyword(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
987 """``keyword(string)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
988 Search commit message, user name, and names of changed files for |
14357 | 989 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
|
990 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
991 # 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
|
992 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
|
993 |
abb91b74f758
revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20446
diff
changeset
|
994 def matches(r): |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
995 c = repo[r] |
20447
abb91b74f758
revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20446
diff
changeset
|
996 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
|
997 c.description()]) |
abb91b74f758
revset: added lazyset implementation to keyword revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20446
diff
changeset
|
998 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
999 return subset.filter(matches) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1000 |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1001 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
|
1002 """``limit(set, [n])`` |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
1003 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
|
1004 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1005 # 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
|
1006 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
|
1007 try: |
15116
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
1008 lim = 1 |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
1009 if len(l) == 2: |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
1010 # 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
|
1011 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
|
1012 except (TypeError, ValueError): |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1013 # i18n: "limit" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1014 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
|
1015 ss = subset.set() |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
1016 os = getset(repo, spanset(repo), l[0]) |
20446
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
1017 bs = baseset([]) |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
1018 it = iter(os) |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
1019 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
|
1020 try: |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
1021 y = it.next() |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
1022 if y in ss: |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
1023 bs.append(y) |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
1024 except (StopIteration): |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
1025 break |
d258486604f4
revset: changed limit revset implementation to work with lazy revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20445
diff
changeset
|
1026 return bs |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1027 |
14061
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
1028 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
|
1029 """``last(set, [n])`` |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
1030 Last n members of set, defaulting to 1. |
14061
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
1031 """ |
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
1032 # 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
|
1033 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
|
1034 try: |
15116
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
1035 lim = 1 |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
1036 if len(l) == 2: |
d8501bcbb221
revset: add default of 1 to limit and last functions
Matt Mackall <mpm@selenic.com>
parents:
14901
diff
changeset
|
1037 # 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
|
1038 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
|
1039 except (TypeError, ValueError): |
14061
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
1040 # i18n: "last" is a keyword |
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
1041 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
|
1042 ss = subset.set() |
20534
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1043 os = getset(repo, spanset(repo), l[0]) |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1044 os.reverse() |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1045 bs = baseset([]) |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1046 it = iter(os) |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1047 for x in xrange(lim): |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1048 try: |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1049 y = it.next() |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1050 if y in ss: |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1051 bs.append(y) |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1052 except (StopIteration): |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1053 break |
4849f574aa24
revset: changed last implementation to use lazy classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20527
diff
changeset
|
1054 return bs |
14061
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
1055 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1056 def maxrev(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1057 """``max(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1058 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
|
1059 """ |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
1060 os = getset(repo, spanset(repo), x) |
14153
f8047a059ca0
revset: avoid over-aggresive optimizations of non-filtering functions (issue2549)
Mads Kiilerich <mads@kiilerich.com>
parents:
14098
diff
changeset
|
1061 if os: |
20754
f15ff553b762
revset: changed minrev and maxrev implementations to use ordered sets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20753
diff
changeset
|
1062 m = os.max() |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1063 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
|
1064 return baseset([m]) |
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1065 return baseset([]) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1066 |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1067 def merge(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1068 """``merge()`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1069 Changeset is a merge changeset. |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1070 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1071 # i18n: "merge" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1072 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
|
1073 cl = repo.changelog |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1074 return subset.filter(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
|
1075 |
17753
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1076 def branchpoint(repo, subset, x): |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1077 """``branchpoint()`` |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1078 Changesets with more than one child. |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1079 """ |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1080 # i18n: "branchpoint" is a keyword |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1081 getargs(x, 0, 0, _("branchpoint takes no arguments")) |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1082 cl = repo.changelog |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1083 if not subset: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1084 return baseset([]) |
17753
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1085 baserev = min(subset) |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1086 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
|
1087 for r in cl.revs(start=baserev + 1): |
17753
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1088 for p in cl.parentrevs(r): |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1089 if p >= baserev: |
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1090 parentscount[p - baserev] += 1 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1091 return subset.filter(lambda r: parentscount[r - baserev] > 1) |
17753
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1092 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1093 def minrev(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1094 """``min(set)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1095 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
|
1096 """ |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
1097 os = getset(repo, spanset(repo), x) |
14153
f8047a059ca0
revset: avoid over-aggresive optimizations of non-filtering functions (issue2549)
Mads Kiilerich <mads@kiilerich.com>
parents:
14098
diff
changeset
|
1098 if os: |
20754
f15ff553b762
revset: changed minrev and maxrev implementations to use ordered sets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20753
diff
changeset
|
1099 m = os.min() |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1100 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
|
1101 return baseset([m]) |
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1102 return baseset([]) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1103 |
20498
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1104 def _missingancestors(repo, subset, x): |
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1105 # i18n: "_missingancestors" is a keyword |
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1106 revs, bases = getargs(x, 2, 2, |
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1107 _("_missingancestors requires two arguments")) |
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1108 rs = baseset(repo) |
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1109 revs = getset(repo, rs, revs) |
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1110 bases = getset(repo, rs, bases) |
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1111 missing = set(repo.changelog.findmissingrevs(bases, revs)) |
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1112 return baseset([r for r in subset if r in missing]) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1113 |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1114 def modifies(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1115 """``modifies(pattern)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1116 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
|
1117 |
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
1118 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
|
1119 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
|
1120 directory. |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1121 """ |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1122 # i18n: "modifies" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1123 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
|
1124 return checkstatus(repo, subset, pat, 0) |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1125 |
16417
b4b0c6931e11
revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents:
16415
diff
changeset
|
1126 def node_(repo, subset, x): |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1127 """``id(string)`` |
12859
76066903ae08
revset: fix missing dot in docstring
Wagner Bruna <wbruna@yahoo.com>
parents:
12855
diff
changeset
|
1128 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
|
1129 """ |
12815
079a618ea89d
revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents:
12786
diff
changeset
|
1130 # 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
|
1131 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
|
1132 # 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
|
1133 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
|
1134 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
|
1135 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
|
1136 else: |
16735
47b8ec0eb7fb
revset: fix traceback for bogus revisions in id(rev)
Matt Harbison <matt_harbison@yahoo.com>
parents:
16640
diff
changeset
|
1137 rn = None |
47b8ec0eb7fb
revset: fix traceback for bogus revisions in id(rev)
Matt Harbison <matt_harbison@yahoo.com>
parents:
16640
diff
changeset
|
1138 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
|
1139 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
|
1140 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
|
1141 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1142 return subset.filter(lambda r: 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
|
1143 |
17170
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1144 def obsolete(repo, subset, x): |
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1145 """``obsolete()`` |
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1146 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
|
1147 # i18n: "obsolete" is a keyword |
17170
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1148 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
|
1149 obsoletes = obsmod.getrevs(repo, 'obsolete') |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1150 return subset & obsoletes |
17170
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1151 |
17185
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1152 def origin(repo, subset, x): |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1153 """``origin([set])`` |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1154 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
|
1155 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
|
1156 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
|
1157 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
|
1158 for the first operation is selected. |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1159 """ |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1160 if x is not None: |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
1161 args = getset(repo, spanset(repo), x).set() |
17185
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1162 else: |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
1163 args = getall(repo, spanset(repo), x).set() |
17185
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1164 |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1165 def _firstsrc(rev): |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1166 src = _getrevsource(repo, rev) |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1167 if src is None: |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1168 return None |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1169 |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1170 while True: |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1171 prev = _getrevsource(repo, src) |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1172 |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1173 if prev is None: |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1174 return src |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1175 src = prev |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1176 |
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1177 o = set([_firstsrc(r) for r in args]) |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1178 return subset.filter(lambda r: r in o) |
17185
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1179 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1180 def outgoing(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1181 """``outgoing([path])`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1182 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
|
1183 default push location. |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1184 """ |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1185 import hg # avoid start-up nasties |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1186 # 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
|
1187 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
|
1188 # i18n: "outgoing" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1189 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
|
1190 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
|
1191 dest, branches = hg.parseurl(dest) |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1192 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
|
1193 if revs: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1194 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
|
1195 other = hg.peer(repo, {}, dest) |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1196 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
|
1197 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
|
1198 repo.ui.popbuffer() |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1199 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
|
1200 o = set([cl.rev(r) for r in outgoing.missing]) |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1201 return subset.filter(lambda r: 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
|
1202 |
11275 | 1203 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
|
1204 """``p1([set])`` |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1205 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
|
1206 """ |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1207 if x is None: |
13878
a8d13ee0ce68
misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents:
13873
diff
changeset
|
1208 p = repo[x].p1().rev() |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1209 return subset.filter(lambda r: r == p) |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1210 |
11275 | 1211 ps = set() |
1212 cl = repo.changelog | |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
1213 for r in getset(repo, spanset(repo), x): |
11275 | 1214 ps.add(cl.parentrevs(r)[0]) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1215 return subset & ps |
11275 | 1216 |
1217 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
|
1218 """``p2([set])`` |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1219 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
|
1220 """ |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1221 if x is None: |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1222 ps = repo[x].parents() |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1223 try: |
12935
98b79c892768
revset: fix p1, p2 and parents in dirstate case (a5f7f1e9340e)
Patrick Mezard <pmezard@gmail.com>
parents:
12929
diff
changeset
|
1224 p = ps[1].rev() |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1225 return subset.filter(lambda r: r == p) |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1226 except IndexError: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1227 return baseset([]) |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12859
diff
changeset
|
1228 |
11275 | 1229 ps = set() |
1230 cl = repo.changelog | |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
1231 for r in getset(repo, spanset(repo), x): |
11275 | 1232 ps.add(cl.parentrevs(r)[1]) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1233 return subset & ps |
11275 | 1234 |
1235 def parents(repo, subset, x): | |
12929
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
1236 """``parents([set])`` |
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
1237 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
|
1238 """ |
12929
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
1239 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
|
1240 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
|
1241 return subset & ps |
12929
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
1242 |
11275 | 1243 ps = set() |
1244 cl = repo.changelog | |
20526
9ad6dae67845
revset: changed revsets to use spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20525
diff
changeset
|
1245 for r in getset(repo, spanset(repo), x): |
11275 | 1246 ps.update(cl.parentrevs(r)) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1247 return subset & ps |
11275 | 1248 |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1249 def parentspec(repo, subset, x, n): |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1250 """``set^0`` |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1251 The set. |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1252 ``set^1`` (or ``set^``), ``set^2`` |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1253 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
|
1254 """ |
12320
40c40c6f20b8
revset: handle re.compile() errors in grep()
Brodie Rao <brodie@bitheap.org>
parents:
11882
diff
changeset
|
1255 try: |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1256 n = int(n[1]) |
14072
2e4d79dcc0a0
revset: add missing whitespace
Kevin Gessner <kevin@kevingessner.com>
parents:
14070
diff
changeset
|
1257 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
|
1258 raise ValueError |
14851
f96c354493d7
revsets: actually catch type error on tip^p1(tip) (issue2884)
Matt Mackall <mpm@selenic.com>
parents:
14842
diff
changeset
|
1259 except (TypeError, ValueError): |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1260 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
|
1261 ps = set() |
11275 | 1262 cl = repo.changelog |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1263 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
|
1264 if n == 0: |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1265 ps.add(r) |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1266 elif n == 1: |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1267 ps.add(cl.parentrevs(r)[0]) |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1268 elif n == 2: |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1269 parents = cl.parentrevs(r) |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1270 if len(parents) > 1: |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1271 ps.add(parents[1]) |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1272 return subset & ps |
11275 | 1273 |
11944
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1274 def present(repo, subset, x): |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1275 """``present(set)`` |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1276 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
|
1277 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
|
1278 |
0a730d3c5aae
doc: add detail explanation for 'present()' predicate of revsets
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16735
diff
changeset
|
1279 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
|
1280 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
|
1281 to continue even in such cases. |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1282 """ |
11944
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1283 try: |
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1284 return getset(repo, subset, x) |
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1285 except error.RepoLookupError: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1286 return baseset([]) |
11944
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1287 |
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1288 def public(repo, subset, x): |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1289 """``public()`` |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1290 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
|
1291 # 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
|
1292 getargs(x, 0, 0, _("public takes no arguments")) |
16657
b6081c2c4647
phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents:
16647
diff
changeset
|
1293 pc = repo._phasecache |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1294 return subset.filter(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
|
1295 |
15936
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1296 def remote(repo, subset, x): |
16007
f06c53ca59a9
revset: fix documentation for 'remote()' predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16006
diff
changeset
|
1297 """``remote([id [,path]])`` |
15936
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1298 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
|
1299 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
|
1300 synonym for the current local branch. |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1301 """ |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1302 |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1303 import hg # avoid start-up nasties |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1304 # i18n: "remote" is a keyword |
16007
f06c53ca59a9
revset: fix documentation for 'remote()' predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16006
diff
changeset
|
1305 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
|
1306 |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1307 q = '.' |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1308 if len(l) > 0: |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1309 # i18n: "remote" is a keyword |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1310 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
|
1311 if q == '.': |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1312 q = repo['.'].branch() |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1313 |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1314 dest = '' |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1315 if len(l) > 1: |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1316 # i18n: "remote" is a keyword |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1317 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
|
1318 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
|
1319 dest, branches = hg.parseurl(dest) |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1320 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
|
1321 if revs: |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1322 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
|
1323 other = hg.peer(repo, {}, dest) |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1324 n = other.lookup(q) |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1325 if n in repo: |
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1326 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
|
1327 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
|
1328 return baseset([r]) |
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1329 return baseset([]) |
15936
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1330 |
11275 | 1331 def removes(repo, subset, x): |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1332 """``removes(pattern)`` |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1333 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
|
1334 |
96be25f1da45
revset: add explanation about the pattern without explicit kind
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20288
diff
changeset
|
1335 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
|
1336 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
|
1337 directory. |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1338 """ |
12815
079a618ea89d
revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents:
12786
diff
changeset
|
1339 # 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
|
1340 pat = getstring(x, _("removes requires a pattern")) |
11275 | 1341 return checkstatus(repo, subset, pat, 2) |
1342 | |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1343 def rev(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1344 """``rev(number)`` |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1345 Revision with the given numeric identifier. |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1346 """ |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1347 # i18n: "rev" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1348 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
|
1349 try: |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1350 # i18n: "rev" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1351 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
|
1352 except (TypeError, ValueError): |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1353 # i18n: "rev" is a keyword |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1354 raise error.ParseError(_("rev expects a number")) |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1355 return subset.filter(lambda r: r == l) |
11275 | 1356 |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1357 def matching(repo, subset, x): |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1358 """``matching(revision [, field])`` |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1359 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
|
1360 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
|
1361 |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1362 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
|
1363 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
|
1364 |
5d803620ca05
doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16521
diff
changeset
|
1365 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
|
1366 |
5d803620ca05
doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16521
diff
changeset
|
1367 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
|
1368 ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` |
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1369 and ``diff``. |
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1370 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
|
1371 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
|
1372 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
|
1373 |
5d803620ca05
doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16521
diff
changeset
|
1374 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
|
1375 ``summary`` matches the first line of the description. |
16639
00290bd359fe
revset: documentation typo "metatadata"
Jesse Glick <jesse.glick@oracle.com>
parents:
16528
diff
changeset
|
1376 ``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
|
1377 (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
|
1378 |
5d803620ca05
doc: flatten description of 'matching()' predicate to be formatted well
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16521
diff
changeset
|
1379 ``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
|
1380 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
|
1381 """ |
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
|
1382 # i18n: "matching" is a keyword |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1383 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
|
1384 |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1385 revs = getset(repo, baseset(repo.changelog), l[0]) |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1386 |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1387 fieldlist = ['metadata'] |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1388 if len(l) > 1: |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1389 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
|
1390 # i18n: "matching" is a keyword |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1391 _("matching requires a string " |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1392 "as its second argument")).split() |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1393 |
17102
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1394 # 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
|
1395 # expand the 'special' 'metadata' field type |
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1396 # 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
|
1397 fields = [] |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1398 for field in fieldlist: |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1399 if field == 'metadata': |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1400 fields += ['user', 'description', 'date'] |
17102
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1401 elif field == 'diff': |
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1402 # 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
|
1403 # 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
|
1404 # also match the files first |
d9a046ae4d8e
revset: add "diff" field to "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
17100
diff
changeset
|
1405 fields += ['files', 'diff'] |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1406 else: |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1407 if field == 'author': |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1408 field = 'user' |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1409 fields.append(field) |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1410 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
|
1411 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
|
1412 # 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
|
1413 fields.discard('summary') |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1414 |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1415 # 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
|
1416 # 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
|
1417 # 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
|
1418 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
|
1419 '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
|
1420 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
|
1421 try: |
984e0412e82b
revset: speedup matching() by first matching fields that take less time to
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16445
diff
changeset
|
1422 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
|
1423 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
|
1424 # 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
|
1425 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
|
1426 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
|
1427 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
|
1428 |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1429 # 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
|
1430 # 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
|
1431 getfieldfuncs = [] |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1432 _funcs = { |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1433 'user': lambda r: repo[r].user(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1434 'branch': lambda r: repo[r].branch(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1435 'date': lambda r: repo[r].date(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1436 'description': lambda r: repo[r].description(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1437 'files': lambda r: repo[r].files(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1438 'parents': lambda r: repo[r].parents(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1439 'phase': lambda r: repo[r].phase(), |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1440 'substate': lambda r: repo[r].substate, |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1441 '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
|
1442 '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
|
1443 } |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1444 for info in fields: |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1445 getfield = _funcs.get(info, None) |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1446 if getfield is None: |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1447 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
|
1448 # i18n: "matching" is a keyword |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1449 _("unexpected field name passed to matching: %s") % info) |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1450 getfieldfuncs.append(getfield) |
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1451 # 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
|
1452 # 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
|
1453 # 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
|
1454 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
|
1455 |
20459
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1456 def matches(x): |
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1457 for rev in revs: |
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1458 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
|
1459 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
|
1460 for n, f in enumerate(getfieldfuncs): |
20459
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1461 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
|
1462 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
|
1463 if match: |
20459
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1464 return True |
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1465 return False |
51890507c6b3
revset: added lazyset implementation to matching revset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20458
diff
changeset
|
1466 |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1467 return subset.filter(matches) |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1468 |
11275 | 1469 def reverse(repo, subset, x): |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1470 """``reverse(set)`` |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1471 Reverse order of set. |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1472 """ |
11275 | 1473 l = getset(repo, subset, x) |
1474 l.reverse() | |
1475 return l | |
1476 | |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1477 def roots(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1478 """``roots(set)`` |
16394
f3df7d34791e
revset: do not ignore input revisions in roots()
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1479 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
|
1480 """ |
20895
f52e4ca93529
revset: improve roots revset performance
Durham Goode <durham@fb.com>
parents:
20894
diff
changeset
|
1481 s = getset(repo, spanset(repo), x).set() |
f52e4ca93529
revset: improve roots revset performance
Durham Goode <durham@fb.com>
parents:
20894
diff
changeset
|
1482 subset = baseset([r for r in s if r in subset.set()]) |
16394
f3df7d34791e
revset: do not ignore input revisions in roots()
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1483 cs = _children(repo, subset, s) |
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
1484 return subset - cs |
11944
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1485 |
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1486 def secret(repo, subset, x): |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1487 """``secret()`` |
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1488 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
|
1489 # 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
|
1490 getargs(x, 0, 0, _("secret takes no arguments")) |
16657
b6081c2c4647
phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents:
16647
diff
changeset
|
1491 pc = repo._phasecache |
20611
6490f8385391
revset: changed revset code to use filter method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20610
diff
changeset
|
1492 return subset.filter(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
|
1493 |
11275 | 1494 def sort(repo, subset, x): |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1495 """``sort(set[, [-]key...])`` |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1496 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
|
1497 as ``-key`` to sort in descending order. |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1498 |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1499 The keys can be: |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1500 |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1501 - ``rev`` for the revision number, |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1502 - ``branch`` for the branch name, |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1503 - ``desc`` for the commit message (description), |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1504 - ``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
|
1505 - ``date`` for the commit date |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1506 """ |
12815
079a618ea89d
revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents:
12786
diff
changeset
|
1507 # 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
|
1508 l = getargs(x, 1, 2, _("sort requires one or two arguments")) |
11275 | 1509 keys = "rev" |
1510 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
|
1511 # i18n: "sort" is a keyword |
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
1512 keys = getstring(l[1], _("sort spec must be a string")) |
11275 | 1513 |
1514 s = l[0] | |
1515 keys = keys.split() | |
1516 l = [] | |
1517 def invert(s): | |
1518 return "".join(chr(255 - ord(c)) for c in s) | |
20719
cce8fbedc82a
revset: changed sort method to use native sort implementation of smartsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20718
diff
changeset
|
1519 revs = getset(repo, subset, s) |
cce8fbedc82a
revset: changed sort method to use native sort implementation of smartsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20718
diff
changeset
|
1520 if keys == ["rev"]: |
cce8fbedc82a
revset: changed sort method to use native sort implementation of smartsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20718
diff
changeset
|
1521 revs.sort() |
cce8fbedc82a
revset: changed sort method to use native sort implementation of smartsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20718
diff
changeset
|
1522 return revs |
cce8fbedc82a
revset: changed sort method to use native sort implementation of smartsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20718
diff
changeset
|
1523 elif keys == ["-rev"]: |
cce8fbedc82a
revset: changed sort method to use native sort implementation of smartsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20718
diff
changeset
|
1524 revs.sort(reverse=True) |
cce8fbedc82a
revset: changed sort method to use native sort implementation of smartsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20718
diff
changeset
|
1525 return revs |
cce8fbedc82a
revset: changed sort method to use native sort implementation of smartsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20718
diff
changeset
|
1526 for r in revs: |
11275 | 1527 c = repo[r] |
1528 e = [] | |
1529 for k in keys: | |
1530 if k == 'rev': | |
1531 e.append(r) | |
1532 elif k == '-rev': | |
1533 e.append(-r) | |
1534 elif k == 'branch': | |
1535 e.append(c.branch()) | |
1536 elif k == '-branch': | |
1537 e.append(invert(c.branch())) | |
1538 elif k == 'desc': | |
1539 e.append(c.description()) | |
1540 elif k == '-desc': | |
1541 e.append(invert(c.description())) | |
1542 elif k in 'user author': | |
1543 e.append(c.user()) | |
1544 elif k in '-user -author': | |
1545 e.append(invert(c.user())) | |
1546 elif k == 'date': | |
1547 e.append(c.date()[0]) | |
1548 elif k == '-date': | |
1549 e.append(-c.date()[0]) | |
1550 else: | |
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
1551 raise error.ParseError(_("unknown sort key %r") % k) |
11275 | 1552 e.append(r) |
1553 l.append(e) | |
1554 l.sort() | |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1555 return baseset([e[-1] for e in l]) |
11275 | 1556 |
16819
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1557 def _stringmatcher(pattern): |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1558 """ |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1559 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
|
1560 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
|
1561 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
|
1562 |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1563 helper for tests: |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1564 >>> def test(pattern, *tests): |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1565 ... 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
|
1566 ... 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
|
1567 |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1568 exact matching (no prefix): |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1569 >>> 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
|
1570 ('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
|
1571 |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1572 regex matching ('re:' prefix) |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1573 >>> 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
|
1574 ('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
|
1575 |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1576 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
|
1577 >>> 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
|
1578 ('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
|
1579 |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1580 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
|
1581 >>> 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
|
1582 ('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
|
1583 """ |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1584 if pattern.startswith('re:'): |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1585 pattern = pattern[3:] |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1586 try: |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1587 regex = re.compile(pattern) |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1588 except re.error, e: |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1589 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
|
1590 % e) |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1591 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
|
1592 elif pattern.startswith('literal:'): |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1593 pattern = pattern[8:] |
5260a9e93113
revset: add helper function for matching strings to patterns
Simon King <simon@simonking.org.uk>
parents:
16803
diff
changeset
|
1594 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
|
1595 |
16823
b23bacb230c9
revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents:
16822
diff
changeset
|
1596 def _substringmatcher(pattern): |
b23bacb230c9
revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents:
16822
diff
changeset
|
1597 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
|
1598 if kind == 'literal': |
b23bacb230c9
revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents:
16822
diff
changeset
|
1599 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
|
1600 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
|
1601 |
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
|
1602 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
|
1603 """``tag([name])`` |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1604 The specified tag by name, or all tagged revisions if no name is given. |
20824
c57c9cece645
revset: document the regular expression support for tag(name)
Matt Harbison <matt_harbison@yahoo.com>
parents:
20289
diff
changeset
|
1605 |
c57c9cece645
revset: document the regular expression support for tag(name)
Matt Harbison <matt_harbison@yahoo.com>
parents:
20289
diff
changeset
|
1606 If `name` starts with `re:`, the remainder of the name is treated as |
c57c9cece645
revset: document the regular expression support for tag(name)
Matt Harbison <matt_harbison@yahoo.com>
parents:
20289
diff
changeset
|
1607 a regular expression. To match a tag that actually starts with `re:`, |
c57c9cece645
revset: document the regular expression support for tag(name)
Matt Harbison <matt_harbison@yahoo.com>
parents:
20289
diff
changeset
|
1608 use the prefix `literal:`. |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1609 """ |
12815
079a618ea89d
revset: add translator comments to i18n strings
Martin Geisler <mg@lazybytes.net>
parents:
12786
diff
changeset
|
1610 # 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
|
1611 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
|
1612 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
|
1613 if args: |
16820
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1614 pattern = getstring(args[0], |
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1615 # i18n: "tag" is a keyword |
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1616 _('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
|
1617 kind, pattern, matcher = _stringmatcher(pattern) |
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1618 if kind == 'literal': |
16825
b6ef1395d77f
revset: avoid validating all tag nodes for tag(x)
Matt Mackall <mpm@selenic.com>
parents:
16824
diff
changeset
|
1619 # avoid resolving all tags |
b6ef1395d77f
revset: avoid validating all tag nodes for tag(x)
Matt Mackall <mpm@selenic.com>
parents:
16824
diff
changeset
|
1620 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
|
1621 if tn is None: |
16820
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1622 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
|
1623 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
|
1624 else: |
20f55613fb2a
revset: add pattern matching to 'tag' revset expression
Simon King <simon@simonking.org.uk>
parents:
16819
diff
changeset
|
1625 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
|
1626 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
|
1627 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
|
1628 return subset & s |
11280
a5eb0bf7e158
revset: add tagged predicate
Matt Mackall <mpm@selenic.com>
parents:
11279
diff
changeset
|
1629 |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1630 def tagged(repo, subset, x): |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1631 return tag(repo, subset, x) |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1632 |
17171
9c750c3e4fac
obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17170
diff
changeset
|
1633 def unstable(repo, subset, x): |
9c750c3e4fac
obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17170
diff
changeset
|
1634 """``unstable()`` |
17291
2d6bbf87f7b4
revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents:
17272
diff
changeset
|
1635 Non-obsolete changesets with obsolete ancestors. |
2d6bbf87f7b4
revset: minor doc fixes on obsolete related revsets
Patrick Mezard <patrick@mezard.eu>
parents:
17272
diff
changeset
|
1636 """ |
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
|
1637 # 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
|
1638 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
|
1639 unstables = obsmod.getrevs(repo, 'unstable') |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
1640 return subset & unstables |
17171
9c750c3e4fac
obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17170
diff
changeset
|
1641 |
9c750c3e4fac
obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17170
diff
changeset
|
1642 |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1643 def user(repo, subset, x): |
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1644 """``user(string)`` |
14357 | 1645 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
|
1646 |
b23bacb230c9
revset: add pattern matching to the 'user' revset expression
Simon King <simon@simonking.org.uk>
parents:
16822
diff
changeset
|
1647 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
|
1648 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
|
1649 the prefix `literal:`. |
13359
87f248e78173
bookmarks: move revset support to core
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
1650 """ |
13915
8f81d6f4047f
revset: rearrange code so functions are sorted alphabetically
Idan Kamara <idankk86@gmail.com>
parents:
13914
diff
changeset
|
1651 return author(repo, subset, x) |
13359
87f248e78173
bookmarks: move revset support to core
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
1652 |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1653 # for internal use |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1654 def _list(repo, subset, x): |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1655 s = getstring(x, "internal error") |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1656 if not s: |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
1657 return baseset([]) |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1658 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
|
1659 s = subset.set() |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
1660 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
|
1661 |
20566
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1662 # for internal use |
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1663 def _intlist(repo, subset, x): |
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1664 s = getstring(x, "internal error") |
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1665 if not s: |
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1666 return baseset([]) |
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1667 ls = [int(r) for r in s.split('\0')] |
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1668 s = subset.set() |
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1669 return baseset([r for r in ls if r in s]) |
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1670 |
20569
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1671 # for internal use |
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1672 def _hexlist(repo, subset, x): |
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1673 s = getstring(x, "internal error") |
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1674 if not s: |
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1675 return baseset([]) |
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1676 cl = repo.changelog |
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1677 ls = [cl.rev(node.bin(r)) for r in s.split('\0')] |
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1678 s = subset.set() |
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1679 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
|
1680 |
11275 | 1681 symbols = { |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1682 "adds": adds, |
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1683 "all": getall, |
11275 | 1684 "ancestor": ancestor, |
1685 "ancestors": ancestors, | |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
1686 "_firstancestors": _firstancestors, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1687 "author": author, |
20613 | 1688 "only": only, |
15134
81adf7777f8f
revset: rename bisected() to bisect()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents:
15133
diff
changeset
|
1689 "bisect": bisect, |
13602
54b198fe9768
revset: add a revset command to get bisect state.
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13593
diff
changeset
|
1690 "bisected": bisected, |
13359
87f248e78173
bookmarks: move revset support to core
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
1691 "bookmark": bookmark, |
11275 | 1692 "branch": branch, |
17753
69d5078d760d
revsets: add branchpoint() function
Ivan Andrus <darthandrus@gmail.com>
parents:
17675
diff
changeset
|
1693 "branchpoint": branchpoint, |
17829
c73f7a28953c
revset: add a bumped revset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17825
diff
changeset
|
1694 "bumped": bumped, |
17913
03e552aaae67
bundle: add revset expression to show bundle contents (issue3487)
Tomasz Kleczek <tkleczek@fb.com>
parents:
17886
diff
changeset
|
1695 "bundle": bundle, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1696 "children": children, |
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1697 "closed": closed, |
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1698 "contains": contains, |
17002
0eb522625eb2
revset: add a predicate for finding converted changesets
Matt Harbison <matt_harbison@yahoo.com>
parents:
16862
diff
changeset
|
1699 "converted": converted, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1700 "date": date, |
14650
93731b3efd0d
revset: add desc(string) to search in commit messages
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14649
diff
changeset
|
1701 "desc": desc, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1702 "descendants": descendants, |
16409
2cbd7dd0cc1f
graphlog: fix --follow-first --rev combinations
Patrick Mezard <patrick@mezard.eu>
parents:
16402
diff
changeset
|
1703 "_firstdescendants": _firstdescendants, |
17186
a3da6f298592
revset: add destination() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17185
diff
changeset
|
1704 "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
|
1705 "divergent": divergent, |
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1706 "draft": draft, |
17173
c621f84dbb35
obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17171
diff
changeset
|
1707 "extinct": extinct, |
16661
de4b42daf396
revset: add function for matching extra data (issue2767)
Henrik Stuart <hg@hstuart.dk>
parents:
16657
diff
changeset
|
1708 "extra": extra, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1709 "file": hasfile, |
14342
c0b6a734b4f3
revset: introduce filelog() to emulate log's fast path
Matt Mackall <mpm@selenic.com>
parents:
14318
diff
changeset
|
1710 "filelog": filelog, |
15117
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
1711 "first": first, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1712 "follow": follow, |
16174
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
1713 "_followfirst": _followfirst, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1714 "grep": grep, |
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1715 "head": head, |
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1716 "heads": heads, |
17390
74b44f25b4b1
revset: add hidden() revset
Patrick Mezard <patrick@mezard.eu>
parents:
17291
diff
changeset
|
1717 "hidden": hidden, |
16417
b4b0c6931e11
revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents:
16415
diff
changeset
|
1718 "id": node_, |
11275 | 1719 "keyword": keyword, |
14061
611d2f8a4ba2
revsets: add a last function
Matt Mackall <mpm@selenic.com>
parents:
14057
diff
changeset
|
1720 "last": last, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1721 "limit": limit, |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16096
diff
changeset
|
1722 "_matchfiles": _matchfiles, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1723 "max": maxrev, |
14649
a6a8809c6e33
revset: update sorting of symbols
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14556
diff
changeset
|
1724 "merge": merge, |
11708
ba65d61f3158
revset: add min function
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11650
diff
changeset
|
1725 "min": minrev, |
20498
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1726 "_missingancestors": _missingancestors, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1727 "modifies": modifies, |
17170
63a4a3871607
revset: add an `obsolete` symbol
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17102
diff
changeset
|
1728 "obsolete": obsolete, |
17185
2c7c4824969e
revset: add origin() predicate
Matt Harbison <matt_harbison@yahoo.com>
parents:
17173
diff
changeset
|
1729 "origin": origin, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1730 "outgoing": outgoing, |
11275 | 1731 "p1": p1, |
1732 "p2": p2, | |
1733 "parents": parents, | |
11944
df52ff0980fe
revset: predicate to avoid lookup errors
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11886
diff
changeset
|
1734 "present": present, |
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1735 "public": public, |
15936
878bc4a62a73
revset: add remote() predicate to lookup remote revisions
Matt Mackall <mpm@selenic.com>
parents:
15903
diff
changeset
|
1736 "remote": remote, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1737 "removes": removes, |
14649
a6a8809c6e33
revset: update sorting of symbols
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14556
diff
changeset
|
1738 "rev": rev, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1739 "reverse": reverse, |
11275 | 1740 "roots": roots, |
11284
0b5c2e82aeb5
revset: sort the predicate list
Matt Mackall <mpm@selenic.com>
parents:
11283
diff
changeset
|
1741 "sort": sort, |
15819
33ca11b010e2
phases: implements simple revset symbol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15791
diff
changeset
|
1742 "secret": secret, |
16402
1fb2f1400ea8
revset: add "matching" keyword
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16218
diff
changeset
|
1743 "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
|
1744 "tag": tag, |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1745 "tagged": tagged, |
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
1746 "user": user, |
17171
9c750c3e4fac
obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17170
diff
changeset
|
1747 "unstable": unstable, |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
1748 "_list": _list, |
20566
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1749 "_intlist": _intlist, |
20569
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1750 "_hexlist": _hexlist, |
11275 | 1751 } |
1752 | |
19721
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1753 # 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
|
1754 # (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
|
1755 # 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
|
1756 safesymbols = set([ |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1757 "adds", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1758 "all", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1759 "ancestor", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1760 "ancestors", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1761 "_firstancestors", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1762 "author", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1763 "bisect", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1764 "bisected", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1765 "bookmark", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1766 "branch", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1767 "branchpoint", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1768 "bumped", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1769 "bundle", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1770 "children", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1771 "closed", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1772 "converted", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1773 "date", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1774 "desc", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1775 "descendants", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1776 "_firstdescendants", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1777 "destination", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1778 "divergent", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1779 "draft", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1780 "extinct", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1781 "extra", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1782 "file", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1783 "filelog", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1784 "first", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1785 "follow", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1786 "_followfirst", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1787 "head", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1788 "heads", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1789 "hidden", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1790 "id", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1791 "keyword", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1792 "last", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1793 "limit", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1794 "_matchfiles", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1795 "max", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1796 "merge", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1797 "min", |
20498
fb2df4506c87
revset: add an undocumented _missingancestors function
Siddharth Agarwal <sid0@fb.com>
parents:
20484
diff
changeset
|
1798 "_missingancestors", |
19721
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1799 "modifies", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1800 "obsolete", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1801 "origin", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1802 "outgoing", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1803 "p1", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1804 "p2", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1805 "parents", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1806 "present", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1807 "public", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1808 "remote", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1809 "removes", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1810 "rev", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1811 "reverse", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1812 "roots", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1813 "sort", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1814 "secret", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1815 "matching", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1816 "tag", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1817 "tagged", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1818 "user", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1819 "unstable", |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1820 "_list", |
20566
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
1821 "_intlist", |
20569
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
1822 "_hexlist", |
19721
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1823 ]) |
d8ca6d965230
revset: add a whitelist of DoS-safe symbols
Alexander Plavin <alexander@plav.in>
parents:
19720
diff
changeset
|
1824 |
11275 | 1825 methods = { |
1826 "range": rangeset, | |
16860
e1aa1ed30030
revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents:
16859
diff
changeset
|
1827 "dagrange": dagrange, |
11275 | 1828 "string": stringset, |
1829 "symbol": symbolset, | |
1830 "and": andset, | |
1831 "or": orset, | |
1832 "not": notset, | |
1833 "list": listset, | |
1834 "func": func, | |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1835 "ancestor": ancestorspec, |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1836 "parent": parentspec, |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1837 "parentpost": p1, |
11275 | 1838 } |
1839 | |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1840 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
|
1841 if x is None: |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1842 return 0, x |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1843 |
11275 | 1844 smallbonus = 1 |
1845 if small: | |
1846 smallbonus = .5 | |
1847 | |
1848 op = x[0] | |
11283
a6356b2695a3
revset: fix - handling in the optimizer
Matt Mackall <mpm@selenic.com>
parents:
11282
diff
changeset
|
1849 if op == 'minus': |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1850 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
|
1851 elif op == 'dagrangepre': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1852 return optimize(('func', ('symbol', 'ancestors'), x[1]), small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1853 elif op == 'dagrangepost': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1854 return optimize(('func', ('symbol', 'descendants'), x[1]), small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1855 elif op == 'rangepre': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1856 return optimize(('range', ('string', '0'), x[1]), small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1857 elif op == 'rangepost': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1858 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
|
1859 elif op == 'negate': |
6b836d5c8c9e
revset: make negate work for sort specs
Matt Mackall <mpm@selenic.com>
parents:
11456
diff
changeset
|
1860 return optimize(('string', |
6b836d5c8c9e
revset: make negate work for sort specs
Matt Mackall <mpm@selenic.com>
parents:
11456
diff
changeset
|
1861 '-' + 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
|
1862 elif op in 'string symbol negate': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1863 return smallbonus, x # single revisions are small |
16859
eeb464ed7275
revset: drop unreachable code
Bryan O'Sullivan <bryano@fb.com>
parents:
16838
diff
changeset
|
1864 elif op == 'and': |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1865 wa, ta = optimize(x[1], True) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1866 wb, tb = optimize(x[2], True) |
20499
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1867 |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1868 # (::x and not ::y)/(not ::y and ::x) have a fast path |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1869 def ismissingancestors(revs, bases): |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1870 return ( |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1871 revs[0] == 'func' |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1872 and getstring(revs[1], _('not a symbol')) == 'ancestors' |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1873 and bases[0] == 'not' |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1874 and bases[1][0] == 'func' |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1875 and getstring(bases[1][1], _('not a symbol')) == 'ancestors') |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1876 |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1877 w = min(wa, wb) |
20499
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1878 if ismissingancestors(ta, tb): |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1879 return w, ('func', ('symbol', '_missingancestors'), |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1880 ('list', ta[2], tb[1][2])) |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1881 if ismissingancestors(tb, ta): |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1882 return w, ('func', ('symbol', '_missingancestors'), |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1883 ('list', tb[2], ta[1][2])) |
2efd608473fb
revset: optimize missing ancestor expressions
Siddharth Agarwal <sid0@fb.com>
parents:
20498
diff
changeset
|
1884 |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1885 if wa > wb: |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1886 return w, (op, tb, ta) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1887 return w, (op, ta, tb) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1888 elif op == 'or': |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1889 wa, ta = optimize(x[1], False) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1890 wb, tb = optimize(x[2], False) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1891 if wb < wa: |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1892 wb, wa = wa, wb |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1893 return max(wa, wb), (op, ta, tb) |
11275 | 1894 elif op == 'not': |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1895 o = optimize(x[1], not small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1896 return o[0], (op, o[1]) |
14070
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1897 elif op == 'parentpost': |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1898 o = optimize(x[1], small) |
305c97670d7a
revset: add ^ and ~ operators from parentrevspec extension
Kevin Gessner <kevin@kevingessner.com>
parents:
14061
diff
changeset
|
1899 return o[0], (op, o[1]) |
11275 | 1900 elif op == 'group': |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1901 return optimize(x[1], small) |
16860
e1aa1ed30030
revset: turn dagrange into a function
Bryan O'Sullivan <bryano@fb.com>
parents:
16859
diff
changeset
|
1902 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
|
1903 if op == 'parent': |
805651777188
revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents:
14723
diff
changeset
|
1904 # 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
|
1905 post = ('parentpost', x[1]) |
805651777188
revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents:
14723
diff
changeset
|
1906 if x[2][0] == 'dagrangepre': |
805651777188
revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents:
14723
diff
changeset
|
1907 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
|
1908 elif x[2][0] == 'rangepre': |
805651777188
revsets: do the right thing with x^:y (issue2884)
Matt Mackall <mpm@selenic.com>
parents:
14723
diff
changeset
|
1909 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
|
1910 |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1911 wa, ta = optimize(x[1], small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1912 wb, tb = optimize(x[2], small) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1913 return wa + wb, (op, ta, tb) |
11275 | 1914 elif op == 'func': |
11383
de544774ebea
revset: all your error messages are belong to _
Martin Geisler <mg@lazybytes.net>
parents:
11349
diff
changeset
|
1915 f = getstring(x[1], _("not a symbol")) |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1916 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
|
1917 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
|
1918 "outgoing user"): |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1919 w = 10 # slow |
12351
b913232d13c1
revsets: reduce cost of outgoing in the optimizer
Matt Mackall <mpm@selenic.com>
parents:
12321
diff
changeset
|
1920 elif f in "modifies adds removes": |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1921 w = 30 # slower |
11275 | 1922 elif f == "contains": |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1923 w = 100 # very slow |
11275 | 1924 elif f == "ancestor": |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1925 w = 1 * smallbonus |
15117
0ab1c3a1f3b2
revsets: add first alias for last
Matt Mackall <mpm@selenic.com>
parents:
15116
diff
changeset
|
1926 elif f in "reverse limit first": |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1927 w = 0 |
11275 | 1928 elif f in "sort": |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1929 w = 10 # assume most sorts look at changelog |
11275 | 1930 else: |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1931 w = 1 |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1932 return w + wa, (op, x[1], ta) |
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
1933 return 1, x |
11275 | 1934 |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1935 _aliasarg = ('func', ('symbol', '_aliasarg')) |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1936 def _getaliasarg(tree): |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1937 """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
|
1938 return X, None otherwise. |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1939 """ |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1940 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
|
1941 and tree[2][0] == 'string'): |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1942 return tree[2][1] |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1943 return None |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1944 |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1945 def _checkaliasarg(tree, known=None): |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1946 """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
|
1947 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
|
1948 """ |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1949 if isinstance(tree, tuple): |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1950 arg = _getaliasarg(tree) |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1951 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
|
1952 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
|
1953 for t in tree: |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1954 _checkaliasarg(t, known) |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1955 |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1956 class revsetalias(object): |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1957 funcre = re.compile('^([^(]+)\(([^)]+)\)$') |
14723
b9faf94ee196
revset: fix aliases with 0 or more than 2 parameters
Mads Kiilerich <mads@kiilerich.com>
parents:
14717
diff
changeset
|
1958 args = None |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1959 |
14723
b9faf94ee196
revset: fix aliases with 0 or more than 2 parameters
Mads Kiilerich <mads@kiilerich.com>
parents:
14717
diff
changeset
|
1960 def __init__(self, name, value): |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1961 '''Aliases like: |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1962 |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1963 h = heads(default) |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1964 b($1) = ancestors($1) - ancestors(default) |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1965 ''' |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1966 m = self.funcre.search(name) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1967 if m: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1968 self.name = m.group(1) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1969 self.tree = ('func', ('symbol', m.group(1))) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1970 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
|
1971 for arg in self.args: |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1972 # _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
|
1973 # alias argument placeholders from regular strings. |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1974 value = value.replace(arg, '_aliasarg(%r)' % (arg,)) |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1975 else: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1976 self.name = name |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1977 self.tree = ('symbol', name) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1978 |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1979 self.replacement, pos = parse(value) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1980 if pos != len(value): |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1981 raise error.ParseError(_('invalid token'), pos) |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1982 # Check for placeholder injection |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
1983 _checkaliasarg(self.replacement, self.args) |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
1984 |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1985 def _getalias(aliases, tree): |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1986 """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
|
1987 otherwise. |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1988 """ |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1989 if isinstance(tree, tuple) and tree: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1990 if tree[0] == 'symbol' and len(tree) == 2: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1991 name = tree[1] |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1992 alias = aliases.get(name) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1993 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
|
1994 return alias |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1995 if tree[0] == 'func' and len(tree) > 1: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1996 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
|
1997 name = tree[1][1] |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1998 alias = aliases.get(name) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
1999 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
|
2000 return alias |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2001 return None |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
2002 |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2003 def _expandargs(tree, args): |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
2004 """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
|
2005 same name in args, recursively. |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2006 """ |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
2007 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
|
2008 return tree |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
2009 arg = _getaliasarg(tree) |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
2010 if arg is not None: |
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
2011 return args[arg] |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2012 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
|
2013 |
16838
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
2014 def _expandaliases(aliases, tree, expanding, cache): |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2015 """Expand aliases in tree, recursively. |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2016 |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2017 '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
|
2018 revsetalias objects. |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2019 """ |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2020 if not isinstance(tree, tuple): |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2021 # Do not expand raw strings |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
2022 return tree |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2023 alias = _getalias(aliases, tree) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2024 if alias is not None: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2025 if alias in expanding: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2026 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
|
2027 'detected') % alias.name) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2028 expanding.append(alias) |
16838
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
2029 if alias.name not in cache: |
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
2030 cache[alias.name] = _expandaliases(aliases, alias.replacement, |
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
2031 expanding, cache) |
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
2032 result = cache[alias.name] |
16772
30e46d7138de
revset: fix infinite alias expansion detection
Patrick Mezard <patrick@mezard.eu>
parents:
16771
diff
changeset
|
2033 expanding.pop() |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2034 if alias.args is not None: |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2035 l = getlist(tree[2]) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2036 if len(l) != len(alias.args): |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2037 raise error.ParseError( |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2038 _('invalid number of arguments: %s') % len(l)) |
16838
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
2039 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
|
2040 result = _expandargs(result, dict(zip(alias.args, l))) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2041 else: |
16838
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
2042 result = tuple(_expandaliases(aliases, t, expanding, cache) |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2043 for t in tree) |
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2044 return result |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
2045 |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
2046 def findaliases(ui, tree): |
16771
2f3317d53d51
revset: explicitely tag alias arguments for expansion
Patrick Mezard <patrick@mezard.eu>
parents:
16748
diff
changeset
|
2047 _checkaliasarg(tree) |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2048 aliases = {} |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
2049 for k, v in ui.configitems('revsetalias'): |
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
2050 alias = revsetalias(k, v) |
16096
b8be450638f6
revset: fix alias substitution recursion (issue3240)
Patrick Mezard <patrick@mezard.eu>
parents:
16007
diff
changeset
|
2051 aliases[alias.name] = alias |
16838
d37d221334be
revset: cache alias expansions
Patrick Mezard <patrick@mezard.eu>
parents:
16834
diff
changeset
|
2052 return _expandaliases(aliases, tree, [], {}) |
14098
9f5a0acb0056
revset aliases
Alexander Solovyov <alexander@solovyov.net>
parents:
14073
diff
changeset
|
2053 |
20779
ffc2295c6b80
revset: pass a lookup function to the tokenizer
Matt Mackall <mpm@selenic.com>
parents:
20754
diff
changeset
|
2054 def parse(spec, lookup=None): |
20208
61a47fd64f30
fileset, revset: do not use global parser object for thread safety
Yuya Nishihara <yuya@tcha.org>
parents:
19721
diff
changeset
|
2055 p = parser.parser(tokenize, elements) |
20779
ffc2295c6b80
revset: pass a lookup function to the tokenizer
Matt Mackall <mpm@selenic.com>
parents:
20754
diff
changeset
|
2056 return p.parse(spec, lookup=lookup) |
ffc2295c6b80
revset: pass a lookup function to the tokenizer
Matt Mackall <mpm@selenic.com>
parents:
20754
diff
changeset
|
2057 |
ffc2295c6b80
revset: pass a lookup function to the tokenizer
Matt Mackall <mpm@selenic.com>
parents:
20754
diff
changeset
|
2058 def match(ui, spec, repo=None): |
11385
e5a2134c083b
revset: nicer exception for empty queries
Matt Mackall <mpm@selenic.com>
parents:
11383
diff
changeset
|
2059 if not spec: |
e5a2134c083b
revset: nicer exception for empty queries
Matt Mackall <mpm@selenic.com>
parents:
11383
diff
changeset
|
2060 raise error.ParseError(_("empty query")) |
20779
ffc2295c6b80
revset: pass a lookup function to the tokenizer
Matt Mackall <mpm@selenic.com>
parents:
20754
diff
changeset
|
2061 lookup = None |
ffc2295c6b80
revset: pass a lookup function to the tokenizer
Matt Mackall <mpm@selenic.com>
parents:
20754
diff
changeset
|
2062 if repo: |
ffc2295c6b80
revset: pass a lookup function to the tokenizer
Matt Mackall <mpm@selenic.com>
parents:
20754
diff
changeset
|
2063 lookup = repo.__contains__ |
ffc2295c6b80
revset: pass a lookup function to the tokenizer
Matt Mackall <mpm@selenic.com>
parents:
20754
diff
changeset
|
2064 tree, pos = parse(spec, lookup) |
14496
ffcb7e4d719f
revset: report a parse error if a revset is not parsed completely (issue2654)
Bernhard Leiner <bleiner@gmail.com>
parents:
14356
diff
changeset
|
2065 if (pos != len(spec)): |
14701
4b93bd041772
parsers: fix localization markup of parser errors
Mads Kiilerich <mads@kiilerich.com>
parents:
14650
diff
changeset
|
2066 raise error.ParseError(_("invalid token"), pos) |
14900
fc3d6f300d7d
revset: allow bypassing alias expansion
Matt Mackall <mpm@selenic.com>
parents:
14851
diff
changeset
|
2067 if ui: |
fc3d6f300d7d
revset: allow bypassing alias expansion
Matt Mackall <mpm@selenic.com>
parents:
14851
diff
changeset
|
2068 tree = findaliases(ui, tree) |
11279
62ccf4cd6e7f
revset: optimize the parse tree directly
Matt Mackall <mpm@selenic.com>
parents:
11278
diff
changeset
|
2069 weight, tree = optimize(tree, True) |
11275 | 2070 def mfunc(repo, subset): |
20527
bde426f18e0a
revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20526
diff
changeset
|
2071 if util.safehasattr(subset, 'set'): |
bde426f18e0a
revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20526
diff
changeset
|
2072 return getset(repo, subset, tree) |
bde426f18e0a
revset: changed mfunc and getset to work with old style revset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20526
diff
changeset
|
2073 return getset(repo, baseset(subset), tree) |
11275 | 2074 return mfunc |
12821
165079e564f0
revsets: generate predicate help dynamically
Patrick Mezard <pmezard@gmail.com>
parents:
12815
diff
changeset
|
2075 |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2076 def formatspec(expr, *args): |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2077 ''' |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2078 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
|
2079 escapes arguments appropriately. Aliases are intentionally ignored |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2080 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
|
2081 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2082 Supported arguments: |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2083 |
15266
8bea39ca9acb
revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents:
15153
diff
changeset
|
2084 %r = revset expression, parenthesized |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2085 %d = int(arg), no quoting |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2086 %s = string(arg), escaped and single-quoted |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2087 %b = arg.branch(), escaped and single-quoted |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2088 %n = hex(arg), single-quoted |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2089 %% = a literal '%' |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2090 |
15266
8bea39ca9acb
revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents:
15153
diff
changeset
|
2091 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
|
2092 |
15268
bd5103819c2e
revset: fix %r handling in formatspec
Matt Mackall <mpm@selenic.com>
parents:
15266
diff
changeset
|
2093 >>> 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
|
2094 '(10 or 11):: and ((this()) or (that()))' |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2095 >>> formatspec('%d:: and not %d::', 10, 20) |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2096 '10:: and not 20::' |
15325
cdf1daa3b83f
revset: deal with empty lists in formatspec
Matt Mackall <mpm@selenic.com>
parents:
15268
diff
changeset
|
2097 >>> formatspec('%ld or %ld', [], [1]) |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
2098 "_list('') or 1" |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2099 >>> formatspec('keyword(%s)', 'foo\\xe9') |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2100 "keyword('foo\\\\xe9')" |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2101 >>> b = lambda: 'default' |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2102 >>> b.branch = b |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2103 >>> formatspec('branch(%b)', b) |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2104 "branch('default')" |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2105 >>> 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
|
2106 "root(_list('a\\x00b\\x00c\\x00d'))" |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2107 ''' |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2108 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2109 def quote(s): |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2110 return repr(str(s)) |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2111 |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2112 def argtype(c, arg): |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2113 if c == 'd': |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2114 return str(int(arg)) |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2115 elif c == 's': |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2116 return quote(arg) |
15266
8bea39ca9acb
revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents:
15153
diff
changeset
|
2117 elif c == 'r': |
8bea39ca9acb
revset: add %r for embedded revset support to formatspec
Matt Mackall <mpm@selenic.com>
parents:
15153
diff
changeset
|
2118 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
|
2119 return '(%s)' % arg |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2120 elif c == 'n': |
16417
b4b0c6931e11
revset: avoid demandimport bug
Matt Mackall <mpm@selenic.com>
parents:
16415
diff
changeset
|
2121 return quote(node.hex(arg)) |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2122 elif c == 'b': |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2123 return quote(arg.branch()) |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2124 |
15595
a585d78e7b2f
revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents:
15532
diff
changeset
|
2125 def listexp(s, t): |
a585d78e7b2f
revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents:
15532
diff
changeset
|
2126 l = len(s) |
a585d78e7b2f
revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents:
15532
diff
changeset
|
2127 if l == 0: |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
2128 return "_list('')" |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
2129 elif l == 1: |
15595
a585d78e7b2f
revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents:
15532
diff
changeset
|
2130 return argtype(t, s[0]) |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
2131 elif t == 'd': |
20566
98024950ade0
revset: added _intlist method to replace _list for %ld
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20552
diff
changeset
|
2132 return "_intlist('%s')" % "\0".join(str(int(a)) for a in s) |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
2133 elif t == 's': |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
2134 return "_list('%s')" % "\0".join(s) |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
2135 elif t == 'n': |
20569
0d4be103c734
revset: added _hexlist method to replace _list for %ln
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20566
diff
changeset
|
2136 return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s) |
15898
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
2137 elif t == 'b': |
6902e13ddd03
revset: optimize building large lists in formatrevspec
Matt Mackall <mpm@selenic.com>
parents:
15837
diff
changeset
|
2138 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
|
2139 |
15791
a814f8fcc65a
Use explicit integer division
Martin Geisler <mg@aragost.com>
parents:
15726
diff
changeset
|
2140 m = l // 2 |
15595
a585d78e7b2f
revset: balance %l or-expressions (issue3129)
Matt Mackall <mpm@selenic.com>
parents:
15532
diff
changeset
|
2141 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
|
2142 |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2143 ret = '' |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2144 pos = 0 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2145 arg = 0 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2146 while pos < len(expr): |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2147 c = expr[pos] |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2148 if c == '%': |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2149 pos += 1 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2150 d = expr[pos] |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2151 if d == '%': |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2152 ret += d |
15268
bd5103819c2e
revset: fix %r handling in formatspec
Matt Mackall <mpm@selenic.com>
parents:
15266
diff
changeset
|
2153 elif d in 'dsnbr': |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2154 ret += argtype(d, args[arg]) |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2155 arg += 1 |
15140
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2156 elif d == 'l': |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2157 # a list of some type |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2158 pos += 1 |
353a1ba928f6
revset: add 'l' flag to formatspec for args
Matt Mackall <mpm@selenic.com>
parents:
15138
diff
changeset
|
2159 d = expr[pos] |
15596 | 2160 ret += listexp(list(args[arg]), d) |
14901
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2161 arg += 1 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2162 else: |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2163 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
|
2164 else: |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2165 ret += c |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2166 pos += 1 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2167 |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2168 return ret |
a773119f30ba
revset: add formatspec convenience query builder
Matt Mackall <mpm@selenic.com>
parents:
14900
diff
changeset
|
2169 |
16218
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2170 def prettyformat(tree): |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2171 def _prettyformat(tree, level, lines): |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2172 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
|
2173 lines.append((level, str(tree))) |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2174 else: |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2175 lines.append((level, '(%s' % tree[0])) |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2176 for s in tree[1:]: |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2177 _prettyformat(s, level + 1, lines) |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2178 lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2179 |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2180 lines = [] |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2181 _prettyformat(tree, 0, lines) |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2182 output = '\n'.join((' '*l + s) for l, s in lines) |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2183 return output |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
16185
diff
changeset
|
2184 |
19719
2f9d5c5256ea
revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents:
19706
diff
changeset
|
2185 def depth(tree): |
2f9d5c5256ea
revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents:
19706
diff
changeset
|
2186 if isinstance(tree, tuple): |
2f9d5c5256ea
revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents:
19706
diff
changeset
|
2187 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
|
2188 else: |
2f9d5c5256ea
revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents:
19706
diff
changeset
|
2189 return 0 |
2f9d5c5256ea
revset: add helper function to get revset parse tree depth
Alexander Plavin <alexander@plav.in>
parents:
19706
diff
changeset
|
2190 |
19720
f0b992a9be9c
revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents:
19719
diff
changeset
|
2191 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
|
2192 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
|
2193 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
|
2194 else: |
f0b992a9be9c
revset: add helper function to get functions used in a revset parse tree
Alexander Plavin <alexander@plav.in>
parents:
19719
diff
changeset
|
2195 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
|
2196 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
|
2197 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
|
2198 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
|
2199 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
|
2200 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
|
2201 |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
2202 class baseset(list): |
20416
e72bcc245ecb
revset: added docstring to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20393
diff
changeset
|
2203 """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
|
2204 operation that it should be able to perform. |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2205 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2206 Every method in this class should be implemented by any smartset class. |
20416
e72bcc245ecb
revset: added docstring to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20393
diff
changeset
|
2207 """ |
20752
6744f4621434
revset: add a default argument for baseset.__init__
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20751
diff
changeset
|
2208 def __init__(self, data=()): |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2209 super(baseset, self).__init__(data) |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2210 self._set = None |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2211 |
20657
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2212 def ascending(self): |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2213 """Sorts the set in ascending order (in place). |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2214 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2215 This is part of the mandatory API for smartset.""" |
20657
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2216 self.sort() |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2217 |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2218 def descending(self): |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2219 """Sorts the set in descending order (in place). |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2220 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2221 This is part of the mandatory API for smartset.""" |
20657
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2222 self.sort(reverse=True) |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2223 |
20748
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2224 def min(self): |
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2225 return min(self) |
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2226 |
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2227 def max(self): |
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2228 return max(self) |
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2229 |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2230 def set(self): |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2231 """Returns a set or a smartset containing all the elements. |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2232 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2233 The returned structure should be the fastest option for membership |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2234 testing. |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2235 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2236 This is part of the mandatory API for smartset.""" |
20365
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2237 if not self._set: |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2238 self._set = set(self) |
bc770ee6a351
revset: implemented set caching for revset evaluation
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20364
diff
changeset
|
2239 return self._set |
20364
a6cf48b2880d
revset: added baseset class (still empty) to improve revset performance
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20289
diff
changeset
|
2240 |
20726
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2241 def __sub__(self, other): |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2242 """Returns a new object with the substraction of the two collections. |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2243 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2244 This is part of the mandatory API for smartset.""" |
20726
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2245 if isinstance(other, baseset): |
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2246 s = other.set() |
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
2247 else: |
20726
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2248 s = set(other) |
20366
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
2249 return baseset(self.set() - s) |
5ec6321f49a9
revset: added substraction to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20365
diff
changeset
|
2250 |
20726
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2251 def __and__(self, other): |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2252 """Returns a new object with the intersection of the two collections. |
20367
2ac278aab2b4
revset: added intersection to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20366
diff
changeset
|
2253 |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2254 This is part of the mandatory API for smartset.""" |
20726
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2255 if isinstance(other, baseset): |
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2256 other = other.set() |
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2257 return baseset([y for y in self if y in other]) |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2258 |
20726
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2259 def __add__(self, other): |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2260 """Returns a new object with the union of the two collections. |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2261 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2262 This is part of the mandatory API for smartset.""" |
20417
827561a99569
revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20416
diff
changeset
|
2263 s = self.set() |
20726
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2264 l = [r for r in other if r not in s] |
20417
827561a99569
revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20416
diff
changeset
|
2265 return baseset(list(self) + l) |
827561a99569
revset: added __add__ method to baseset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20416
diff
changeset
|
2266 |
20725
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2267 def isascending(self): |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2268 """Returns True if the collection is ascending order, False if not. |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2269 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2270 This is part of the mandatory API for smartset.""" |
20725
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2271 return False |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2272 |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2273 def isdescending(self): |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2274 """Returns True if the collection is descending order, False if not. |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2275 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2276 This is part of the mandatory API for smartset.""" |
20725
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2277 return False |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2278 |
20726
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2279 def filter(self, condition): |
20727
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2280 """Returns this smartset filtered by condition as a new smartset. |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2281 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2282 `condition` is a callable which takes a revision number and returns a |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2283 boolean. |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2284 |
1e59f760d850
revset: added comments to all methods needed to duck-type from baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20726
diff
changeset
|
2285 This is part of the mandatory API for smartset.""" |
20726
6eb9c4a9a12b
revset: use more explicit argument names for baseset methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20725
diff
changeset
|
2286 return lazyset(self, condition) |
20610
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2287 |
20749
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2288 class _orderedsetmixin(object): |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2289 """Mixin class with utility methods for smartsets |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2290 |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2291 This should be extended by smartsets which have the isascending(), |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2292 isdescending() and reverse() methods""" |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2293 |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2294 def _first(self): |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2295 """return the first revision in the set""" |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2296 for r in self: |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2297 return r |
20863
876c17336b4e
revset: raise ValueError when calling min or max on empty smartset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20845
diff
changeset
|
2298 raise ValueError('arg is an empty sequence') |
20749
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2299 |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2300 def _last(self): |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2301 """return the last revision in the set""" |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2302 self.reverse() |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2303 m = self._first() |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2304 self.reverse() |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2305 return m |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2306 |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2307 def min(self): |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2308 """return the smallest element in the set""" |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2309 if self.isascending(): |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2310 return self._first() |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2311 return self._last() |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2312 |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2313 def max(self): |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2314 """return the largest element in the set""" |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2315 if self.isascending(): |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2316 return self._last() |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2317 return self._first() |
c3e49b127de0
revset: added _orderedsetmixin class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20748
diff
changeset
|
2318 |
20427
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2319 class lazyset(object): |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2320 """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
|
2321 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
|
2322 revset |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2323 """ |
20586
2d52f37937b0
revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20569
diff
changeset
|
2324 def __init__(self, subset, condition=lambda x: True): |
20738
33943add5d65
revset: add some documentation for lazyset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20737
diff
changeset
|
2325 """ |
33943add5d65
revset: add some documentation for lazyset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20737
diff
changeset
|
2326 condition: a function that decide whether a revision in the subset |
33943add5d65
revset: add some documentation for lazyset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20737
diff
changeset
|
2327 belongs to the revset or not. |
33943add5d65
revset: add some documentation for lazyset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20737
diff
changeset
|
2328 """ |
20427
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2329 self._subset = subset |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2330 self._condition = condition |
20512
659b8d8ddf19
revset: added cache to lazysets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20499
diff
changeset
|
2331 self._cache = {} |
20427
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2332 |
20657
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2333 def ascending(self): |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2334 self._subset.sort() |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2335 |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2336 def descending(self): |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2337 self._subset.sort(reverse=True) |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2338 |
20748
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2339 def min(self): |
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2340 return min(self) |
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2341 |
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2342 def max(self): |
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2343 return max(self) |
6b731b29e154
revset: added min and max methods to baseset and lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20739
diff
changeset
|
2344 |
20427
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2345 def __contains__(self, x): |
20512
659b8d8ddf19
revset: added cache to lazysets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20499
diff
changeset
|
2346 c = self._cache |
659b8d8ddf19
revset: added cache to lazysets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20499
diff
changeset
|
2347 if x not in c: |
659b8d8ddf19
revset: added cache to lazysets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20499
diff
changeset
|
2348 c[x] = x in self._subset and self._condition(x) |
659b8d8ddf19
revset: added cache to lazysets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20499
diff
changeset
|
2349 return c[x] |
20427
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2350 |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2351 def __iter__(self): |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2352 cond = self._condition |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2353 for x in self._subset: |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2354 if cond(x): |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2355 yield x |
4a9191ca848e
revset: added lazyset class with basic operations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20424
diff
changeset
|
2356 |
20428
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2357 def __and__(self, x): |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2358 return lazyset(self, lambda r: r in x) |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2359 |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2360 def __sub__(self, x): |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2361 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
|
2362 |
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2363 def __add__(self, x): |
20734
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2364 return _addset(self, x) |
20428
2e33cda452f6
revset: added basic operations to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20427
diff
changeset
|
2365 |
20552
0e99a66eb7bc
revset: added __nonzero__ method to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20540
diff
changeset
|
2366 def __nonzero__(self): |
0e99a66eb7bc
revset: added __nonzero__ method to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20540
diff
changeset
|
2367 for r in self: |
0e99a66eb7bc
revset: added __nonzero__ method to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20540
diff
changeset
|
2368 return True |
0e99a66eb7bc
revset: added __nonzero__ method to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20540
diff
changeset
|
2369 return False |
0e99a66eb7bc
revset: added __nonzero__ method to lazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20540
diff
changeset
|
2370 |
20429
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2371 def __len__(self): |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2372 # 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
|
2373 l = baseset([r for r in self]) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2374 return len(l) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2375 |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2376 def __getitem__(self, x): |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2377 # 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
|
2378 l = baseset([r for r in self]) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2379 return l[x] |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2380 |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2381 def sort(self, reverse=False): |
20714
41e1064486f9
revset: optimized sort method in lazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20713
diff
changeset
|
2382 if not util.safehasattr(self._subset, 'sort'): |
41e1064486f9
revset: optimized sort method in lazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20713
diff
changeset
|
2383 self._subset = baseset(self._subset) |
20429
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2384 self._subset.sort(reverse=reverse) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2385 |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2386 def reverse(self): |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2387 self._subset.reverse() |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2388 |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2389 def set(self): |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2390 return set([r for r in self]) |
f5b560c60bcd
revset: added operations to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20428
diff
changeset
|
2391 |
20725
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2392 def isascending(self): |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2393 return False |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2394 |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2395 def isdescending(self): |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2396 return False |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2397 |
20610
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2398 def filter(self, l): |
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2399 return lazyset(self, l) |
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2400 |
20751
91a3d50f0e3a
revset: changed orderedlazyset to also extend _orderedsetmixin
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20750
diff
changeset
|
2401 class orderedlazyset(_orderedsetmixin, lazyset): |
20609
56ecc82fcd67
revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20587
diff
changeset
|
2402 """Subclass of lazyset which subset can be ordered either ascending or |
56ecc82fcd67
revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20587
diff
changeset
|
2403 descendingly |
56ecc82fcd67
revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20587
diff
changeset
|
2404 """ |
56ecc82fcd67
revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20587
diff
changeset
|
2405 def __init__(self, subset, condition, ascending=True): |
56ecc82fcd67
revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20587
diff
changeset
|
2406 super(orderedlazyset, self).__init__(subset, condition) |
56ecc82fcd67
revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20587
diff
changeset
|
2407 self._ascending = ascending |
56ecc82fcd67
revset: added orderedlazyset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20587
diff
changeset
|
2408 |
20610
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2409 def filter(self, l): |
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2410 return orderedlazyset(self, l, ascending=self._ascending) |
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2411 |
20657
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2412 def ascending(self): |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2413 if not self._ascending: |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2414 self.reverse() |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2415 |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2416 def descending(self): |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2417 if self._ascending: |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2418 self.reverse() |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2419 |
20612
60c308b932eb
revset: added basic operators to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20611
diff
changeset
|
2420 def __and__(self, x): |
60c308b932eb
revset: added basic operators to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20611
diff
changeset
|
2421 return orderedlazyset(self, lambda r: r in x, |
60c308b932eb
revset: added basic operators to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20611
diff
changeset
|
2422 ascending=self._ascending) |
60c308b932eb
revset: added basic operators to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20611
diff
changeset
|
2423 |
60c308b932eb
revset: added basic operators to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20611
diff
changeset
|
2424 def __sub__(self, x): |
60c308b932eb
revset: added basic operators to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20611
diff
changeset
|
2425 return orderedlazyset(self, lambda r: r not in x, |
60c308b932eb
revset: added basic operators to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20611
diff
changeset
|
2426 ascending=self._ascending) |
60c308b932eb
revset: added basic operators to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20611
diff
changeset
|
2427 |
20734
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2428 def __add__(self, x): |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2429 kwargs = {} |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2430 if self.isascending() and x.isascending(): |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2431 kwargs['ascending'] = True |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2432 if self.isdescending() and x.isdescending(): |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2433 kwargs['ascending'] = False |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2434 return _addset(self, x, **kwargs) |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2435 |
20658
d7e96dd8e995
revset: added sort method to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20657
diff
changeset
|
2436 def sort(self, reverse=False): |
d7e96dd8e995
revset: added sort method to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20657
diff
changeset
|
2437 if reverse: |
d7e96dd8e995
revset: added sort method to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20657
diff
changeset
|
2438 if self._ascending: |
d7e96dd8e995
revset: added sort method to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20657
diff
changeset
|
2439 self._subset.sort(reverse=reverse) |
d7e96dd8e995
revset: added sort method to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20657
diff
changeset
|
2440 else: |
d7e96dd8e995
revset: added sort method to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20657
diff
changeset
|
2441 if not self._ascending: |
d7e96dd8e995
revset: added sort method to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20657
diff
changeset
|
2442 self._subset.sort(reverse=reverse) |
d7e96dd8e995
revset: added sort method to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20657
diff
changeset
|
2443 self._ascending = not reverse |
d7e96dd8e995
revset: added sort method to orderedlazyset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20657
diff
changeset
|
2444 |
20725
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2445 def isascending(self): |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2446 return self._ascending |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2447 |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2448 def isdescending(self): |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2449 return not self._ascending |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2450 |
20657
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2451 def reverse(self): |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2452 self._subset.reverse() |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2453 self._ascending = not self._ascending |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2454 |
20753
13c38b1aeebe
revset: changed addset to extend _orderedsetmixin
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20752
diff
changeset
|
2455 class _addset(_orderedsetmixin): |
20708
17c89e5a5627
revset: made addset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20707
diff
changeset
|
2456 """Represent the addition of two sets |
17c89e5a5627
revset: made addset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20707
diff
changeset
|
2457 |
17c89e5a5627
revset: made addset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20707
diff
changeset
|
2458 Wrapper structure for lazily adding two structures without losing much |
20694
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2459 performance on the __contains__ method |
20708
17c89e5a5627
revset: made addset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20707
diff
changeset
|
2460 |
20712
c152e538b85b
revset: added ascending attribute to addset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20711
diff
changeset
|
2461 If the ascending attribute is set, that means the two structures are |
c152e538b85b
revset: added ascending attribute to addset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20711
diff
changeset
|
2462 ordered in either an ascending or descending way. Therefore, we can add |
21024
7731a2281cf0
spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20991
diff
changeset
|
2463 them maintaining the order by iterating over both at the same time |
20712
c152e538b85b
revset: added ascending attribute to addset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20711
diff
changeset
|
2464 |
20708
17c89e5a5627
revset: made addset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20707
diff
changeset
|
2465 This class does not duck-type baseset and it's only supposed to be used |
17c89e5a5627
revset: made addset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20707
diff
changeset
|
2466 internally |
20694
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2467 """ |
20712
c152e538b85b
revset: added ascending attribute to addset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20711
diff
changeset
|
2468 def __init__(self, revs1, revs2, ascending=None): |
20694
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2469 self._r1 = revs1 |
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2470 self._r2 = revs2 |
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2471 self._iter = None |
20712
c152e538b85b
revset: added ascending attribute to addset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20711
diff
changeset
|
2472 self._ascending = ascending |
20720
5f8400efca0b
revset: added cached generated list to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20719
diff
changeset
|
2473 self._genlist = None |
5f8400efca0b
revset: added cached generated list to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20719
diff
changeset
|
2474 |
20845
bc95143446e8
_addset: add a __len__ method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20833
diff
changeset
|
2475 def __len__(self): |
bc95143446e8
_addset: add a __len__ method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20833
diff
changeset
|
2476 return len(self._list) |
bc95143446e8
_addset: add a __len__ method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20833
diff
changeset
|
2477 |
20720
5f8400efca0b
revset: added cached generated list to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20719
diff
changeset
|
2478 @util.propertycache |
5f8400efca0b
revset: added cached generated list to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20719
diff
changeset
|
2479 def _list(self): |
5f8400efca0b
revset: added cached generated list to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20719
diff
changeset
|
2480 if not self._genlist: |
5f8400efca0b
revset: added cached generated list to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20719
diff
changeset
|
2481 self._genlist = baseset(self._iterator()) |
5f8400efca0b
revset: added cached generated list to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20719
diff
changeset
|
2482 return self._genlist |
20694
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2483 |
20728
1c8b62c0a47e
revset: added filter method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20727
diff
changeset
|
2484 def filter(self, condition): |
1c8b62c0a47e
revset: added filter method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20727
diff
changeset
|
2485 if self._ascending is not None: |
1c8b62c0a47e
revset: added filter method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20727
diff
changeset
|
2486 return orderedlazyset(self, condition, ascending=self._ascending) |
1c8b62c0a47e
revset: added filter method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20727
diff
changeset
|
2487 return lazyset(self, condition) |
1c8b62c0a47e
revset: added filter method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20727
diff
changeset
|
2488 |
20729
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2489 def ascending(self): |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2490 if self._ascending is None: |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2491 self.sort() |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2492 self._ascending = True |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2493 else: |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2494 if not self._ascending: |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2495 self.reverse() |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2496 |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2497 def descending(self): |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2498 if self._ascending is None: |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2499 self.sort(reverse=True) |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2500 self._ascending = False |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2501 else: |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2502 if self._ascending: |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2503 self.reverse() |
caa69cb223b0
revset: added ascending and descending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20728
diff
changeset
|
2504 |
20730
180d47e1fb68
revset: added __and__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20729
diff
changeset
|
2505 def __and__(self, other): |
180d47e1fb68
revset: added __and__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20729
diff
changeset
|
2506 filterfunc = other.__contains__ |
180d47e1fb68
revset: added __and__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20729
diff
changeset
|
2507 if self._ascending is not None: |
180d47e1fb68
revset: added __and__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20729
diff
changeset
|
2508 return orderedlazyset(self, filterfunc, ascending=self._ascending) |
180d47e1fb68
revset: added __and__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20729
diff
changeset
|
2509 return lazyset(self, filterfunc) |
180d47e1fb68
revset: added __and__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20729
diff
changeset
|
2510 |
20731
88aae5382519
revset: added __sub__ mehtod to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20730
diff
changeset
|
2511 def __sub__(self, other): |
88aae5382519
revset: added __sub__ mehtod to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20730
diff
changeset
|
2512 filterfunc = lambda r: r not in other |
88aae5382519
revset: added __sub__ mehtod to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20730
diff
changeset
|
2513 if self._ascending is not None: |
88aae5382519
revset: added __sub__ mehtod to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20730
diff
changeset
|
2514 return orderedlazyset(self, filterfunc, ascending=self._ascending) |
88aae5382519
revset: added __sub__ mehtod to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20730
diff
changeset
|
2515 return lazyset(self, filterfunc) |
88aae5382519
revset: added __sub__ mehtod to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20730
diff
changeset
|
2516 |
20732
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2517 def __add__(self, other): |
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2518 """When both collections are ascending or descending, preserve the order |
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2519 """ |
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2520 kwargs = {} |
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2521 if self._ascending is not None: |
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2522 if self.isascending() and other.isascending(): |
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2523 kwargs['ascending'] = True |
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2524 if self.isdescending() and other.isdescending(): |
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2525 kwargs['ascending'] = False |
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2526 return _addset(self, other, **kwargs) |
728438da3090
revset: added __add__ method to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20731
diff
changeset
|
2527 |
20694
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2528 def _iterator(self): |
20722
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2529 """Iterate over both collections without repeating elements |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2530 |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2531 If the ascending attribute is not set, iterate over the first one and |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2532 then over the second one checking for membership on the first one so we |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2533 dont yield any duplicates. |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2534 |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2535 If the ascending attribute is set, iterate over both collections at the |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2536 same time, yielding only one value at a time in the given order. |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2537 """ |
20694
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2538 if not self._iter: |
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2539 def gen(): |
20722
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2540 if self._ascending is None: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2541 for r in self._r1: |
20694
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2542 yield r |
20722
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2543 s = self._r1.set() |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2544 for r in self._r2: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2545 if r not in s: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2546 yield r |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2547 else: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2548 iter1 = iter(self._r1) |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2549 iter2 = iter(self._r2) |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2550 |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2551 val1 = None |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2552 val2 = None |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2553 |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2554 choice = max |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2555 if self._ascending: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2556 choice = min |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2557 try: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2558 # Consume both iterators in an ordered way until one is |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2559 # empty |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2560 while True: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2561 if val1 is None: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2562 val1 = iter1.next() |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2563 if val2 is None: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2564 val2 = iter2.next() |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2565 next = choice(val1, val2) |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2566 yield next |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2567 if val1 == next: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2568 val1 = None |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2569 if val2 == next: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2570 val2 = None |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2571 except StopIteration: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2572 # Flush any remaining values and consume the other one |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2573 it = iter2 |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2574 if val1 is not None: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2575 yield val1 |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2576 it = iter1 |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2577 elif val2 is not None: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2578 # might have been equality and both are empty |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2579 yield val2 |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2580 for val in it: |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2581 yield val |
6894223ebc38
revset: changed _iterator() method on addset to work with a given order
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20721
diff
changeset
|
2582 |
20705
9cc2249a9461
revset: made generatorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20703
diff
changeset
|
2583 self._iter = _generatorset(gen()) |
20694
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2584 |
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2585 return self._iter |
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2586 |
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2587 def __iter__(self): |
20721
d642f176df52
revset: changed _iterator() in addset to use the generated list when available
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20720
diff
changeset
|
2588 if self._genlist: |
d642f176df52
revset: changed _iterator() in addset to use the generated list when available
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20720
diff
changeset
|
2589 return iter(self._genlist) |
d642f176df52
revset: changed _iterator() in addset to use the generated list when available
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20720
diff
changeset
|
2590 return iter(self._iterator()) |
20694
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2591 |
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2592 def __contains__(self, x): |
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2593 return x in self._r1 or x in self._r2 |
621c94378d0d
revset: added addset class with its basic methods
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20693
diff
changeset
|
2594 |
20711
b95490cf8abd
revset: added set method to addset to duck type generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20709
diff
changeset
|
2595 def set(self): |
b95490cf8abd
revset: added set method to addset to duck type generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20709
diff
changeset
|
2596 return self |
b95490cf8abd
revset: added set method to addset to duck type generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20709
diff
changeset
|
2597 |
20724
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2598 def sort(self, reverse=False): |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2599 """Sort the added set |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2600 |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2601 For this we use the cached list with all the generated values and if we |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2602 know they are ascending or descending we can sort them in a smart way. |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2603 """ |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2604 if self._ascending is None: |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2605 self._list.sort(reverse=reverse) |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2606 self._ascending = not reverse |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2607 else: |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2608 if bool(self._ascending) == bool(reverse): |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2609 self.reverse() |
e9a64b3f2925
revset: added sort method in addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20723
diff
changeset
|
2610 |
20733
adf4ec7e6f60
revset: added isascending and isdescending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20732
diff
changeset
|
2611 def isascending(self): |
adf4ec7e6f60
revset: added isascending and isdescending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20732
diff
changeset
|
2612 return self._ascending is not None and self._ascending |
adf4ec7e6f60
revset: added isascending and isdescending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20732
diff
changeset
|
2613 |
adf4ec7e6f60
revset: added isascending and isdescending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20732
diff
changeset
|
2614 def isdescending(self): |
adf4ec7e6f60
revset: added isascending and isdescending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20732
diff
changeset
|
2615 return self._ascending is not None and not self._ascending |
adf4ec7e6f60
revset: added isascending and isdescending methods to _addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20732
diff
changeset
|
2616 |
20723
fb9852c46a42
revset: added reverse method to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20722
diff
changeset
|
2617 def reverse(self): |
fb9852c46a42
revset: added reverse method to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20722
diff
changeset
|
2618 self._list.reverse() |
fb9852c46a42
revset: added reverse method to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20722
diff
changeset
|
2619 if self._ascending is not None: |
fb9852c46a42
revset: added reverse method to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20722
diff
changeset
|
2620 self._ascending = not self._ascending |
fb9852c46a42
revset: added reverse method to addset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20722
diff
changeset
|
2621 |
20705
9cc2249a9461
revset: made generatorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20703
diff
changeset
|
2622 class _generatorset(object): |
9cc2249a9461
revset: made generatorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20703
diff
changeset
|
2623 """Wrap a generator for lazy iteration |
9cc2249a9461
revset: made generatorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20703
diff
changeset
|
2624 |
9cc2249a9461
revset: made generatorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20703
diff
changeset
|
2625 Wrapper structure for generators that provides lazy membership and can |
20540
fa16c710a3d8
revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20538
diff
changeset
|
2626 be iterated more than once. |
fa16c710a3d8
revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20538
diff
changeset
|
2627 When asked for membership it generates values until either it finds the |
fa16c710a3d8
revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20538
diff
changeset
|
2628 requested one or has gone through all the elements in the generator |
20705
9cc2249a9461
revset: made generatorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20703
diff
changeset
|
2629 |
9cc2249a9461
revset: made generatorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20703
diff
changeset
|
2630 This class does not duck-type baseset and it's only supposed to be used |
9cc2249a9461
revset: made generatorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20703
diff
changeset
|
2631 internally |
20540
fa16c710a3d8
revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20538
diff
changeset
|
2632 """ |
20536
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2633 def __init__(self, gen): |
20739
1b4f2399f3c4
revset: add documentation and comment for _generatorset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20738
diff
changeset
|
2634 """ |
1b4f2399f3c4
revset: add documentation and comment for _generatorset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20738
diff
changeset
|
2635 gen: a generator producing the values for the generatorset. |
1b4f2399f3c4
revset: add documentation and comment for _generatorset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20738
diff
changeset
|
2636 """ |
20536
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2637 self._gen = gen |
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2638 self._cache = {} |
20540
fa16c710a3d8
revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20538
diff
changeset
|
2639 self._genlist = baseset([]) |
20703
e07b1fd30805
revset: added sort methods to generatorsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20695
diff
changeset
|
2640 self._finished = False |
20540
fa16c710a3d8
revset: added cached generated list on generatorset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20538
diff
changeset
|
2641 |
20536
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2642 def __contains__(self, x): |
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2643 if x in self._cache: |
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2644 return self._cache[x] |
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2645 |
20828
3210b7930899
revset: improve performance of _generatorset.__contains__ (issue 4201)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20780
diff
changeset
|
2646 # Use new values only, as existing values would be cached. |
3210b7930899
revset: improve performance of _generatorset.__contains__ (issue 4201)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20780
diff
changeset
|
2647 for l in self._consumegen(): |
20634
f2bb7ba59456
revset: changed generatorset code to remove unnecesary function call
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20613
diff
changeset
|
2648 if l == x: |
f2bb7ba59456
revset: changed generatorset code to remove unnecesary function call
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20613
diff
changeset
|
2649 return True |
20536
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2650 |
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2651 self._cache[x] = False |
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2652 return False |
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2653 |
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2654 def __iter__(self): |
20833
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2655 if self._finished: |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2656 for x in self._genlist: |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2657 yield x |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2658 return |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2659 |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2660 i = 0 |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2661 genlist = self._genlist |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2662 consume = self._consumegen() |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2663 while True: |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2664 if i < len(genlist): |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2665 yield genlist[i] |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2666 else: |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2667 yield consume.next() |
47d43e2323c5
revset: fix generatorset race condition
Durham Goode <durham@fb.com>
parents:
20829
diff
changeset
|
2668 i += 1 |
20828
3210b7930899
revset: improve performance of _generatorset.__contains__ (issue 4201)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20780
diff
changeset
|
2669 |
3210b7930899
revset: improve performance of _generatorset.__contains__ (issue 4201)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20780
diff
changeset
|
2670 def _consumegen(self): |
20634
f2bb7ba59456
revset: changed generatorset code to remove unnecesary function call
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20613
diff
changeset
|
2671 for item in self._gen: |
f2bb7ba59456
revset: changed generatorset code to remove unnecesary function call
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20613
diff
changeset
|
2672 self._cache[item] = True |
f2bb7ba59456
revset: changed generatorset code to remove unnecesary function call
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20613
diff
changeset
|
2673 self._genlist.append(item) |
f2bb7ba59456
revset: changed generatorset code to remove unnecesary function call
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20613
diff
changeset
|
2674 yield item |
20703
e07b1fd30805
revset: added sort methods to generatorsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20695
diff
changeset
|
2675 self._finished = True |
e07b1fd30805
revset: added sort methods to generatorsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20695
diff
changeset
|
2676 |
20536
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2677 def set(self): |
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2678 return self |
532b114a6e02
revset: added generatorset class with cached __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20534
diff
changeset
|
2679 |
20703
e07b1fd30805
revset: added sort methods to generatorsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20695
diff
changeset
|
2680 def sort(self, reverse=False): |
e07b1fd30805
revset: added sort methods to generatorsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20695
diff
changeset
|
2681 if not self._finished: |
e07b1fd30805
revset: added sort methods to generatorsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20695
diff
changeset
|
2682 for i in self: |
e07b1fd30805
revset: added sort methods to generatorsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20695
diff
changeset
|
2683 continue |
e07b1fd30805
revset: added sort methods to generatorsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20695
diff
changeset
|
2684 self._genlist.sort(reverse=reverse) |
e07b1fd30805
revset: added sort methods to generatorsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20695
diff
changeset
|
2685 |
20706
efb34b066e7a
revset: made ascgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20705
diff
changeset
|
2686 class _ascgeneratorset(_generatorset): |
efb34b066e7a
revset: made ascgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20705
diff
changeset
|
2687 """Wrap a generator of ascending elements for lazy iteration |
efb34b066e7a
revset: made ascgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20705
diff
changeset
|
2688 |
efb34b066e7a
revset: made ascgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20705
diff
changeset
|
2689 Same structure as _generatorset but stops iterating after it goes past |
20643
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2690 the value when asked for membership and the element is not contained |
20706
efb34b066e7a
revset: made ascgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20705
diff
changeset
|
2691 |
efb34b066e7a
revset: made ascgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20705
diff
changeset
|
2692 This class does not duck-type baseset and it's only supposed to be used |
efb34b066e7a
revset: made ascgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20705
diff
changeset
|
2693 internally |
20643
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2694 """ |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2695 def __contains__(self, x): |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2696 if x in self._cache: |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2697 return self._cache[x] |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2698 |
20828
3210b7930899
revset: improve performance of _generatorset.__contains__ (issue 4201)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20780
diff
changeset
|
2699 # Use new values only, as existing values would be cached. |
3210b7930899
revset: improve performance of _generatorset.__contains__ (issue 4201)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20780
diff
changeset
|
2700 for l in self._consumegen(): |
20643
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2701 if l == x: |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2702 return True |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2703 if l > x: |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2704 break |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2705 |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2706 self._cache[x] = False |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2707 return False |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2708 |
20707
1d5d6f622b94
revset: made descgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20706
diff
changeset
|
2709 class _descgeneratorset(_generatorset): |
1d5d6f622b94
revset: made descgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20706
diff
changeset
|
2710 """Wrap a generator of descending elements for lazy iteration |
1d5d6f622b94
revset: made descgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20706
diff
changeset
|
2711 |
1d5d6f622b94
revset: made descgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20706
diff
changeset
|
2712 Same structure as _generatorset but stops iterating after it goes past |
20643
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2713 the value when asked for membership and the element is not contained |
20707
1d5d6f622b94
revset: made descgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20706
diff
changeset
|
2714 |
1d5d6f622b94
revset: made descgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20706
diff
changeset
|
2715 This class does not duck-type baseset and it's only supposed to be used |
1d5d6f622b94
revset: made descgeneratorset a private class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20706
diff
changeset
|
2716 internally |
20643
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2717 """ |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2718 def __contains__(self, x): |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2719 if x in self._cache: |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2720 return self._cache[x] |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2721 |
20828
3210b7930899
revset: improve performance of _generatorset.__contains__ (issue 4201)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20780
diff
changeset
|
2722 # Use new values only, as existing values would be cached. |
3210b7930899
revset: improve performance of _generatorset.__contains__ (issue 4201)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20780
diff
changeset
|
2723 for l in self._consumegen(): |
20643
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2724 if l == x: |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2725 return True |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2726 if l < x: |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2727 break |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2728 |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2729 self._cache[x] = False |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2730 return False |
7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20634
diff
changeset
|
2731 |
20750
d4f2f2d74210
revset: changed spanset to extend _orderedsetmixin
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20749
diff
changeset
|
2732 class spanset(_orderedsetmixin): |
20482
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2733 """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
|
2734 can work lazily and without having all the range in memory |
20737
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2735 |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2736 Note that spanset(x, y) behave almost like xrange(x, y) except for two |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2737 notable points: |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2738 - when x < y it will be automatically descending, |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2739 - revision filtered with this repoview will be skipped. |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2740 |
20482
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2741 """ |
20525
aa73a6327df4
revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20521
diff
changeset
|
2742 def __init__(self, repo, start=0, end=None): |
20737
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2743 """ |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2744 start: first revision included the set |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2745 (default to 0) |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2746 end: first revision excluded (last+1) |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2747 (default to len(repo) |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2748 |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2749 Spanset will be descending if `end` < `start`. |
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2750 """ |
20482
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2751 self._start = start |
20525
aa73a6327df4
revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20521
diff
changeset
|
2752 if end is not None: |
aa73a6327df4
revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20521
diff
changeset
|
2753 self._end = end |
aa73a6327df4
revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20521
diff
changeset
|
2754 else: |
aa73a6327df4
revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20521
diff
changeset
|
2755 self._end = len(repo) |
aa73a6327df4
revset: changed spanset to take a repo argument
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20521
diff
changeset
|
2756 self._hiddenrevs = repo.changelog.filteredrevs |
20521
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2757 |
20657
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2758 def ascending(self): |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2759 if self._start > self._end: |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2760 self.reverse() |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2761 |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2762 def descending(self): |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2763 if self._start < self._end: |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2764 self.reverse() |
379e89e4b079
revset: added order methods to lazyset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20643
diff
changeset
|
2765 |
20521
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2766 def _contained(self, rev): |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2767 return (rev <= self._start and rev > self._end) or (rev >= self._start |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2768 and rev < self._end) |
20482
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2769 |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2770 def __iter__(self): |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2771 if self._start <= self._end: |
20521
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2772 iterrange = xrange(self._start, self._end) |
20482
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2773 else: |
20521
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2774 iterrange = xrange(self._start, self._end, -1) |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2775 |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2776 if self._hiddenrevs: |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2777 s = self._hiddenrevs |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2778 for r in iterrange: |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2779 if r not in s: |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2780 yield r |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2781 else: |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2782 for r in iterrange: |
20482
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2783 yield r |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2784 |
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2785 def __contains__(self, x): |
20521
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2786 return self._contained(x) and not (self._hiddenrevs and rev in |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2787 self._hiddenrevs) |
20482
a979078bd788
revset: added spanset class to represent revision ranges
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20481
diff
changeset
|
2788 |
20716
fa1ac5faa7c4
revset: added __nonzero__ method to spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20714
diff
changeset
|
2789 def __nonzero__(self): |
fa1ac5faa7c4
revset: added __nonzero__ method to spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20714
diff
changeset
|
2790 for r in self: |
fa1ac5faa7c4
revset: added __nonzero__ method to spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20714
diff
changeset
|
2791 return True |
fa1ac5faa7c4
revset: added __nonzero__ method to spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20714
diff
changeset
|
2792 return False |
fa1ac5faa7c4
revset: added __nonzero__ method to spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20714
diff
changeset
|
2793 |
20483
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2794 def __and__(self, x): |
20538
fe220013e4db
revset: fixed bug where log -f was taking too long to return
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20536
diff
changeset
|
2795 if isinstance(x, baseset): |
fe220013e4db
revset: fixed bug where log -f was taking too long to return
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20536
diff
changeset
|
2796 x = x.set() |
20659
4f68acdb22ff
revset: changed methods in spanset to return ordered sets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20658
diff
changeset
|
2797 if self._start <= self._end: |
4f68acdb22ff
revset: changed methods in spanset to return ordered sets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20658
diff
changeset
|
2798 return orderedlazyset(self, lambda r: r in x) |
4f68acdb22ff
revset: changed methods in spanset to return ordered sets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20658
diff
changeset
|
2799 else: |
4f68acdb22ff
revset: changed methods in spanset to return ordered sets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20658
diff
changeset
|
2800 return orderedlazyset(self, lambda r: r in x, ascending=False) |
20483
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2801 |
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2802 def __sub__(self, x): |
20538
fe220013e4db
revset: fixed bug where log -f was taking too long to return
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20536
diff
changeset
|
2803 if isinstance(x, baseset): |
fe220013e4db
revset: fixed bug where log -f was taking too long to return
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20536
diff
changeset
|
2804 x = x.set() |
20659
4f68acdb22ff
revset: changed methods in spanset to return ordered sets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20658
diff
changeset
|
2805 if self._start <= self._end: |
4f68acdb22ff
revset: changed methods in spanset to return ordered sets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20658
diff
changeset
|
2806 return orderedlazyset(self, lambda r: r not in x) |
4f68acdb22ff
revset: changed methods in spanset to return ordered sets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20658
diff
changeset
|
2807 else: |
4f68acdb22ff
revset: changed methods in spanset to return ordered sets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20658
diff
changeset
|
2808 return orderedlazyset(self, lambda r: r not in x, ascending=False) |
20483
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2809 |
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2810 def __add__(self, x): |
20734
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2811 kwargs = {} |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2812 if self.isascending() and x.isascending(): |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2813 kwargs['ascending'] = True |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2814 if self.isdescending() and x.isdescending(): |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2815 kwargs['ascending'] = False |
4d27c30d58d5
revset: changed smartset methods to return ordered addsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20733
diff
changeset
|
2816 return _addset(self, x, **kwargs) |
20483
ed57358398af
revset: added basic operations to spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20482
diff
changeset
|
2817 |
20484
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2818 def __len__(self): |
20521
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2819 if not self._hiddenrevs: |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2820 return abs(self._end - self._start) |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2821 else: |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2822 count = 0 |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2823 for rev in self._hiddenrevs: |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2824 if self._contained(rev): |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2825 count += 1 |
1850a7f5fb66
revset: changed spanset implementation to take hidden revisions into account
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20512
diff
changeset
|
2826 return abs(self._end - self._start) - count |
20484
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2827 |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2828 def __getitem__(self, x): |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2829 # 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
|
2830 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
|
2831 return l[x] |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2832 |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2833 def sort(self, reverse=False): |
20718
d7b7ec0459c6
revset: fixed sorting issue with spanset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20716
diff
changeset
|
2834 if bool(reverse) != (self._start > self._end): |
20484
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2835 self.reverse() |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2836 |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2837 def reverse(self): |
20737
b141080e70c5
revset: added documentation and comment for spanset class
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20734
diff
changeset
|
2838 # Just switch the _start and _end parameters |
20484
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2839 if self._start <= self._end: |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2840 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
|
2841 else: |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2842 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
|
2843 |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2844 def set(self): |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2845 return self |
0f1ef9e9e904
revset: added operations to spanset to duck type baseset
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20483
diff
changeset
|
2846 |
20725
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2847 def isascending(self): |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2848 return self._start < self._end |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2849 |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2850 def isdescending(self): |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2851 return self._start > self._end |
cf628b50afbb
revset: added isascending and isdescending methods to smartset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20724
diff
changeset
|
2852 |
20610
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2853 def filter(self, l): |
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2854 if self._start <= self._end: |
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2855 return orderedlazyset(self, l) |
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2856 else: |
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2857 return orderedlazyset(self, l, ascending=False) |
34bb07e70c68
revset: added filter method to revset classes
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20609
diff
changeset
|
2858 |
12823
80deae3bc5ea
hggettext: handle i18nfunctions declaration for docstrings translations
Patrick Mezard <pmezard@gmail.com>
parents:
12821
diff
changeset
|
2859 # 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
|
2860 i18nfunctions = symbols.values() |