Show More
@@ -1,2163 +1,2185 | |||||
1 | # revset.py - revision set queries for mercurial |
|
1 | # revset.py - revision set queries for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2010 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2010 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
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. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | import re |
|
8 | import re | |
9 | import parser, util, error, discovery, hbisect, phases |
|
9 | import parser, util, error, discovery, hbisect, phases | |
10 | import node |
|
10 | import node | |
11 | import match as matchmod |
|
11 | import match as matchmod | |
12 | from i18n import _ |
|
12 | from i18n import _ | |
13 | import encoding |
|
13 | import encoding | |
14 | import obsolete as obsmod |
|
14 | import obsolete as obsmod | |
15 | import pathutil |
|
15 | import pathutil | |
16 | import repoview |
|
16 | import repoview | |
17 |
|
17 | |||
18 | def _revancestors(repo, revs, followfirst): |
|
18 | def _revancestors(repo, revs, followfirst): | |
19 | """Like revlog.ancestors(), but supports followfirst.""" |
|
19 | """Like revlog.ancestors(), but supports followfirst.""" | |
20 | cut = followfirst and 1 or None |
|
20 | cut = followfirst and 1 or None | |
21 | cl = repo.changelog |
|
21 | cl = repo.changelog | |
22 | visit = util.deque(revs) |
|
22 | visit = util.deque(revs) | |
23 | seen = set([node.nullrev]) |
|
23 | seen = set([node.nullrev]) | |
24 | while visit: |
|
24 | while visit: | |
25 | for parent in cl.parentrevs(visit.popleft())[:cut]: |
|
25 | for parent in cl.parentrevs(visit.popleft())[:cut]: | |
26 | if parent not in seen: |
|
26 | if parent not in seen: | |
27 | visit.append(parent) |
|
27 | visit.append(parent) | |
28 | seen.add(parent) |
|
28 | seen.add(parent) | |
29 | yield parent |
|
29 | yield parent | |
30 |
|
30 | |||
31 | def _revdescendants(repo, revs, followfirst): |
|
31 | def _revdescendants(repo, revs, followfirst): | |
32 | """Like revlog.descendants() but supports followfirst.""" |
|
32 | """Like revlog.descendants() but supports followfirst.""" | |
33 | cut = followfirst and 1 or None |
|
33 | cut = followfirst and 1 or None | |
34 | cl = repo.changelog |
|
34 | cl = repo.changelog | |
35 | first = min(revs) |
|
35 | first = min(revs) | |
36 | nullrev = node.nullrev |
|
36 | nullrev = node.nullrev | |
37 | if first == nullrev: |
|
37 | if first == nullrev: | |
38 | # Are there nodes with a null first parent and a non-null |
|
38 | # Are there nodes with a null first parent and a non-null | |
39 | # second one? Maybe. Do we care? Probably not. |
|
39 | # second one? Maybe. Do we care? Probably not. | |
40 | for i in cl: |
|
40 | for i in cl: | |
41 | yield i |
|
41 | yield i | |
42 | return |
|
42 | return | |
43 |
|
43 | |||
44 | seen = set(revs) |
|
44 | seen = set(revs) | |
45 | for i in cl.revs(first + 1): |
|
45 | for i in cl.revs(first + 1): | |
46 | for x in cl.parentrevs(i)[:cut]: |
|
46 | for x in cl.parentrevs(i)[:cut]: | |
47 | if x != nullrev and x in seen: |
|
47 | if x != nullrev and x in seen: | |
48 | seen.add(i) |
|
48 | seen.add(i) | |
49 | yield i |
|
49 | yield i | |
50 | break |
|
50 | break | |
51 |
|
51 | |||
52 | def _revsbetween(repo, roots, heads): |
|
52 | def _revsbetween(repo, roots, heads): | |
53 | """Return all paths between roots and heads, inclusive of both endpoint |
|
53 | """Return all paths between roots and heads, inclusive of both endpoint | |
54 | sets.""" |
|
54 | sets.""" | |
55 | if not roots: |
|
55 | if not roots: | |
56 | return baseset([]) |
|
56 | return baseset([]) | |
57 | parentrevs = repo.changelog.parentrevs |
|
57 | parentrevs = repo.changelog.parentrevs | |
58 | visit = baseset(heads) |
|
58 | visit = baseset(heads) | |
59 | reachable = set() |
|
59 | reachable = set() | |
60 | seen = {} |
|
60 | seen = {} | |
61 | minroot = min(roots) |
|
61 | minroot = min(roots) | |
62 | roots = set(roots) |
|
62 | roots = set(roots) | |
63 | # open-code the post-order traversal due to the tiny size of |
|
63 | # open-code the post-order traversal due to the tiny size of | |
64 | # sys.getrecursionlimit() |
|
64 | # sys.getrecursionlimit() | |
65 | while visit: |
|
65 | while visit: | |
66 | rev = visit.pop() |
|
66 | rev = visit.pop() | |
67 | if rev in roots: |
|
67 | if rev in roots: | |
68 | reachable.add(rev) |
|
68 | reachable.add(rev) | |
69 | parents = parentrevs(rev) |
|
69 | parents = parentrevs(rev) | |
70 | seen[rev] = parents |
|
70 | seen[rev] = parents | |
71 | for parent in parents: |
|
71 | for parent in parents: | |
72 | if parent >= minroot and parent not in seen: |
|
72 | if parent >= minroot and parent not in seen: | |
73 | visit.append(parent) |
|
73 | visit.append(parent) | |
74 | if not reachable: |
|
74 | if not reachable: | |
75 | return baseset([]) |
|
75 | return baseset([]) | |
76 | for rev in sorted(seen): |
|
76 | for rev in sorted(seen): | |
77 | for parent in seen[rev]: |
|
77 | for parent in seen[rev]: | |
78 | if parent in reachable: |
|
78 | if parent in reachable: | |
79 | reachable.add(rev) |
|
79 | reachable.add(rev) | |
80 | return baseset(sorted(reachable)) |
|
80 | return baseset(sorted(reachable)) | |
81 |
|
81 | |||
82 | elements = { |
|
82 | elements = { | |
83 | "(": (20, ("group", 1, ")"), ("func", 1, ")")), |
|
83 | "(": (20, ("group", 1, ")"), ("func", 1, ")")), | |
84 | "~": (18, None, ("ancestor", 18)), |
|
84 | "~": (18, None, ("ancestor", 18)), | |
85 | "^": (18, None, ("parent", 18), ("parentpost", 18)), |
|
85 | "^": (18, None, ("parent", 18), ("parentpost", 18)), | |
86 | "-": (5, ("negate", 19), ("minus", 5)), |
|
86 | "-": (5, ("negate", 19), ("minus", 5)), | |
87 | "::": (17, ("dagrangepre", 17), ("dagrange", 17), |
|
87 | "::": (17, ("dagrangepre", 17), ("dagrange", 17), | |
88 | ("dagrangepost", 17)), |
|
88 | ("dagrangepost", 17)), | |
89 | "..": (17, ("dagrangepre", 17), ("dagrange", 17), |
|
89 | "..": (17, ("dagrangepre", 17), ("dagrange", 17), | |
90 | ("dagrangepost", 17)), |
|
90 | ("dagrangepost", 17)), | |
91 | ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)), |
|
91 | ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)), | |
92 | "not": (10, ("not", 10)), |
|
92 | "not": (10, ("not", 10)), | |
93 | "!": (10, ("not", 10)), |
|
93 | "!": (10, ("not", 10)), | |
94 | "and": (5, None, ("and", 5)), |
|
94 | "and": (5, None, ("and", 5)), | |
95 | "&": (5, None, ("and", 5)), |
|
95 | "&": (5, None, ("and", 5)), | |
96 | "or": (4, None, ("or", 4)), |
|
96 | "or": (4, None, ("or", 4)), | |
97 | "|": (4, None, ("or", 4)), |
|
97 | "|": (4, None, ("or", 4)), | |
98 | "+": (4, None, ("or", 4)), |
|
98 | "+": (4, None, ("or", 4)), | |
99 | ",": (2, None, ("list", 2)), |
|
99 | ",": (2, None, ("list", 2)), | |
100 | ")": (0, None, None), |
|
100 | ")": (0, None, None), | |
101 | "symbol": (0, ("symbol",), None), |
|
101 | "symbol": (0, ("symbol",), None), | |
102 | "string": (0, ("string",), None), |
|
102 | "string": (0, ("string",), None), | |
103 | "end": (0, None, None), |
|
103 | "end": (0, None, None), | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | keywords = set(['and', 'or', 'not']) |
|
106 | keywords = set(['and', 'or', 'not']) | |
107 |
|
107 | |||
108 | def tokenize(program): |
|
108 | def tokenize(program): | |
109 | ''' |
|
109 | ''' | |
110 | Parse a revset statement into a stream of tokens |
|
110 | Parse a revset statement into a stream of tokens | |
111 |
|
111 | |||
112 | Check that @ is a valid unquoted token character (issue3686): |
|
112 | Check that @ is a valid unquoted token character (issue3686): | |
113 | >>> list(tokenize("@::")) |
|
113 | >>> list(tokenize("@::")) | |
114 | [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)] |
|
114 | [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)] | |
115 |
|
115 | |||
116 | ''' |
|
116 | ''' | |
117 |
|
117 | |||
118 | pos, l = 0, len(program) |
|
118 | pos, l = 0, len(program) | |
119 | while pos < l: |
|
119 | while pos < l: | |
120 | c = program[pos] |
|
120 | c = program[pos] | |
121 | if c.isspace(): # skip inter-token whitespace |
|
121 | if c.isspace(): # skip inter-token whitespace | |
122 | pass |
|
122 | pass | |
123 | elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully |
|
123 | elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully | |
124 | yield ('::', None, pos) |
|
124 | yield ('::', None, pos) | |
125 | pos += 1 # skip ahead |
|
125 | pos += 1 # skip ahead | |
126 | elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully |
|
126 | elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully | |
127 | yield ('..', None, pos) |
|
127 | yield ('..', None, pos) | |
128 | pos += 1 # skip ahead |
|
128 | pos += 1 # skip ahead | |
129 | elif c in "():,-|&+!~^": # handle simple operators |
|
129 | elif c in "():,-|&+!~^": # handle simple operators | |
130 | yield (c, None, pos) |
|
130 | yield (c, None, pos) | |
131 | elif (c in '"\'' or c == 'r' and |
|
131 | elif (c in '"\'' or c == 'r' and | |
132 | program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings |
|
132 | program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings | |
133 | if c == 'r': |
|
133 | if c == 'r': | |
134 | pos += 1 |
|
134 | pos += 1 | |
135 | c = program[pos] |
|
135 | c = program[pos] | |
136 | decode = lambda x: x |
|
136 | decode = lambda x: x | |
137 | else: |
|
137 | else: | |
138 | decode = lambda x: x.decode('string-escape') |
|
138 | decode = lambda x: x.decode('string-escape') | |
139 | pos += 1 |
|
139 | pos += 1 | |
140 | s = pos |
|
140 | s = pos | |
141 | while pos < l: # find closing quote |
|
141 | while pos < l: # find closing quote | |
142 | d = program[pos] |
|
142 | d = program[pos] | |
143 | if d == '\\': # skip over escaped characters |
|
143 | if d == '\\': # skip over escaped characters | |
144 | pos += 2 |
|
144 | pos += 2 | |
145 | continue |
|
145 | continue | |
146 | if d == c: |
|
146 | if d == c: | |
147 | yield ('string', decode(program[s:pos]), s) |
|
147 | yield ('string', decode(program[s:pos]), s) | |
148 | break |
|
148 | break | |
149 | pos += 1 |
|
149 | pos += 1 | |
150 | else: |
|
150 | else: | |
151 | raise error.ParseError(_("unterminated string"), s) |
|
151 | raise error.ParseError(_("unterminated string"), s) | |
152 | # gather up a symbol/keyword |
|
152 | # gather up a symbol/keyword | |
153 | elif c.isalnum() or c in '._@' or ord(c) > 127: |
|
153 | elif c.isalnum() or c in '._@' or ord(c) > 127: | |
154 | s = pos |
|
154 | s = pos | |
155 | pos += 1 |
|
155 | pos += 1 | |
156 | while pos < l: # find end of symbol |
|
156 | while pos < l: # find end of symbol | |
157 | d = program[pos] |
|
157 | d = program[pos] | |
158 | if not (d.isalnum() or d in "._/@" or ord(d) > 127): |
|
158 | if not (d.isalnum() or d in "._/@" or ord(d) > 127): | |
159 | break |
|
159 | break | |
160 | if d == '.' and program[pos - 1] == '.': # special case for .. |
|
160 | if d == '.' and program[pos - 1] == '.': # special case for .. | |
161 | pos -= 1 |
|
161 | pos -= 1 | |
162 | break |
|
162 | break | |
163 | pos += 1 |
|
163 | pos += 1 | |
164 | sym = program[s:pos] |
|
164 | sym = program[s:pos] | |
165 | if sym in keywords: # operator keywords |
|
165 | if sym in keywords: # operator keywords | |
166 | yield (sym, None, s) |
|
166 | yield (sym, None, s) | |
167 | else: |
|
167 | else: | |
168 | yield ('symbol', sym, s) |
|
168 | yield ('symbol', sym, s) | |
169 | pos -= 1 |
|
169 | pos -= 1 | |
170 | else: |
|
170 | else: | |
171 | raise error.ParseError(_("syntax error"), pos) |
|
171 | raise error.ParseError(_("syntax error"), pos) | |
172 | pos += 1 |
|
172 | pos += 1 | |
173 | yield ('end', None, pos) |
|
173 | yield ('end', None, pos) | |
174 |
|
174 | |||
175 | # helpers |
|
175 | # helpers | |
176 |
|
176 | |||
177 | def getstring(x, err): |
|
177 | def getstring(x, err): | |
178 | if x and (x[0] == 'string' or x[0] == 'symbol'): |
|
178 | if x and (x[0] == 'string' or x[0] == 'symbol'): | |
179 | return x[1] |
|
179 | return x[1] | |
180 | raise error.ParseError(err) |
|
180 | raise error.ParseError(err) | |
181 |
|
181 | |||
182 | def getlist(x): |
|
182 | def getlist(x): | |
183 | if not x: |
|
183 | if not x: | |
184 | return [] |
|
184 | return [] | |
185 | if x[0] == 'list': |
|
185 | if x[0] == 'list': | |
186 | return getlist(x[1]) + [x[2]] |
|
186 | return getlist(x[1]) + [x[2]] | |
187 | return [x] |
|
187 | return [x] | |
188 |
|
188 | |||
189 | def getargs(x, min, max, err): |
|
189 | def getargs(x, min, max, err): | |
190 | l = getlist(x) |
|
190 | l = getlist(x) | |
191 | if len(l) < min or (max >= 0 and len(l) > max): |
|
191 | if len(l) < min or (max >= 0 and len(l) > max): | |
192 | raise error.ParseError(err) |
|
192 | raise error.ParseError(err) | |
193 | return l |
|
193 | return l | |
194 |
|
194 | |||
195 | def getset(repo, subset, x): |
|
195 | def getset(repo, subset, x): | |
196 | if not x: |
|
196 | if not x: | |
197 | raise error.ParseError(_("missing argument")) |
|
197 | raise error.ParseError(_("missing argument")) | |
198 | return methods[x[0]](repo, subset, *x[1:]) |
|
198 | return methods[x[0]](repo, subset, *x[1:]) | |
199 |
|
199 | |||
200 | def _getrevsource(repo, r): |
|
200 | def _getrevsource(repo, r): | |
201 | extra = repo[r].extra() |
|
201 | extra = repo[r].extra() | |
202 | for label in ('source', 'transplant_source', 'rebase_source'): |
|
202 | for label in ('source', 'transplant_source', 'rebase_source'): | |
203 | if label in extra: |
|
203 | if label in extra: | |
204 | try: |
|
204 | try: | |
205 | return repo[extra[label]].rev() |
|
205 | return repo[extra[label]].rev() | |
206 | except error.RepoLookupError: |
|
206 | except error.RepoLookupError: | |
207 | pass |
|
207 | pass | |
208 | return None |
|
208 | return None | |
209 |
|
209 | |||
210 | # operator methods |
|
210 | # operator methods | |
211 |
|
211 | |||
212 | def stringset(repo, subset, x): |
|
212 | def stringset(repo, subset, x): | |
213 | x = repo[x].rev() |
|
213 | x = repo[x].rev() | |
214 | if x == -1 and len(subset) == len(repo): |
|
214 | if x == -1 and len(subset) == len(repo): | |
215 | return baseset([-1]) |
|
215 | return baseset([-1]) | |
216 | if len(subset) == len(repo) or x in subset: |
|
216 | if len(subset) == len(repo) or x in subset: | |
217 | return baseset([x]) |
|
217 | return baseset([x]) | |
218 | return baseset([]) |
|
218 | return baseset([]) | |
219 |
|
219 | |||
220 | def symbolset(repo, subset, x): |
|
220 | def symbolset(repo, subset, x): | |
221 | if x in symbols: |
|
221 | if x in symbols: | |
222 | raise error.ParseError(_("can't use %s here") % x) |
|
222 | raise error.ParseError(_("can't use %s here") % x) | |
223 | return stringset(repo, subset, x) |
|
223 | return stringset(repo, subset, x) | |
224 |
|
224 | |||
225 | def rangeset(repo, subset, x, y): |
|
225 | def rangeset(repo, subset, x, y): | |
226 | cl = baseset(repo.changelog) |
|
226 | cl = baseset(repo.changelog) | |
227 | m = getset(repo, cl, x) |
|
227 | m = getset(repo, cl, x) | |
228 | n = getset(repo, cl, y) |
|
228 | n = getset(repo, cl, y) | |
229 |
|
229 | |||
230 | if not m or not n: |
|
230 | if not m or not n: | |
231 | return baseset([]) |
|
231 | return baseset([]) | |
232 | m, n = m[0], n[-1] |
|
232 | m, n = m[0], n[-1] | |
233 |
|
233 | |||
234 | if m < n: |
|
234 | if m < n: | |
235 | r = range(m, n + 1) |
|
235 | r = range(m, n + 1) | |
236 | else: |
|
236 | else: | |
237 | r = range(m, n - 1, -1) |
|
237 | r = range(m, n - 1, -1) | |
238 | s = subset.set() |
|
238 | s = subset.set() | |
239 | return baseset([x for x in r if x in s]) |
|
239 | return baseset([x for x in r if x in s]) | |
240 |
|
240 | |||
241 | def dagrange(repo, subset, x, y): |
|
241 | def dagrange(repo, subset, x, y): | |
242 | r = baseset(repo) |
|
242 | r = baseset(repo) | |
243 | xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y)) |
|
243 | xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y)) | |
244 | s = subset.set() |
|
244 | s = subset.set() | |
245 | return baseset([r for r in xs if r in s]) |
|
245 | return baseset([r for r in xs if r in s]) | |
246 |
|
246 | |||
247 | def andset(repo, subset, x, y): |
|
247 | def andset(repo, subset, x, y): | |
248 | return getset(repo, getset(repo, subset, x), y) |
|
248 | return getset(repo, getset(repo, subset, x), y) | |
249 |
|
249 | |||
250 | def orset(repo, subset, x, y): |
|
250 | def orset(repo, subset, x, y): | |
251 | xl = getset(repo, subset, x) |
|
251 | xl = getset(repo, subset, x) | |
252 | yl = getset(repo, subset - xl, y) |
|
252 | yl = getset(repo, subset - xl, y) | |
253 | return xl + yl |
|
253 | return xl + yl | |
254 |
|
254 | |||
255 | def notset(repo, subset, x): |
|
255 | def notset(repo, subset, x): | |
256 | return subset - getset(repo, subset, x) |
|
256 | return subset - getset(repo, subset, x) | |
257 |
|
257 | |||
258 | def listset(repo, subset, a, b): |
|
258 | def listset(repo, subset, a, b): | |
259 | raise error.ParseError(_("can't use a list in this context")) |
|
259 | raise error.ParseError(_("can't use a list in this context")) | |
260 |
|
260 | |||
261 | def func(repo, subset, a, b): |
|
261 | def func(repo, subset, a, b): | |
262 | if a[0] == 'symbol' and a[1] in symbols: |
|
262 | if a[0] == 'symbol' and a[1] in symbols: | |
263 | return symbols[a[1]](repo, subset, b) |
|
263 | return symbols[a[1]](repo, subset, b) | |
264 | raise error.ParseError(_("not a function: %s") % a[1]) |
|
264 | raise error.ParseError(_("not a function: %s") % a[1]) | |
265 |
|
265 | |||
266 | # functions |
|
266 | # functions | |
267 |
|
267 | |||
268 | def adds(repo, subset, x): |
|
268 | def adds(repo, subset, x): | |
269 | """``adds(pattern)`` |
|
269 | """``adds(pattern)`` | |
270 | Changesets that add a file matching pattern. |
|
270 | Changesets that add a file matching pattern. | |
271 |
|
271 | |||
272 | The pattern without explicit kind like ``glob:`` is expected to be |
|
272 | The pattern without explicit kind like ``glob:`` is expected to be | |
273 | relative to the current directory and match against a file or a |
|
273 | relative to the current directory and match against a file or a | |
274 | directory. |
|
274 | directory. | |
275 | """ |
|
275 | """ | |
276 | # i18n: "adds" is a keyword |
|
276 | # i18n: "adds" is a keyword | |
277 | pat = getstring(x, _("adds requires a pattern")) |
|
277 | pat = getstring(x, _("adds requires a pattern")) | |
278 | return checkstatus(repo, subset, pat, 1) |
|
278 | return checkstatus(repo, subset, pat, 1) | |
279 |
|
279 | |||
280 | def ancestor(repo, subset, x): |
|
280 | def ancestor(repo, subset, x): | |
281 | """``ancestor(*changeset)`` |
|
281 | """``ancestor(*changeset)`` | |
282 | Greatest common ancestor of the changesets. |
|
282 | Greatest common ancestor of the changesets. | |
283 |
|
283 | |||
284 | Accepts 0 or more changesets. |
|
284 | Accepts 0 or more changesets. | |
285 | Will return empty list when passed no args. |
|
285 | Will return empty list when passed no args. | |
286 | Greatest common ancestor of a single changeset is that changeset. |
|
286 | Greatest common ancestor of a single changeset is that changeset. | |
287 | """ |
|
287 | """ | |
288 | # i18n: "ancestor" is a keyword |
|
288 | # i18n: "ancestor" is a keyword | |
289 | l = getlist(x) |
|
289 | l = getlist(x) | |
290 | rl = baseset(repo) |
|
290 | rl = baseset(repo) | |
291 | anc = None |
|
291 | anc = None | |
292 |
|
292 | |||
293 | # (getset(repo, rl, i) for i in l) generates a list of lists |
|
293 | # (getset(repo, rl, i) for i in l) generates a list of lists | |
294 | rev = repo.changelog.rev |
|
294 | rev = repo.changelog.rev | |
295 | ancestor = repo.changelog.ancestor |
|
295 | ancestor = repo.changelog.ancestor | |
296 | node = repo.changelog.node |
|
296 | node = repo.changelog.node | |
297 | for revs in (getset(repo, rl, i) for i in l): |
|
297 | for revs in (getset(repo, rl, i) for i in l): | |
298 | for r in revs: |
|
298 | for r in revs: | |
299 | if anc is None: |
|
299 | if anc is None: | |
300 | anc = r |
|
300 | anc = r | |
301 | else: |
|
301 | else: | |
302 | anc = rev(ancestor(node(anc), node(r))) |
|
302 | anc = rev(ancestor(node(anc), node(r))) | |
303 |
|
303 | |||
304 | if anc is not None and anc in subset: |
|
304 | if anc is not None and anc in subset: | |
305 | return baseset([anc]) |
|
305 | return baseset([anc]) | |
306 | return baseset([]) |
|
306 | return baseset([]) | |
307 |
|
307 | |||
308 | def _ancestors(repo, subset, x, followfirst=False): |
|
308 | def _ancestors(repo, subset, x, followfirst=False): | |
309 | args = getset(repo, baseset(repo), x) |
|
309 | args = getset(repo, baseset(repo), x) | |
310 | if not args: |
|
310 | if not args: | |
311 | return baseset([]) |
|
311 | return baseset([]) | |
312 | s = set(_revancestors(repo, args, followfirst)) | set(args) |
|
312 | s = set(_revancestors(repo, args, followfirst)) | set(args) | |
313 | return baseset([r for r in subset if r in s]) |
|
313 | return baseset([r for r in subset if r in s]) | |
314 |
|
314 | |||
315 | def ancestors(repo, subset, x): |
|
315 | def ancestors(repo, subset, x): | |
316 | """``ancestors(set)`` |
|
316 | """``ancestors(set)`` | |
317 | Changesets that are ancestors of a changeset in set. |
|
317 | Changesets that are ancestors of a changeset in set. | |
318 | """ |
|
318 | """ | |
319 | return _ancestors(repo, subset, x) |
|
319 | return _ancestors(repo, subset, x) | |
320 |
|
320 | |||
321 | def _firstancestors(repo, subset, x): |
|
321 | def _firstancestors(repo, subset, x): | |
322 | # ``_firstancestors(set)`` |
|
322 | # ``_firstancestors(set)`` | |
323 | # Like ``ancestors(set)`` but follows only the first parents. |
|
323 | # Like ``ancestors(set)`` but follows only the first parents. | |
324 | return _ancestors(repo, subset, x, followfirst=True) |
|
324 | return _ancestors(repo, subset, x, followfirst=True) | |
325 |
|
325 | |||
326 | def ancestorspec(repo, subset, x, n): |
|
326 | def ancestorspec(repo, subset, x, n): | |
327 | """``set~n`` |
|
327 | """``set~n`` | |
328 | Changesets that are the Nth ancestor (first parents only) of a changeset |
|
328 | Changesets that are the Nth ancestor (first parents only) of a changeset | |
329 | in set. |
|
329 | in set. | |
330 | """ |
|
330 | """ | |
331 | try: |
|
331 | try: | |
332 | n = int(n[1]) |
|
332 | n = int(n[1]) | |
333 | except (TypeError, ValueError): |
|
333 | except (TypeError, ValueError): | |
334 | raise error.ParseError(_("~ expects a number")) |
|
334 | raise error.ParseError(_("~ expects a number")) | |
335 | ps = set() |
|
335 | ps = set() | |
336 | cl = repo.changelog |
|
336 | cl = repo.changelog | |
337 | for r in getset(repo, baseset(cl), x): |
|
337 | for r in getset(repo, baseset(cl), x): | |
338 | for i in range(n): |
|
338 | for i in range(n): | |
339 | r = cl.parentrevs(r)[0] |
|
339 | r = cl.parentrevs(r)[0] | |
340 | ps.add(r) |
|
340 | ps.add(r) | |
341 | return baseset([r for r in subset if r in ps]) |
|
341 | return baseset([r for r in subset if r in ps]) | |
342 |
|
342 | |||
343 | def author(repo, subset, x): |
|
343 | def author(repo, subset, x): | |
344 | """``author(string)`` |
|
344 | """``author(string)`` | |
345 | Alias for ``user(string)``. |
|
345 | Alias for ``user(string)``. | |
346 | """ |
|
346 | """ | |
347 | # i18n: "author" is a keyword |
|
347 | # i18n: "author" is a keyword | |
348 | n = encoding.lower(getstring(x, _("author requires a string"))) |
|
348 | n = encoding.lower(getstring(x, _("author requires a string"))) | |
349 | kind, pattern, matcher = _substringmatcher(n) |
|
349 | kind, pattern, matcher = _substringmatcher(n) | |
350 | return lazyset(subset, lambda x: matcher(encoding.lower(repo[x].user()))) |
|
350 | return lazyset(subset, lambda x: matcher(encoding.lower(repo[x].user()))) | |
351 |
|
351 | |||
352 | def bisect(repo, subset, x): |
|
352 | def bisect(repo, subset, x): | |
353 | """``bisect(string)`` |
|
353 | """``bisect(string)`` | |
354 | Changesets marked in the specified bisect status: |
|
354 | Changesets marked in the specified bisect status: | |
355 |
|
355 | |||
356 | - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip |
|
356 | - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip | |
357 | - ``goods``, ``bads`` : csets topologically good/bad |
|
357 | - ``goods``, ``bads`` : csets topologically good/bad | |
358 | - ``range`` : csets taking part in the bisection |
|
358 | - ``range`` : csets taking part in the bisection | |
359 | - ``pruned`` : csets that are goods, bads or skipped |
|
359 | - ``pruned`` : csets that are goods, bads or skipped | |
360 | - ``untested`` : csets whose fate is yet unknown |
|
360 | - ``untested`` : csets whose fate is yet unknown | |
361 | - ``ignored`` : csets ignored due to DAG topology |
|
361 | - ``ignored`` : csets ignored due to DAG topology | |
362 | - ``current`` : the cset currently being bisected |
|
362 | - ``current`` : the cset currently being bisected | |
363 | """ |
|
363 | """ | |
364 | # i18n: "bisect" is a keyword |
|
364 | # i18n: "bisect" is a keyword | |
365 | status = getstring(x, _("bisect requires a string")).lower() |
|
365 | status = getstring(x, _("bisect requires a string")).lower() | |
366 | state = set(hbisect.get(repo, status)) |
|
366 | state = set(hbisect.get(repo, status)) | |
367 | return baseset([r for r in subset if r in state]) |
|
367 | return baseset([r for r in subset if r in state]) | |
368 |
|
368 | |||
369 | # Backward-compatibility |
|
369 | # Backward-compatibility | |
370 | # - no help entry so that we do not advertise it any more |
|
370 | # - no help entry so that we do not advertise it any more | |
371 | def bisected(repo, subset, x): |
|
371 | def bisected(repo, subset, x): | |
372 | return bisect(repo, subset, x) |
|
372 | return bisect(repo, subset, x) | |
373 |
|
373 | |||
374 | def bookmark(repo, subset, x): |
|
374 | def bookmark(repo, subset, x): | |
375 | """``bookmark([name])`` |
|
375 | """``bookmark([name])`` | |
376 | The named bookmark or all bookmarks. |
|
376 | The named bookmark or all bookmarks. | |
377 |
|
377 | |||
378 | If `name` starts with `re:`, the remainder of the name is treated as |
|
378 | If `name` starts with `re:`, the remainder of the name is treated as | |
379 | a regular expression. To match a bookmark that actually starts with `re:`, |
|
379 | a regular expression. To match a bookmark that actually starts with `re:`, | |
380 | use the prefix `literal:`. |
|
380 | use the prefix `literal:`. | |
381 | """ |
|
381 | """ | |
382 | # i18n: "bookmark" is a keyword |
|
382 | # i18n: "bookmark" is a keyword | |
383 | args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) |
|
383 | args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) | |
384 | if args: |
|
384 | if args: | |
385 | bm = getstring(args[0], |
|
385 | bm = getstring(args[0], | |
386 | # i18n: "bookmark" is a keyword |
|
386 | # i18n: "bookmark" is a keyword | |
387 | _('the argument to bookmark must be a string')) |
|
387 | _('the argument to bookmark must be a string')) | |
388 | kind, pattern, matcher = _stringmatcher(bm) |
|
388 | kind, pattern, matcher = _stringmatcher(bm) | |
389 | if kind == 'literal': |
|
389 | if kind == 'literal': | |
390 | bmrev = repo._bookmarks.get(bm, None) |
|
390 | bmrev = repo._bookmarks.get(bm, None) | |
391 | if not bmrev: |
|
391 | if not bmrev: | |
392 | raise util.Abort(_("bookmark '%s' does not exist") % bm) |
|
392 | raise util.Abort(_("bookmark '%s' does not exist") % bm) | |
393 | bmrev = repo[bmrev].rev() |
|
393 | bmrev = repo[bmrev].rev() | |
394 | return lazyset(subset, lambda r: r == bmrev) |
|
394 | return lazyset(subset, lambda r: r == bmrev) | |
395 | else: |
|
395 | else: | |
396 | matchrevs = set() |
|
396 | matchrevs = set() | |
397 | for name, bmrev in repo._bookmarks.iteritems(): |
|
397 | for name, bmrev in repo._bookmarks.iteritems(): | |
398 | if matcher(name): |
|
398 | if matcher(name): | |
399 | matchrevs.add(bmrev) |
|
399 | matchrevs.add(bmrev) | |
400 | if not matchrevs: |
|
400 | if not matchrevs: | |
401 | raise util.Abort(_("no bookmarks exist that match '%s'") |
|
401 | raise util.Abort(_("no bookmarks exist that match '%s'") | |
402 | % pattern) |
|
402 | % pattern) | |
403 | bmrevs = set() |
|
403 | bmrevs = set() | |
404 | for bmrev in matchrevs: |
|
404 | for bmrev in matchrevs: | |
405 | bmrevs.add(repo[bmrev].rev()) |
|
405 | bmrevs.add(repo[bmrev].rev()) | |
406 | return subset & bmrevs |
|
406 | return subset & bmrevs | |
407 |
|
407 | |||
408 | bms = set([repo[r].rev() |
|
408 | bms = set([repo[r].rev() | |
409 | for r in repo._bookmarks.values()]) |
|
409 | for r in repo._bookmarks.values()]) | |
410 | return lazyset(subset, lambda r: r in bms) |
|
410 | return lazyset(subset, lambda r: r in bms) | |
411 |
|
411 | |||
412 | def branch(repo, subset, x): |
|
412 | def branch(repo, subset, x): | |
413 | """``branch(string or set)`` |
|
413 | """``branch(string or set)`` | |
414 | All changesets belonging to the given branch or the branches of the given |
|
414 | All changesets belonging to the given branch or the branches of the given | |
415 | changesets. |
|
415 | changesets. | |
416 |
|
416 | |||
417 | If `string` starts with `re:`, the remainder of the name is treated as |
|
417 | If `string` starts with `re:`, the remainder of the name is treated as | |
418 | a regular expression. To match a branch that actually starts with `re:`, |
|
418 | a regular expression. To match a branch that actually starts with `re:`, | |
419 | use the prefix `literal:`. |
|
419 | use the prefix `literal:`. | |
420 | """ |
|
420 | """ | |
421 | try: |
|
421 | try: | |
422 | b = getstring(x, '') |
|
422 | b = getstring(x, '') | |
423 | except error.ParseError: |
|
423 | except error.ParseError: | |
424 | # not a string, but another revspec, e.g. tip() |
|
424 | # not a string, but another revspec, e.g. tip() | |
425 | pass |
|
425 | pass | |
426 | else: |
|
426 | else: | |
427 | kind, pattern, matcher = _stringmatcher(b) |
|
427 | kind, pattern, matcher = _stringmatcher(b) | |
428 | if kind == 'literal': |
|
428 | if kind == 'literal': | |
429 | # note: falls through to the revspec case if no branch with |
|
429 | # note: falls through to the revspec case if no branch with | |
430 | # this name exists |
|
430 | # this name exists | |
431 | if pattern in repo.branchmap(): |
|
431 | if pattern in repo.branchmap(): | |
432 | return lazyset(subset, lambda r: matcher(repo[r].branch())) |
|
432 | return lazyset(subset, lambda r: matcher(repo[r].branch())) | |
433 | else: |
|
433 | else: | |
434 | return lazyset(subset, lambda r: matcher(repo[r].branch())) |
|
434 | return lazyset(subset, lambda r: matcher(repo[r].branch())) | |
435 |
|
435 | |||
436 | s = getset(repo, baseset(repo), x) |
|
436 | s = getset(repo, baseset(repo), x) | |
437 | b = set() |
|
437 | b = set() | |
438 | for r in s: |
|
438 | for r in s: | |
439 | b.add(repo[r].branch()) |
|
439 | b.add(repo[r].branch()) | |
440 | s = s.set() |
|
440 | s = s.set() | |
441 | return lazyset(subset, lambda r: r in s or repo[r].branch() in b) |
|
441 | return lazyset(subset, lambda r: r in s or repo[r].branch() in b) | |
442 |
|
442 | |||
443 | def bumped(repo, subset, x): |
|
443 | def bumped(repo, subset, x): | |
444 | """``bumped()`` |
|
444 | """``bumped()`` | |
445 | Mutable changesets marked as successors of public changesets. |
|
445 | Mutable changesets marked as successors of public changesets. | |
446 |
|
446 | |||
447 | Only non-public and non-obsolete changesets can be `bumped`. |
|
447 | Only non-public and non-obsolete changesets can be `bumped`. | |
448 | """ |
|
448 | """ | |
449 | # i18n: "bumped" is a keyword |
|
449 | # i18n: "bumped" is a keyword | |
450 | getargs(x, 0, 0, _("bumped takes no arguments")) |
|
450 | getargs(x, 0, 0, _("bumped takes no arguments")) | |
451 | bumped = obsmod.getrevs(repo, 'bumped') |
|
451 | bumped = obsmod.getrevs(repo, 'bumped') | |
452 | return subset & bumped |
|
452 | return subset & bumped | |
453 |
|
453 | |||
454 | def bundle(repo, subset, x): |
|
454 | def bundle(repo, subset, x): | |
455 | """``bundle()`` |
|
455 | """``bundle()`` | |
456 | Changesets in the bundle. |
|
456 | Changesets in the bundle. | |
457 |
|
457 | |||
458 | Bundle must be specified by the -R option.""" |
|
458 | Bundle must be specified by the -R option.""" | |
459 |
|
459 | |||
460 | try: |
|
460 | try: | |
461 | bundlerevs = repo.changelog.bundlerevs |
|
461 | bundlerevs = repo.changelog.bundlerevs | |
462 | except AttributeError: |
|
462 | except AttributeError: | |
463 | raise util.Abort(_("no bundle provided - specify with -R")) |
|
463 | raise util.Abort(_("no bundle provided - specify with -R")) | |
464 | return subset & bundlerevs |
|
464 | return subset & bundlerevs | |
465 |
|
465 | |||
466 | def checkstatus(repo, subset, pat, field): |
|
466 | def checkstatus(repo, subset, pat, field): | |
467 | hasset = matchmod.patkind(pat) == 'set' |
|
467 | hasset = matchmod.patkind(pat) == 'set' | |
468 |
|
468 | |||
469 | def matches(x): |
|
469 | def matches(x): | |
470 | m = None |
|
470 | m = None | |
471 | fname = None |
|
471 | fname = None | |
472 | c = repo[x] |
|
472 | c = repo[x] | |
473 | if not m or hasset: |
|
473 | if not m or hasset: | |
474 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) |
|
474 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) | |
475 | if not m.anypats() and len(m.files()) == 1: |
|
475 | if not m.anypats() and len(m.files()) == 1: | |
476 | fname = m.files()[0] |
|
476 | fname = m.files()[0] | |
477 | if fname is not None: |
|
477 | if fname is not None: | |
478 | if fname not in c.files(): |
|
478 | if fname not in c.files(): | |
479 | return False |
|
479 | return False | |
480 | else: |
|
480 | else: | |
481 | for f in c.files(): |
|
481 | for f in c.files(): | |
482 | if m(f): |
|
482 | if m(f): | |
483 | break |
|
483 | break | |
484 | else: |
|
484 | else: | |
485 | return False |
|
485 | return False | |
486 | files = repo.status(c.p1().node(), c.node())[field] |
|
486 | files = repo.status(c.p1().node(), c.node())[field] | |
487 | if fname is not None: |
|
487 | if fname is not None: | |
488 | if fname in files: |
|
488 | if fname in files: | |
489 | return True |
|
489 | return True | |
490 | else: |
|
490 | else: | |
491 | for f in files: |
|
491 | for f in files: | |
492 | if m(f): |
|
492 | if m(f): | |
493 | return True |
|
493 | return True | |
494 |
|
494 | |||
495 | return lazyset(subset, matches) |
|
495 | return lazyset(subset, matches) | |
496 |
|
496 | |||
497 | def _children(repo, narrow, parentset): |
|
497 | def _children(repo, narrow, parentset): | |
498 | cs = set() |
|
498 | cs = set() | |
499 | if not parentset: |
|
499 | if not parentset: | |
500 | return baseset(cs) |
|
500 | return baseset(cs) | |
501 | pr = repo.changelog.parentrevs |
|
501 | pr = repo.changelog.parentrevs | |
502 | minrev = min(parentset) |
|
502 | minrev = min(parentset) | |
503 | for r in narrow: |
|
503 | for r in narrow: | |
504 | if r <= minrev: |
|
504 | if r <= minrev: | |
505 | continue |
|
505 | continue | |
506 | for p in pr(r): |
|
506 | for p in pr(r): | |
507 | if p in parentset: |
|
507 | if p in parentset: | |
508 | cs.add(r) |
|
508 | cs.add(r) | |
509 | return baseset(cs) |
|
509 | return baseset(cs) | |
510 |
|
510 | |||
511 | def children(repo, subset, x): |
|
511 | def children(repo, subset, x): | |
512 | """``children(set)`` |
|
512 | """``children(set)`` | |
513 | Child changesets of changesets in set. |
|
513 | Child changesets of changesets in set. | |
514 | """ |
|
514 | """ | |
515 | s = getset(repo, baseset(repo), x).set() |
|
515 | s = getset(repo, baseset(repo), x).set() | |
516 | cs = _children(repo, subset, s) |
|
516 | cs = _children(repo, subset, s) | |
517 | return subset & cs |
|
517 | return subset & cs | |
518 |
|
518 | |||
519 | def closed(repo, subset, x): |
|
519 | def closed(repo, subset, x): | |
520 | """``closed()`` |
|
520 | """``closed()`` | |
521 | Changeset is closed. |
|
521 | Changeset is closed. | |
522 | """ |
|
522 | """ | |
523 | # i18n: "closed" is a keyword |
|
523 | # i18n: "closed" is a keyword | |
524 | getargs(x, 0, 0, _("closed takes no arguments")) |
|
524 | getargs(x, 0, 0, _("closed takes no arguments")) | |
525 | return lazyset(subset, lambda r: repo[r].closesbranch()) |
|
525 | return lazyset(subset, lambda r: repo[r].closesbranch()) | |
526 |
|
526 | |||
527 | def contains(repo, subset, x): |
|
527 | def contains(repo, subset, x): | |
528 | """``contains(pattern)`` |
|
528 | """``contains(pattern)`` | |
529 | Revision contains a file matching pattern. See :hg:`help patterns` |
|
529 | Revision contains a file matching pattern. See :hg:`help patterns` | |
530 | for information about file patterns. |
|
530 | for information about file patterns. | |
531 |
|
531 | |||
532 | The pattern without explicit kind like ``glob:`` is expected to be |
|
532 | The pattern without explicit kind like ``glob:`` is expected to be | |
533 | relative to the current directory and match against a file exactly |
|
533 | relative to the current directory and match against a file exactly | |
534 | for efficiency. |
|
534 | for efficiency. | |
535 | """ |
|
535 | """ | |
536 | # i18n: "contains" is a keyword |
|
536 | # i18n: "contains" is a keyword | |
537 | pat = getstring(x, _("contains requires a pattern")) |
|
537 | pat = getstring(x, _("contains requires a pattern")) | |
538 |
|
538 | |||
539 | def matches(x): |
|
539 | def matches(x): | |
540 | if not matchmod.patkind(pat): |
|
540 | if not matchmod.patkind(pat): | |
541 | pats = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
541 | pats = pathutil.canonpath(repo.root, repo.getcwd(), pat) | |
542 | if pats in repo[x]: |
|
542 | if pats in repo[x]: | |
543 | return True |
|
543 | return True | |
544 | else: |
|
544 | else: | |
545 | c = repo[x] |
|
545 | c = repo[x] | |
546 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) |
|
546 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) | |
547 | for f in c.manifest(): |
|
547 | for f in c.manifest(): | |
548 | if m(f): |
|
548 | if m(f): | |
549 | return True |
|
549 | return True | |
550 | return False |
|
550 | return False | |
551 |
|
551 | |||
552 | return lazyset(subset, matches) |
|
552 | return lazyset(subset, matches) | |
553 |
|
553 | |||
554 | def converted(repo, subset, x): |
|
554 | def converted(repo, subset, x): | |
555 | """``converted([id])`` |
|
555 | """``converted([id])`` | |
556 | Changesets converted from the given identifier in the old repository if |
|
556 | Changesets converted from the given identifier in the old repository if | |
557 | present, or all converted changesets if no identifier is specified. |
|
557 | present, or all converted changesets if no identifier is specified. | |
558 | """ |
|
558 | """ | |
559 |
|
559 | |||
560 | # There is exactly no chance of resolving the revision, so do a simple |
|
560 | # There is exactly no chance of resolving the revision, so do a simple | |
561 | # string compare and hope for the best |
|
561 | # string compare and hope for the best | |
562 |
|
562 | |||
563 | rev = None |
|
563 | rev = None | |
564 | # i18n: "converted" is a keyword |
|
564 | # i18n: "converted" is a keyword | |
565 | l = getargs(x, 0, 1, _('converted takes one or no arguments')) |
|
565 | l = getargs(x, 0, 1, _('converted takes one or no arguments')) | |
566 | if l: |
|
566 | if l: | |
567 | # i18n: "converted" is a keyword |
|
567 | # i18n: "converted" is a keyword | |
568 | rev = getstring(l[0], _('converted requires a revision')) |
|
568 | rev = getstring(l[0], _('converted requires a revision')) | |
569 |
|
569 | |||
570 | def _matchvalue(r): |
|
570 | def _matchvalue(r): | |
571 | source = repo[r].extra().get('convert_revision', None) |
|
571 | source = repo[r].extra().get('convert_revision', None) | |
572 | return source is not None and (rev is None or source.startswith(rev)) |
|
572 | return source is not None and (rev is None or source.startswith(rev)) | |
573 |
|
573 | |||
574 | return lazyset(subset, lambda r: _matchvalue(r)) |
|
574 | return lazyset(subset, lambda r: _matchvalue(r)) | |
575 |
|
575 | |||
576 | def date(repo, subset, x): |
|
576 | def date(repo, subset, x): | |
577 | """``date(interval)`` |
|
577 | """``date(interval)`` | |
578 | Changesets within the interval, see :hg:`help dates`. |
|
578 | Changesets within the interval, see :hg:`help dates`. | |
579 | """ |
|
579 | """ | |
580 | # i18n: "date" is a keyword |
|
580 | # i18n: "date" is a keyword | |
581 | ds = getstring(x, _("date requires a string")) |
|
581 | ds = getstring(x, _("date requires a string")) | |
582 | dm = util.matchdate(ds) |
|
582 | dm = util.matchdate(ds) | |
583 | return lazyset(subset, lambda x: dm(repo[x].date()[0])) |
|
583 | return lazyset(subset, lambda x: dm(repo[x].date()[0])) | |
584 |
|
584 | |||
585 | def desc(repo, subset, x): |
|
585 | def desc(repo, subset, x): | |
586 | """``desc(string)`` |
|
586 | """``desc(string)`` | |
587 | Search commit message for string. The match is case-insensitive. |
|
587 | Search commit message for string. The match is case-insensitive. | |
588 | """ |
|
588 | """ | |
589 | # i18n: "desc" is a keyword |
|
589 | # i18n: "desc" is a keyword | |
590 | ds = encoding.lower(getstring(x, _("desc requires a string"))) |
|
590 | ds = encoding.lower(getstring(x, _("desc requires a string"))) | |
591 |
|
591 | |||
592 | def matches(x): |
|
592 | def matches(x): | |
593 | c = repo[x] |
|
593 | c = repo[x] | |
594 | return ds in encoding.lower(c.description()) |
|
594 | return ds in encoding.lower(c.description()) | |
595 |
|
595 | |||
596 | return lazyset(subset, matches) |
|
596 | return lazyset(subset, matches) | |
597 |
|
597 | |||
598 | def _descendants(repo, subset, x, followfirst=False): |
|
598 | def _descendants(repo, subset, x, followfirst=False): | |
599 | args = getset(repo, baseset(repo), x) |
|
599 | args = getset(repo, baseset(repo), x) | |
600 | if not args: |
|
600 | if not args: | |
601 | return baseset([]) |
|
601 | return baseset([]) | |
602 | s = set(_revdescendants(repo, args, followfirst)) | set(args) |
|
602 | s = set(_revdescendants(repo, args, followfirst)) | set(args) | |
603 | return baseset([r for r in subset if r in s]) |
|
603 | return baseset([r for r in subset if r in s]) | |
604 |
|
604 | |||
605 | def descendants(repo, subset, x): |
|
605 | def descendants(repo, subset, x): | |
606 | """``descendants(set)`` |
|
606 | """``descendants(set)`` | |
607 | Changesets which are descendants of changesets in set. |
|
607 | Changesets which are descendants of changesets in set. | |
608 | """ |
|
608 | """ | |
609 | return _descendants(repo, subset, x) |
|
609 | return _descendants(repo, subset, x) | |
610 |
|
610 | |||
611 | def _firstdescendants(repo, subset, x): |
|
611 | def _firstdescendants(repo, subset, x): | |
612 | # ``_firstdescendants(set)`` |
|
612 | # ``_firstdescendants(set)`` | |
613 | # Like ``descendants(set)`` but follows only the first parents. |
|
613 | # Like ``descendants(set)`` but follows only the first parents. | |
614 | return _descendants(repo, subset, x, followfirst=True) |
|
614 | return _descendants(repo, subset, x, followfirst=True) | |
615 |
|
615 | |||
616 | def destination(repo, subset, x): |
|
616 | def destination(repo, subset, x): | |
617 | """``destination([set])`` |
|
617 | """``destination([set])`` | |
618 | Changesets that were created by a graft, transplant or rebase operation, |
|
618 | Changesets that were created by a graft, transplant or rebase operation, | |
619 | with the given revisions specified as the source. Omitting the optional set |
|
619 | with the given revisions specified as the source. Omitting the optional set | |
620 | is the same as passing all(). |
|
620 | is the same as passing all(). | |
621 | """ |
|
621 | """ | |
622 | if x is not None: |
|
622 | if x is not None: | |
623 | args = getset(repo, baseset(repo), x).set() |
|
623 | args = getset(repo, baseset(repo), x).set() | |
624 | else: |
|
624 | else: | |
625 | args = getall(repo, baseset(repo), x).set() |
|
625 | args = getall(repo, baseset(repo), x).set() | |
626 |
|
626 | |||
627 | dests = set() |
|
627 | dests = set() | |
628 |
|
628 | |||
629 | # subset contains all of the possible destinations that can be returned, so |
|
629 | # subset contains all of the possible destinations that can be returned, so | |
630 | # iterate over them and see if their source(s) were provided in the args. |
|
630 | # iterate over them and see if their source(s) were provided in the args. | |
631 | # Even if the immediate src of r is not in the args, src's source (or |
|
631 | # Even if the immediate src of r is not in the args, src's source (or | |
632 | # further back) may be. Scanning back further than the immediate src allows |
|
632 | # further back) may be. Scanning back further than the immediate src allows | |
633 | # transitive transplants and rebases to yield the same results as transitive |
|
633 | # transitive transplants and rebases to yield the same results as transitive | |
634 | # grafts. |
|
634 | # grafts. | |
635 | for r in subset: |
|
635 | for r in subset: | |
636 | src = _getrevsource(repo, r) |
|
636 | src = _getrevsource(repo, r) | |
637 | lineage = None |
|
637 | lineage = None | |
638 |
|
638 | |||
639 | while src is not None: |
|
639 | while src is not None: | |
640 | if lineage is None: |
|
640 | if lineage is None: | |
641 | lineage = list() |
|
641 | lineage = list() | |
642 |
|
642 | |||
643 | lineage.append(r) |
|
643 | lineage.append(r) | |
644 |
|
644 | |||
645 | # The visited lineage is a match if the current source is in the arg |
|
645 | # The visited lineage is a match if the current source is in the arg | |
646 | # set. Since every candidate dest is visited by way of iterating |
|
646 | # set. Since every candidate dest is visited by way of iterating | |
647 | # subset, any dests further back in the lineage will be tested by a |
|
647 | # subset, any dests further back in the lineage will be tested by a | |
648 | # different iteration over subset. Likewise, if the src was already |
|
648 | # different iteration over subset. Likewise, if the src was already | |
649 | # selected, the current lineage can be selected without going back |
|
649 | # selected, the current lineage can be selected without going back | |
650 | # further. |
|
650 | # further. | |
651 | if src in args or src in dests: |
|
651 | if src in args or src in dests: | |
652 | dests.update(lineage) |
|
652 | dests.update(lineage) | |
653 | break |
|
653 | break | |
654 |
|
654 | |||
655 | r = src |
|
655 | r = src | |
656 | src = _getrevsource(repo, r) |
|
656 | src = _getrevsource(repo, r) | |
657 |
|
657 | |||
658 | return baseset([r for r in subset if r in dests]) |
|
658 | return baseset([r for r in subset if r in dests]) | |
659 |
|
659 | |||
660 | def divergent(repo, subset, x): |
|
660 | def divergent(repo, subset, x): | |
661 | """``divergent()`` |
|
661 | """``divergent()`` | |
662 | Final successors of changesets with an alternative set of final successors. |
|
662 | Final successors of changesets with an alternative set of final successors. | |
663 | """ |
|
663 | """ | |
664 | # i18n: "divergent" is a keyword |
|
664 | # i18n: "divergent" is a keyword | |
665 | getargs(x, 0, 0, _("divergent takes no arguments")) |
|
665 | getargs(x, 0, 0, _("divergent takes no arguments")) | |
666 | divergent = obsmod.getrevs(repo, 'divergent') |
|
666 | divergent = obsmod.getrevs(repo, 'divergent') | |
667 | return baseset([r for r in subset if r in divergent]) |
|
667 | return baseset([r for r in subset if r in divergent]) | |
668 |
|
668 | |||
669 | def draft(repo, subset, x): |
|
669 | def draft(repo, subset, x): | |
670 | """``draft()`` |
|
670 | """``draft()`` | |
671 | Changeset in draft phase.""" |
|
671 | Changeset in draft phase.""" | |
672 | # i18n: "draft" is a keyword |
|
672 | # i18n: "draft" is a keyword | |
673 | getargs(x, 0, 0, _("draft takes no arguments")) |
|
673 | getargs(x, 0, 0, _("draft takes no arguments")) | |
674 | pc = repo._phasecache |
|
674 | pc = repo._phasecache | |
675 | return lazyset(subset, lambda r: pc.phase(repo, r) == phases.draft) |
|
675 | return lazyset(subset, lambda r: pc.phase(repo, r) == phases.draft) | |
676 |
|
676 | |||
677 | def extinct(repo, subset, x): |
|
677 | def extinct(repo, subset, x): | |
678 | """``extinct()`` |
|
678 | """``extinct()`` | |
679 | Obsolete changesets with obsolete descendants only. |
|
679 | Obsolete changesets with obsolete descendants only. | |
680 | """ |
|
680 | """ | |
681 | # i18n: "extinct" is a keyword |
|
681 | # i18n: "extinct" is a keyword | |
682 | getargs(x, 0, 0, _("extinct takes no arguments")) |
|
682 | getargs(x, 0, 0, _("extinct takes no arguments")) | |
683 | extincts = obsmod.getrevs(repo, 'extinct') |
|
683 | extincts = obsmod.getrevs(repo, 'extinct') | |
684 | return subset & extincts |
|
684 | return subset & extincts | |
685 |
|
685 | |||
686 | def extra(repo, subset, x): |
|
686 | def extra(repo, subset, x): | |
687 | """``extra(label, [value])`` |
|
687 | """``extra(label, [value])`` | |
688 | Changesets with the given label in the extra metadata, with the given |
|
688 | Changesets with the given label in the extra metadata, with the given | |
689 | optional value. |
|
689 | optional value. | |
690 |
|
690 | |||
691 | If `value` starts with `re:`, the remainder of the value is treated as |
|
691 | If `value` starts with `re:`, the remainder of the value is treated as | |
692 | a regular expression. To match a value that actually starts with `re:`, |
|
692 | a regular expression. To match a value that actually starts with `re:`, | |
693 | use the prefix `literal:`. |
|
693 | use the prefix `literal:`. | |
694 | """ |
|
694 | """ | |
695 |
|
695 | |||
696 | # i18n: "extra" is a keyword |
|
696 | # i18n: "extra" is a keyword | |
697 | l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments')) |
|
697 | l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments')) | |
698 | # i18n: "extra" is a keyword |
|
698 | # i18n: "extra" is a keyword | |
699 | label = getstring(l[0], _('first argument to extra must be a string')) |
|
699 | label = getstring(l[0], _('first argument to extra must be a string')) | |
700 | value = None |
|
700 | value = None | |
701 |
|
701 | |||
702 | if len(l) > 1: |
|
702 | if len(l) > 1: | |
703 | # i18n: "extra" is a keyword |
|
703 | # i18n: "extra" is a keyword | |
704 | value = getstring(l[1], _('second argument to extra must be a string')) |
|
704 | value = getstring(l[1], _('second argument to extra must be a string')) | |
705 | kind, value, matcher = _stringmatcher(value) |
|
705 | kind, value, matcher = _stringmatcher(value) | |
706 |
|
706 | |||
707 | def _matchvalue(r): |
|
707 | def _matchvalue(r): | |
708 | extra = repo[r].extra() |
|
708 | extra = repo[r].extra() | |
709 | return label in extra and (value is None or matcher(extra[label])) |
|
709 | return label in extra and (value is None or matcher(extra[label])) | |
710 |
|
710 | |||
711 | return lazyset(subset, lambda r: _matchvalue(r)) |
|
711 | return lazyset(subset, lambda r: _matchvalue(r)) | |
712 |
|
712 | |||
713 | def filelog(repo, subset, x): |
|
713 | def filelog(repo, subset, x): | |
714 | """``filelog(pattern)`` |
|
714 | """``filelog(pattern)`` | |
715 | Changesets connected to the specified filelog. |
|
715 | Changesets connected to the specified filelog. | |
716 |
|
716 | |||
717 | For performance reasons, ``filelog()`` does not show every changeset |
|
717 | For performance reasons, ``filelog()`` does not show every changeset | |
718 | that affects the requested file(s). See :hg:`help log` for details. For |
|
718 | that affects the requested file(s). See :hg:`help log` for details. For | |
719 | a slower, more accurate result, use ``file()``. |
|
719 | a slower, more accurate result, use ``file()``. | |
720 |
|
720 | |||
721 | The pattern without explicit kind like ``glob:`` is expected to be |
|
721 | The pattern without explicit kind like ``glob:`` is expected to be | |
722 | relative to the current directory and match against a file exactly |
|
722 | relative to the current directory and match against a file exactly | |
723 | for efficiency. |
|
723 | for efficiency. | |
724 | """ |
|
724 | """ | |
725 |
|
725 | |||
726 | # i18n: "filelog" is a keyword |
|
726 | # i18n: "filelog" is a keyword | |
727 | pat = getstring(x, _("filelog requires a pattern")) |
|
727 | pat = getstring(x, _("filelog requires a pattern")) | |
728 | s = set() |
|
728 | s = set() | |
729 |
|
729 | |||
730 | if not matchmod.patkind(pat): |
|
730 | if not matchmod.patkind(pat): | |
731 | f = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
731 | f = pathutil.canonpath(repo.root, repo.getcwd(), pat) | |
732 | fl = repo.file(f) |
|
732 | fl = repo.file(f) | |
733 | for fr in fl: |
|
733 | for fr in fl: | |
734 | s.add(fl.linkrev(fr)) |
|
734 | s.add(fl.linkrev(fr)) | |
735 | else: |
|
735 | else: | |
736 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None]) |
|
736 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None]) | |
737 | for f in repo[None]: |
|
737 | for f in repo[None]: | |
738 | if m(f): |
|
738 | if m(f): | |
739 | fl = repo.file(f) |
|
739 | fl = repo.file(f) | |
740 | for fr in fl: |
|
740 | for fr in fl: | |
741 | s.add(fl.linkrev(fr)) |
|
741 | s.add(fl.linkrev(fr)) | |
742 |
|
742 | |||
743 | return baseset([r for r in subset if r in s]) |
|
743 | return baseset([r for r in subset if r in s]) | |
744 |
|
744 | |||
745 | def first(repo, subset, x): |
|
745 | def first(repo, subset, x): | |
746 | """``first(set, [n])`` |
|
746 | """``first(set, [n])`` | |
747 | An alias for limit(). |
|
747 | An alias for limit(). | |
748 | """ |
|
748 | """ | |
749 | return limit(repo, subset, x) |
|
749 | return limit(repo, subset, x) | |
750 |
|
750 | |||
751 | def _follow(repo, subset, x, name, followfirst=False): |
|
751 | def _follow(repo, subset, x, name, followfirst=False): | |
752 | l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name) |
|
752 | l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name) | |
753 | c = repo['.'] |
|
753 | c = repo['.'] | |
754 | if l: |
|
754 | if l: | |
755 | x = getstring(l[0], _("%s expected a filename") % name) |
|
755 | x = getstring(l[0], _("%s expected a filename") % name) | |
756 | if x in c: |
|
756 | if x in c: | |
757 | cx = c[x] |
|
757 | cx = c[x] | |
758 | s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst)) |
|
758 | s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst)) | |
759 | # include the revision responsible for the most recent version |
|
759 | # include the revision responsible for the most recent version | |
760 | s.add(cx.linkrev()) |
|
760 | s.add(cx.linkrev()) | |
761 | else: |
|
761 | else: | |
762 | return baseset([]) |
|
762 | return baseset([]) | |
763 | else: |
|
763 | else: | |
764 | s = set(_revancestors(repo, [c.rev()], followfirst)) | set([c.rev()]) |
|
764 | s = set(_revancestors(repo, [c.rev()], followfirst)) | set([c.rev()]) | |
765 |
|
765 | |||
766 | return baseset([r for r in subset if r in s]) |
|
766 | return baseset([r for r in subset if r in s]) | |
767 |
|
767 | |||
768 | def follow(repo, subset, x): |
|
768 | def follow(repo, subset, x): | |
769 | """``follow([file])`` |
|
769 | """``follow([file])`` | |
770 | An alias for ``::.`` (ancestors of the working copy's first parent). |
|
770 | An alias for ``::.`` (ancestors of the working copy's first parent). | |
771 | If a filename is specified, the history of the given file is followed, |
|
771 | If a filename is specified, the history of the given file is followed, | |
772 | including copies. |
|
772 | including copies. | |
773 | """ |
|
773 | """ | |
774 | return _follow(repo, subset, x, 'follow') |
|
774 | return _follow(repo, subset, x, 'follow') | |
775 |
|
775 | |||
776 | def _followfirst(repo, subset, x): |
|
776 | def _followfirst(repo, subset, x): | |
777 | # ``followfirst([file])`` |
|
777 | # ``followfirst([file])`` | |
778 | # Like ``follow([file])`` but follows only the first parent of |
|
778 | # Like ``follow([file])`` but follows only the first parent of | |
779 | # every revision or file revision. |
|
779 | # every revision or file revision. | |
780 | return _follow(repo, subset, x, '_followfirst', followfirst=True) |
|
780 | return _follow(repo, subset, x, '_followfirst', followfirst=True) | |
781 |
|
781 | |||
782 | def getall(repo, subset, x): |
|
782 | def getall(repo, subset, x): | |
783 | """``all()`` |
|
783 | """``all()`` | |
784 | All changesets, the same as ``0:tip``. |
|
784 | All changesets, the same as ``0:tip``. | |
785 | """ |
|
785 | """ | |
786 | # i18n: "all" is a keyword |
|
786 | # i18n: "all" is a keyword | |
787 | getargs(x, 0, 0, _("all takes no arguments")) |
|
787 | getargs(x, 0, 0, _("all takes no arguments")) | |
788 | return subset |
|
788 | return subset | |
789 |
|
789 | |||
790 | def grep(repo, subset, x): |
|
790 | def grep(repo, subset, x): | |
791 | """``grep(regex)`` |
|
791 | """``grep(regex)`` | |
792 | Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` |
|
792 | Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` | |
793 | to ensure special escape characters are handled correctly. Unlike |
|
793 | to ensure special escape characters are handled correctly. Unlike | |
794 | ``keyword(string)``, the match is case-sensitive. |
|
794 | ``keyword(string)``, the match is case-sensitive. | |
795 | """ |
|
795 | """ | |
796 | try: |
|
796 | try: | |
797 | # i18n: "grep" is a keyword |
|
797 | # i18n: "grep" is a keyword | |
798 | gr = re.compile(getstring(x, _("grep requires a string"))) |
|
798 | gr = re.compile(getstring(x, _("grep requires a string"))) | |
799 | except re.error, e: |
|
799 | except re.error, e: | |
800 | raise error.ParseError(_('invalid match pattern: %s') % e) |
|
800 | raise error.ParseError(_('invalid match pattern: %s') % e) | |
801 |
|
801 | |||
802 | def matches(x): |
|
802 | def matches(x): | |
803 | c = repo[x] |
|
803 | c = repo[x] | |
804 | for e in c.files() + [c.user(), c.description()]: |
|
804 | for e in c.files() + [c.user(), c.description()]: | |
805 | if gr.search(e): |
|
805 | if gr.search(e): | |
806 | return True |
|
806 | return True | |
807 | return False |
|
807 | return False | |
808 |
|
808 | |||
809 | return lazyset(subset, matches) |
|
809 | return lazyset(subset, matches) | |
810 |
|
810 | |||
811 | def _matchfiles(repo, subset, x): |
|
811 | def _matchfiles(repo, subset, x): | |
812 | # _matchfiles takes a revset list of prefixed arguments: |
|
812 | # _matchfiles takes a revset list of prefixed arguments: | |
813 | # |
|
813 | # | |
814 | # [p:foo, i:bar, x:baz] |
|
814 | # [p:foo, i:bar, x:baz] | |
815 | # |
|
815 | # | |
816 | # builds a match object from them and filters subset. Allowed |
|
816 | # builds a match object from them and filters subset. Allowed | |
817 | # prefixes are 'p:' for regular patterns, 'i:' for include |
|
817 | # prefixes are 'p:' for regular patterns, 'i:' for include | |
818 | # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass |
|
818 | # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass | |
819 | # a revision identifier, or the empty string to reference the |
|
819 | # a revision identifier, or the empty string to reference the | |
820 | # working directory, from which the match object is |
|
820 | # working directory, from which the match object is | |
821 | # initialized. Use 'd:' to set the default matching mode, default |
|
821 | # initialized. Use 'd:' to set the default matching mode, default | |
822 | # to 'glob'. At most one 'r:' and 'd:' argument can be passed. |
|
822 | # to 'glob'. At most one 'r:' and 'd:' argument can be passed. | |
823 |
|
823 | |||
824 | # i18n: "_matchfiles" is a keyword |
|
824 | # i18n: "_matchfiles" is a keyword | |
825 | l = getargs(x, 1, -1, _("_matchfiles requires at least one argument")) |
|
825 | l = getargs(x, 1, -1, _("_matchfiles requires at least one argument")) | |
826 | pats, inc, exc = [], [], [] |
|
826 | pats, inc, exc = [], [], [] | |
827 | hasset = False |
|
827 | hasset = False | |
828 | rev, default = None, None |
|
828 | rev, default = None, None | |
829 | for arg in l: |
|
829 | for arg in l: | |
830 | # i18n: "_matchfiles" is a keyword |
|
830 | # i18n: "_matchfiles" is a keyword | |
831 | s = getstring(arg, _("_matchfiles requires string arguments")) |
|
831 | s = getstring(arg, _("_matchfiles requires string arguments")) | |
832 | prefix, value = s[:2], s[2:] |
|
832 | prefix, value = s[:2], s[2:] | |
833 | if prefix == 'p:': |
|
833 | if prefix == 'p:': | |
834 | pats.append(value) |
|
834 | pats.append(value) | |
835 | elif prefix == 'i:': |
|
835 | elif prefix == 'i:': | |
836 | inc.append(value) |
|
836 | inc.append(value) | |
837 | elif prefix == 'x:': |
|
837 | elif prefix == 'x:': | |
838 | exc.append(value) |
|
838 | exc.append(value) | |
839 | elif prefix == 'r:': |
|
839 | elif prefix == 'r:': | |
840 | if rev is not None: |
|
840 | if rev is not None: | |
841 | # i18n: "_matchfiles" is a keyword |
|
841 | # i18n: "_matchfiles" is a keyword | |
842 | raise error.ParseError(_('_matchfiles expected at most one ' |
|
842 | raise error.ParseError(_('_matchfiles expected at most one ' | |
843 | 'revision')) |
|
843 | 'revision')) | |
844 | rev = value |
|
844 | rev = value | |
845 | elif prefix == 'd:': |
|
845 | elif prefix == 'd:': | |
846 | if default is not None: |
|
846 | if default is not None: | |
847 | # i18n: "_matchfiles" is a keyword |
|
847 | # i18n: "_matchfiles" is a keyword | |
848 | raise error.ParseError(_('_matchfiles expected at most one ' |
|
848 | raise error.ParseError(_('_matchfiles expected at most one ' | |
849 | 'default mode')) |
|
849 | 'default mode')) | |
850 | default = value |
|
850 | default = value | |
851 | else: |
|
851 | else: | |
852 | # i18n: "_matchfiles" is a keyword |
|
852 | # i18n: "_matchfiles" is a keyword | |
853 | raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix) |
|
853 | raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix) | |
854 | if not hasset and matchmod.patkind(value) == 'set': |
|
854 | if not hasset and matchmod.patkind(value) == 'set': | |
855 | hasset = True |
|
855 | hasset = True | |
856 | if not default: |
|
856 | if not default: | |
857 | default = 'glob' |
|
857 | default = 'glob' | |
858 |
|
858 | |||
859 | def matches(x): |
|
859 | def matches(x): | |
860 | m = None |
|
860 | m = None | |
861 | c = repo[x] |
|
861 | c = repo[x] | |
862 | if not m or (hasset and rev is None): |
|
862 | if not m or (hasset and rev is None): | |
863 | ctx = c |
|
863 | ctx = c | |
864 | if rev is not None: |
|
864 | if rev is not None: | |
865 | ctx = repo[rev or None] |
|
865 | ctx = repo[rev or None] | |
866 | m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, |
|
866 | m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, | |
867 | exclude=exc, ctx=ctx, default=default) |
|
867 | exclude=exc, ctx=ctx, default=default) | |
868 | for f in c.files(): |
|
868 | for f in c.files(): | |
869 | if m(f): |
|
869 | if m(f): | |
870 | return True |
|
870 | return True | |
871 | return False |
|
871 | return False | |
872 |
|
872 | |||
873 | return lazyset(subset, matches) |
|
873 | return lazyset(subset, matches) | |
874 |
|
874 | |||
875 | def hasfile(repo, subset, x): |
|
875 | def hasfile(repo, subset, x): | |
876 | """``file(pattern)`` |
|
876 | """``file(pattern)`` | |
877 | Changesets affecting files matched by pattern. |
|
877 | Changesets affecting files matched by pattern. | |
878 |
|
878 | |||
879 | For a faster but less accurate result, consider using ``filelog()`` |
|
879 | For a faster but less accurate result, consider using ``filelog()`` | |
880 | instead. |
|
880 | instead. | |
881 |
|
881 | |||
882 | This predicate uses ``glob:`` as the default kind of pattern. |
|
882 | This predicate uses ``glob:`` as the default kind of pattern. | |
883 | """ |
|
883 | """ | |
884 | # i18n: "file" is a keyword |
|
884 | # i18n: "file" is a keyword | |
885 | pat = getstring(x, _("file requires a pattern")) |
|
885 | pat = getstring(x, _("file requires a pattern")) | |
886 | return _matchfiles(repo, subset, ('string', 'p:' + pat)) |
|
886 | return _matchfiles(repo, subset, ('string', 'p:' + pat)) | |
887 |
|
887 | |||
888 | def head(repo, subset, x): |
|
888 | def head(repo, subset, x): | |
889 | """``head()`` |
|
889 | """``head()`` | |
890 | Changeset is a named branch head. |
|
890 | Changeset is a named branch head. | |
891 | """ |
|
891 | """ | |
892 | # i18n: "head" is a keyword |
|
892 | # i18n: "head" is a keyword | |
893 | getargs(x, 0, 0, _("head takes no arguments")) |
|
893 | getargs(x, 0, 0, _("head takes no arguments")) | |
894 | hs = set() |
|
894 | hs = set() | |
895 | for b, ls in repo.branchmap().iteritems(): |
|
895 | for b, ls in repo.branchmap().iteritems(): | |
896 | hs.update(repo[h].rev() for h in ls) |
|
896 | hs.update(repo[h].rev() for h in ls) | |
897 | return baseset([r for r in subset if r in hs]) |
|
897 | return baseset([r for r in subset if r in hs]) | |
898 |
|
898 | |||
899 | def heads(repo, subset, x): |
|
899 | def heads(repo, subset, x): | |
900 | """``heads(set)`` |
|
900 | """``heads(set)`` | |
901 | Members of set with no children in set. |
|
901 | Members of set with no children in set. | |
902 | """ |
|
902 | """ | |
903 | s = getset(repo, subset, x) |
|
903 | s = getset(repo, subset, x) | |
904 | ps = parents(repo, subset, x) |
|
904 | ps = parents(repo, subset, x) | |
905 | return s - ps |
|
905 | return s - ps | |
906 |
|
906 | |||
907 | def hidden(repo, subset, x): |
|
907 | def hidden(repo, subset, x): | |
908 | """``hidden()`` |
|
908 | """``hidden()`` | |
909 | Hidden changesets. |
|
909 | Hidden changesets. | |
910 | """ |
|
910 | """ | |
911 | # i18n: "hidden" is a keyword |
|
911 | # i18n: "hidden" is a keyword | |
912 | getargs(x, 0, 0, _("hidden takes no arguments")) |
|
912 | getargs(x, 0, 0, _("hidden takes no arguments")) | |
913 | hiddenrevs = repoview.filterrevs(repo, 'visible') |
|
913 | hiddenrevs = repoview.filterrevs(repo, 'visible') | |
914 | return subset & hiddenrevs |
|
914 | return subset & hiddenrevs | |
915 |
|
915 | |||
916 | def keyword(repo, subset, x): |
|
916 | def keyword(repo, subset, x): | |
917 | """``keyword(string)`` |
|
917 | """``keyword(string)`` | |
918 | Search commit message, user name, and names of changed files for |
|
918 | Search commit message, user name, and names of changed files for | |
919 | string. The match is case-insensitive. |
|
919 | string. The match is case-insensitive. | |
920 | """ |
|
920 | """ | |
921 | # i18n: "keyword" is a keyword |
|
921 | # i18n: "keyword" is a keyword | |
922 | kw = encoding.lower(getstring(x, _("keyword requires a string"))) |
|
922 | kw = encoding.lower(getstring(x, _("keyword requires a string"))) | |
923 |
|
923 | |||
924 | def matches(r): |
|
924 | def matches(r): | |
925 | c = repo[r] |
|
925 | c = repo[r] | |
926 | return util.any(kw in encoding.lower(t) for t in c.files() + [c.user(), |
|
926 | return util.any(kw in encoding.lower(t) for t in c.files() + [c.user(), | |
927 | c.description()]) |
|
927 | c.description()]) | |
928 |
|
928 | |||
929 | return lazyset(subset, matches) |
|
929 | return lazyset(subset, matches) | |
930 |
|
930 | |||
931 | def limit(repo, subset, x): |
|
931 | def limit(repo, subset, x): | |
932 | """``limit(set, [n])`` |
|
932 | """``limit(set, [n])`` | |
933 | First n members of set, defaulting to 1. |
|
933 | First n members of set, defaulting to 1. | |
934 | """ |
|
934 | """ | |
935 | # i18n: "limit" is a keyword |
|
935 | # i18n: "limit" is a keyword | |
936 | l = getargs(x, 1, 2, _("limit requires one or two arguments")) |
|
936 | l = getargs(x, 1, 2, _("limit requires one or two arguments")) | |
937 | try: |
|
937 | try: | |
938 | lim = 1 |
|
938 | lim = 1 | |
939 | if len(l) == 2: |
|
939 | if len(l) == 2: | |
940 | # i18n: "limit" is a keyword |
|
940 | # i18n: "limit" is a keyword | |
941 | lim = int(getstring(l[1], _("limit requires a number"))) |
|
941 | lim = int(getstring(l[1], _("limit requires a number"))) | |
942 | except (TypeError, ValueError): |
|
942 | except (TypeError, ValueError): | |
943 | # i18n: "limit" is a keyword |
|
943 | # i18n: "limit" is a keyword | |
944 | raise error.ParseError(_("limit expects a number")) |
|
944 | raise error.ParseError(_("limit expects a number")) | |
945 | ss = subset.set() |
|
945 | ss = subset.set() | |
946 | os = getset(repo, baseset(repo), l[0]) |
|
946 | os = getset(repo, baseset(repo), l[0]) | |
947 | bs = baseset([]) |
|
947 | bs = baseset([]) | |
948 | it = iter(os) |
|
948 | it = iter(os) | |
949 | for x in xrange(lim): |
|
949 | for x in xrange(lim): | |
950 | try: |
|
950 | try: | |
951 | y = it.next() |
|
951 | y = it.next() | |
952 | if y in ss: |
|
952 | if y in ss: | |
953 | bs.append(y) |
|
953 | bs.append(y) | |
954 | except (StopIteration): |
|
954 | except (StopIteration): | |
955 | break |
|
955 | break | |
956 | return bs |
|
956 | return bs | |
957 |
|
957 | |||
958 | def last(repo, subset, x): |
|
958 | def last(repo, subset, x): | |
959 | """``last(set, [n])`` |
|
959 | """``last(set, [n])`` | |
960 | Last n members of set, defaulting to 1. |
|
960 | Last n members of set, defaulting to 1. | |
961 | """ |
|
961 | """ | |
962 | # i18n: "last" is a keyword |
|
962 | # i18n: "last" is a keyword | |
963 | l = getargs(x, 1, 2, _("last requires one or two arguments")) |
|
963 | l = getargs(x, 1, 2, _("last requires one or two arguments")) | |
964 | try: |
|
964 | try: | |
965 | lim = 1 |
|
965 | lim = 1 | |
966 | if len(l) == 2: |
|
966 | if len(l) == 2: | |
967 | # i18n: "last" is a keyword |
|
967 | # i18n: "last" is a keyword | |
968 | lim = int(getstring(l[1], _("last requires a number"))) |
|
968 | lim = int(getstring(l[1], _("last requires a number"))) | |
969 | except (TypeError, ValueError): |
|
969 | except (TypeError, ValueError): | |
970 | # i18n: "last" is a keyword |
|
970 | # i18n: "last" is a keyword | |
971 | raise error.ParseError(_("last expects a number")) |
|
971 | raise error.ParseError(_("last expects a number")) | |
972 | ss = subset.set() |
|
972 | ss = subset.set() | |
973 | os = getset(repo, baseset(repo), l[0])[-lim:] |
|
973 | os = getset(repo, baseset(repo), l[0])[-lim:] | |
974 | return baseset([r for r in os if r in ss]) |
|
974 | return baseset([r for r in os if r in ss]) | |
975 |
|
975 | |||
976 | def maxrev(repo, subset, x): |
|
976 | def maxrev(repo, subset, x): | |
977 | """``max(set)`` |
|
977 | """``max(set)`` | |
978 | Changeset with highest revision number in set. |
|
978 | Changeset with highest revision number in set. | |
979 | """ |
|
979 | """ | |
980 | os = getset(repo, baseset(repo), x) |
|
980 | os = getset(repo, baseset(repo), x) | |
981 | if os: |
|
981 | if os: | |
982 | m = max(os) |
|
982 | m = max(os) | |
983 | if m in subset: |
|
983 | if m in subset: | |
984 | return baseset([m]) |
|
984 | return baseset([m]) | |
985 | return baseset([]) |
|
985 | return baseset([]) | |
986 |
|
986 | |||
987 | def merge(repo, subset, x): |
|
987 | def merge(repo, subset, x): | |
988 | """``merge()`` |
|
988 | """``merge()`` | |
989 | Changeset is a merge changeset. |
|
989 | Changeset is a merge changeset. | |
990 | """ |
|
990 | """ | |
991 | # i18n: "merge" is a keyword |
|
991 | # i18n: "merge" is a keyword | |
992 | getargs(x, 0, 0, _("merge takes no arguments")) |
|
992 | getargs(x, 0, 0, _("merge takes no arguments")) | |
993 | cl = repo.changelog |
|
993 | cl = repo.changelog | |
994 | return lazyset(subset, lambda r: cl.parentrevs(r)[1] != -1) |
|
994 | return lazyset(subset, lambda r: cl.parentrevs(r)[1] != -1) | |
995 |
|
995 | |||
996 | def branchpoint(repo, subset, x): |
|
996 | def branchpoint(repo, subset, x): | |
997 | """``branchpoint()`` |
|
997 | """``branchpoint()`` | |
998 | Changesets with more than one child. |
|
998 | Changesets with more than one child. | |
999 | """ |
|
999 | """ | |
1000 | # i18n: "branchpoint" is a keyword |
|
1000 | # i18n: "branchpoint" is a keyword | |
1001 | getargs(x, 0, 0, _("branchpoint takes no arguments")) |
|
1001 | getargs(x, 0, 0, _("branchpoint takes no arguments")) | |
1002 | cl = repo.changelog |
|
1002 | cl = repo.changelog | |
1003 | if not subset: |
|
1003 | if not subset: | |
1004 | return baseset([]) |
|
1004 | return baseset([]) | |
1005 | baserev = min(subset) |
|
1005 | baserev = min(subset) | |
1006 | parentscount = [0]*(len(repo) - baserev) |
|
1006 | parentscount = [0]*(len(repo) - baserev) | |
1007 | for r in cl.revs(start=baserev + 1): |
|
1007 | for r in cl.revs(start=baserev + 1): | |
1008 | for p in cl.parentrevs(r): |
|
1008 | for p in cl.parentrevs(r): | |
1009 | if p >= baserev: |
|
1009 | if p >= baserev: | |
1010 | parentscount[p - baserev] += 1 |
|
1010 | parentscount[p - baserev] += 1 | |
1011 | return baseset([r for r in subset if (parentscount[r - baserev] > 1)]) |
|
1011 | return baseset([r for r in subset if (parentscount[r - baserev] > 1)]) | |
1012 |
|
1012 | |||
1013 | def minrev(repo, subset, x): |
|
1013 | def minrev(repo, subset, x): | |
1014 | """``min(set)`` |
|
1014 | """``min(set)`` | |
1015 | Changeset with lowest revision number in set. |
|
1015 | Changeset with lowest revision number in set. | |
1016 | """ |
|
1016 | """ | |
1017 | os = getset(repo, baseset(repo), x) |
|
1017 | os = getset(repo, baseset(repo), x) | |
1018 | if os: |
|
1018 | if os: | |
1019 | m = min(os) |
|
1019 | m = min(os) | |
1020 | if m in subset: |
|
1020 | if m in subset: | |
1021 | return baseset([m]) |
|
1021 | return baseset([m]) | |
1022 | return baseset([]) |
|
1022 | return baseset([]) | |
1023 |
|
1023 | |||
1024 | def modifies(repo, subset, x): |
|
1024 | def modifies(repo, subset, x): | |
1025 | """``modifies(pattern)`` |
|
1025 | """``modifies(pattern)`` | |
1026 | Changesets modifying files matched by pattern. |
|
1026 | Changesets modifying files matched by pattern. | |
1027 |
|
1027 | |||
1028 | The pattern without explicit kind like ``glob:`` is expected to be |
|
1028 | The pattern without explicit kind like ``glob:`` is expected to be | |
1029 | relative to the current directory and match against a file or a |
|
1029 | relative to the current directory and match against a file or a | |
1030 | directory. |
|
1030 | directory. | |
1031 | """ |
|
1031 | """ | |
1032 | # i18n: "modifies" is a keyword |
|
1032 | # i18n: "modifies" is a keyword | |
1033 | pat = getstring(x, _("modifies requires a pattern")) |
|
1033 | pat = getstring(x, _("modifies requires a pattern")) | |
1034 | return checkstatus(repo, subset, pat, 0) |
|
1034 | return checkstatus(repo, subset, pat, 0) | |
1035 |
|
1035 | |||
1036 | def node_(repo, subset, x): |
|
1036 | def node_(repo, subset, x): | |
1037 | """``id(string)`` |
|
1037 | """``id(string)`` | |
1038 | Revision non-ambiguously specified by the given hex string prefix. |
|
1038 | Revision non-ambiguously specified by the given hex string prefix. | |
1039 | """ |
|
1039 | """ | |
1040 | # i18n: "id" is a keyword |
|
1040 | # i18n: "id" is a keyword | |
1041 | l = getargs(x, 1, 1, _("id requires one argument")) |
|
1041 | l = getargs(x, 1, 1, _("id requires one argument")) | |
1042 | # i18n: "id" is a keyword |
|
1042 | # i18n: "id" is a keyword | |
1043 | n = getstring(l[0], _("id requires a string")) |
|
1043 | n = getstring(l[0], _("id requires a string")) | |
1044 | if len(n) == 40: |
|
1044 | if len(n) == 40: | |
1045 | rn = repo[n].rev() |
|
1045 | rn = repo[n].rev() | |
1046 | else: |
|
1046 | else: | |
1047 | rn = None |
|
1047 | rn = None | |
1048 | pm = repo.changelog._partialmatch(n) |
|
1048 | pm = repo.changelog._partialmatch(n) | |
1049 | if pm is not None: |
|
1049 | if pm is not None: | |
1050 | rn = repo.changelog.rev(pm) |
|
1050 | rn = repo.changelog.rev(pm) | |
1051 |
|
1051 | |||
1052 | return baseset([r for r in subset if r == rn]) |
|
1052 | return baseset([r for r in subset if r == rn]) | |
1053 |
|
1053 | |||
1054 | def obsolete(repo, subset, x): |
|
1054 | def obsolete(repo, subset, x): | |
1055 | """``obsolete()`` |
|
1055 | """``obsolete()`` | |
1056 | Mutable changeset with a newer version.""" |
|
1056 | Mutable changeset with a newer version.""" | |
1057 | # i18n: "obsolete" is a keyword |
|
1057 | # i18n: "obsolete" is a keyword | |
1058 | getargs(x, 0, 0, _("obsolete takes no arguments")) |
|
1058 | getargs(x, 0, 0, _("obsolete takes no arguments")) | |
1059 | obsoletes = obsmod.getrevs(repo, 'obsolete') |
|
1059 | obsoletes = obsmod.getrevs(repo, 'obsolete') | |
1060 | return subset & obsoletes |
|
1060 | return subset & obsoletes | |
1061 |
|
1061 | |||
1062 | def origin(repo, subset, x): |
|
1062 | def origin(repo, subset, x): | |
1063 | """``origin([set])`` |
|
1063 | """``origin([set])`` | |
1064 | Changesets that were specified as a source for the grafts, transplants or |
|
1064 | Changesets that were specified as a source for the grafts, transplants or | |
1065 | rebases that created the given revisions. Omitting the optional set is the |
|
1065 | rebases that created the given revisions. Omitting the optional set is the | |
1066 | same as passing all(). If a changeset created by these operations is itself |
|
1066 | same as passing all(). If a changeset created by these operations is itself | |
1067 | specified as a source for one of these operations, only the source changeset |
|
1067 | specified as a source for one of these operations, only the source changeset | |
1068 | for the first operation is selected. |
|
1068 | for the first operation is selected. | |
1069 | """ |
|
1069 | """ | |
1070 | if x is not None: |
|
1070 | if x is not None: | |
1071 | args = getset(repo, baseset(repo), x).set() |
|
1071 | args = getset(repo, baseset(repo), x).set() | |
1072 | else: |
|
1072 | else: | |
1073 | args = getall(repo, baseset(repo), x).set() |
|
1073 | args = getall(repo, baseset(repo), x).set() | |
1074 |
|
1074 | |||
1075 | def _firstsrc(rev): |
|
1075 | def _firstsrc(rev): | |
1076 | src = _getrevsource(repo, rev) |
|
1076 | src = _getrevsource(repo, rev) | |
1077 | if src is None: |
|
1077 | if src is None: | |
1078 | return None |
|
1078 | return None | |
1079 |
|
1079 | |||
1080 | while True: |
|
1080 | while True: | |
1081 | prev = _getrevsource(repo, src) |
|
1081 | prev = _getrevsource(repo, src) | |
1082 |
|
1082 | |||
1083 | if prev is None: |
|
1083 | if prev is None: | |
1084 | return src |
|
1084 | return src | |
1085 | src = prev |
|
1085 | src = prev | |
1086 |
|
1086 | |||
1087 | o = set([_firstsrc(r) for r in args]) |
|
1087 | o = set([_firstsrc(r) for r in args]) | |
1088 | return baseset([r for r in subset if r in o]) |
|
1088 | return baseset([r for r in subset if r in o]) | |
1089 |
|
1089 | |||
1090 | def outgoing(repo, subset, x): |
|
1090 | def outgoing(repo, subset, x): | |
1091 | """``outgoing([path])`` |
|
1091 | """``outgoing([path])`` | |
1092 | Changesets not found in the specified destination repository, or the |
|
1092 | Changesets not found in the specified destination repository, or the | |
1093 | default push location. |
|
1093 | default push location. | |
1094 | """ |
|
1094 | """ | |
1095 | import hg # avoid start-up nasties |
|
1095 | import hg # avoid start-up nasties | |
1096 | # i18n: "outgoing" is a keyword |
|
1096 | # i18n: "outgoing" is a keyword | |
1097 | l = getargs(x, 0, 1, _("outgoing takes one or no arguments")) |
|
1097 | l = getargs(x, 0, 1, _("outgoing takes one or no arguments")) | |
1098 | # i18n: "outgoing" is a keyword |
|
1098 | # i18n: "outgoing" is a keyword | |
1099 | dest = l and getstring(l[0], _("outgoing requires a repository path")) or '' |
|
1099 | dest = l and getstring(l[0], _("outgoing requires a repository path")) or '' | |
1100 | dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') |
|
1100 | dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') | |
1101 | dest, branches = hg.parseurl(dest) |
|
1101 | dest, branches = hg.parseurl(dest) | |
1102 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) |
|
1102 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) | |
1103 | if revs: |
|
1103 | if revs: | |
1104 | revs = [repo.lookup(rev) for rev in revs] |
|
1104 | revs = [repo.lookup(rev) for rev in revs] | |
1105 | other = hg.peer(repo, {}, dest) |
|
1105 | other = hg.peer(repo, {}, dest) | |
1106 | repo.ui.pushbuffer() |
|
1106 | repo.ui.pushbuffer() | |
1107 | outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) |
|
1107 | outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) | |
1108 | repo.ui.popbuffer() |
|
1108 | repo.ui.popbuffer() | |
1109 | cl = repo.changelog |
|
1109 | cl = repo.changelog | |
1110 | o = set([cl.rev(r) for r in outgoing.missing]) |
|
1110 | o = set([cl.rev(r) for r in outgoing.missing]) | |
1111 | return baseset([r for r in subset if r in o]) |
|
1111 | return baseset([r for r in subset if r in o]) | |
1112 |
|
1112 | |||
1113 | def p1(repo, subset, x): |
|
1113 | def p1(repo, subset, x): | |
1114 | """``p1([set])`` |
|
1114 | """``p1([set])`` | |
1115 | First parent of changesets in set, or the working directory. |
|
1115 | First parent of changesets in set, or the working directory. | |
1116 | """ |
|
1116 | """ | |
1117 | if x is None: |
|
1117 | if x is None: | |
1118 | p = repo[x].p1().rev() |
|
1118 | p = repo[x].p1().rev() | |
1119 | return baseset([r for r in subset if r == p]) |
|
1119 | return baseset([r for r in subset if r == p]) | |
1120 |
|
1120 | |||
1121 | ps = set() |
|
1121 | ps = set() | |
1122 | cl = repo.changelog |
|
1122 | cl = repo.changelog | |
1123 | for r in getset(repo, baseset(repo), x): |
|
1123 | for r in getset(repo, baseset(repo), x): | |
1124 | ps.add(cl.parentrevs(r)[0]) |
|
1124 | ps.add(cl.parentrevs(r)[0]) | |
1125 | return subset & ps |
|
1125 | return subset & ps | |
1126 |
|
1126 | |||
1127 | def p2(repo, subset, x): |
|
1127 | def p2(repo, subset, x): | |
1128 | """``p2([set])`` |
|
1128 | """``p2([set])`` | |
1129 | Second parent of changesets in set, or the working directory. |
|
1129 | Second parent of changesets in set, or the working directory. | |
1130 | """ |
|
1130 | """ | |
1131 | if x is None: |
|
1131 | if x is None: | |
1132 | ps = repo[x].parents() |
|
1132 | ps = repo[x].parents() | |
1133 | try: |
|
1133 | try: | |
1134 | p = ps[1].rev() |
|
1134 | p = ps[1].rev() | |
1135 | return baseset([r for r in subset if r == p]) |
|
1135 | return baseset([r for r in subset if r == p]) | |
1136 | except IndexError: |
|
1136 | except IndexError: | |
1137 | return baseset([]) |
|
1137 | return baseset([]) | |
1138 |
|
1138 | |||
1139 | ps = set() |
|
1139 | ps = set() | |
1140 | cl = repo.changelog |
|
1140 | cl = repo.changelog | |
1141 | for r in getset(repo, baseset(repo), x): |
|
1141 | for r in getset(repo, baseset(repo), x): | |
1142 | ps.add(cl.parentrevs(r)[1]) |
|
1142 | ps.add(cl.parentrevs(r)[1]) | |
1143 | return subset & ps |
|
1143 | return subset & ps | |
1144 |
|
1144 | |||
1145 | def parents(repo, subset, x): |
|
1145 | def parents(repo, subset, x): | |
1146 | """``parents([set])`` |
|
1146 | """``parents([set])`` | |
1147 | The set of all parents for all changesets in set, or the working directory. |
|
1147 | The set of all parents for all changesets in set, or the working directory. | |
1148 | """ |
|
1148 | """ | |
1149 | if x is None: |
|
1149 | if x is None: | |
1150 | ps = tuple(p.rev() for p in repo[x].parents()) |
|
1150 | ps = tuple(p.rev() for p in repo[x].parents()) | |
1151 | return subset & ps |
|
1151 | return subset & ps | |
1152 |
|
1152 | |||
1153 | ps = set() |
|
1153 | ps = set() | |
1154 | cl = repo.changelog |
|
1154 | cl = repo.changelog | |
1155 | for r in getset(repo, baseset(repo), x): |
|
1155 | for r in getset(repo, baseset(repo), x): | |
1156 | ps.update(cl.parentrevs(r)) |
|
1156 | ps.update(cl.parentrevs(r)) | |
1157 | return subset & ps |
|
1157 | return subset & ps | |
1158 |
|
1158 | |||
1159 | def parentspec(repo, subset, x, n): |
|
1159 | def parentspec(repo, subset, x, n): | |
1160 | """``set^0`` |
|
1160 | """``set^0`` | |
1161 | The set. |
|
1161 | The set. | |
1162 | ``set^1`` (or ``set^``), ``set^2`` |
|
1162 | ``set^1`` (or ``set^``), ``set^2`` | |
1163 | First or second parent, respectively, of all changesets in set. |
|
1163 | First or second parent, respectively, of all changesets in set. | |
1164 | """ |
|
1164 | """ | |
1165 | try: |
|
1165 | try: | |
1166 | n = int(n[1]) |
|
1166 | n = int(n[1]) | |
1167 | if n not in (0, 1, 2): |
|
1167 | if n not in (0, 1, 2): | |
1168 | raise ValueError |
|
1168 | raise ValueError | |
1169 | except (TypeError, ValueError): |
|
1169 | except (TypeError, ValueError): | |
1170 | raise error.ParseError(_("^ expects a number 0, 1, or 2")) |
|
1170 | raise error.ParseError(_("^ expects a number 0, 1, or 2")) | |
1171 | ps = set() |
|
1171 | ps = set() | |
1172 | cl = repo.changelog |
|
1172 | cl = repo.changelog | |
1173 | for r in getset(repo, baseset(cl), x): |
|
1173 | for r in getset(repo, baseset(cl), x): | |
1174 | if n == 0: |
|
1174 | if n == 0: | |
1175 | ps.add(r) |
|
1175 | ps.add(r) | |
1176 | elif n == 1: |
|
1176 | elif n == 1: | |
1177 | ps.add(cl.parentrevs(r)[0]) |
|
1177 | ps.add(cl.parentrevs(r)[0]) | |
1178 | elif n == 2: |
|
1178 | elif n == 2: | |
1179 | parents = cl.parentrevs(r) |
|
1179 | parents = cl.parentrevs(r) | |
1180 | if len(parents) > 1: |
|
1180 | if len(parents) > 1: | |
1181 | ps.add(parents[1]) |
|
1181 | ps.add(parents[1]) | |
1182 | return subset & ps |
|
1182 | return subset & ps | |
1183 |
|
1183 | |||
1184 | def present(repo, subset, x): |
|
1184 | def present(repo, subset, x): | |
1185 | """``present(set)`` |
|
1185 | """``present(set)`` | |
1186 | An empty set, if any revision in set isn't found; otherwise, |
|
1186 | An empty set, if any revision in set isn't found; otherwise, | |
1187 | all revisions in set. |
|
1187 | all revisions in set. | |
1188 |
|
1188 | |||
1189 | If any of specified revisions is not present in the local repository, |
|
1189 | If any of specified revisions is not present in the local repository, | |
1190 | the query is normally aborted. But this predicate allows the query |
|
1190 | the query is normally aborted. But this predicate allows the query | |
1191 | to continue even in such cases. |
|
1191 | to continue even in such cases. | |
1192 | """ |
|
1192 | """ | |
1193 | try: |
|
1193 | try: | |
1194 | return getset(repo, subset, x) |
|
1194 | return getset(repo, subset, x) | |
1195 | except error.RepoLookupError: |
|
1195 | except error.RepoLookupError: | |
1196 | return baseset([]) |
|
1196 | return baseset([]) | |
1197 |
|
1197 | |||
1198 | def public(repo, subset, x): |
|
1198 | def public(repo, subset, x): | |
1199 | """``public()`` |
|
1199 | """``public()`` | |
1200 | Changeset in public phase.""" |
|
1200 | Changeset in public phase.""" | |
1201 | # i18n: "public" is a keyword |
|
1201 | # i18n: "public" is a keyword | |
1202 | getargs(x, 0, 0, _("public takes no arguments")) |
|
1202 | getargs(x, 0, 0, _("public takes no arguments")) | |
1203 | pc = repo._phasecache |
|
1203 | pc = repo._phasecache | |
1204 | return lazyset(subset, lambda r: pc.phase(repo, r) == phases.public) |
|
1204 | return lazyset(subset, lambda r: pc.phase(repo, r) == phases.public) | |
1205 |
|
1205 | |||
1206 | def remote(repo, subset, x): |
|
1206 | def remote(repo, subset, x): | |
1207 | """``remote([id [,path]])`` |
|
1207 | """``remote([id [,path]])`` | |
1208 | Local revision that corresponds to the given identifier in a |
|
1208 | Local revision that corresponds to the given identifier in a | |
1209 | remote repository, if present. Here, the '.' identifier is a |
|
1209 | remote repository, if present. Here, the '.' identifier is a | |
1210 | synonym for the current local branch. |
|
1210 | synonym for the current local branch. | |
1211 | """ |
|
1211 | """ | |
1212 |
|
1212 | |||
1213 | import hg # avoid start-up nasties |
|
1213 | import hg # avoid start-up nasties | |
1214 | # i18n: "remote" is a keyword |
|
1214 | # i18n: "remote" is a keyword | |
1215 | l = getargs(x, 0, 2, _("remote takes one, two or no arguments")) |
|
1215 | l = getargs(x, 0, 2, _("remote takes one, two or no arguments")) | |
1216 |
|
1216 | |||
1217 | q = '.' |
|
1217 | q = '.' | |
1218 | if len(l) > 0: |
|
1218 | if len(l) > 0: | |
1219 | # i18n: "remote" is a keyword |
|
1219 | # i18n: "remote" is a keyword | |
1220 | q = getstring(l[0], _("remote requires a string id")) |
|
1220 | q = getstring(l[0], _("remote requires a string id")) | |
1221 | if q == '.': |
|
1221 | if q == '.': | |
1222 | q = repo['.'].branch() |
|
1222 | q = repo['.'].branch() | |
1223 |
|
1223 | |||
1224 | dest = '' |
|
1224 | dest = '' | |
1225 | if len(l) > 1: |
|
1225 | if len(l) > 1: | |
1226 | # i18n: "remote" is a keyword |
|
1226 | # i18n: "remote" is a keyword | |
1227 | dest = getstring(l[1], _("remote requires a repository path")) |
|
1227 | dest = getstring(l[1], _("remote requires a repository path")) | |
1228 | dest = repo.ui.expandpath(dest or 'default') |
|
1228 | dest = repo.ui.expandpath(dest or 'default') | |
1229 | dest, branches = hg.parseurl(dest) |
|
1229 | dest, branches = hg.parseurl(dest) | |
1230 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) |
|
1230 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) | |
1231 | if revs: |
|
1231 | if revs: | |
1232 | revs = [repo.lookup(rev) for rev in revs] |
|
1232 | revs = [repo.lookup(rev) for rev in revs] | |
1233 | other = hg.peer(repo, {}, dest) |
|
1233 | other = hg.peer(repo, {}, dest) | |
1234 | n = other.lookup(q) |
|
1234 | n = other.lookup(q) | |
1235 | if n in repo: |
|
1235 | if n in repo: | |
1236 | r = repo[n].rev() |
|
1236 | r = repo[n].rev() | |
1237 | if r in subset: |
|
1237 | if r in subset: | |
1238 | return baseset([r]) |
|
1238 | return baseset([r]) | |
1239 | return baseset([]) |
|
1239 | return baseset([]) | |
1240 |
|
1240 | |||
1241 | def removes(repo, subset, x): |
|
1241 | def removes(repo, subset, x): | |
1242 | """``removes(pattern)`` |
|
1242 | """``removes(pattern)`` | |
1243 | Changesets which remove files matching pattern. |
|
1243 | Changesets which remove files matching pattern. | |
1244 |
|
1244 | |||
1245 | The pattern without explicit kind like ``glob:`` is expected to be |
|
1245 | The pattern without explicit kind like ``glob:`` is expected to be | |
1246 | relative to the current directory and match against a file or a |
|
1246 | relative to the current directory and match against a file or a | |
1247 | directory. |
|
1247 | directory. | |
1248 | """ |
|
1248 | """ | |
1249 | # i18n: "removes" is a keyword |
|
1249 | # i18n: "removes" is a keyword | |
1250 | pat = getstring(x, _("removes requires a pattern")) |
|
1250 | pat = getstring(x, _("removes requires a pattern")) | |
1251 | return checkstatus(repo, subset, pat, 2) |
|
1251 | return checkstatus(repo, subset, pat, 2) | |
1252 |
|
1252 | |||
1253 | def rev(repo, subset, x): |
|
1253 | def rev(repo, subset, x): | |
1254 | """``rev(number)`` |
|
1254 | """``rev(number)`` | |
1255 | Revision with the given numeric identifier. |
|
1255 | Revision with the given numeric identifier. | |
1256 | """ |
|
1256 | """ | |
1257 | # i18n: "rev" is a keyword |
|
1257 | # i18n: "rev" is a keyword | |
1258 | l = getargs(x, 1, 1, _("rev requires one argument")) |
|
1258 | l = getargs(x, 1, 1, _("rev requires one argument")) | |
1259 | try: |
|
1259 | try: | |
1260 | # i18n: "rev" is a keyword |
|
1260 | # i18n: "rev" is a keyword | |
1261 | l = int(getstring(l[0], _("rev requires a number"))) |
|
1261 | l = int(getstring(l[0], _("rev requires a number"))) | |
1262 | except (TypeError, ValueError): |
|
1262 | except (TypeError, ValueError): | |
1263 | # i18n: "rev" is a keyword |
|
1263 | # i18n: "rev" is a keyword | |
1264 | raise error.ParseError(_("rev expects a number")) |
|
1264 | raise error.ParseError(_("rev expects a number")) | |
1265 | return baseset([r for r in subset if r == l]) |
|
1265 | return baseset([r for r in subset if r == l]) | |
1266 |
|
1266 | |||
1267 | def matching(repo, subset, x): |
|
1267 | def matching(repo, subset, x): | |
1268 | """``matching(revision [, field])`` |
|
1268 | """``matching(revision [, field])`` | |
1269 | Changesets in which a given set of fields match the set of fields in the |
|
1269 | Changesets in which a given set of fields match the set of fields in the | |
1270 | selected revision or set. |
|
1270 | selected revision or set. | |
1271 |
|
1271 | |||
1272 | To match more than one field pass the list of fields to match separated |
|
1272 | To match more than one field pass the list of fields to match separated | |
1273 | by spaces (e.g. ``author description``). |
|
1273 | by spaces (e.g. ``author description``). | |
1274 |
|
1274 | |||
1275 | Valid fields are most regular revision fields and some special fields. |
|
1275 | Valid fields are most regular revision fields and some special fields. | |
1276 |
|
1276 | |||
1277 | Regular revision fields are ``description``, ``author``, ``branch``, |
|
1277 | Regular revision fields are ``description``, ``author``, ``branch``, | |
1278 | ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` |
|
1278 | ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` | |
1279 | and ``diff``. |
|
1279 | and ``diff``. | |
1280 | Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the |
|
1280 | Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the | |
1281 | contents of the revision. Two revisions matching their ``diff`` will |
|
1281 | contents of the revision. Two revisions matching their ``diff`` will | |
1282 | also match their ``files``. |
|
1282 | also match their ``files``. | |
1283 |
|
1283 | |||
1284 | Special fields are ``summary`` and ``metadata``: |
|
1284 | Special fields are ``summary`` and ``metadata``: | |
1285 | ``summary`` matches the first line of the description. |
|
1285 | ``summary`` matches the first line of the description. | |
1286 | ``metadata`` is equivalent to matching ``description user date`` |
|
1286 | ``metadata`` is equivalent to matching ``description user date`` | |
1287 | (i.e. it matches the main metadata fields). |
|
1287 | (i.e. it matches the main metadata fields). | |
1288 |
|
1288 | |||
1289 | ``metadata`` is the default field which is used when no fields are |
|
1289 | ``metadata`` is the default field which is used when no fields are | |
1290 | specified. You can match more than one field at a time. |
|
1290 | specified. You can match more than one field at a time. | |
1291 | """ |
|
1291 | """ | |
1292 | # i18n: "matching" is a keyword |
|
1292 | # i18n: "matching" is a keyword | |
1293 | l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments")) |
|
1293 | l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments")) | |
1294 |
|
1294 | |||
1295 | revs = getset(repo, baseset(repo.changelog), l[0]) |
|
1295 | revs = getset(repo, baseset(repo.changelog), l[0]) | |
1296 |
|
1296 | |||
1297 | fieldlist = ['metadata'] |
|
1297 | fieldlist = ['metadata'] | |
1298 | if len(l) > 1: |
|
1298 | if len(l) > 1: | |
1299 | fieldlist = getstring(l[1], |
|
1299 | fieldlist = getstring(l[1], | |
1300 | # i18n: "matching" is a keyword |
|
1300 | # i18n: "matching" is a keyword | |
1301 | _("matching requires a string " |
|
1301 | _("matching requires a string " | |
1302 | "as its second argument")).split() |
|
1302 | "as its second argument")).split() | |
1303 |
|
1303 | |||
1304 | # Make sure that there are no repeated fields, |
|
1304 | # Make sure that there are no repeated fields, | |
1305 | # expand the 'special' 'metadata' field type |
|
1305 | # expand the 'special' 'metadata' field type | |
1306 | # and check the 'files' whenever we check the 'diff' |
|
1306 | # and check the 'files' whenever we check the 'diff' | |
1307 | fields = [] |
|
1307 | fields = [] | |
1308 | for field in fieldlist: |
|
1308 | for field in fieldlist: | |
1309 | if field == 'metadata': |
|
1309 | if field == 'metadata': | |
1310 | fields += ['user', 'description', 'date'] |
|
1310 | fields += ['user', 'description', 'date'] | |
1311 | elif field == 'diff': |
|
1311 | elif field == 'diff': | |
1312 | # a revision matching the diff must also match the files |
|
1312 | # a revision matching the diff must also match the files | |
1313 | # since matching the diff is very costly, make sure to |
|
1313 | # since matching the diff is very costly, make sure to | |
1314 | # also match the files first |
|
1314 | # also match the files first | |
1315 | fields += ['files', 'diff'] |
|
1315 | fields += ['files', 'diff'] | |
1316 | else: |
|
1316 | else: | |
1317 | if field == 'author': |
|
1317 | if field == 'author': | |
1318 | field = 'user' |
|
1318 | field = 'user' | |
1319 | fields.append(field) |
|
1319 | fields.append(field) | |
1320 | fields = set(fields) |
|
1320 | fields = set(fields) | |
1321 | if 'summary' in fields and 'description' in fields: |
|
1321 | if 'summary' in fields and 'description' in fields: | |
1322 | # If a revision matches its description it also matches its summary |
|
1322 | # If a revision matches its description it also matches its summary | |
1323 | fields.discard('summary') |
|
1323 | fields.discard('summary') | |
1324 |
|
1324 | |||
1325 | # We may want to match more than one field |
|
1325 | # We may want to match more than one field | |
1326 | # Not all fields take the same amount of time to be matched |
|
1326 | # Not all fields take the same amount of time to be matched | |
1327 | # Sort the selected fields in order of increasing matching cost |
|
1327 | # Sort the selected fields in order of increasing matching cost | |
1328 | fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary', |
|
1328 | fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary', | |
1329 | 'files', 'description', 'substate', 'diff'] |
|
1329 | 'files', 'description', 'substate', 'diff'] | |
1330 | def fieldkeyfunc(f): |
|
1330 | def fieldkeyfunc(f): | |
1331 | try: |
|
1331 | try: | |
1332 | return fieldorder.index(f) |
|
1332 | return fieldorder.index(f) | |
1333 | except ValueError: |
|
1333 | except ValueError: | |
1334 | # assume an unknown field is very costly |
|
1334 | # assume an unknown field is very costly | |
1335 | return len(fieldorder) |
|
1335 | return len(fieldorder) | |
1336 | fields = list(fields) |
|
1336 | fields = list(fields) | |
1337 | fields.sort(key=fieldkeyfunc) |
|
1337 | fields.sort(key=fieldkeyfunc) | |
1338 |
|
1338 | |||
1339 | # Each field will be matched with its own "getfield" function |
|
1339 | # Each field will be matched with its own "getfield" function | |
1340 | # which will be added to the getfieldfuncs array of functions |
|
1340 | # which will be added to the getfieldfuncs array of functions | |
1341 | getfieldfuncs = [] |
|
1341 | getfieldfuncs = [] | |
1342 | _funcs = { |
|
1342 | _funcs = { | |
1343 | 'user': lambda r: repo[r].user(), |
|
1343 | 'user': lambda r: repo[r].user(), | |
1344 | 'branch': lambda r: repo[r].branch(), |
|
1344 | 'branch': lambda r: repo[r].branch(), | |
1345 | 'date': lambda r: repo[r].date(), |
|
1345 | 'date': lambda r: repo[r].date(), | |
1346 | 'description': lambda r: repo[r].description(), |
|
1346 | 'description': lambda r: repo[r].description(), | |
1347 | 'files': lambda r: repo[r].files(), |
|
1347 | 'files': lambda r: repo[r].files(), | |
1348 | 'parents': lambda r: repo[r].parents(), |
|
1348 | 'parents': lambda r: repo[r].parents(), | |
1349 | 'phase': lambda r: repo[r].phase(), |
|
1349 | 'phase': lambda r: repo[r].phase(), | |
1350 | 'substate': lambda r: repo[r].substate, |
|
1350 | 'substate': lambda r: repo[r].substate, | |
1351 | 'summary': lambda r: repo[r].description().splitlines()[0], |
|
1351 | 'summary': lambda r: repo[r].description().splitlines()[0], | |
1352 | 'diff': lambda r: list(repo[r].diff(git=True),) |
|
1352 | 'diff': lambda r: list(repo[r].diff(git=True),) | |
1353 | } |
|
1353 | } | |
1354 | for info in fields: |
|
1354 | for info in fields: | |
1355 | getfield = _funcs.get(info, None) |
|
1355 | getfield = _funcs.get(info, None) | |
1356 | if getfield is None: |
|
1356 | if getfield is None: | |
1357 | raise error.ParseError( |
|
1357 | raise error.ParseError( | |
1358 | # i18n: "matching" is a keyword |
|
1358 | # i18n: "matching" is a keyword | |
1359 | _("unexpected field name passed to matching: %s") % info) |
|
1359 | _("unexpected field name passed to matching: %s") % info) | |
1360 | getfieldfuncs.append(getfield) |
|
1360 | getfieldfuncs.append(getfield) | |
1361 | # convert the getfield array of functions into a "getinfo" function |
|
1361 | # convert the getfield array of functions into a "getinfo" function | |
1362 | # which returns an array of field values (or a single value if there |
|
1362 | # which returns an array of field values (or a single value if there | |
1363 | # is only one field to match) |
|
1363 | # is only one field to match) | |
1364 | getinfo = lambda r: [f(r) for f in getfieldfuncs] |
|
1364 | getinfo = lambda r: [f(r) for f in getfieldfuncs] | |
1365 |
|
1365 | |||
1366 | def matches(x): |
|
1366 | def matches(x): | |
1367 | for rev in revs: |
|
1367 | for rev in revs: | |
1368 | target = getinfo(rev) |
|
1368 | target = getinfo(rev) | |
1369 | match = True |
|
1369 | match = True | |
1370 | for n, f in enumerate(getfieldfuncs): |
|
1370 | for n, f in enumerate(getfieldfuncs): | |
1371 | if target[n] != f(x): |
|
1371 | if target[n] != f(x): | |
1372 | match = False |
|
1372 | match = False | |
1373 | if match: |
|
1373 | if match: | |
1374 | return True |
|
1374 | return True | |
1375 | return False |
|
1375 | return False | |
1376 |
|
1376 | |||
1377 | return lazyset(subset, matches) |
|
1377 | return lazyset(subset, matches) | |
1378 |
|
1378 | |||
1379 | def reverse(repo, subset, x): |
|
1379 | def reverse(repo, subset, x): | |
1380 | """``reverse(set)`` |
|
1380 | """``reverse(set)`` | |
1381 | Reverse order of set. |
|
1381 | Reverse order of set. | |
1382 | """ |
|
1382 | """ | |
1383 | l = getset(repo, subset, x) |
|
1383 | l = getset(repo, subset, x) | |
1384 | l.reverse() |
|
1384 | l.reverse() | |
1385 | return l |
|
1385 | return l | |
1386 |
|
1386 | |||
1387 | def roots(repo, subset, x): |
|
1387 | def roots(repo, subset, x): | |
1388 | """``roots(set)`` |
|
1388 | """``roots(set)`` | |
1389 | Changesets in set with no parent changeset in set. |
|
1389 | Changesets in set with no parent changeset in set. | |
1390 | """ |
|
1390 | """ | |
1391 | s = getset(repo, baseset(repo.changelog), x).set() |
|
1391 | s = getset(repo, baseset(repo.changelog), x).set() | |
1392 | subset = baseset([r for r in subset if r in s]) |
|
1392 | subset = baseset([r for r in subset if r in s]) | |
1393 | cs = _children(repo, subset, s) |
|
1393 | cs = _children(repo, subset, s) | |
1394 | return subset - cs |
|
1394 | return subset - cs | |
1395 |
|
1395 | |||
1396 | def secret(repo, subset, x): |
|
1396 | def secret(repo, subset, x): | |
1397 | """``secret()`` |
|
1397 | """``secret()`` | |
1398 | Changeset in secret phase.""" |
|
1398 | Changeset in secret phase.""" | |
1399 | # i18n: "secret" is a keyword |
|
1399 | # i18n: "secret" is a keyword | |
1400 | getargs(x, 0, 0, _("secret takes no arguments")) |
|
1400 | getargs(x, 0, 0, _("secret takes no arguments")) | |
1401 | pc = repo._phasecache |
|
1401 | pc = repo._phasecache | |
1402 | return lazyset(subset, lambda x: pc.phase(repo, x) == phases.secret) |
|
1402 | return lazyset(subset, lambda x: pc.phase(repo, x) == phases.secret) | |
1403 |
|
1403 | |||
1404 | def sort(repo, subset, x): |
|
1404 | def sort(repo, subset, x): | |
1405 | """``sort(set[, [-]key...])`` |
|
1405 | """``sort(set[, [-]key...])`` | |
1406 | Sort set by keys. The default sort order is ascending, specify a key |
|
1406 | Sort set by keys. The default sort order is ascending, specify a key | |
1407 | as ``-key`` to sort in descending order. |
|
1407 | as ``-key`` to sort in descending order. | |
1408 |
|
1408 | |||
1409 | The keys can be: |
|
1409 | The keys can be: | |
1410 |
|
1410 | |||
1411 | - ``rev`` for the revision number, |
|
1411 | - ``rev`` for the revision number, | |
1412 | - ``branch`` for the branch name, |
|
1412 | - ``branch`` for the branch name, | |
1413 | - ``desc`` for the commit message (description), |
|
1413 | - ``desc`` for the commit message (description), | |
1414 | - ``user`` for user name (``author`` can be used as an alias), |
|
1414 | - ``user`` for user name (``author`` can be used as an alias), | |
1415 | - ``date`` for the commit date |
|
1415 | - ``date`` for the commit date | |
1416 | """ |
|
1416 | """ | |
1417 | # i18n: "sort" is a keyword |
|
1417 | # i18n: "sort" is a keyword | |
1418 | l = getargs(x, 1, 2, _("sort requires one or two arguments")) |
|
1418 | l = getargs(x, 1, 2, _("sort requires one or two arguments")) | |
1419 | keys = "rev" |
|
1419 | keys = "rev" | |
1420 | if len(l) == 2: |
|
1420 | if len(l) == 2: | |
1421 | # i18n: "sort" is a keyword |
|
1421 | # i18n: "sort" is a keyword | |
1422 | keys = getstring(l[1], _("sort spec must be a string")) |
|
1422 | keys = getstring(l[1], _("sort spec must be a string")) | |
1423 |
|
1423 | |||
1424 | s = l[0] |
|
1424 | s = l[0] | |
1425 | keys = keys.split() |
|
1425 | keys = keys.split() | |
1426 | l = [] |
|
1426 | l = [] | |
1427 | def invert(s): |
|
1427 | def invert(s): | |
1428 | return "".join(chr(255 - ord(c)) for c in s) |
|
1428 | return "".join(chr(255 - ord(c)) for c in s) | |
1429 | for r in getset(repo, subset, s): |
|
1429 | for r in getset(repo, subset, s): | |
1430 | c = repo[r] |
|
1430 | c = repo[r] | |
1431 | e = [] |
|
1431 | e = [] | |
1432 | for k in keys: |
|
1432 | for k in keys: | |
1433 | if k == 'rev': |
|
1433 | if k == 'rev': | |
1434 | e.append(r) |
|
1434 | e.append(r) | |
1435 | elif k == '-rev': |
|
1435 | elif k == '-rev': | |
1436 | e.append(-r) |
|
1436 | e.append(-r) | |
1437 | elif k == 'branch': |
|
1437 | elif k == 'branch': | |
1438 | e.append(c.branch()) |
|
1438 | e.append(c.branch()) | |
1439 | elif k == '-branch': |
|
1439 | elif k == '-branch': | |
1440 | e.append(invert(c.branch())) |
|
1440 | e.append(invert(c.branch())) | |
1441 | elif k == 'desc': |
|
1441 | elif k == 'desc': | |
1442 | e.append(c.description()) |
|
1442 | e.append(c.description()) | |
1443 | elif k == '-desc': |
|
1443 | elif k == '-desc': | |
1444 | e.append(invert(c.description())) |
|
1444 | e.append(invert(c.description())) | |
1445 | elif k in 'user author': |
|
1445 | elif k in 'user author': | |
1446 | e.append(c.user()) |
|
1446 | e.append(c.user()) | |
1447 | elif k in '-user -author': |
|
1447 | elif k in '-user -author': | |
1448 | e.append(invert(c.user())) |
|
1448 | e.append(invert(c.user())) | |
1449 | elif k == 'date': |
|
1449 | elif k == 'date': | |
1450 | e.append(c.date()[0]) |
|
1450 | e.append(c.date()[0]) | |
1451 | elif k == '-date': |
|
1451 | elif k == '-date': | |
1452 | e.append(-c.date()[0]) |
|
1452 | e.append(-c.date()[0]) | |
1453 | else: |
|
1453 | else: | |
1454 | raise error.ParseError(_("unknown sort key %r") % k) |
|
1454 | raise error.ParseError(_("unknown sort key %r") % k) | |
1455 | e.append(r) |
|
1455 | e.append(r) | |
1456 | l.append(e) |
|
1456 | l.append(e) | |
1457 | l.sort() |
|
1457 | l.sort() | |
1458 | return baseset([e[-1] for e in l]) |
|
1458 | return baseset([e[-1] for e in l]) | |
1459 |
|
1459 | |||
1460 | def _stringmatcher(pattern): |
|
1460 | def _stringmatcher(pattern): | |
1461 | """ |
|
1461 | """ | |
1462 | accepts a string, possibly starting with 're:' or 'literal:' prefix. |
|
1462 | accepts a string, possibly starting with 're:' or 'literal:' prefix. | |
1463 | returns the matcher name, pattern, and matcher function. |
|
1463 | returns the matcher name, pattern, and matcher function. | |
1464 | missing or unknown prefixes are treated as literal matches. |
|
1464 | missing or unknown prefixes are treated as literal matches. | |
1465 |
|
1465 | |||
1466 | helper for tests: |
|
1466 | helper for tests: | |
1467 | >>> def test(pattern, *tests): |
|
1467 | >>> def test(pattern, *tests): | |
1468 | ... kind, pattern, matcher = _stringmatcher(pattern) |
|
1468 | ... kind, pattern, matcher = _stringmatcher(pattern) | |
1469 | ... return (kind, pattern, [bool(matcher(t)) for t in tests]) |
|
1469 | ... return (kind, pattern, [bool(matcher(t)) for t in tests]) | |
1470 |
|
1470 | |||
1471 | exact matching (no prefix): |
|
1471 | exact matching (no prefix): | |
1472 | >>> test('abcdefg', 'abc', 'def', 'abcdefg') |
|
1472 | >>> test('abcdefg', 'abc', 'def', 'abcdefg') | |
1473 | ('literal', 'abcdefg', [False, False, True]) |
|
1473 | ('literal', 'abcdefg', [False, False, True]) | |
1474 |
|
1474 | |||
1475 | regex matching ('re:' prefix) |
|
1475 | regex matching ('re:' prefix) | |
1476 | >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar') |
|
1476 | >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar') | |
1477 | ('re', 'a.+b', [False, False, True]) |
|
1477 | ('re', 'a.+b', [False, False, True]) | |
1478 |
|
1478 | |||
1479 | force exact matches ('literal:' prefix) |
|
1479 | force exact matches ('literal:' prefix) | |
1480 | >>> test('literal:re:foobar', 'foobar', 're:foobar') |
|
1480 | >>> test('literal:re:foobar', 'foobar', 're:foobar') | |
1481 | ('literal', 're:foobar', [False, True]) |
|
1481 | ('literal', 're:foobar', [False, True]) | |
1482 |
|
1482 | |||
1483 | unknown prefixes are ignored and treated as literals |
|
1483 | unknown prefixes are ignored and treated as literals | |
1484 | >>> test('foo:bar', 'foo', 'bar', 'foo:bar') |
|
1484 | >>> test('foo:bar', 'foo', 'bar', 'foo:bar') | |
1485 | ('literal', 'foo:bar', [False, False, True]) |
|
1485 | ('literal', 'foo:bar', [False, False, True]) | |
1486 | """ |
|
1486 | """ | |
1487 | if pattern.startswith('re:'): |
|
1487 | if pattern.startswith('re:'): | |
1488 | pattern = pattern[3:] |
|
1488 | pattern = pattern[3:] | |
1489 | try: |
|
1489 | try: | |
1490 | regex = re.compile(pattern) |
|
1490 | regex = re.compile(pattern) | |
1491 | except re.error, e: |
|
1491 | except re.error, e: | |
1492 | raise error.ParseError(_('invalid regular expression: %s') |
|
1492 | raise error.ParseError(_('invalid regular expression: %s') | |
1493 | % e) |
|
1493 | % e) | |
1494 | return 're', pattern, regex.search |
|
1494 | return 're', pattern, regex.search | |
1495 | elif pattern.startswith('literal:'): |
|
1495 | elif pattern.startswith('literal:'): | |
1496 | pattern = pattern[8:] |
|
1496 | pattern = pattern[8:] | |
1497 | return 'literal', pattern, pattern.__eq__ |
|
1497 | return 'literal', pattern, pattern.__eq__ | |
1498 |
|
1498 | |||
1499 | def _substringmatcher(pattern): |
|
1499 | def _substringmatcher(pattern): | |
1500 | kind, pattern, matcher = _stringmatcher(pattern) |
|
1500 | kind, pattern, matcher = _stringmatcher(pattern) | |
1501 | if kind == 'literal': |
|
1501 | if kind == 'literal': | |
1502 | matcher = lambda s: pattern in s |
|
1502 | matcher = lambda s: pattern in s | |
1503 | return kind, pattern, matcher |
|
1503 | return kind, pattern, matcher | |
1504 |
|
1504 | |||
1505 | def tag(repo, subset, x): |
|
1505 | def tag(repo, subset, x): | |
1506 | """``tag([name])`` |
|
1506 | """``tag([name])`` | |
1507 | The specified tag by name, or all tagged revisions if no name is given. |
|
1507 | The specified tag by name, or all tagged revisions if no name is given. | |
1508 | """ |
|
1508 | """ | |
1509 | # i18n: "tag" is a keyword |
|
1509 | # i18n: "tag" is a keyword | |
1510 | args = getargs(x, 0, 1, _("tag takes one or no arguments")) |
|
1510 | args = getargs(x, 0, 1, _("tag takes one or no arguments")) | |
1511 | cl = repo.changelog |
|
1511 | cl = repo.changelog | |
1512 | if args: |
|
1512 | if args: | |
1513 | pattern = getstring(args[0], |
|
1513 | pattern = getstring(args[0], | |
1514 | # i18n: "tag" is a keyword |
|
1514 | # i18n: "tag" is a keyword | |
1515 | _('the argument to tag must be a string')) |
|
1515 | _('the argument to tag must be a string')) | |
1516 | kind, pattern, matcher = _stringmatcher(pattern) |
|
1516 | kind, pattern, matcher = _stringmatcher(pattern) | |
1517 | if kind == 'literal': |
|
1517 | if kind == 'literal': | |
1518 | # avoid resolving all tags |
|
1518 | # avoid resolving all tags | |
1519 | tn = repo._tagscache.tags.get(pattern, None) |
|
1519 | tn = repo._tagscache.tags.get(pattern, None) | |
1520 | if tn is None: |
|
1520 | if tn is None: | |
1521 | raise util.Abort(_("tag '%s' does not exist") % pattern) |
|
1521 | raise util.Abort(_("tag '%s' does not exist") % pattern) | |
1522 | s = set([repo[tn].rev()]) |
|
1522 | s = set([repo[tn].rev()]) | |
1523 | else: |
|
1523 | else: | |
1524 | s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)]) |
|
1524 | s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)]) | |
1525 | else: |
|
1525 | else: | |
1526 | s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) |
|
1526 | s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) | |
1527 | return subset & s |
|
1527 | return subset & s | |
1528 |
|
1528 | |||
1529 | def tagged(repo, subset, x): |
|
1529 | def tagged(repo, subset, x): | |
1530 | return tag(repo, subset, x) |
|
1530 | return tag(repo, subset, x) | |
1531 |
|
1531 | |||
1532 | def unstable(repo, subset, x): |
|
1532 | def unstable(repo, subset, x): | |
1533 | """``unstable()`` |
|
1533 | """``unstable()`` | |
1534 | Non-obsolete changesets with obsolete ancestors. |
|
1534 | Non-obsolete changesets with obsolete ancestors. | |
1535 | """ |
|
1535 | """ | |
1536 | # i18n: "unstable" is a keyword |
|
1536 | # i18n: "unstable" is a keyword | |
1537 | getargs(x, 0, 0, _("unstable takes no arguments")) |
|
1537 | getargs(x, 0, 0, _("unstable takes no arguments")) | |
1538 | unstables = obsmod.getrevs(repo, 'unstable') |
|
1538 | unstables = obsmod.getrevs(repo, 'unstable') | |
1539 | return subset & unstables |
|
1539 | return subset & unstables | |
1540 |
|
1540 | |||
1541 |
|
1541 | |||
1542 | def user(repo, subset, x): |
|
1542 | def user(repo, subset, x): | |
1543 | """``user(string)`` |
|
1543 | """``user(string)`` | |
1544 | User name contains string. The match is case-insensitive. |
|
1544 | User name contains string. The match is case-insensitive. | |
1545 |
|
1545 | |||
1546 | If `string` starts with `re:`, the remainder of the string is treated as |
|
1546 | If `string` starts with `re:`, the remainder of the string is treated as | |
1547 | a regular expression. To match a user that actually contains `re:`, use |
|
1547 | a regular expression. To match a user that actually contains `re:`, use | |
1548 | the prefix `literal:`. |
|
1548 | the prefix `literal:`. | |
1549 | """ |
|
1549 | """ | |
1550 | return author(repo, subset, x) |
|
1550 | return author(repo, subset, x) | |
1551 |
|
1551 | |||
1552 | # for internal use |
|
1552 | # for internal use | |
1553 | def _list(repo, subset, x): |
|
1553 | def _list(repo, subset, x): | |
1554 | s = getstring(x, "internal error") |
|
1554 | s = getstring(x, "internal error") | |
1555 | if not s: |
|
1555 | if not s: | |
1556 | return baseset([]) |
|
1556 | return baseset([]) | |
1557 | ls = [repo[r].rev() for r in s.split('\0')] |
|
1557 | ls = [repo[r].rev() for r in s.split('\0')] | |
1558 | s = subset.set() |
|
1558 | s = subset.set() | |
1559 | return baseset([r for r in ls if r in s]) |
|
1559 | return baseset([r for r in ls if r in s]) | |
1560 |
|
1560 | |||
1561 | symbols = { |
|
1561 | symbols = { | |
1562 | "adds": adds, |
|
1562 | "adds": adds, | |
1563 | "all": getall, |
|
1563 | "all": getall, | |
1564 | "ancestor": ancestor, |
|
1564 | "ancestor": ancestor, | |
1565 | "ancestors": ancestors, |
|
1565 | "ancestors": ancestors, | |
1566 | "_firstancestors": _firstancestors, |
|
1566 | "_firstancestors": _firstancestors, | |
1567 | "author": author, |
|
1567 | "author": author, | |
1568 | "bisect": bisect, |
|
1568 | "bisect": bisect, | |
1569 | "bisected": bisected, |
|
1569 | "bisected": bisected, | |
1570 | "bookmark": bookmark, |
|
1570 | "bookmark": bookmark, | |
1571 | "branch": branch, |
|
1571 | "branch": branch, | |
1572 | "branchpoint": branchpoint, |
|
1572 | "branchpoint": branchpoint, | |
1573 | "bumped": bumped, |
|
1573 | "bumped": bumped, | |
1574 | "bundle": bundle, |
|
1574 | "bundle": bundle, | |
1575 | "children": children, |
|
1575 | "children": children, | |
1576 | "closed": closed, |
|
1576 | "closed": closed, | |
1577 | "contains": contains, |
|
1577 | "contains": contains, | |
1578 | "converted": converted, |
|
1578 | "converted": converted, | |
1579 | "date": date, |
|
1579 | "date": date, | |
1580 | "desc": desc, |
|
1580 | "desc": desc, | |
1581 | "descendants": descendants, |
|
1581 | "descendants": descendants, | |
1582 | "_firstdescendants": _firstdescendants, |
|
1582 | "_firstdescendants": _firstdescendants, | |
1583 | "destination": destination, |
|
1583 | "destination": destination, | |
1584 | "divergent": divergent, |
|
1584 | "divergent": divergent, | |
1585 | "draft": draft, |
|
1585 | "draft": draft, | |
1586 | "extinct": extinct, |
|
1586 | "extinct": extinct, | |
1587 | "extra": extra, |
|
1587 | "extra": extra, | |
1588 | "file": hasfile, |
|
1588 | "file": hasfile, | |
1589 | "filelog": filelog, |
|
1589 | "filelog": filelog, | |
1590 | "first": first, |
|
1590 | "first": first, | |
1591 | "follow": follow, |
|
1591 | "follow": follow, | |
1592 | "_followfirst": _followfirst, |
|
1592 | "_followfirst": _followfirst, | |
1593 | "grep": grep, |
|
1593 | "grep": grep, | |
1594 | "head": head, |
|
1594 | "head": head, | |
1595 | "heads": heads, |
|
1595 | "heads": heads, | |
1596 | "hidden": hidden, |
|
1596 | "hidden": hidden, | |
1597 | "id": node_, |
|
1597 | "id": node_, | |
1598 | "keyword": keyword, |
|
1598 | "keyword": keyword, | |
1599 | "last": last, |
|
1599 | "last": last, | |
1600 | "limit": limit, |
|
1600 | "limit": limit, | |
1601 | "_matchfiles": _matchfiles, |
|
1601 | "_matchfiles": _matchfiles, | |
1602 | "max": maxrev, |
|
1602 | "max": maxrev, | |
1603 | "merge": merge, |
|
1603 | "merge": merge, | |
1604 | "min": minrev, |
|
1604 | "min": minrev, | |
1605 | "modifies": modifies, |
|
1605 | "modifies": modifies, | |
1606 | "obsolete": obsolete, |
|
1606 | "obsolete": obsolete, | |
1607 | "origin": origin, |
|
1607 | "origin": origin, | |
1608 | "outgoing": outgoing, |
|
1608 | "outgoing": outgoing, | |
1609 | "p1": p1, |
|
1609 | "p1": p1, | |
1610 | "p2": p2, |
|
1610 | "p2": p2, | |
1611 | "parents": parents, |
|
1611 | "parents": parents, | |
1612 | "present": present, |
|
1612 | "present": present, | |
1613 | "public": public, |
|
1613 | "public": public, | |
1614 | "remote": remote, |
|
1614 | "remote": remote, | |
1615 | "removes": removes, |
|
1615 | "removes": removes, | |
1616 | "rev": rev, |
|
1616 | "rev": rev, | |
1617 | "reverse": reverse, |
|
1617 | "reverse": reverse, | |
1618 | "roots": roots, |
|
1618 | "roots": roots, | |
1619 | "sort": sort, |
|
1619 | "sort": sort, | |
1620 | "secret": secret, |
|
1620 | "secret": secret, | |
1621 | "matching": matching, |
|
1621 | "matching": matching, | |
1622 | "tag": tag, |
|
1622 | "tag": tag, | |
1623 | "tagged": tagged, |
|
1623 | "tagged": tagged, | |
1624 | "user": user, |
|
1624 | "user": user, | |
1625 | "unstable": unstable, |
|
1625 | "unstable": unstable, | |
1626 | "_list": _list, |
|
1626 | "_list": _list, | |
1627 | } |
|
1627 | } | |
1628 |
|
1628 | |||
1629 | # symbols which can't be used for a DoS attack for any given input |
|
1629 | # symbols which can't be used for a DoS attack for any given input | |
1630 | # (e.g. those which accept regexes as plain strings shouldn't be included) |
|
1630 | # (e.g. those which accept regexes as plain strings shouldn't be included) | |
1631 | # functions that just return a lot of changesets (like all) don't count here |
|
1631 | # functions that just return a lot of changesets (like all) don't count here | |
1632 | safesymbols = set([ |
|
1632 | safesymbols = set([ | |
1633 | "adds", |
|
1633 | "adds", | |
1634 | "all", |
|
1634 | "all", | |
1635 | "ancestor", |
|
1635 | "ancestor", | |
1636 | "ancestors", |
|
1636 | "ancestors", | |
1637 | "_firstancestors", |
|
1637 | "_firstancestors", | |
1638 | "author", |
|
1638 | "author", | |
1639 | "bisect", |
|
1639 | "bisect", | |
1640 | "bisected", |
|
1640 | "bisected", | |
1641 | "bookmark", |
|
1641 | "bookmark", | |
1642 | "branch", |
|
1642 | "branch", | |
1643 | "branchpoint", |
|
1643 | "branchpoint", | |
1644 | "bumped", |
|
1644 | "bumped", | |
1645 | "bundle", |
|
1645 | "bundle", | |
1646 | "children", |
|
1646 | "children", | |
1647 | "closed", |
|
1647 | "closed", | |
1648 | "converted", |
|
1648 | "converted", | |
1649 | "date", |
|
1649 | "date", | |
1650 | "desc", |
|
1650 | "desc", | |
1651 | "descendants", |
|
1651 | "descendants", | |
1652 | "_firstdescendants", |
|
1652 | "_firstdescendants", | |
1653 | "destination", |
|
1653 | "destination", | |
1654 | "divergent", |
|
1654 | "divergent", | |
1655 | "draft", |
|
1655 | "draft", | |
1656 | "extinct", |
|
1656 | "extinct", | |
1657 | "extra", |
|
1657 | "extra", | |
1658 | "file", |
|
1658 | "file", | |
1659 | "filelog", |
|
1659 | "filelog", | |
1660 | "first", |
|
1660 | "first", | |
1661 | "follow", |
|
1661 | "follow", | |
1662 | "_followfirst", |
|
1662 | "_followfirst", | |
1663 | "head", |
|
1663 | "head", | |
1664 | "heads", |
|
1664 | "heads", | |
1665 | "hidden", |
|
1665 | "hidden", | |
1666 | "id", |
|
1666 | "id", | |
1667 | "keyword", |
|
1667 | "keyword", | |
1668 | "last", |
|
1668 | "last", | |
1669 | "limit", |
|
1669 | "limit", | |
1670 | "_matchfiles", |
|
1670 | "_matchfiles", | |
1671 | "max", |
|
1671 | "max", | |
1672 | "merge", |
|
1672 | "merge", | |
1673 | "min", |
|
1673 | "min", | |
1674 | "modifies", |
|
1674 | "modifies", | |
1675 | "obsolete", |
|
1675 | "obsolete", | |
1676 | "origin", |
|
1676 | "origin", | |
1677 | "outgoing", |
|
1677 | "outgoing", | |
1678 | "p1", |
|
1678 | "p1", | |
1679 | "p2", |
|
1679 | "p2", | |
1680 | "parents", |
|
1680 | "parents", | |
1681 | "present", |
|
1681 | "present", | |
1682 | "public", |
|
1682 | "public", | |
1683 | "remote", |
|
1683 | "remote", | |
1684 | "removes", |
|
1684 | "removes", | |
1685 | "rev", |
|
1685 | "rev", | |
1686 | "reverse", |
|
1686 | "reverse", | |
1687 | "roots", |
|
1687 | "roots", | |
1688 | "sort", |
|
1688 | "sort", | |
1689 | "secret", |
|
1689 | "secret", | |
1690 | "matching", |
|
1690 | "matching", | |
1691 | "tag", |
|
1691 | "tag", | |
1692 | "tagged", |
|
1692 | "tagged", | |
1693 | "user", |
|
1693 | "user", | |
1694 | "unstable", |
|
1694 | "unstable", | |
1695 | "_list", |
|
1695 | "_list", | |
1696 | ]) |
|
1696 | ]) | |
1697 |
|
1697 | |||
1698 | methods = { |
|
1698 | methods = { | |
1699 | "range": rangeset, |
|
1699 | "range": rangeset, | |
1700 | "dagrange": dagrange, |
|
1700 | "dagrange": dagrange, | |
1701 | "string": stringset, |
|
1701 | "string": stringset, | |
1702 | "symbol": symbolset, |
|
1702 | "symbol": symbolset, | |
1703 | "and": andset, |
|
1703 | "and": andset, | |
1704 | "or": orset, |
|
1704 | "or": orset, | |
1705 | "not": notset, |
|
1705 | "not": notset, | |
1706 | "list": listset, |
|
1706 | "list": listset, | |
1707 | "func": func, |
|
1707 | "func": func, | |
1708 | "ancestor": ancestorspec, |
|
1708 | "ancestor": ancestorspec, | |
1709 | "parent": parentspec, |
|
1709 | "parent": parentspec, | |
1710 | "parentpost": p1, |
|
1710 | "parentpost": p1, | |
1711 | } |
|
1711 | } | |
1712 |
|
1712 | |||
1713 | def optimize(x, small): |
|
1713 | def optimize(x, small): | |
1714 | if x is None: |
|
1714 | if x is None: | |
1715 | return 0, x |
|
1715 | return 0, x | |
1716 |
|
1716 | |||
1717 | smallbonus = 1 |
|
1717 | smallbonus = 1 | |
1718 | if small: |
|
1718 | if small: | |
1719 | smallbonus = .5 |
|
1719 | smallbonus = .5 | |
1720 |
|
1720 | |||
1721 | op = x[0] |
|
1721 | op = x[0] | |
1722 | if op == 'minus': |
|
1722 | if op == 'minus': | |
1723 | return optimize(('and', x[1], ('not', x[2])), small) |
|
1723 | return optimize(('and', x[1], ('not', x[2])), small) | |
1724 | elif op == 'dagrangepre': |
|
1724 | elif op == 'dagrangepre': | |
1725 | return optimize(('func', ('symbol', 'ancestors'), x[1]), small) |
|
1725 | return optimize(('func', ('symbol', 'ancestors'), x[1]), small) | |
1726 | elif op == 'dagrangepost': |
|
1726 | elif op == 'dagrangepost': | |
1727 | return optimize(('func', ('symbol', 'descendants'), x[1]), small) |
|
1727 | return optimize(('func', ('symbol', 'descendants'), x[1]), small) | |
1728 | elif op == 'rangepre': |
|
1728 | elif op == 'rangepre': | |
1729 | return optimize(('range', ('string', '0'), x[1]), small) |
|
1729 | return optimize(('range', ('string', '0'), x[1]), small) | |
1730 | elif op == 'rangepost': |
|
1730 | elif op == 'rangepost': | |
1731 | return optimize(('range', x[1], ('string', 'tip')), small) |
|
1731 | return optimize(('range', x[1], ('string', 'tip')), small) | |
1732 | elif op == 'negate': |
|
1732 | elif op == 'negate': | |
1733 | return optimize(('string', |
|
1733 | return optimize(('string', | |
1734 | '-' + getstring(x[1], _("can't negate that"))), small) |
|
1734 | '-' + getstring(x[1], _("can't negate that"))), small) | |
1735 | elif op in 'string symbol negate': |
|
1735 | elif op in 'string symbol negate': | |
1736 | return smallbonus, x # single revisions are small |
|
1736 | return smallbonus, x # single revisions are small | |
1737 | elif op == 'and': |
|
1737 | elif op == 'and': | |
1738 | wa, ta = optimize(x[1], True) |
|
1738 | wa, ta = optimize(x[1], True) | |
1739 | wb, tb = optimize(x[2], True) |
|
1739 | wb, tb = optimize(x[2], True) | |
1740 | w = min(wa, wb) |
|
1740 | w = min(wa, wb) | |
1741 | if wa > wb: |
|
1741 | if wa > wb: | |
1742 | return w, (op, tb, ta) |
|
1742 | return w, (op, tb, ta) | |
1743 | return w, (op, ta, tb) |
|
1743 | return w, (op, ta, tb) | |
1744 | elif op == 'or': |
|
1744 | elif op == 'or': | |
1745 | wa, ta = optimize(x[1], False) |
|
1745 | wa, ta = optimize(x[1], False) | |
1746 | wb, tb = optimize(x[2], False) |
|
1746 | wb, tb = optimize(x[2], False) | |
1747 | if wb < wa: |
|
1747 | if wb < wa: | |
1748 | wb, wa = wa, wb |
|
1748 | wb, wa = wa, wb | |
1749 | return max(wa, wb), (op, ta, tb) |
|
1749 | return max(wa, wb), (op, ta, tb) | |
1750 | elif op == 'not': |
|
1750 | elif op == 'not': | |
1751 | o = optimize(x[1], not small) |
|
1751 | o = optimize(x[1], not small) | |
1752 | return o[0], (op, o[1]) |
|
1752 | return o[0], (op, o[1]) | |
1753 | elif op == 'parentpost': |
|
1753 | elif op == 'parentpost': | |
1754 | o = optimize(x[1], small) |
|
1754 | o = optimize(x[1], small) | |
1755 | return o[0], (op, o[1]) |
|
1755 | return o[0], (op, o[1]) | |
1756 | elif op == 'group': |
|
1756 | elif op == 'group': | |
1757 | return optimize(x[1], small) |
|
1757 | return optimize(x[1], small) | |
1758 | elif op in 'dagrange range list parent ancestorspec': |
|
1758 | elif op in 'dagrange range list parent ancestorspec': | |
1759 | if op == 'parent': |
|
1759 | if op == 'parent': | |
1760 | # x^:y means (x^) : y, not x ^ (:y) |
|
1760 | # x^:y means (x^) : y, not x ^ (:y) | |
1761 | post = ('parentpost', x[1]) |
|
1761 | post = ('parentpost', x[1]) | |
1762 | if x[2][0] == 'dagrangepre': |
|
1762 | if x[2][0] == 'dagrangepre': | |
1763 | return optimize(('dagrange', post, x[2][1]), small) |
|
1763 | return optimize(('dagrange', post, x[2][1]), small) | |
1764 | elif x[2][0] == 'rangepre': |
|
1764 | elif x[2][0] == 'rangepre': | |
1765 | return optimize(('range', post, x[2][1]), small) |
|
1765 | return optimize(('range', post, x[2][1]), small) | |
1766 |
|
1766 | |||
1767 | wa, ta = optimize(x[1], small) |
|
1767 | wa, ta = optimize(x[1], small) | |
1768 | wb, tb = optimize(x[2], small) |
|
1768 | wb, tb = optimize(x[2], small) | |
1769 | return wa + wb, (op, ta, tb) |
|
1769 | return wa + wb, (op, ta, tb) | |
1770 | elif op == 'func': |
|
1770 | elif op == 'func': | |
1771 | f = getstring(x[1], _("not a symbol")) |
|
1771 | f = getstring(x[1], _("not a symbol")) | |
1772 | wa, ta = optimize(x[2], small) |
|
1772 | wa, ta = optimize(x[2], small) | |
1773 | if f in ("author branch closed date desc file grep keyword " |
|
1773 | if f in ("author branch closed date desc file grep keyword " | |
1774 | "outgoing user"): |
|
1774 | "outgoing user"): | |
1775 | w = 10 # slow |
|
1775 | w = 10 # slow | |
1776 | elif f in "modifies adds removes": |
|
1776 | elif f in "modifies adds removes": | |
1777 | w = 30 # slower |
|
1777 | w = 30 # slower | |
1778 | elif f == "contains": |
|
1778 | elif f == "contains": | |
1779 | w = 100 # very slow |
|
1779 | w = 100 # very slow | |
1780 | elif f == "ancestor": |
|
1780 | elif f == "ancestor": | |
1781 | w = 1 * smallbonus |
|
1781 | w = 1 * smallbonus | |
1782 | elif f in "reverse limit first": |
|
1782 | elif f in "reverse limit first": | |
1783 | w = 0 |
|
1783 | w = 0 | |
1784 | elif f in "sort": |
|
1784 | elif f in "sort": | |
1785 | w = 10 # assume most sorts look at changelog |
|
1785 | w = 10 # assume most sorts look at changelog | |
1786 | else: |
|
1786 | else: | |
1787 | w = 1 |
|
1787 | w = 1 | |
1788 | return w + wa, (op, x[1], ta) |
|
1788 | return w + wa, (op, x[1], ta) | |
1789 | return 1, x |
|
1789 | return 1, x | |
1790 |
|
1790 | |||
1791 | _aliasarg = ('func', ('symbol', '_aliasarg')) |
|
1791 | _aliasarg = ('func', ('symbol', '_aliasarg')) | |
1792 | def _getaliasarg(tree): |
|
1792 | def _getaliasarg(tree): | |
1793 | """If tree matches ('func', ('symbol', '_aliasarg'), ('string', X)) |
|
1793 | """If tree matches ('func', ('symbol', '_aliasarg'), ('string', X)) | |
1794 | return X, None otherwise. |
|
1794 | return X, None otherwise. | |
1795 | """ |
|
1795 | """ | |
1796 | if (len(tree) == 3 and tree[:2] == _aliasarg |
|
1796 | if (len(tree) == 3 and tree[:2] == _aliasarg | |
1797 | and tree[2][0] == 'string'): |
|
1797 | and tree[2][0] == 'string'): | |
1798 | return tree[2][1] |
|
1798 | return tree[2][1] | |
1799 | return None |
|
1799 | return None | |
1800 |
|
1800 | |||
1801 | def _checkaliasarg(tree, known=None): |
|
1801 | def _checkaliasarg(tree, known=None): | |
1802 | """Check tree contains no _aliasarg construct or only ones which |
|
1802 | """Check tree contains no _aliasarg construct or only ones which | |
1803 | value is in known. Used to avoid alias placeholders injection. |
|
1803 | value is in known. Used to avoid alias placeholders injection. | |
1804 | """ |
|
1804 | """ | |
1805 | if isinstance(tree, tuple): |
|
1805 | if isinstance(tree, tuple): | |
1806 | arg = _getaliasarg(tree) |
|
1806 | arg = _getaliasarg(tree) | |
1807 | if arg is not None and (not known or arg not in known): |
|
1807 | if arg is not None and (not known or arg not in known): | |
1808 | raise error.ParseError(_("not a function: %s") % '_aliasarg') |
|
1808 | raise error.ParseError(_("not a function: %s") % '_aliasarg') | |
1809 | for t in tree: |
|
1809 | for t in tree: | |
1810 | _checkaliasarg(t, known) |
|
1810 | _checkaliasarg(t, known) | |
1811 |
|
1811 | |||
1812 | class revsetalias(object): |
|
1812 | class revsetalias(object): | |
1813 | funcre = re.compile('^([^(]+)\(([^)]+)\)$') |
|
1813 | funcre = re.compile('^([^(]+)\(([^)]+)\)$') | |
1814 | args = None |
|
1814 | args = None | |
1815 |
|
1815 | |||
1816 | def __init__(self, name, value): |
|
1816 | def __init__(self, name, value): | |
1817 | '''Aliases like: |
|
1817 | '''Aliases like: | |
1818 |
|
1818 | |||
1819 | h = heads(default) |
|
1819 | h = heads(default) | |
1820 | b($1) = ancestors($1) - ancestors(default) |
|
1820 | b($1) = ancestors($1) - ancestors(default) | |
1821 | ''' |
|
1821 | ''' | |
1822 | m = self.funcre.search(name) |
|
1822 | m = self.funcre.search(name) | |
1823 | if m: |
|
1823 | if m: | |
1824 | self.name = m.group(1) |
|
1824 | self.name = m.group(1) | |
1825 | self.tree = ('func', ('symbol', m.group(1))) |
|
1825 | self.tree = ('func', ('symbol', m.group(1))) | |
1826 | self.args = [x.strip() for x in m.group(2).split(',')] |
|
1826 | self.args = [x.strip() for x in m.group(2).split(',')] | |
1827 | for arg in self.args: |
|
1827 | for arg in self.args: | |
1828 | # _aliasarg() is an unknown symbol only used separate |
|
1828 | # _aliasarg() is an unknown symbol only used separate | |
1829 | # alias argument placeholders from regular strings. |
|
1829 | # alias argument placeholders from regular strings. | |
1830 | value = value.replace(arg, '_aliasarg(%r)' % (arg,)) |
|
1830 | value = value.replace(arg, '_aliasarg(%r)' % (arg,)) | |
1831 | else: |
|
1831 | else: | |
1832 | self.name = name |
|
1832 | self.name = name | |
1833 | self.tree = ('symbol', name) |
|
1833 | self.tree = ('symbol', name) | |
1834 |
|
1834 | |||
1835 | self.replacement, pos = parse(value) |
|
1835 | self.replacement, pos = parse(value) | |
1836 | if pos != len(value): |
|
1836 | if pos != len(value): | |
1837 | raise error.ParseError(_('invalid token'), pos) |
|
1837 | raise error.ParseError(_('invalid token'), pos) | |
1838 | # Check for placeholder injection |
|
1838 | # Check for placeholder injection | |
1839 | _checkaliasarg(self.replacement, self.args) |
|
1839 | _checkaliasarg(self.replacement, self.args) | |
1840 |
|
1840 | |||
1841 | def _getalias(aliases, tree): |
|
1841 | def _getalias(aliases, tree): | |
1842 | """If tree looks like an unexpanded alias, return it. Return None |
|
1842 | """If tree looks like an unexpanded alias, return it. Return None | |
1843 | otherwise. |
|
1843 | otherwise. | |
1844 | """ |
|
1844 | """ | |
1845 | if isinstance(tree, tuple) and tree: |
|
1845 | if isinstance(tree, tuple) and tree: | |
1846 | if tree[0] == 'symbol' and len(tree) == 2: |
|
1846 | if tree[0] == 'symbol' and len(tree) == 2: | |
1847 | name = tree[1] |
|
1847 | name = tree[1] | |
1848 | alias = aliases.get(name) |
|
1848 | alias = aliases.get(name) | |
1849 | if alias and alias.args is None and alias.tree == tree: |
|
1849 | if alias and alias.args is None and alias.tree == tree: | |
1850 | return alias |
|
1850 | return alias | |
1851 | if tree[0] == 'func' and len(tree) > 1: |
|
1851 | if tree[0] == 'func' and len(tree) > 1: | |
1852 | if tree[1][0] == 'symbol' and len(tree[1]) == 2: |
|
1852 | if tree[1][0] == 'symbol' and len(tree[1]) == 2: | |
1853 | name = tree[1][1] |
|
1853 | name = tree[1][1] | |
1854 | alias = aliases.get(name) |
|
1854 | alias = aliases.get(name) | |
1855 | if alias and alias.args is not None and alias.tree == tree[:2]: |
|
1855 | if alias and alias.args is not None and alias.tree == tree[:2]: | |
1856 | return alias |
|
1856 | return alias | |
1857 | return None |
|
1857 | return None | |
1858 |
|
1858 | |||
1859 | def _expandargs(tree, args): |
|
1859 | def _expandargs(tree, args): | |
1860 | """Replace _aliasarg instances with the substitution value of the |
|
1860 | """Replace _aliasarg instances with the substitution value of the | |
1861 | same name in args, recursively. |
|
1861 | same name in args, recursively. | |
1862 | """ |
|
1862 | """ | |
1863 | if not tree or not isinstance(tree, tuple): |
|
1863 | if not tree or not isinstance(tree, tuple): | |
1864 | return tree |
|
1864 | return tree | |
1865 | arg = _getaliasarg(tree) |
|
1865 | arg = _getaliasarg(tree) | |
1866 | if arg is not None: |
|
1866 | if arg is not None: | |
1867 | return args[arg] |
|
1867 | return args[arg] | |
1868 | return tuple(_expandargs(t, args) for t in tree) |
|
1868 | return tuple(_expandargs(t, args) for t in tree) | |
1869 |
|
1869 | |||
1870 | def _expandaliases(aliases, tree, expanding, cache): |
|
1870 | def _expandaliases(aliases, tree, expanding, cache): | |
1871 | """Expand aliases in tree, recursively. |
|
1871 | """Expand aliases in tree, recursively. | |
1872 |
|
1872 | |||
1873 | 'aliases' is a dictionary mapping user defined aliases to |
|
1873 | 'aliases' is a dictionary mapping user defined aliases to | |
1874 | revsetalias objects. |
|
1874 | revsetalias objects. | |
1875 | """ |
|
1875 | """ | |
1876 | if not isinstance(tree, tuple): |
|
1876 | if not isinstance(tree, tuple): | |
1877 | # Do not expand raw strings |
|
1877 | # Do not expand raw strings | |
1878 | return tree |
|
1878 | return tree | |
1879 | alias = _getalias(aliases, tree) |
|
1879 | alias = _getalias(aliases, tree) | |
1880 | if alias is not None: |
|
1880 | if alias is not None: | |
1881 | if alias in expanding: |
|
1881 | if alias in expanding: | |
1882 | raise error.ParseError(_('infinite expansion of revset alias "%s" ' |
|
1882 | raise error.ParseError(_('infinite expansion of revset alias "%s" ' | |
1883 | 'detected') % alias.name) |
|
1883 | 'detected') % alias.name) | |
1884 | expanding.append(alias) |
|
1884 | expanding.append(alias) | |
1885 | if alias.name not in cache: |
|
1885 | if alias.name not in cache: | |
1886 | cache[alias.name] = _expandaliases(aliases, alias.replacement, |
|
1886 | cache[alias.name] = _expandaliases(aliases, alias.replacement, | |
1887 | expanding, cache) |
|
1887 | expanding, cache) | |
1888 | result = cache[alias.name] |
|
1888 | result = cache[alias.name] | |
1889 | expanding.pop() |
|
1889 | expanding.pop() | |
1890 | if alias.args is not None: |
|
1890 | if alias.args is not None: | |
1891 | l = getlist(tree[2]) |
|
1891 | l = getlist(tree[2]) | |
1892 | if len(l) != len(alias.args): |
|
1892 | if len(l) != len(alias.args): | |
1893 | raise error.ParseError( |
|
1893 | raise error.ParseError( | |
1894 | _('invalid number of arguments: %s') % len(l)) |
|
1894 | _('invalid number of arguments: %s') % len(l)) | |
1895 | l = [_expandaliases(aliases, a, [], cache) for a in l] |
|
1895 | l = [_expandaliases(aliases, a, [], cache) for a in l] | |
1896 | result = _expandargs(result, dict(zip(alias.args, l))) |
|
1896 | result = _expandargs(result, dict(zip(alias.args, l))) | |
1897 | else: |
|
1897 | else: | |
1898 | result = tuple(_expandaliases(aliases, t, expanding, cache) |
|
1898 | result = tuple(_expandaliases(aliases, t, expanding, cache) | |
1899 | for t in tree) |
|
1899 | for t in tree) | |
1900 | return result |
|
1900 | return result | |
1901 |
|
1901 | |||
1902 | def findaliases(ui, tree): |
|
1902 | def findaliases(ui, tree): | |
1903 | _checkaliasarg(tree) |
|
1903 | _checkaliasarg(tree) | |
1904 | aliases = {} |
|
1904 | aliases = {} | |
1905 | for k, v in ui.configitems('revsetalias'): |
|
1905 | for k, v in ui.configitems('revsetalias'): | |
1906 | alias = revsetalias(k, v) |
|
1906 | alias = revsetalias(k, v) | |
1907 | aliases[alias.name] = alias |
|
1907 | aliases[alias.name] = alias | |
1908 | return _expandaliases(aliases, tree, [], {}) |
|
1908 | return _expandaliases(aliases, tree, [], {}) | |
1909 |
|
1909 | |||
1910 | def parse(spec): |
|
1910 | def parse(spec): | |
1911 | p = parser.parser(tokenize, elements) |
|
1911 | p = parser.parser(tokenize, elements) | |
1912 | return p.parse(spec) |
|
1912 | return p.parse(spec) | |
1913 |
|
1913 | |||
1914 | def match(ui, spec): |
|
1914 | def match(ui, spec): | |
1915 | if not spec: |
|
1915 | if not spec: | |
1916 | raise error.ParseError(_("empty query")) |
|
1916 | raise error.ParseError(_("empty query")) | |
1917 | tree, pos = parse(spec) |
|
1917 | tree, pos = parse(spec) | |
1918 | if (pos != len(spec)): |
|
1918 | if (pos != len(spec)): | |
1919 | raise error.ParseError(_("invalid token"), pos) |
|
1919 | raise error.ParseError(_("invalid token"), pos) | |
1920 | if ui: |
|
1920 | if ui: | |
1921 | tree = findaliases(ui, tree) |
|
1921 | tree = findaliases(ui, tree) | |
1922 | weight, tree = optimize(tree, True) |
|
1922 | weight, tree = optimize(tree, True) | |
1923 | def mfunc(repo, subset): |
|
1923 | def mfunc(repo, subset): | |
1924 | return getset(repo, subset, tree) |
|
1924 | return getset(repo, subset, tree) | |
1925 | return mfunc |
|
1925 | return mfunc | |
1926 |
|
1926 | |||
1927 | def formatspec(expr, *args): |
|
1927 | def formatspec(expr, *args): | |
1928 | ''' |
|
1928 | ''' | |
1929 | This is a convenience function for using revsets internally, and |
|
1929 | This is a convenience function for using revsets internally, and | |
1930 | escapes arguments appropriately. Aliases are intentionally ignored |
|
1930 | escapes arguments appropriately. Aliases are intentionally ignored | |
1931 | so that intended expression behavior isn't accidentally subverted. |
|
1931 | so that intended expression behavior isn't accidentally subverted. | |
1932 |
|
1932 | |||
1933 | Supported arguments: |
|
1933 | Supported arguments: | |
1934 |
|
1934 | |||
1935 | %r = revset expression, parenthesized |
|
1935 | %r = revset expression, parenthesized | |
1936 | %d = int(arg), no quoting |
|
1936 | %d = int(arg), no quoting | |
1937 | %s = string(arg), escaped and single-quoted |
|
1937 | %s = string(arg), escaped and single-quoted | |
1938 | %b = arg.branch(), escaped and single-quoted |
|
1938 | %b = arg.branch(), escaped and single-quoted | |
1939 | %n = hex(arg), single-quoted |
|
1939 | %n = hex(arg), single-quoted | |
1940 | %% = a literal '%' |
|
1940 | %% = a literal '%' | |
1941 |
|
1941 | |||
1942 | Prefixing the type with 'l' specifies a parenthesized list of that type. |
|
1942 | Prefixing the type with 'l' specifies a parenthesized list of that type. | |
1943 |
|
1943 | |||
1944 | >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()")) |
|
1944 | >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()")) | |
1945 | '(10 or 11):: and ((this()) or (that()))' |
|
1945 | '(10 or 11):: and ((this()) or (that()))' | |
1946 | >>> formatspec('%d:: and not %d::', 10, 20) |
|
1946 | >>> formatspec('%d:: and not %d::', 10, 20) | |
1947 | '10:: and not 20::' |
|
1947 | '10:: and not 20::' | |
1948 | >>> formatspec('%ld or %ld', [], [1]) |
|
1948 | >>> formatspec('%ld or %ld', [], [1]) | |
1949 | "_list('') or 1" |
|
1949 | "_list('') or 1" | |
1950 | >>> formatspec('keyword(%s)', 'foo\\xe9') |
|
1950 | >>> formatspec('keyword(%s)', 'foo\\xe9') | |
1951 | "keyword('foo\\\\xe9')" |
|
1951 | "keyword('foo\\\\xe9')" | |
1952 | >>> b = lambda: 'default' |
|
1952 | >>> b = lambda: 'default' | |
1953 | >>> b.branch = b |
|
1953 | >>> b.branch = b | |
1954 | >>> formatspec('branch(%b)', b) |
|
1954 | >>> formatspec('branch(%b)', b) | |
1955 | "branch('default')" |
|
1955 | "branch('default')" | |
1956 | >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) |
|
1956 | >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) | |
1957 | "root(_list('a\\x00b\\x00c\\x00d'))" |
|
1957 | "root(_list('a\\x00b\\x00c\\x00d'))" | |
1958 | ''' |
|
1958 | ''' | |
1959 |
|
1959 | |||
1960 | def quote(s): |
|
1960 | def quote(s): | |
1961 | return repr(str(s)) |
|
1961 | return repr(str(s)) | |
1962 |
|
1962 | |||
1963 | def argtype(c, arg): |
|
1963 | def argtype(c, arg): | |
1964 | if c == 'd': |
|
1964 | if c == 'd': | |
1965 | return str(int(arg)) |
|
1965 | return str(int(arg)) | |
1966 | elif c == 's': |
|
1966 | elif c == 's': | |
1967 | return quote(arg) |
|
1967 | return quote(arg) | |
1968 | elif c == 'r': |
|
1968 | elif c == 'r': | |
1969 | parse(arg) # make sure syntax errors are confined |
|
1969 | parse(arg) # make sure syntax errors are confined | |
1970 | return '(%s)' % arg |
|
1970 | return '(%s)' % arg | |
1971 | elif c == 'n': |
|
1971 | elif c == 'n': | |
1972 | return quote(node.hex(arg)) |
|
1972 | return quote(node.hex(arg)) | |
1973 | elif c == 'b': |
|
1973 | elif c == 'b': | |
1974 | return quote(arg.branch()) |
|
1974 | return quote(arg.branch()) | |
1975 |
|
1975 | |||
1976 | def listexp(s, t): |
|
1976 | def listexp(s, t): | |
1977 | l = len(s) |
|
1977 | l = len(s) | |
1978 | if l == 0: |
|
1978 | if l == 0: | |
1979 | return "_list('')" |
|
1979 | return "_list('')" | |
1980 | elif l == 1: |
|
1980 | elif l == 1: | |
1981 | return argtype(t, s[0]) |
|
1981 | return argtype(t, s[0]) | |
1982 | elif t == 'd': |
|
1982 | elif t == 'd': | |
1983 | return "_list('%s')" % "\0".join(str(int(a)) for a in s) |
|
1983 | return "_list('%s')" % "\0".join(str(int(a)) for a in s) | |
1984 | elif t == 's': |
|
1984 | elif t == 's': | |
1985 | return "_list('%s')" % "\0".join(s) |
|
1985 | return "_list('%s')" % "\0".join(s) | |
1986 | elif t == 'n': |
|
1986 | elif t == 'n': | |
1987 | return "_list('%s')" % "\0".join(node.hex(a) for a in s) |
|
1987 | return "_list('%s')" % "\0".join(node.hex(a) for a in s) | |
1988 | elif t == 'b': |
|
1988 | elif t == 'b': | |
1989 | return "_list('%s')" % "\0".join(a.branch() for a in s) |
|
1989 | return "_list('%s')" % "\0".join(a.branch() for a in s) | |
1990 |
|
1990 | |||
1991 | m = l // 2 |
|
1991 | m = l // 2 | |
1992 | return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) |
|
1992 | return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) | |
1993 |
|
1993 | |||
1994 | ret = '' |
|
1994 | ret = '' | |
1995 | pos = 0 |
|
1995 | pos = 0 | |
1996 | arg = 0 |
|
1996 | arg = 0 | |
1997 | while pos < len(expr): |
|
1997 | while pos < len(expr): | |
1998 | c = expr[pos] |
|
1998 | c = expr[pos] | |
1999 | if c == '%': |
|
1999 | if c == '%': | |
2000 | pos += 1 |
|
2000 | pos += 1 | |
2001 | d = expr[pos] |
|
2001 | d = expr[pos] | |
2002 | if d == '%': |
|
2002 | if d == '%': | |
2003 | ret += d |
|
2003 | ret += d | |
2004 | elif d in 'dsnbr': |
|
2004 | elif d in 'dsnbr': | |
2005 | ret += argtype(d, args[arg]) |
|
2005 | ret += argtype(d, args[arg]) | |
2006 | arg += 1 |
|
2006 | arg += 1 | |
2007 | elif d == 'l': |
|
2007 | elif d == 'l': | |
2008 | # a list of some type |
|
2008 | # a list of some type | |
2009 | pos += 1 |
|
2009 | pos += 1 | |
2010 | d = expr[pos] |
|
2010 | d = expr[pos] | |
2011 | ret += listexp(list(args[arg]), d) |
|
2011 | ret += listexp(list(args[arg]), d) | |
2012 | arg += 1 |
|
2012 | arg += 1 | |
2013 | else: |
|
2013 | else: | |
2014 | raise util.Abort('unexpected revspec format character %s' % d) |
|
2014 | raise util.Abort('unexpected revspec format character %s' % d) | |
2015 | else: |
|
2015 | else: | |
2016 | ret += c |
|
2016 | ret += c | |
2017 | pos += 1 |
|
2017 | pos += 1 | |
2018 |
|
2018 | |||
2019 | return ret |
|
2019 | return ret | |
2020 |
|
2020 | |||
2021 | def prettyformat(tree): |
|
2021 | def prettyformat(tree): | |
2022 | def _prettyformat(tree, level, lines): |
|
2022 | def _prettyformat(tree, level, lines): | |
2023 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): |
|
2023 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): | |
2024 | lines.append((level, str(tree))) |
|
2024 | lines.append((level, str(tree))) | |
2025 | else: |
|
2025 | else: | |
2026 | lines.append((level, '(%s' % tree[0])) |
|
2026 | lines.append((level, '(%s' % tree[0])) | |
2027 | for s in tree[1:]: |
|
2027 | for s in tree[1:]: | |
2028 | _prettyformat(s, level + 1, lines) |
|
2028 | _prettyformat(s, level + 1, lines) | |
2029 | lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] |
|
2029 | lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] | |
2030 |
|
2030 | |||
2031 | lines = [] |
|
2031 | lines = [] | |
2032 | _prettyformat(tree, 0, lines) |
|
2032 | _prettyformat(tree, 0, lines) | |
2033 | output = '\n'.join((' '*l + s) for l, s in lines) |
|
2033 | output = '\n'.join((' '*l + s) for l, s in lines) | |
2034 | return output |
|
2034 | return output | |
2035 |
|
2035 | |||
2036 | def depth(tree): |
|
2036 | def depth(tree): | |
2037 | if isinstance(tree, tuple): |
|
2037 | if isinstance(tree, tuple): | |
2038 | return max(map(depth, tree)) + 1 |
|
2038 | return max(map(depth, tree)) + 1 | |
2039 | else: |
|
2039 | else: | |
2040 | return 0 |
|
2040 | return 0 | |
2041 |
|
2041 | |||
2042 | def funcsused(tree): |
|
2042 | def funcsused(tree): | |
2043 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): |
|
2043 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): | |
2044 | return set() |
|
2044 | return set() | |
2045 | else: |
|
2045 | else: | |
2046 | funcs = set() |
|
2046 | funcs = set() | |
2047 | for s in tree[1:]: |
|
2047 | for s in tree[1:]: | |
2048 | funcs |= funcsused(s) |
|
2048 | funcs |= funcsused(s) | |
2049 | if tree[0] == 'func': |
|
2049 | if tree[0] == 'func': | |
2050 | funcs.add(tree[1][1]) |
|
2050 | funcs.add(tree[1][1]) | |
2051 | return funcs |
|
2051 | return funcs | |
2052 |
|
2052 | |||
2053 | class baseset(list): |
|
2053 | class baseset(list): | |
2054 | """Basic data structure that represents a revset and contains the basic |
|
2054 | """Basic data structure that represents a revset and contains the basic | |
2055 | operation that it should be able to perform. |
|
2055 | operation that it should be able to perform. | |
2056 | """ |
|
2056 | """ | |
2057 | def __init__(self, data): |
|
2057 | def __init__(self, data): | |
2058 | super(baseset, self).__init__(data) |
|
2058 | super(baseset, self).__init__(data) | |
2059 | self._set = None |
|
2059 | self._set = None | |
2060 |
|
2060 | |||
2061 | def set(self): |
|
2061 | def set(self): | |
2062 | if not self._set: |
|
2062 | if not self._set: | |
2063 | self._set = set(self) |
|
2063 | self._set = set(self) | |
2064 | return self._set |
|
2064 | return self._set | |
2065 |
|
2065 | |||
2066 | def __sub__(self, x): |
|
2066 | def __sub__(self, x): | |
2067 | if isinstance(x, baseset): |
|
2067 | if isinstance(x, baseset): | |
2068 | s = x.set() |
|
2068 | s = x.set() | |
2069 | else: |
|
2069 | else: | |
2070 | s = set(x) |
|
2070 | s = set(x) | |
2071 | return baseset(self.set() - s) |
|
2071 | return baseset(self.set() - s) | |
2072 |
|
2072 | |||
2073 | def __and__(self, x): |
|
2073 | def __and__(self, x): | |
2074 | if isinstance(x, baseset): |
|
2074 | if isinstance(x, baseset): | |
2075 | x = x.set() |
|
2075 | x = x.set() | |
2076 | return baseset([y for y in self if y in x]) |
|
2076 | return baseset([y for y in self if y in x]) | |
2077 |
|
2077 | |||
2078 | def __add__(self, x): |
|
2078 | def __add__(self, x): | |
2079 | s = self.set() |
|
2079 | s = self.set() | |
2080 | l = [r for r in x if r not in s] |
|
2080 | l = [r for r in x if r not in s] | |
2081 | return baseset(list(self) + l) |
|
2081 | return baseset(list(self) + l) | |
2082 |
|
2082 | |||
2083 | class lazyset(object): |
|
2083 | class lazyset(object): | |
2084 | """Duck type for baseset class which iterates lazily over the revisions in |
|
2084 | """Duck type for baseset class which iterates lazily over the revisions in | |
2085 | the subset and contains a function which tests for membership in the |
|
2085 | the subset and contains a function which tests for membership in the | |
2086 | revset |
|
2086 | revset | |
2087 | """ |
|
2087 | """ | |
2088 | def __init__(self, subset, condition): |
|
2088 | def __init__(self, subset, condition): | |
2089 | self._subset = subset |
|
2089 | self._subset = subset | |
2090 | self._condition = condition |
|
2090 | self._condition = condition | |
2091 |
|
2091 | |||
2092 | def __contains__(self, x): |
|
2092 | def __contains__(self, x): | |
2093 | return x in self._subset and self._condition(x) |
|
2093 | return x in self._subset and self._condition(x) | |
2094 |
|
2094 | |||
2095 | def __iter__(self): |
|
2095 | def __iter__(self): | |
2096 | cond = self._condition |
|
2096 | cond = self._condition | |
2097 | for x in self._subset: |
|
2097 | for x in self._subset: | |
2098 | if cond(x): |
|
2098 | if cond(x): | |
2099 | yield x |
|
2099 | yield x | |
2100 |
|
2100 | |||
2101 | def __and__(self, x): |
|
2101 | def __and__(self, x): | |
2102 | return lazyset(self, lambda r: r in x) |
|
2102 | return lazyset(self, lambda r: r in x) | |
2103 |
|
2103 | |||
2104 | def __sub__(self, x): |
|
2104 | def __sub__(self, x): | |
2105 | return lazyset(self, lambda r: r not in x) |
|
2105 | return lazyset(self, lambda r: r not in x) | |
2106 |
|
2106 | |||
2107 | def __add__(self, x): |
|
2107 | def __add__(self, x): | |
2108 | l = baseset([r for r in self]) |
|
2108 | l = baseset([r for r in self]) | |
2109 | return l + baseset(x) |
|
2109 | return l + baseset(x) | |
2110 |
|
2110 | |||
2111 | def __len__(self): |
|
2111 | def __len__(self): | |
2112 | # Basic implementation to be changed in future patches. |
|
2112 | # Basic implementation to be changed in future patches. | |
2113 | l = baseset([r for r in self]) |
|
2113 | l = baseset([r for r in self]) | |
2114 | return len(l) |
|
2114 | return len(l) | |
2115 |
|
2115 | |||
2116 | def __getitem__(self, x): |
|
2116 | def __getitem__(self, x): | |
2117 | # Basic implementation to be changed in future patches. |
|
2117 | # Basic implementation to be changed in future patches. | |
2118 | l = baseset([r for r in self]) |
|
2118 | l = baseset([r for r in self]) | |
2119 | return l[x] |
|
2119 | return l[x] | |
2120 |
|
2120 | |||
2121 | def sort(self, reverse=False): |
|
2121 | def sort(self, reverse=False): | |
2122 | # Basic implementation to be changed in future patches. |
|
2122 | # Basic implementation to be changed in future patches. | |
2123 | self._subset = baseset(self._subset) |
|
2123 | self._subset = baseset(self._subset) | |
2124 | self._subset.sort(reverse=reverse) |
|
2124 | self._subset.sort(reverse=reverse) | |
2125 |
|
2125 | |||
2126 | def reverse(self): |
|
2126 | def reverse(self): | |
2127 | self._subset.reverse() |
|
2127 | self._subset.reverse() | |
2128 |
|
2128 | |||
2129 | def set(self): |
|
2129 | def set(self): | |
2130 | return set([r for r in self]) |
|
2130 | return set([r for r in self]) | |
2131 |
|
2131 | |||
2132 | class spanset(object): |
|
2132 | class spanset(object): | |
2133 | """Duck type for baseset class which represents a range of revisions and |
|
2133 | """Duck type for baseset class which represents a range of revisions and | |
2134 | can work lazily and without having all the range in memory |
|
2134 | can work lazily and without having all the range in memory | |
2135 | """ |
|
2135 | """ | |
2136 | def __init__(self, start, end): |
|
2136 | def __init__(self, start, end): | |
2137 | self._start = start |
|
2137 | self._start = start | |
2138 | self._end = end |
|
2138 | self._end = end | |
2139 |
|
2139 | |||
2140 | def __iter__(self): |
|
2140 | def __iter__(self): | |
2141 | if self._start <= self._end: |
|
2141 | if self._start <= self._end: | |
2142 | for r in xrange(self._start, self._end): |
|
2142 | for r in xrange(self._start, self._end): | |
2143 | yield r |
|
2143 | yield r | |
2144 | else: |
|
2144 | else: | |
2145 | for r in xrange(self._start, self._end, -1): |
|
2145 | for r in xrange(self._start, self._end, -1): | |
2146 | yield r |
|
2146 | yield r | |
2147 |
|
2147 | |||
2148 | def __contains__(self, x): |
|
2148 | def __contains__(self, x): | |
2149 | return (x <= self._start and x > self._end) or (x >= self._start and x< |
|
2149 | return (x <= self._start and x > self._end) or (x >= self._start and x< | |
2150 | self._end) |
|
2150 | self._end) | |
2151 |
|
2151 | |||
2152 | def __and__(self, x): |
|
2152 | def __and__(self, x): | |
2153 | return lazyset(self, lambda r: r in x) |
|
2153 | return lazyset(self, lambda r: r in x) | |
2154 |
|
2154 | |||
2155 | def __sub__(self, x): |
|
2155 | def __sub__(self, x): | |
2156 | return lazyset(self, lambda r: r not in x) |
|
2156 | return lazyset(self, lambda r: r not in x) | |
2157 |
|
2157 | |||
2158 | def __add__(self, x): |
|
2158 | def __add__(self, x): | |
2159 | l = baseset(self) |
|
2159 | l = baseset(self) | |
2160 | return l + baseset(x) |
|
2160 | return l + baseset(x) | |
2161 |
|
2161 | |||
|
2162 | def __len__(self): | |||
|
2163 | return abs(self._end - self._start) | |||
|
2164 | ||||
|
2165 | def __getitem__(self, x): | |||
|
2166 | # Basic implementation to be changed in future patches. | |||
|
2167 | l = baseset([r for r in self]) | |||
|
2168 | return l[x] | |||
|
2169 | ||||
|
2170 | def sort(self, reverse=False): | |||
|
2171 | # Basic implementation to be changed in future patches. | |||
|
2172 | if reverse: | |||
|
2173 | self.reverse() | |||
|
2174 | ||||
|
2175 | def reverse(self): | |||
|
2176 | if self._start <= self._end: | |||
|
2177 | self._start, self._end = self._end - 1, self._start - 1 | |||
|
2178 | else: | |||
|
2179 | self._start, self._end = self._end + 1, self._start + 1 | |||
|
2180 | ||||
|
2181 | def set(self): | |||
|
2182 | return self | |||
|
2183 | ||||
2162 | # tell hggettext to extract docstrings from these functions: |
|
2184 | # tell hggettext to extract docstrings from these functions: | |
2163 | i18nfunctions = symbols.values() |
|
2185 | i18nfunctions = symbols.values() |
General Comments 0
You need to be logged in to leave comments.
Login now