Show More
@@ -1,3448 +1,3443 b'' | |||||
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, hbisect, phases |
|
9 | import parser, util, error, hbisect, phases | |
10 | import node |
|
10 | import node | |
11 | import heapq |
|
11 | import heapq | |
12 | import match as matchmod |
|
12 | import match as matchmod | |
13 | from i18n import _ |
|
13 | from i18n import _ | |
14 | import encoding |
|
14 | import encoding | |
15 | import obsolete as obsmod |
|
15 | import obsolete as obsmod | |
16 | import pathutil |
|
16 | import pathutil | |
17 | import repoview |
|
17 | import repoview | |
18 |
|
18 | |||
19 | def _revancestors(repo, revs, followfirst): |
|
19 | def _revancestors(repo, revs, followfirst): | |
20 | """Like revlog.ancestors(), but supports followfirst.""" |
|
20 | """Like revlog.ancestors(), but supports followfirst.""" | |
21 | if followfirst: |
|
21 | if followfirst: | |
22 | cut = 1 |
|
22 | cut = 1 | |
23 | else: |
|
23 | else: | |
24 | cut = None |
|
24 | cut = None | |
25 | cl = repo.changelog |
|
25 | cl = repo.changelog | |
26 |
|
26 | |||
27 | def iterate(): |
|
27 | def iterate(): | |
28 | revqueue, revsnode = None, None |
|
28 | revqueue, revsnode = None, None | |
29 | h = [] |
|
29 | h = [] | |
30 |
|
30 | |||
31 | revs.sort(reverse=True) |
|
31 | revs.sort(reverse=True) | |
32 | revqueue = util.deque(revs) |
|
32 | revqueue = util.deque(revs) | |
33 | if revqueue: |
|
33 | if revqueue: | |
34 | revsnode = revqueue.popleft() |
|
34 | revsnode = revqueue.popleft() | |
35 | heapq.heappush(h, -revsnode) |
|
35 | heapq.heappush(h, -revsnode) | |
36 |
|
36 | |||
37 | seen = set() |
|
37 | seen = set() | |
38 | while h: |
|
38 | while h: | |
39 | current = -heapq.heappop(h) |
|
39 | current = -heapq.heappop(h) | |
40 | if current not in seen: |
|
40 | if current not in seen: | |
41 | if revsnode and current == revsnode: |
|
41 | if revsnode and current == revsnode: | |
42 | if revqueue: |
|
42 | if revqueue: | |
43 | revsnode = revqueue.popleft() |
|
43 | revsnode = revqueue.popleft() | |
44 | heapq.heappush(h, -revsnode) |
|
44 | heapq.heappush(h, -revsnode) | |
45 | seen.add(current) |
|
45 | seen.add(current) | |
46 | yield current |
|
46 | yield current | |
47 | for parent in cl.parentrevs(current)[:cut]: |
|
47 | for parent in cl.parentrevs(current)[:cut]: | |
48 | if parent != node.nullrev: |
|
48 | if parent != node.nullrev: | |
49 | heapq.heappush(h, -parent) |
|
49 | heapq.heappush(h, -parent) | |
50 |
|
50 | |||
51 | return generatorset(iterate(), iterasc=False) |
|
51 | return generatorset(iterate(), iterasc=False) | |
52 |
|
52 | |||
53 | def _revdescendants(repo, revs, followfirst): |
|
53 | def _revdescendants(repo, revs, followfirst): | |
54 | """Like revlog.descendants() but supports followfirst.""" |
|
54 | """Like revlog.descendants() but supports followfirst.""" | |
55 | if followfirst: |
|
55 | if followfirst: | |
56 | cut = 1 |
|
56 | cut = 1 | |
57 | else: |
|
57 | else: | |
58 | cut = None |
|
58 | cut = None | |
59 |
|
59 | |||
60 | def iterate(): |
|
60 | def iterate(): | |
61 | cl = repo.changelog |
|
61 | cl = repo.changelog | |
62 | first = min(revs) |
|
62 | first = min(revs) | |
63 | nullrev = node.nullrev |
|
63 | nullrev = node.nullrev | |
64 | if first == nullrev: |
|
64 | if first == nullrev: | |
65 | # Are there nodes with a null first parent and a non-null |
|
65 | # Are there nodes with a null first parent and a non-null | |
66 | # second one? Maybe. Do we care? Probably not. |
|
66 | # second one? Maybe. Do we care? Probably not. | |
67 | for i in cl: |
|
67 | for i in cl: | |
68 | yield i |
|
68 | yield i | |
69 | else: |
|
69 | else: | |
70 | seen = set(revs) |
|
70 | seen = set(revs) | |
71 | for i in cl.revs(first + 1): |
|
71 | for i in cl.revs(first + 1): | |
72 | for x in cl.parentrevs(i)[:cut]: |
|
72 | for x in cl.parentrevs(i)[:cut]: | |
73 | if x != nullrev and x in seen: |
|
73 | if x != nullrev and x in seen: | |
74 | seen.add(i) |
|
74 | seen.add(i) | |
75 | yield i |
|
75 | yield i | |
76 | break |
|
76 | break | |
77 |
|
77 | |||
78 | return generatorset(iterate(), iterasc=True) |
|
78 | return generatorset(iterate(), iterasc=True) | |
79 |
|
79 | |||
80 | def _revsbetween(repo, roots, heads): |
|
80 | def _revsbetween(repo, roots, heads): | |
81 | """Return all paths between roots and heads, inclusive of both endpoint |
|
81 | """Return all paths between roots and heads, inclusive of both endpoint | |
82 | sets.""" |
|
82 | sets.""" | |
83 | if not roots: |
|
83 | if not roots: | |
84 | return baseset() |
|
84 | return baseset() | |
85 | parentrevs = repo.changelog.parentrevs |
|
85 | parentrevs = repo.changelog.parentrevs | |
86 | visit = list(heads) |
|
86 | visit = list(heads) | |
87 | reachable = set() |
|
87 | reachable = set() | |
88 | seen = {} |
|
88 | seen = {} | |
89 | minroot = min(roots) |
|
89 | minroot = min(roots) | |
90 | roots = set(roots) |
|
90 | roots = set(roots) | |
91 | # open-code the post-order traversal due to the tiny size of |
|
91 | # open-code the post-order traversal due to the tiny size of | |
92 | # sys.getrecursionlimit() |
|
92 | # sys.getrecursionlimit() | |
93 | while visit: |
|
93 | while visit: | |
94 | rev = visit.pop() |
|
94 | rev = visit.pop() | |
95 | if rev in roots: |
|
95 | if rev in roots: | |
96 | reachable.add(rev) |
|
96 | reachable.add(rev) | |
97 | parents = parentrevs(rev) |
|
97 | parents = parentrevs(rev) | |
98 | seen[rev] = parents |
|
98 | seen[rev] = parents | |
99 | for parent in parents: |
|
99 | for parent in parents: | |
100 | if parent >= minroot and parent not in seen: |
|
100 | if parent >= minroot and parent not in seen: | |
101 | visit.append(parent) |
|
101 | visit.append(parent) | |
102 | if not reachable: |
|
102 | if not reachable: | |
103 | return baseset() |
|
103 | return baseset() | |
104 | for rev in sorted(seen): |
|
104 | for rev in sorted(seen): | |
105 | for parent in seen[rev]: |
|
105 | for parent in seen[rev]: | |
106 | if parent in reachable: |
|
106 | if parent in reachable: | |
107 | reachable.add(rev) |
|
107 | reachable.add(rev) | |
108 | return baseset(sorted(reachable)) |
|
108 | return baseset(sorted(reachable)) | |
109 |
|
109 | |||
110 | elements = { |
|
110 | elements = { | |
111 | "(": (21, ("group", 1, ")"), ("func", 1, ")")), |
|
111 | "(": (21, ("group", 1, ")"), ("func", 1, ")")), | |
112 | "##": (20, None, ("_concat", 20)), |
|
112 | "##": (20, None, ("_concat", 20)), | |
113 | "~": (18, None, ("ancestor", 18)), |
|
113 | "~": (18, None, ("ancestor", 18)), | |
114 | "^": (18, None, ("parent", 18), ("parentpost", 18)), |
|
114 | "^": (18, None, ("parent", 18), ("parentpost", 18)), | |
115 | "-": (5, ("negate", 19), ("minus", 5)), |
|
115 | "-": (5, ("negate", 19), ("minus", 5)), | |
116 | "::": (17, ("dagrangepre", 17), ("dagrange", 17), |
|
116 | "::": (17, ("dagrangepre", 17), ("dagrange", 17), | |
117 | ("dagrangepost", 17)), |
|
117 | ("dagrangepost", 17)), | |
118 | "..": (17, ("dagrangepre", 17), ("dagrange", 17), |
|
118 | "..": (17, ("dagrangepre", 17), ("dagrange", 17), | |
119 | ("dagrangepost", 17)), |
|
119 | ("dagrangepost", 17)), | |
120 | ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)), |
|
120 | ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)), | |
121 | "not": (10, ("not", 10)), |
|
121 | "not": (10, ("not", 10)), | |
122 | "!": (10, ("not", 10)), |
|
122 | "!": (10, ("not", 10)), | |
123 | "and": (5, None, ("and", 5)), |
|
123 | "and": (5, None, ("and", 5)), | |
124 | "&": (5, None, ("and", 5)), |
|
124 | "&": (5, None, ("and", 5)), | |
125 | "%": (5, None, ("only", 5), ("onlypost", 5)), |
|
125 | "%": (5, None, ("only", 5), ("onlypost", 5)), | |
126 | "or": (4, None, ("or", 4)), |
|
126 | "or": (4, None, ("or", 4)), | |
127 | "|": (4, None, ("or", 4)), |
|
127 | "|": (4, None, ("or", 4)), | |
128 | "+": (4, None, ("or", 4)), |
|
128 | "+": (4, None, ("or", 4)), | |
129 | ",": (2, None, ("list", 2)), |
|
129 | ",": (2, None, ("list", 2)), | |
130 | ")": (0, None, None), |
|
130 | ")": (0, None, None), | |
131 | "symbol": (0, ("symbol",), None), |
|
131 | "symbol": (0, ("symbol",), None), | |
132 | "string": (0, ("string",), None), |
|
132 | "string": (0, ("string",), None), | |
133 | "end": (0, None, None), |
|
133 | "end": (0, None, None), | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | keywords = set(['and', 'or', 'not']) |
|
136 | keywords = set(['and', 'or', 'not']) | |
137 |
|
137 | |||
138 | # default set of valid characters for the initial letter of symbols |
|
138 | # default set of valid characters for the initial letter of symbols | |
139 | _syminitletters = set(c for c in [chr(i) for i in xrange(256)] |
|
139 | _syminitletters = set(c for c in [chr(i) for i in xrange(256)] | |
140 | if c.isalnum() or c in '._@' or ord(c) > 127) |
|
140 | if c.isalnum() or c in '._@' or ord(c) > 127) | |
141 |
|
141 | |||
142 | # default set of valid characters for non-initial letters of symbols |
|
142 | # default set of valid characters for non-initial letters of symbols | |
143 | _symletters = set(c for c in [chr(i) for i in xrange(256)] |
|
143 | _symletters = set(c for c in [chr(i) for i in xrange(256)] | |
144 | if c.isalnum() or c in '-._/@' or ord(c) > 127) |
|
144 | if c.isalnum() or c in '-._/@' or ord(c) > 127) | |
145 |
|
145 | |||
146 | def tokenize(program, lookup=None, syminitletters=None, symletters=None): |
|
146 | def tokenize(program, lookup=None, syminitletters=None, symletters=None): | |
147 | ''' |
|
147 | ''' | |
148 | Parse a revset statement into a stream of tokens |
|
148 | Parse a revset statement into a stream of tokens | |
149 |
|
149 | |||
150 | ``syminitletters`` is the set of valid characters for the initial |
|
150 | ``syminitletters`` is the set of valid characters for the initial | |
151 | letter of symbols. |
|
151 | letter of symbols. | |
152 |
|
152 | |||
153 | By default, character ``c`` is recognized as valid for initial |
|
153 | By default, character ``c`` is recognized as valid for initial | |
154 | letter of symbols, if ``c.isalnum() or c in '._@' or ord(c) > 127``. |
|
154 | letter of symbols, if ``c.isalnum() or c in '._@' or ord(c) > 127``. | |
155 |
|
155 | |||
156 | ``symletters`` is the set of valid characters for non-initial |
|
156 | ``symletters`` is the set of valid characters for non-initial | |
157 | letters of symbols. |
|
157 | letters of symbols. | |
158 |
|
158 | |||
159 | By default, character ``c`` is recognized as valid for non-initial |
|
159 | By default, character ``c`` is recognized as valid for non-initial | |
160 | letters of symbols, if ``c.isalnum() or c in '-._/@' or ord(c) > 127``. |
|
160 | letters of symbols, if ``c.isalnum() or c in '-._/@' or ord(c) > 127``. | |
161 |
|
161 | |||
162 | Check that @ is a valid unquoted token character (issue3686): |
|
162 | Check that @ is a valid unquoted token character (issue3686): | |
163 | >>> list(tokenize("@::")) |
|
163 | >>> list(tokenize("@::")) | |
164 | [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)] |
|
164 | [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)] | |
165 |
|
165 | |||
166 | ''' |
|
166 | ''' | |
167 | if syminitletters is None: |
|
167 | if syminitletters is None: | |
168 | syminitletters = _syminitletters |
|
168 | syminitletters = _syminitletters | |
169 | if symletters is None: |
|
169 | if symletters is None: | |
170 | symletters = _symletters |
|
170 | symletters = _symletters | |
171 |
|
171 | |||
172 | pos, l = 0, len(program) |
|
172 | pos, l = 0, len(program) | |
173 | while pos < l: |
|
173 | while pos < l: | |
174 | c = program[pos] |
|
174 | c = program[pos] | |
175 | if c.isspace(): # skip inter-token whitespace |
|
175 | if c.isspace(): # skip inter-token whitespace | |
176 | pass |
|
176 | pass | |
177 | elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully |
|
177 | elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully | |
178 | yield ('::', None, pos) |
|
178 | yield ('::', None, pos) | |
179 | pos += 1 # skip ahead |
|
179 | pos += 1 # skip ahead | |
180 | elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully |
|
180 | elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully | |
181 | yield ('..', None, pos) |
|
181 | yield ('..', None, pos) | |
182 | pos += 1 # skip ahead |
|
182 | pos += 1 # skip ahead | |
183 | elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully |
|
183 | elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully | |
184 | yield ('##', None, pos) |
|
184 | yield ('##', None, pos) | |
185 | pos += 1 # skip ahead |
|
185 | pos += 1 # skip ahead | |
186 | elif c in "():,-|&+!~^%": # handle simple operators |
|
186 | elif c in "():,-|&+!~^%": # handle simple operators | |
187 | yield (c, None, pos) |
|
187 | yield (c, None, pos) | |
188 | elif (c in '"\'' or c == 'r' and |
|
188 | elif (c in '"\'' or c == 'r' and | |
189 | program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings |
|
189 | program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings | |
190 | if c == 'r': |
|
190 | if c == 'r': | |
191 | pos += 1 |
|
191 | pos += 1 | |
192 | c = program[pos] |
|
192 | c = program[pos] | |
193 | decode = lambda x: x |
|
193 | decode = lambda x: x | |
194 | else: |
|
194 | else: | |
195 | decode = lambda x: x.decode('string-escape') |
|
195 | decode = lambda x: x.decode('string-escape') | |
196 | pos += 1 |
|
196 | pos += 1 | |
197 | s = pos |
|
197 | s = pos | |
198 | while pos < l: # find closing quote |
|
198 | while pos < l: # find closing quote | |
199 | d = program[pos] |
|
199 | d = program[pos] | |
200 | if d == '\\': # skip over escaped characters |
|
200 | if d == '\\': # skip over escaped characters | |
201 | pos += 2 |
|
201 | pos += 2 | |
202 | continue |
|
202 | continue | |
203 | if d == c: |
|
203 | if d == c: | |
204 | yield ('string', decode(program[s:pos]), s) |
|
204 | yield ('string', decode(program[s:pos]), s) | |
205 | break |
|
205 | break | |
206 | pos += 1 |
|
206 | pos += 1 | |
207 | else: |
|
207 | else: | |
208 | raise error.ParseError(_("unterminated string"), s) |
|
208 | raise error.ParseError(_("unterminated string"), s) | |
209 | # gather up a symbol/keyword |
|
209 | # gather up a symbol/keyword | |
210 | elif c in syminitletters: |
|
210 | elif c in syminitletters: | |
211 | s = pos |
|
211 | s = pos | |
212 | pos += 1 |
|
212 | pos += 1 | |
213 | while pos < l: # find end of symbol |
|
213 | while pos < l: # find end of symbol | |
214 | d = program[pos] |
|
214 | d = program[pos] | |
215 | if d not in symletters: |
|
215 | if d not in symletters: | |
216 | break |
|
216 | break | |
217 | if d == '.' and program[pos - 1] == '.': # special case for .. |
|
217 | if d == '.' and program[pos - 1] == '.': # special case for .. | |
218 | pos -= 1 |
|
218 | pos -= 1 | |
219 | break |
|
219 | break | |
220 | pos += 1 |
|
220 | pos += 1 | |
221 | sym = program[s:pos] |
|
221 | sym = program[s:pos] | |
222 | if sym in keywords: # operator keywords |
|
222 | if sym in keywords: # operator keywords | |
223 | yield (sym, None, s) |
|
223 | yield (sym, None, s) | |
224 | elif '-' in sym: |
|
224 | elif '-' in sym: | |
225 | # some jerk gave us foo-bar-baz, try to check if it's a symbol |
|
225 | # some jerk gave us foo-bar-baz, try to check if it's a symbol | |
226 | if lookup and lookup(sym): |
|
226 | if lookup and lookup(sym): | |
227 | # looks like a real symbol |
|
227 | # looks like a real symbol | |
228 | yield ('symbol', sym, s) |
|
228 | yield ('symbol', sym, s) | |
229 | else: |
|
229 | else: | |
230 | # looks like an expression |
|
230 | # looks like an expression | |
231 | parts = sym.split('-') |
|
231 | parts = sym.split('-') | |
232 | for p in parts[:-1]: |
|
232 | for p in parts[:-1]: | |
233 | if p: # possible consecutive - |
|
233 | if p: # possible consecutive - | |
234 | yield ('symbol', p, s) |
|
234 | yield ('symbol', p, s) | |
235 | s += len(p) |
|
235 | s += len(p) | |
236 | yield ('-', None, pos) |
|
236 | yield ('-', None, pos) | |
237 | s += 1 |
|
237 | s += 1 | |
238 | if parts[-1]: # possible trailing - |
|
238 | if parts[-1]: # possible trailing - | |
239 | yield ('symbol', parts[-1], s) |
|
239 | yield ('symbol', parts[-1], s) | |
240 | else: |
|
240 | else: | |
241 | yield ('symbol', sym, s) |
|
241 | yield ('symbol', sym, s) | |
242 | pos -= 1 |
|
242 | pos -= 1 | |
243 | else: |
|
243 | else: | |
244 | raise error.ParseError(_("syntax error in revset '%s'") % |
|
244 | raise error.ParseError(_("syntax error in revset '%s'") % | |
245 | program, pos) |
|
245 | program, pos) | |
246 | pos += 1 |
|
246 | pos += 1 | |
247 | yield ('end', None, pos) |
|
247 | yield ('end', None, pos) | |
248 |
|
248 | |||
249 | def parseerrordetail(inst): |
|
249 | def parseerrordetail(inst): | |
250 | """Compose error message from specified ParseError object |
|
250 | """Compose error message from specified ParseError object | |
251 | """ |
|
251 | """ | |
252 | if len(inst.args) > 1: |
|
252 | if len(inst.args) > 1: | |
253 | return _('at %s: %s') % (inst.args[1], inst.args[0]) |
|
253 | return _('at %s: %s') % (inst.args[1], inst.args[0]) | |
254 | else: |
|
254 | else: | |
255 | return inst.args[0] |
|
255 | return inst.args[0] | |
256 |
|
256 | |||
257 | # helpers |
|
257 | # helpers | |
258 |
|
258 | |||
259 | def getstring(x, err): |
|
259 | def getstring(x, err): | |
260 | if x and (x[0] == 'string' or x[0] == 'symbol'): |
|
260 | if x and (x[0] == 'string' or x[0] == 'symbol'): | |
261 | return x[1] |
|
261 | return x[1] | |
262 | raise error.ParseError(err) |
|
262 | raise error.ParseError(err) | |
263 |
|
263 | |||
264 | def getlist(x): |
|
264 | def getlist(x): | |
265 | if not x: |
|
265 | if not x: | |
266 | return [] |
|
266 | return [] | |
267 | if x[0] == 'list': |
|
267 | if x[0] == 'list': | |
268 | return getlist(x[1]) + [x[2]] |
|
268 | return getlist(x[1]) + [x[2]] | |
269 | return [x] |
|
269 | return [x] | |
270 |
|
270 | |||
271 | def getargs(x, min, max, err): |
|
271 | def getargs(x, min, max, err): | |
272 | l = getlist(x) |
|
272 | l = getlist(x) | |
273 | if len(l) < min or (max >= 0 and len(l) > max): |
|
273 | if len(l) < min or (max >= 0 and len(l) > max): | |
274 | raise error.ParseError(err) |
|
274 | raise error.ParseError(err) | |
275 | return l |
|
275 | return l | |
276 |
|
276 | |||
277 | def isvalidsymbol(tree): |
|
277 | def isvalidsymbol(tree): | |
278 | """Examine whether specified ``tree`` is valid ``symbol`` or not |
|
278 | """Examine whether specified ``tree`` is valid ``symbol`` or not | |
279 | """ |
|
279 | """ | |
280 | return tree[0] == 'symbol' and len(tree) > 1 |
|
280 | return tree[0] == 'symbol' and len(tree) > 1 | |
281 |
|
281 | |||
282 | def getsymbol(tree): |
|
282 | def getsymbol(tree): | |
283 | """Get symbol name from valid ``symbol`` in ``tree`` |
|
283 | """Get symbol name from valid ``symbol`` in ``tree`` | |
284 |
|
284 | |||
285 | This assumes that ``tree`` is already examined by ``isvalidsymbol``. |
|
285 | This assumes that ``tree`` is already examined by ``isvalidsymbol``. | |
286 | """ |
|
286 | """ | |
287 | return tree[1] |
|
287 | return tree[1] | |
288 |
|
288 | |||
289 | def isvalidfunc(tree): |
|
289 | def isvalidfunc(tree): | |
290 | """Examine whether specified ``tree`` is valid ``func`` or not |
|
290 | """Examine whether specified ``tree`` is valid ``func`` or not | |
291 | """ |
|
291 | """ | |
292 | return tree[0] == 'func' and len(tree) > 1 and isvalidsymbol(tree[1]) |
|
292 | return tree[0] == 'func' and len(tree) > 1 and isvalidsymbol(tree[1]) | |
293 |
|
293 | |||
294 | def getfuncname(tree): |
|
294 | def getfuncname(tree): | |
295 | """Get function name from valid ``func`` in ``tree`` |
|
295 | """Get function name from valid ``func`` in ``tree`` | |
296 |
|
296 | |||
297 | This assumes that ``tree`` is already examined by ``isvalidfunc``. |
|
297 | This assumes that ``tree`` is already examined by ``isvalidfunc``. | |
298 | """ |
|
298 | """ | |
299 | return getsymbol(tree[1]) |
|
299 | return getsymbol(tree[1]) | |
300 |
|
300 | |||
301 | def getfuncargs(tree): |
|
301 | def getfuncargs(tree): | |
302 | """Get list of function arguments from valid ``func`` in ``tree`` |
|
302 | """Get list of function arguments from valid ``func`` in ``tree`` | |
303 |
|
303 | |||
304 | This assumes that ``tree`` is already examined by ``isvalidfunc``. |
|
304 | This assumes that ``tree`` is already examined by ``isvalidfunc``. | |
305 | """ |
|
305 | """ | |
306 | if len(tree) > 2: |
|
306 | if len(tree) > 2: | |
307 | return getlist(tree[2]) |
|
307 | return getlist(tree[2]) | |
308 | else: |
|
308 | else: | |
309 | return [] |
|
309 | return [] | |
310 |
|
310 | |||
311 | def getset(repo, subset, x): |
|
311 | def getset(repo, subset, x): | |
312 | if not x: |
|
312 | if not x: | |
313 | raise error.ParseError(_("missing argument")) |
|
313 | raise error.ParseError(_("missing argument")) | |
314 | s = methods[x[0]](repo, subset, *x[1:]) |
|
314 | s = methods[x[0]](repo, subset, *x[1:]) | |
315 | if util.safehasattr(s, 'isascending'): |
|
315 | if util.safehasattr(s, 'isascending'): | |
316 | return s |
|
316 | return s | |
317 | return baseset(s) |
|
317 | return baseset(s) | |
318 |
|
318 | |||
319 | def _getrevsource(repo, r): |
|
319 | def _getrevsource(repo, r): | |
320 | extra = repo[r].extra() |
|
320 | extra = repo[r].extra() | |
321 | for label in ('source', 'transplant_source', 'rebase_source'): |
|
321 | for label in ('source', 'transplant_source', 'rebase_source'): | |
322 | if label in extra: |
|
322 | if label in extra: | |
323 | try: |
|
323 | try: | |
324 | return repo[extra[label]].rev() |
|
324 | return repo[extra[label]].rev() | |
325 | except error.RepoLookupError: |
|
325 | except error.RepoLookupError: | |
326 | pass |
|
326 | pass | |
327 | return None |
|
327 | return None | |
328 |
|
328 | |||
329 | # operator methods |
|
329 | # operator methods | |
330 |
|
330 | |||
331 | def stringset(repo, subset, x): |
|
331 | def stringset(repo, subset, x): | |
332 | x = repo[x].rev() |
|
332 | x = repo[x].rev() | |
333 | if x in subset: |
|
333 | if x in subset: | |
334 | return baseset([x]) |
|
334 | return baseset([x]) | |
335 | return baseset() |
|
335 | return baseset() | |
336 |
|
336 | |||
337 | def symbolset(repo, subset, x): |
|
|||
338 | if x in symbols: |
|
|||
339 | raise error.ParseError(_("can't use %s here") % x) |
|
|||
340 | return stringset(repo, subset, x) |
|
|||
341 |
|
||||
342 | def rangeset(repo, subset, x, y): |
|
337 | def rangeset(repo, subset, x, y): | |
343 | m = getset(repo, fullreposet(repo), x) |
|
338 | m = getset(repo, fullreposet(repo), x) | |
344 | n = getset(repo, fullreposet(repo), y) |
|
339 | n = getset(repo, fullreposet(repo), y) | |
345 |
|
340 | |||
346 | if not m or not n: |
|
341 | if not m or not n: | |
347 | return baseset() |
|
342 | return baseset() | |
348 | m, n = m.first(), n.last() |
|
343 | m, n = m.first(), n.last() | |
349 |
|
344 | |||
350 | if m < n: |
|
345 | if m < n: | |
351 | r = spanset(repo, m, n + 1) |
|
346 | r = spanset(repo, m, n + 1) | |
352 | else: |
|
347 | else: | |
353 | r = spanset(repo, m, n - 1) |
|
348 | r = spanset(repo, m, n - 1) | |
354 | return r & subset |
|
349 | return r & subset | |
355 |
|
350 | |||
356 | def dagrange(repo, subset, x, y): |
|
351 | def dagrange(repo, subset, x, y): | |
357 | r = fullreposet(repo) |
|
352 | r = fullreposet(repo) | |
358 | xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y)) |
|
353 | xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y)) | |
359 | return xs & subset |
|
354 | return xs & subset | |
360 |
|
355 | |||
361 | def andset(repo, subset, x, y): |
|
356 | def andset(repo, subset, x, y): | |
362 | return getset(repo, getset(repo, subset, x), y) |
|
357 | return getset(repo, getset(repo, subset, x), y) | |
363 |
|
358 | |||
364 | def orset(repo, subset, x, y): |
|
359 | def orset(repo, subset, x, y): | |
365 | xl = getset(repo, subset, x) |
|
360 | xl = getset(repo, subset, x) | |
366 | yl = getset(repo, subset - xl, y) |
|
361 | yl = getset(repo, subset - xl, y) | |
367 | return xl + yl |
|
362 | return xl + yl | |
368 |
|
363 | |||
369 | def notset(repo, subset, x): |
|
364 | def notset(repo, subset, x): | |
370 | return subset - getset(repo, subset, x) |
|
365 | return subset - getset(repo, subset, x) | |
371 |
|
366 | |||
372 | def listset(repo, subset, a, b): |
|
367 | def listset(repo, subset, a, b): | |
373 | raise error.ParseError(_("can't use a list in this context")) |
|
368 | raise error.ParseError(_("can't use a list in this context")) | |
374 |
|
369 | |||
375 | def func(repo, subset, a, b): |
|
370 | def func(repo, subset, a, b): | |
376 | if a[0] == 'symbol' and a[1] in symbols: |
|
371 | if a[0] == 'symbol' and a[1] in symbols: | |
377 | return symbols[a[1]](repo, subset, b) |
|
372 | return symbols[a[1]](repo, subset, b) | |
378 | raise error.UnknownIdentifier(a[1], symbols.keys()) |
|
373 | raise error.UnknownIdentifier(a[1], symbols.keys()) | |
379 |
|
374 | |||
380 | # functions |
|
375 | # functions | |
381 |
|
376 | |||
382 | def adds(repo, subset, x): |
|
377 | def adds(repo, subset, x): | |
383 | """``adds(pattern)`` |
|
378 | """``adds(pattern)`` | |
384 | Changesets that add a file matching pattern. |
|
379 | Changesets that add a file matching pattern. | |
385 |
|
380 | |||
386 | The pattern without explicit kind like ``glob:`` is expected to be |
|
381 | The pattern without explicit kind like ``glob:`` is expected to be | |
387 | relative to the current directory and match against a file or a |
|
382 | relative to the current directory and match against a file or a | |
388 | directory. |
|
383 | directory. | |
389 | """ |
|
384 | """ | |
390 | # i18n: "adds" is a keyword |
|
385 | # i18n: "adds" is a keyword | |
391 | pat = getstring(x, _("adds requires a pattern")) |
|
386 | pat = getstring(x, _("adds requires a pattern")) | |
392 | return checkstatus(repo, subset, pat, 1) |
|
387 | return checkstatus(repo, subset, pat, 1) | |
393 |
|
388 | |||
394 | def ancestor(repo, subset, x): |
|
389 | def ancestor(repo, subset, x): | |
395 | """``ancestor(*changeset)`` |
|
390 | """``ancestor(*changeset)`` | |
396 | A greatest common ancestor of the changesets. |
|
391 | A greatest common ancestor of the changesets. | |
397 |
|
392 | |||
398 | Accepts 0 or more changesets. |
|
393 | Accepts 0 or more changesets. | |
399 | Will return empty list when passed no args. |
|
394 | Will return empty list when passed no args. | |
400 | Greatest common ancestor of a single changeset is that changeset. |
|
395 | Greatest common ancestor of a single changeset is that changeset. | |
401 | """ |
|
396 | """ | |
402 | # i18n: "ancestor" is a keyword |
|
397 | # i18n: "ancestor" is a keyword | |
403 | l = getlist(x) |
|
398 | l = getlist(x) | |
404 | rl = fullreposet(repo) |
|
399 | rl = fullreposet(repo) | |
405 | anc = None |
|
400 | anc = None | |
406 |
|
401 | |||
407 | # (getset(repo, rl, i) for i in l) generates a list of lists |
|
402 | # (getset(repo, rl, i) for i in l) generates a list of lists | |
408 | for revs in (getset(repo, rl, i) for i in l): |
|
403 | for revs in (getset(repo, rl, i) for i in l): | |
409 | for r in revs: |
|
404 | for r in revs: | |
410 | if anc is None: |
|
405 | if anc is None: | |
411 | anc = repo[r] |
|
406 | anc = repo[r] | |
412 | else: |
|
407 | else: | |
413 | anc = anc.ancestor(repo[r]) |
|
408 | anc = anc.ancestor(repo[r]) | |
414 |
|
409 | |||
415 | if anc is not None and anc.rev() in subset: |
|
410 | if anc is not None and anc.rev() in subset: | |
416 | return baseset([anc.rev()]) |
|
411 | return baseset([anc.rev()]) | |
417 | return baseset() |
|
412 | return baseset() | |
418 |
|
413 | |||
419 | def _ancestors(repo, subset, x, followfirst=False): |
|
414 | def _ancestors(repo, subset, x, followfirst=False): | |
420 | heads = getset(repo, fullreposet(repo), x) |
|
415 | heads = getset(repo, fullreposet(repo), x) | |
421 | if not heads: |
|
416 | if not heads: | |
422 | return baseset() |
|
417 | return baseset() | |
423 | s = _revancestors(repo, heads, followfirst) |
|
418 | s = _revancestors(repo, heads, followfirst) | |
424 | return subset & s |
|
419 | return subset & s | |
425 |
|
420 | |||
426 | def ancestors(repo, subset, x): |
|
421 | def ancestors(repo, subset, x): | |
427 | """``ancestors(set)`` |
|
422 | """``ancestors(set)`` | |
428 | Changesets that are ancestors of a changeset in set. |
|
423 | Changesets that are ancestors of a changeset in set. | |
429 | """ |
|
424 | """ | |
430 | return _ancestors(repo, subset, x) |
|
425 | return _ancestors(repo, subset, x) | |
431 |
|
426 | |||
432 | def _firstancestors(repo, subset, x): |
|
427 | def _firstancestors(repo, subset, x): | |
433 | # ``_firstancestors(set)`` |
|
428 | # ``_firstancestors(set)`` | |
434 | # Like ``ancestors(set)`` but follows only the first parents. |
|
429 | # Like ``ancestors(set)`` but follows only the first parents. | |
435 | return _ancestors(repo, subset, x, followfirst=True) |
|
430 | return _ancestors(repo, subset, x, followfirst=True) | |
436 |
|
431 | |||
437 | def ancestorspec(repo, subset, x, n): |
|
432 | def ancestorspec(repo, subset, x, n): | |
438 | """``set~n`` |
|
433 | """``set~n`` | |
439 | Changesets that are the Nth ancestor (first parents only) of a changeset |
|
434 | Changesets that are the Nth ancestor (first parents only) of a changeset | |
440 | in set. |
|
435 | in set. | |
441 | """ |
|
436 | """ | |
442 | try: |
|
437 | try: | |
443 | n = int(n[1]) |
|
438 | n = int(n[1]) | |
444 | except (TypeError, ValueError): |
|
439 | except (TypeError, ValueError): | |
445 | raise error.ParseError(_("~ expects a number")) |
|
440 | raise error.ParseError(_("~ expects a number")) | |
446 | ps = set() |
|
441 | ps = set() | |
447 | cl = repo.changelog |
|
442 | cl = repo.changelog | |
448 | for r in getset(repo, fullreposet(repo), x): |
|
443 | for r in getset(repo, fullreposet(repo), x): | |
449 | for i in range(n): |
|
444 | for i in range(n): | |
450 | r = cl.parentrevs(r)[0] |
|
445 | r = cl.parentrevs(r)[0] | |
451 | ps.add(r) |
|
446 | ps.add(r) | |
452 | return subset & ps |
|
447 | return subset & ps | |
453 |
|
448 | |||
454 | def author(repo, subset, x): |
|
449 | def author(repo, subset, x): | |
455 | """``author(string)`` |
|
450 | """``author(string)`` | |
456 | Alias for ``user(string)``. |
|
451 | Alias for ``user(string)``. | |
457 | """ |
|
452 | """ | |
458 | # i18n: "author" is a keyword |
|
453 | # i18n: "author" is a keyword | |
459 | n = encoding.lower(getstring(x, _("author requires a string"))) |
|
454 | n = encoding.lower(getstring(x, _("author requires a string"))) | |
460 | kind, pattern, matcher = _substringmatcher(n) |
|
455 | kind, pattern, matcher = _substringmatcher(n) | |
461 | return subset.filter(lambda x: matcher(encoding.lower(repo[x].user()))) |
|
456 | return subset.filter(lambda x: matcher(encoding.lower(repo[x].user()))) | |
462 |
|
457 | |||
463 | def bisect(repo, subset, x): |
|
458 | def bisect(repo, subset, x): | |
464 | """``bisect(string)`` |
|
459 | """``bisect(string)`` | |
465 | Changesets marked in the specified bisect status: |
|
460 | Changesets marked in the specified bisect status: | |
466 |
|
461 | |||
467 | - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip |
|
462 | - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip | |
468 | - ``goods``, ``bads`` : csets topologically good/bad |
|
463 | - ``goods``, ``bads`` : csets topologically good/bad | |
469 | - ``range`` : csets taking part in the bisection |
|
464 | - ``range`` : csets taking part in the bisection | |
470 | - ``pruned`` : csets that are goods, bads or skipped |
|
465 | - ``pruned`` : csets that are goods, bads or skipped | |
471 | - ``untested`` : csets whose fate is yet unknown |
|
466 | - ``untested`` : csets whose fate is yet unknown | |
472 | - ``ignored`` : csets ignored due to DAG topology |
|
467 | - ``ignored`` : csets ignored due to DAG topology | |
473 | - ``current`` : the cset currently being bisected |
|
468 | - ``current`` : the cset currently being bisected | |
474 | """ |
|
469 | """ | |
475 | # i18n: "bisect" is a keyword |
|
470 | # i18n: "bisect" is a keyword | |
476 | status = getstring(x, _("bisect requires a string")).lower() |
|
471 | status = getstring(x, _("bisect requires a string")).lower() | |
477 | state = set(hbisect.get(repo, status)) |
|
472 | state = set(hbisect.get(repo, status)) | |
478 | return subset & state |
|
473 | return subset & state | |
479 |
|
474 | |||
480 | # Backward-compatibility |
|
475 | # Backward-compatibility | |
481 | # - no help entry so that we do not advertise it any more |
|
476 | # - no help entry so that we do not advertise it any more | |
482 | def bisected(repo, subset, x): |
|
477 | def bisected(repo, subset, x): | |
483 | return bisect(repo, subset, x) |
|
478 | return bisect(repo, subset, x) | |
484 |
|
479 | |||
485 | def bookmark(repo, subset, x): |
|
480 | def bookmark(repo, subset, x): | |
486 | """``bookmark([name])`` |
|
481 | """``bookmark([name])`` | |
487 | The named bookmark or all bookmarks. |
|
482 | The named bookmark or all bookmarks. | |
488 |
|
483 | |||
489 | If `name` starts with `re:`, the remainder of the name is treated as |
|
484 | If `name` starts with `re:`, the remainder of the name is treated as | |
490 | a regular expression. To match a bookmark that actually starts with `re:`, |
|
485 | a regular expression. To match a bookmark that actually starts with `re:`, | |
491 | use the prefix `literal:`. |
|
486 | use the prefix `literal:`. | |
492 | """ |
|
487 | """ | |
493 | # i18n: "bookmark" is a keyword |
|
488 | # i18n: "bookmark" is a keyword | |
494 | args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) |
|
489 | args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) | |
495 | if args: |
|
490 | if args: | |
496 | bm = getstring(args[0], |
|
491 | bm = getstring(args[0], | |
497 | # i18n: "bookmark" is a keyword |
|
492 | # i18n: "bookmark" is a keyword | |
498 | _('the argument to bookmark must be a string')) |
|
493 | _('the argument to bookmark must be a string')) | |
499 | kind, pattern, matcher = _stringmatcher(bm) |
|
494 | kind, pattern, matcher = _stringmatcher(bm) | |
500 | bms = set() |
|
495 | bms = set() | |
501 | if kind == 'literal': |
|
496 | if kind == 'literal': | |
502 | bmrev = repo._bookmarks.get(pattern, None) |
|
497 | bmrev = repo._bookmarks.get(pattern, None) | |
503 | if not bmrev: |
|
498 | if not bmrev: | |
504 | raise error.RepoLookupError(_("bookmark '%s' does not exist") |
|
499 | raise error.RepoLookupError(_("bookmark '%s' does not exist") | |
505 | % bm) |
|
500 | % bm) | |
506 | bms.add(repo[bmrev].rev()) |
|
501 | bms.add(repo[bmrev].rev()) | |
507 | else: |
|
502 | else: | |
508 | matchrevs = set() |
|
503 | matchrevs = set() | |
509 | for name, bmrev in repo._bookmarks.iteritems(): |
|
504 | for name, bmrev in repo._bookmarks.iteritems(): | |
510 | if matcher(name): |
|
505 | if matcher(name): | |
511 | matchrevs.add(bmrev) |
|
506 | matchrevs.add(bmrev) | |
512 | if not matchrevs: |
|
507 | if not matchrevs: | |
513 | raise error.RepoLookupError(_("no bookmarks exist" |
|
508 | raise error.RepoLookupError(_("no bookmarks exist" | |
514 | " that match '%s'") % pattern) |
|
509 | " that match '%s'") % pattern) | |
515 | for bmrev in matchrevs: |
|
510 | for bmrev in matchrevs: | |
516 | bms.add(repo[bmrev].rev()) |
|
511 | bms.add(repo[bmrev].rev()) | |
517 | else: |
|
512 | else: | |
518 | bms = set([repo[r].rev() |
|
513 | bms = set([repo[r].rev() | |
519 | for r in repo._bookmarks.values()]) |
|
514 | for r in repo._bookmarks.values()]) | |
520 | bms -= set([node.nullrev]) |
|
515 | bms -= set([node.nullrev]) | |
521 | return subset & bms |
|
516 | return subset & bms | |
522 |
|
517 | |||
523 | def branch(repo, subset, x): |
|
518 | def branch(repo, subset, x): | |
524 | """``branch(string or set)`` |
|
519 | """``branch(string or set)`` | |
525 | All changesets belonging to the given branch or the branches of the given |
|
520 | All changesets belonging to the given branch or the branches of the given | |
526 | changesets. |
|
521 | changesets. | |
527 |
|
522 | |||
528 | If `string` starts with `re:`, the remainder of the name is treated as |
|
523 | If `string` starts with `re:`, the remainder of the name is treated as | |
529 | a regular expression. To match a branch that actually starts with `re:`, |
|
524 | a regular expression. To match a branch that actually starts with `re:`, | |
530 | use the prefix `literal:`. |
|
525 | use the prefix `literal:`. | |
531 | """ |
|
526 | """ | |
532 | getbi = repo.revbranchcache().branchinfo |
|
527 | getbi = repo.revbranchcache().branchinfo | |
533 |
|
528 | |||
534 | try: |
|
529 | try: | |
535 | b = getstring(x, '') |
|
530 | b = getstring(x, '') | |
536 | except error.ParseError: |
|
531 | except error.ParseError: | |
537 | # not a string, but another revspec, e.g. tip() |
|
532 | # not a string, but another revspec, e.g. tip() | |
538 | pass |
|
533 | pass | |
539 | else: |
|
534 | else: | |
540 | kind, pattern, matcher = _stringmatcher(b) |
|
535 | kind, pattern, matcher = _stringmatcher(b) | |
541 | if kind == 'literal': |
|
536 | if kind == 'literal': | |
542 | # note: falls through to the revspec case if no branch with |
|
537 | # note: falls through to the revspec case if no branch with | |
543 | # this name exists |
|
538 | # this name exists | |
544 | if pattern in repo.branchmap(): |
|
539 | if pattern in repo.branchmap(): | |
545 | return subset.filter(lambda r: matcher(getbi(r)[0])) |
|
540 | return subset.filter(lambda r: matcher(getbi(r)[0])) | |
546 | else: |
|
541 | else: | |
547 | return subset.filter(lambda r: matcher(getbi(r)[0])) |
|
542 | return subset.filter(lambda r: matcher(getbi(r)[0])) | |
548 |
|
543 | |||
549 | s = getset(repo, fullreposet(repo), x) |
|
544 | s = getset(repo, fullreposet(repo), x) | |
550 | b = set() |
|
545 | b = set() | |
551 | for r in s: |
|
546 | for r in s: | |
552 | b.add(getbi(r)[0]) |
|
547 | b.add(getbi(r)[0]) | |
553 | c = s.__contains__ |
|
548 | c = s.__contains__ | |
554 | return subset.filter(lambda r: c(r) or getbi(r)[0] in b) |
|
549 | return subset.filter(lambda r: c(r) or getbi(r)[0] in b) | |
555 |
|
550 | |||
556 | def bumped(repo, subset, x): |
|
551 | def bumped(repo, subset, x): | |
557 | """``bumped()`` |
|
552 | """``bumped()`` | |
558 | Mutable changesets marked as successors of public changesets. |
|
553 | Mutable changesets marked as successors of public changesets. | |
559 |
|
554 | |||
560 | Only non-public and non-obsolete changesets can be `bumped`. |
|
555 | Only non-public and non-obsolete changesets can be `bumped`. | |
561 | """ |
|
556 | """ | |
562 | # i18n: "bumped" is a keyword |
|
557 | # i18n: "bumped" is a keyword | |
563 | getargs(x, 0, 0, _("bumped takes no arguments")) |
|
558 | getargs(x, 0, 0, _("bumped takes no arguments")) | |
564 | bumped = obsmod.getrevs(repo, 'bumped') |
|
559 | bumped = obsmod.getrevs(repo, 'bumped') | |
565 | return subset & bumped |
|
560 | return subset & bumped | |
566 |
|
561 | |||
567 | def bundle(repo, subset, x): |
|
562 | def bundle(repo, subset, x): | |
568 | """``bundle()`` |
|
563 | """``bundle()`` | |
569 | Changesets in the bundle. |
|
564 | Changesets in the bundle. | |
570 |
|
565 | |||
571 | Bundle must be specified by the -R option.""" |
|
566 | Bundle must be specified by the -R option.""" | |
572 |
|
567 | |||
573 | try: |
|
568 | try: | |
574 | bundlerevs = repo.changelog.bundlerevs |
|
569 | bundlerevs = repo.changelog.bundlerevs | |
575 | except AttributeError: |
|
570 | except AttributeError: | |
576 | raise util.Abort(_("no bundle provided - specify with -R")) |
|
571 | raise util.Abort(_("no bundle provided - specify with -R")) | |
577 | return subset & bundlerevs |
|
572 | return subset & bundlerevs | |
578 |
|
573 | |||
579 | def checkstatus(repo, subset, pat, field): |
|
574 | def checkstatus(repo, subset, pat, field): | |
580 | hasset = matchmod.patkind(pat) == 'set' |
|
575 | hasset = matchmod.patkind(pat) == 'set' | |
581 |
|
576 | |||
582 | mcache = [None] |
|
577 | mcache = [None] | |
583 | def matches(x): |
|
578 | def matches(x): | |
584 | c = repo[x] |
|
579 | c = repo[x] | |
585 | if not mcache[0] or hasset: |
|
580 | if not mcache[0] or hasset: | |
586 | mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) |
|
581 | mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) | |
587 | m = mcache[0] |
|
582 | m = mcache[0] | |
588 | fname = None |
|
583 | fname = None | |
589 | if not m.anypats() and len(m.files()) == 1: |
|
584 | if not m.anypats() and len(m.files()) == 1: | |
590 | fname = m.files()[0] |
|
585 | fname = m.files()[0] | |
591 | if fname is not None: |
|
586 | if fname is not None: | |
592 | if fname not in c.files(): |
|
587 | if fname not in c.files(): | |
593 | return False |
|
588 | return False | |
594 | else: |
|
589 | else: | |
595 | for f in c.files(): |
|
590 | for f in c.files(): | |
596 | if m(f): |
|
591 | if m(f): | |
597 | break |
|
592 | break | |
598 | else: |
|
593 | else: | |
599 | return False |
|
594 | return False | |
600 | files = repo.status(c.p1().node(), c.node())[field] |
|
595 | files = repo.status(c.p1().node(), c.node())[field] | |
601 | if fname is not None: |
|
596 | if fname is not None: | |
602 | if fname in files: |
|
597 | if fname in files: | |
603 | return True |
|
598 | return True | |
604 | else: |
|
599 | else: | |
605 | for f in files: |
|
600 | for f in files: | |
606 | if m(f): |
|
601 | if m(f): | |
607 | return True |
|
602 | return True | |
608 |
|
603 | |||
609 | return subset.filter(matches) |
|
604 | return subset.filter(matches) | |
610 |
|
605 | |||
611 | def _children(repo, narrow, parentset): |
|
606 | def _children(repo, narrow, parentset): | |
612 | cs = set() |
|
607 | cs = set() | |
613 | if not parentset: |
|
608 | if not parentset: | |
614 | return baseset(cs) |
|
609 | return baseset(cs) | |
615 | pr = repo.changelog.parentrevs |
|
610 | pr = repo.changelog.parentrevs | |
616 | minrev = min(parentset) |
|
611 | minrev = min(parentset) | |
617 | for r in narrow: |
|
612 | for r in narrow: | |
618 | if r <= minrev: |
|
613 | if r <= minrev: | |
619 | continue |
|
614 | continue | |
620 | for p in pr(r): |
|
615 | for p in pr(r): | |
621 | if p in parentset: |
|
616 | if p in parentset: | |
622 | cs.add(r) |
|
617 | cs.add(r) | |
623 | return baseset(cs) |
|
618 | return baseset(cs) | |
624 |
|
619 | |||
625 | def children(repo, subset, x): |
|
620 | def children(repo, subset, x): | |
626 | """``children(set)`` |
|
621 | """``children(set)`` | |
627 | Child changesets of changesets in set. |
|
622 | Child changesets of changesets in set. | |
628 | """ |
|
623 | """ | |
629 | s = getset(repo, fullreposet(repo), x) |
|
624 | s = getset(repo, fullreposet(repo), x) | |
630 | cs = _children(repo, subset, s) |
|
625 | cs = _children(repo, subset, s) | |
631 | return subset & cs |
|
626 | return subset & cs | |
632 |
|
627 | |||
633 | def closed(repo, subset, x): |
|
628 | def closed(repo, subset, x): | |
634 | """``closed()`` |
|
629 | """``closed()`` | |
635 | Changeset is closed. |
|
630 | Changeset is closed. | |
636 | """ |
|
631 | """ | |
637 | # i18n: "closed" is a keyword |
|
632 | # i18n: "closed" is a keyword | |
638 | getargs(x, 0, 0, _("closed takes no arguments")) |
|
633 | getargs(x, 0, 0, _("closed takes no arguments")) | |
639 | return subset.filter(lambda r: repo[r].closesbranch()) |
|
634 | return subset.filter(lambda r: repo[r].closesbranch()) | |
640 |
|
635 | |||
641 | def contains(repo, subset, x): |
|
636 | def contains(repo, subset, x): | |
642 | """``contains(pattern)`` |
|
637 | """``contains(pattern)`` | |
643 | The revision's manifest contains a file matching pattern (but might not |
|
638 | The revision's manifest contains a file matching pattern (but might not | |
644 | modify it). See :hg:`help patterns` for information about file patterns. |
|
639 | modify it). See :hg:`help patterns` for information about file patterns. | |
645 |
|
640 | |||
646 | The pattern without explicit kind like ``glob:`` is expected to be |
|
641 | The pattern without explicit kind like ``glob:`` is expected to be | |
647 | relative to the current directory and match against a file exactly |
|
642 | relative to the current directory and match against a file exactly | |
648 | for efficiency. |
|
643 | for efficiency. | |
649 | """ |
|
644 | """ | |
650 | # i18n: "contains" is a keyword |
|
645 | # i18n: "contains" is a keyword | |
651 | pat = getstring(x, _("contains requires a pattern")) |
|
646 | pat = getstring(x, _("contains requires a pattern")) | |
652 |
|
647 | |||
653 | def matches(x): |
|
648 | def matches(x): | |
654 | if not matchmod.patkind(pat): |
|
649 | if not matchmod.patkind(pat): | |
655 | pats = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
650 | pats = pathutil.canonpath(repo.root, repo.getcwd(), pat) | |
656 | if pats in repo[x]: |
|
651 | if pats in repo[x]: | |
657 | return True |
|
652 | return True | |
658 | else: |
|
653 | else: | |
659 | c = repo[x] |
|
654 | c = repo[x] | |
660 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) |
|
655 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) | |
661 | for f in c.manifest(): |
|
656 | for f in c.manifest(): | |
662 | if m(f): |
|
657 | if m(f): | |
663 | return True |
|
658 | return True | |
664 | return False |
|
659 | return False | |
665 |
|
660 | |||
666 | return subset.filter(matches) |
|
661 | return subset.filter(matches) | |
667 |
|
662 | |||
668 | def converted(repo, subset, x): |
|
663 | def converted(repo, subset, x): | |
669 | """``converted([id])`` |
|
664 | """``converted([id])`` | |
670 | Changesets converted from the given identifier in the old repository if |
|
665 | Changesets converted from the given identifier in the old repository if | |
671 | present, or all converted changesets if no identifier is specified. |
|
666 | present, or all converted changesets if no identifier is specified. | |
672 | """ |
|
667 | """ | |
673 |
|
668 | |||
674 | # There is exactly no chance of resolving the revision, so do a simple |
|
669 | # There is exactly no chance of resolving the revision, so do a simple | |
675 | # string compare and hope for the best |
|
670 | # string compare and hope for the best | |
676 |
|
671 | |||
677 | rev = None |
|
672 | rev = None | |
678 | # i18n: "converted" is a keyword |
|
673 | # i18n: "converted" is a keyword | |
679 | l = getargs(x, 0, 1, _('converted takes one or no arguments')) |
|
674 | l = getargs(x, 0, 1, _('converted takes one or no arguments')) | |
680 | if l: |
|
675 | if l: | |
681 | # i18n: "converted" is a keyword |
|
676 | # i18n: "converted" is a keyword | |
682 | rev = getstring(l[0], _('converted requires a revision')) |
|
677 | rev = getstring(l[0], _('converted requires a revision')) | |
683 |
|
678 | |||
684 | def _matchvalue(r): |
|
679 | def _matchvalue(r): | |
685 | source = repo[r].extra().get('convert_revision', None) |
|
680 | source = repo[r].extra().get('convert_revision', None) | |
686 | return source is not None and (rev is None or source.startswith(rev)) |
|
681 | return source is not None and (rev is None or source.startswith(rev)) | |
687 |
|
682 | |||
688 | return subset.filter(lambda r: _matchvalue(r)) |
|
683 | return subset.filter(lambda r: _matchvalue(r)) | |
689 |
|
684 | |||
690 | def date(repo, subset, x): |
|
685 | def date(repo, subset, x): | |
691 | """``date(interval)`` |
|
686 | """``date(interval)`` | |
692 | Changesets within the interval, see :hg:`help dates`. |
|
687 | Changesets within the interval, see :hg:`help dates`. | |
693 | """ |
|
688 | """ | |
694 | # i18n: "date" is a keyword |
|
689 | # i18n: "date" is a keyword | |
695 | ds = getstring(x, _("date requires a string")) |
|
690 | ds = getstring(x, _("date requires a string")) | |
696 | dm = util.matchdate(ds) |
|
691 | dm = util.matchdate(ds) | |
697 | return subset.filter(lambda x: dm(repo[x].date()[0])) |
|
692 | return subset.filter(lambda x: dm(repo[x].date()[0])) | |
698 |
|
693 | |||
699 | def desc(repo, subset, x): |
|
694 | def desc(repo, subset, x): | |
700 | """``desc(string)`` |
|
695 | """``desc(string)`` | |
701 | Search commit message for string. The match is case-insensitive. |
|
696 | Search commit message for string. The match is case-insensitive. | |
702 | """ |
|
697 | """ | |
703 | # i18n: "desc" is a keyword |
|
698 | # i18n: "desc" is a keyword | |
704 | ds = encoding.lower(getstring(x, _("desc requires a string"))) |
|
699 | ds = encoding.lower(getstring(x, _("desc requires a string"))) | |
705 |
|
700 | |||
706 | def matches(x): |
|
701 | def matches(x): | |
707 | c = repo[x] |
|
702 | c = repo[x] | |
708 | return ds in encoding.lower(c.description()) |
|
703 | return ds in encoding.lower(c.description()) | |
709 |
|
704 | |||
710 | return subset.filter(matches) |
|
705 | return subset.filter(matches) | |
711 |
|
706 | |||
712 | def _descendants(repo, subset, x, followfirst=False): |
|
707 | def _descendants(repo, subset, x, followfirst=False): | |
713 | roots = getset(repo, fullreposet(repo), x) |
|
708 | roots = getset(repo, fullreposet(repo), x) | |
714 | if not roots: |
|
709 | if not roots: | |
715 | return baseset() |
|
710 | return baseset() | |
716 | s = _revdescendants(repo, roots, followfirst) |
|
711 | s = _revdescendants(repo, roots, followfirst) | |
717 |
|
712 | |||
718 | # Both sets need to be ascending in order to lazily return the union |
|
713 | # Both sets need to be ascending in order to lazily return the union | |
719 | # in the correct order. |
|
714 | # in the correct order. | |
720 | base = subset & roots |
|
715 | base = subset & roots | |
721 | desc = subset & s |
|
716 | desc = subset & s | |
722 | result = base + desc |
|
717 | result = base + desc | |
723 | if subset.isascending(): |
|
718 | if subset.isascending(): | |
724 | result.sort() |
|
719 | result.sort() | |
725 | elif subset.isdescending(): |
|
720 | elif subset.isdescending(): | |
726 | result.sort(reverse=True) |
|
721 | result.sort(reverse=True) | |
727 | else: |
|
722 | else: | |
728 | result = subset & result |
|
723 | result = subset & result | |
729 | return result |
|
724 | return result | |
730 |
|
725 | |||
731 | def descendants(repo, subset, x): |
|
726 | def descendants(repo, subset, x): | |
732 | """``descendants(set)`` |
|
727 | """``descendants(set)`` | |
733 | Changesets which are descendants of changesets in set. |
|
728 | Changesets which are descendants of changesets in set. | |
734 | """ |
|
729 | """ | |
735 | return _descendants(repo, subset, x) |
|
730 | return _descendants(repo, subset, x) | |
736 |
|
731 | |||
737 | def _firstdescendants(repo, subset, x): |
|
732 | def _firstdescendants(repo, subset, x): | |
738 | # ``_firstdescendants(set)`` |
|
733 | # ``_firstdescendants(set)`` | |
739 | # Like ``descendants(set)`` but follows only the first parents. |
|
734 | # Like ``descendants(set)`` but follows only the first parents. | |
740 | return _descendants(repo, subset, x, followfirst=True) |
|
735 | return _descendants(repo, subset, x, followfirst=True) | |
741 |
|
736 | |||
742 | def destination(repo, subset, x): |
|
737 | def destination(repo, subset, x): | |
743 | """``destination([set])`` |
|
738 | """``destination([set])`` | |
744 | Changesets that were created by a graft, transplant or rebase operation, |
|
739 | Changesets that were created by a graft, transplant or rebase operation, | |
745 | with the given revisions specified as the source. Omitting the optional set |
|
740 | with the given revisions specified as the source. Omitting the optional set | |
746 | is the same as passing all(). |
|
741 | is the same as passing all(). | |
747 | """ |
|
742 | """ | |
748 | if x is not None: |
|
743 | if x is not None: | |
749 | sources = getset(repo, fullreposet(repo), x) |
|
744 | sources = getset(repo, fullreposet(repo), x) | |
750 | else: |
|
745 | else: | |
751 | sources = fullreposet(repo) |
|
746 | sources = fullreposet(repo) | |
752 |
|
747 | |||
753 | dests = set() |
|
748 | dests = set() | |
754 |
|
749 | |||
755 | # subset contains all of the possible destinations that can be returned, so |
|
750 | # subset contains all of the possible destinations that can be returned, so | |
756 | # iterate over them and see if their source(s) were provided in the arg set. |
|
751 | # iterate over them and see if their source(s) were provided in the arg set. | |
757 | # Even if the immediate src of r is not in the arg set, src's source (or |
|
752 | # Even if the immediate src of r is not in the arg set, src's source (or | |
758 | # further back) may be. Scanning back further than the immediate src allows |
|
753 | # further back) may be. Scanning back further than the immediate src allows | |
759 | # transitive transplants and rebases to yield the same results as transitive |
|
754 | # transitive transplants and rebases to yield the same results as transitive | |
760 | # grafts. |
|
755 | # grafts. | |
761 | for r in subset: |
|
756 | for r in subset: | |
762 | src = _getrevsource(repo, r) |
|
757 | src = _getrevsource(repo, r) | |
763 | lineage = None |
|
758 | lineage = None | |
764 |
|
759 | |||
765 | while src is not None: |
|
760 | while src is not None: | |
766 | if lineage is None: |
|
761 | if lineage is None: | |
767 | lineage = list() |
|
762 | lineage = list() | |
768 |
|
763 | |||
769 | lineage.append(r) |
|
764 | lineage.append(r) | |
770 |
|
765 | |||
771 | # The visited lineage is a match if the current source is in the arg |
|
766 | # The visited lineage is a match if the current source is in the arg | |
772 | # set. Since every candidate dest is visited by way of iterating |
|
767 | # set. Since every candidate dest is visited by way of iterating | |
773 | # subset, any dests further back in the lineage will be tested by a |
|
768 | # subset, any dests further back in the lineage will be tested by a | |
774 | # different iteration over subset. Likewise, if the src was already |
|
769 | # different iteration over subset. Likewise, if the src was already | |
775 | # selected, the current lineage can be selected without going back |
|
770 | # selected, the current lineage can be selected without going back | |
776 | # further. |
|
771 | # further. | |
777 | if src in sources or src in dests: |
|
772 | if src in sources or src in dests: | |
778 | dests.update(lineage) |
|
773 | dests.update(lineage) | |
779 | break |
|
774 | break | |
780 |
|
775 | |||
781 | r = src |
|
776 | r = src | |
782 | src = _getrevsource(repo, r) |
|
777 | src = _getrevsource(repo, r) | |
783 |
|
778 | |||
784 | return subset.filter(dests.__contains__) |
|
779 | return subset.filter(dests.__contains__) | |
785 |
|
780 | |||
786 | def divergent(repo, subset, x): |
|
781 | def divergent(repo, subset, x): | |
787 | """``divergent()`` |
|
782 | """``divergent()`` | |
788 | Final successors of changesets with an alternative set of final successors. |
|
783 | Final successors of changesets with an alternative set of final successors. | |
789 | """ |
|
784 | """ | |
790 | # i18n: "divergent" is a keyword |
|
785 | # i18n: "divergent" is a keyword | |
791 | getargs(x, 0, 0, _("divergent takes no arguments")) |
|
786 | getargs(x, 0, 0, _("divergent takes no arguments")) | |
792 | divergent = obsmod.getrevs(repo, 'divergent') |
|
787 | divergent = obsmod.getrevs(repo, 'divergent') | |
793 | return subset & divergent |
|
788 | return subset & divergent | |
794 |
|
789 | |||
795 | def draft(repo, subset, x): |
|
790 | def draft(repo, subset, x): | |
796 | """``draft()`` |
|
791 | """``draft()`` | |
797 | Changeset in draft phase.""" |
|
792 | Changeset in draft phase.""" | |
798 | # i18n: "draft" is a keyword |
|
793 | # i18n: "draft" is a keyword | |
799 | getargs(x, 0, 0, _("draft takes no arguments")) |
|
794 | getargs(x, 0, 0, _("draft takes no arguments")) | |
800 | phase = repo._phasecache.phase |
|
795 | phase = repo._phasecache.phase | |
801 | target = phases.draft |
|
796 | target = phases.draft | |
802 | condition = lambda r: phase(repo, r) == target |
|
797 | condition = lambda r: phase(repo, r) == target | |
803 | return subset.filter(condition, cache=False) |
|
798 | return subset.filter(condition, cache=False) | |
804 |
|
799 | |||
805 | def extinct(repo, subset, x): |
|
800 | def extinct(repo, subset, x): | |
806 | """``extinct()`` |
|
801 | """``extinct()`` | |
807 | Obsolete changesets with obsolete descendants only. |
|
802 | Obsolete changesets with obsolete descendants only. | |
808 | """ |
|
803 | """ | |
809 | # i18n: "extinct" is a keyword |
|
804 | # i18n: "extinct" is a keyword | |
810 | getargs(x, 0, 0, _("extinct takes no arguments")) |
|
805 | getargs(x, 0, 0, _("extinct takes no arguments")) | |
811 | extincts = obsmod.getrevs(repo, 'extinct') |
|
806 | extincts = obsmod.getrevs(repo, 'extinct') | |
812 | return subset & extincts |
|
807 | return subset & extincts | |
813 |
|
808 | |||
814 | def extra(repo, subset, x): |
|
809 | def extra(repo, subset, x): | |
815 | """``extra(label, [value])`` |
|
810 | """``extra(label, [value])`` | |
816 | Changesets with the given label in the extra metadata, with the given |
|
811 | Changesets with the given label in the extra metadata, with the given | |
817 | optional value. |
|
812 | optional value. | |
818 |
|
813 | |||
819 | If `value` starts with `re:`, the remainder of the value is treated as |
|
814 | If `value` starts with `re:`, the remainder of the value is treated as | |
820 | a regular expression. To match a value that actually starts with `re:`, |
|
815 | a regular expression. To match a value that actually starts with `re:`, | |
821 | use the prefix `literal:`. |
|
816 | use the prefix `literal:`. | |
822 | """ |
|
817 | """ | |
823 |
|
818 | |||
824 | # i18n: "extra" is a keyword |
|
819 | # i18n: "extra" is a keyword | |
825 | l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments')) |
|
820 | l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments')) | |
826 | # i18n: "extra" is a keyword |
|
821 | # i18n: "extra" is a keyword | |
827 | label = getstring(l[0], _('first argument to extra must be a string')) |
|
822 | label = getstring(l[0], _('first argument to extra must be a string')) | |
828 | value = None |
|
823 | value = None | |
829 |
|
824 | |||
830 | if len(l) > 1: |
|
825 | if len(l) > 1: | |
831 | # i18n: "extra" is a keyword |
|
826 | # i18n: "extra" is a keyword | |
832 | value = getstring(l[1], _('second argument to extra must be a string')) |
|
827 | value = getstring(l[1], _('second argument to extra must be a string')) | |
833 | kind, value, matcher = _stringmatcher(value) |
|
828 | kind, value, matcher = _stringmatcher(value) | |
834 |
|
829 | |||
835 | def _matchvalue(r): |
|
830 | def _matchvalue(r): | |
836 | extra = repo[r].extra() |
|
831 | extra = repo[r].extra() | |
837 | return label in extra and (value is None or matcher(extra[label])) |
|
832 | return label in extra and (value is None or matcher(extra[label])) | |
838 |
|
833 | |||
839 | return subset.filter(lambda r: _matchvalue(r)) |
|
834 | return subset.filter(lambda r: _matchvalue(r)) | |
840 |
|
835 | |||
841 | def filelog(repo, subset, x): |
|
836 | def filelog(repo, subset, x): | |
842 | """``filelog(pattern)`` |
|
837 | """``filelog(pattern)`` | |
843 | Changesets connected to the specified filelog. |
|
838 | Changesets connected to the specified filelog. | |
844 |
|
839 | |||
845 | For performance reasons, visits only revisions mentioned in the file-level |
|
840 | For performance reasons, visits only revisions mentioned in the file-level | |
846 | filelog, rather than filtering through all changesets (much faster, but |
|
841 | filelog, rather than filtering through all changesets (much faster, but | |
847 | doesn't include deletes or duplicate changes). For a slower, more accurate |
|
842 | doesn't include deletes or duplicate changes). For a slower, more accurate | |
848 | result, use ``file()``. |
|
843 | result, use ``file()``. | |
849 |
|
844 | |||
850 | The pattern without explicit kind like ``glob:`` is expected to be |
|
845 | The pattern without explicit kind like ``glob:`` is expected to be | |
851 | relative to the current directory and match against a file exactly |
|
846 | relative to the current directory and match against a file exactly | |
852 | for efficiency. |
|
847 | for efficiency. | |
853 |
|
848 | |||
854 | If some linkrev points to revisions filtered by the current repoview, we'll |
|
849 | If some linkrev points to revisions filtered by the current repoview, we'll | |
855 | work around it to return a non-filtered value. |
|
850 | work around it to return a non-filtered value. | |
856 | """ |
|
851 | """ | |
857 |
|
852 | |||
858 | # i18n: "filelog" is a keyword |
|
853 | # i18n: "filelog" is a keyword | |
859 | pat = getstring(x, _("filelog requires a pattern")) |
|
854 | pat = getstring(x, _("filelog requires a pattern")) | |
860 | s = set() |
|
855 | s = set() | |
861 | cl = repo.changelog |
|
856 | cl = repo.changelog | |
862 |
|
857 | |||
863 | if not matchmod.patkind(pat): |
|
858 | if not matchmod.patkind(pat): | |
864 | f = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
859 | f = pathutil.canonpath(repo.root, repo.getcwd(), pat) | |
865 | files = [f] |
|
860 | files = [f] | |
866 | else: |
|
861 | else: | |
867 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None]) |
|
862 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None]) | |
868 | files = (f for f in repo[None] if m(f)) |
|
863 | files = (f for f in repo[None] if m(f)) | |
869 |
|
864 | |||
870 | for f in files: |
|
865 | for f in files: | |
871 | backrevref = {} # final value for: filerev -> changerev |
|
866 | backrevref = {} # final value for: filerev -> changerev | |
872 | lowestchild = {} # lowest known filerev child of a filerev |
|
867 | lowestchild = {} # lowest known filerev child of a filerev | |
873 | delayed = [] # filerev with filtered linkrev, for post-processing |
|
868 | delayed = [] # filerev with filtered linkrev, for post-processing | |
874 | lowesthead = None # cache for manifest content of all head revisions |
|
869 | lowesthead = None # cache for manifest content of all head revisions | |
875 | fl = repo.file(f) |
|
870 | fl = repo.file(f) | |
876 | for fr in list(fl): |
|
871 | for fr in list(fl): | |
877 | rev = fl.linkrev(fr) |
|
872 | rev = fl.linkrev(fr) | |
878 | if rev not in cl: |
|
873 | if rev not in cl: | |
879 | # changerev pointed in linkrev is filtered |
|
874 | # changerev pointed in linkrev is filtered | |
880 | # record it for post processing. |
|
875 | # record it for post processing. | |
881 | delayed.append((fr, rev)) |
|
876 | delayed.append((fr, rev)) | |
882 | continue |
|
877 | continue | |
883 | for p in fl.parentrevs(fr): |
|
878 | for p in fl.parentrevs(fr): | |
884 | if 0 <= p and p not in lowestchild: |
|
879 | if 0 <= p and p not in lowestchild: | |
885 | lowestchild[p] = fr |
|
880 | lowestchild[p] = fr | |
886 | backrevref[fr] = rev |
|
881 | backrevref[fr] = rev | |
887 | s.add(rev) |
|
882 | s.add(rev) | |
888 |
|
883 | |||
889 | # Post-processing of all filerevs we skipped because they were |
|
884 | # Post-processing of all filerevs we skipped because they were | |
890 | # filtered. If such filerevs have known and unfiltered children, this |
|
885 | # filtered. If such filerevs have known and unfiltered children, this | |
891 | # means they have an unfiltered appearance out there. We'll use linkrev |
|
886 | # means they have an unfiltered appearance out there. We'll use linkrev | |
892 | # adjustment to find one of these appearances. The lowest known child |
|
887 | # adjustment to find one of these appearances. The lowest known child | |
893 | # will be used as a starting point because it is the best upper-bound we |
|
888 | # will be used as a starting point because it is the best upper-bound we | |
894 | # have. |
|
889 | # have. | |
895 | # |
|
890 | # | |
896 | # This approach will fail when an unfiltered but linkrev-shadowed |
|
891 | # This approach will fail when an unfiltered but linkrev-shadowed | |
897 | # appearance exists in a head changeset without unfiltered filerev |
|
892 | # appearance exists in a head changeset without unfiltered filerev | |
898 | # children anywhere. |
|
893 | # children anywhere. | |
899 | while delayed: |
|
894 | while delayed: | |
900 | # must be a descending iteration. To slowly fill lowest child |
|
895 | # must be a descending iteration. To slowly fill lowest child | |
901 | # information that is of potential use by the next item. |
|
896 | # information that is of potential use by the next item. | |
902 | fr, rev = delayed.pop() |
|
897 | fr, rev = delayed.pop() | |
903 | lkr = rev |
|
898 | lkr = rev | |
904 |
|
899 | |||
905 | child = lowestchild.get(fr) |
|
900 | child = lowestchild.get(fr) | |
906 |
|
901 | |||
907 | if child is None: |
|
902 | if child is None: | |
908 | # search for existence of this file revision in a head revision. |
|
903 | # search for existence of this file revision in a head revision. | |
909 | # There are three possibilities: |
|
904 | # There are three possibilities: | |
910 | # - the revision exists in a head and we can find an |
|
905 | # - the revision exists in a head and we can find an | |
911 | # introduction from there, |
|
906 | # introduction from there, | |
912 | # - the revision does not exist in a head because it has been |
|
907 | # - the revision does not exist in a head because it has been | |
913 | # changed since its introduction: we would have found a child |
|
908 | # changed since its introduction: we would have found a child | |
914 | # and be in the other 'else' clause, |
|
909 | # and be in the other 'else' clause, | |
915 | # - all versions of the revision are hidden. |
|
910 | # - all versions of the revision are hidden. | |
916 | if lowesthead is None: |
|
911 | if lowesthead is None: | |
917 | lowesthead = {} |
|
912 | lowesthead = {} | |
918 | for h in repo.heads(): |
|
913 | for h in repo.heads(): | |
919 | fnode = repo[h].manifest().get(f) |
|
914 | fnode = repo[h].manifest().get(f) | |
920 | if fnode is not None: |
|
915 | if fnode is not None: | |
921 | lowesthead[fl.rev(fnode)] = h |
|
916 | lowesthead[fl.rev(fnode)] = h | |
922 | headrev = lowesthead.get(fr) |
|
917 | headrev = lowesthead.get(fr) | |
923 | if headrev is None: |
|
918 | if headrev is None: | |
924 | # content is nowhere unfiltered |
|
919 | # content is nowhere unfiltered | |
925 | continue |
|
920 | continue | |
926 | rev = repo[headrev][f].introrev() |
|
921 | rev = repo[headrev][f].introrev() | |
927 | else: |
|
922 | else: | |
928 | # the lowest known child is a good upper bound |
|
923 | # the lowest known child is a good upper bound | |
929 | childcrev = backrevref[child] |
|
924 | childcrev = backrevref[child] | |
930 | # XXX this does not guarantee returning the lowest |
|
925 | # XXX this does not guarantee returning the lowest | |
931 | # introduction of this revision, but this gives a |
|
926 | # introduction of this revision, but this gives a | |
932 | # result which is a good start and will fit in most |
|
927 | # result which is a good start and will fit in most | |
933 | # cases. We probably need to fix the multiple |
|
928 | # cases. We probably need to fix the multiple | |
934 | # introductions case properly (report each |
|
929 | # introductions case properly (report each | |
935 | # introduction, even for identical file revisions) |
|
930 | # introduction, even for identical file revisions) | |
936 | # once and for all at some point anyway. |
|
931 | # once and for all at some point anyway. | |
937 | for p in repo[childcrev][f].parents(): |
|
932 | for p in repo[childcrev][f].parents(): | |
938 | if p.filerev() == fr: |
|
933 | if p.filerev() == fr: | |
939 | rev = p.rev() |
|
934 | rev = p.rev() | |
940 | break |
|
935 | break | |
941 | if rev == lkr: # no shadowed entry found |
|
936 | if rev == lkr: # no shadowed entry found | |
942 | # XXX This should never happen unless some manifest points |
|
937 | # XXX This should never happen unless some manifest points | |
943 | # to biggish file revisions (like a revision that uses a |
|
938 | # to biggish file revisions (like a revision that uses a | |
944 | # parent that never appears in the manifest ancestors) |
|
939 | # parent that never appears in the manifest ancestors) | |
945 | continue |
|
940 | continue | |
946 |
|
941 | |||
947 | # Fill the data for the next iteration. |
|
942 | # Fill the data for the next iteration. | |
948 | for p in fl.parentrevs(fr): |
|
943 | for p in fl.parentrevs(fr): | |
949 | if 0 <= p and p not in lowestchild: |
|
944 | if 0 <= p and p not in lowestchild: | |
950 | lowestchild[p] = fr |
|
945 | lowestchild[p] = fr | |
951 | backrevref[fr] = rev |
|
946 | backrevref[fr] = rev | |
952 | s.add(rev) |
|
947 | s.add(rev) | |
953 |
|
948 | |||
954 | return subset & s |
|
949 | return subset & s | |
955 |
|
950 | |||
956 | def first(repo, subset, x): |
|
951 | def first(repo, subset, x): | |
957 | """``first(set, [n])`` |
|
952 | """``first(set, [n])`` | |
958 | An alias for limit(). |
|
953 | An alias for limit(). | |
959 | """ |
|
954 | """ | |
960 | return limit(repo, subset, x) |
|
955 | return limit(repo, subset, x) | |
961 |
|
956 | |||
962 | def _follow(repo, subset, x, name, followfirst=False): |
|
957 | def _follow(repo, subset, x, name, followfirst=False): | |
963 | l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name) |
|
958 | l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name) | |
964 | c = repo['.'] |
|
959 | c = repo['.'] | |
965 | if l: |
|
960 | if l: | |
966 | x = getstring(l[0], _("%s expected a filename") % name) |
|
961 | x = getstring(l[0], _("%s expected a filename") % name) | |
967 | if x in c: |
|
962 | if x in c: | |
968 | cx = c[x] |
|
963 | cx = c[x] | |
969 | s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst)) |
|
964 | s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst)) | |
970 | # include the revision responsible for the most recent version |
|
965 | # include the revision responsible for the most recent version | |
971 | s.add(cx.introrev()) |
|
966 | s.add(cx.introrev()) | |
972 | else: |
|
967 | else: | |
973 | return baseset() |
|
968 | return baseset() | |
974 | else: |
|
969 | else: | |
975 | s = _revancestors(repo, baseset([c.rev()]), followfirst) |
|
970 | s = _revancestors(repo, baseset([c.rev()]), followfirst) | |
976 |
|
971 | |||
977 | return subset & s |
|
972 | return subset & s | |
978 |
|
973 | |||
979 | def follow(repo, subset, x): |
|
974 | def follow(repo, subset, x): | |
980 | """``follow([file])`` |
|
975 | """``follow([file])`` | |
981 | An alias for ``::.`` (ancestors of the working directory's first parent). |
|
976 | An alias for ``::.`` (ancestors of the working directory's first parent). | |
982 | If a filename is specified, the history of the given file is followed, |
|
977 | If a filename is specified, the history of the given file is followed, | |
983 | including copies. |
|
978 | including copies. | |
984 | """ |
|
979 | """ | |
985 | return _follow(repo, subset, x, 'follow') |
|
980 | return _follow(repo, subset, x, 'follow') | |
986 |
|
981 | |||
987 | def _followfirst(repo, subset, x): |
|
982 | def _followfirst(repo, subset, x): | |
988 | # ``followfirst([file])`` |
|
983 | # ``followfirst([file])`` | |
989 | # Like ``follow([file])`` but follows only the first parent of |
|
984 | # Like ``follow([file])`` but follows only the first parent of | |
990 | # every revision or file revision. |
|
985 | # every revision or file revision. | |
991 | return _follow(repo, subset, x, '_followfirst', followfirst=True) |
|
986 | return _follow(repo, subset, x, '_followfirst', followfirst=True) | |
992 |
|
987 | |||
993 | def getall(repo, subset, x): |
|
988 | def getall(repo, subset, x): | |
994 | """``all()`` |
|
989 | """``all()`` | |
995 | All changesets, the same as ``0:tip``. |
|
990 | All changesets, the same as ``0:tip``. | |
996 | """ |
|
991 | """ | |
997 | # i18n: "all" is a keyword |
|
992 | # i18n: "all" is a keyword | |
998 | getargs(x, 0, 0, _("all takes no arguments")) |
|
993 | getargs(x, 0, 0, _("all takes no arguments")) | |
999 | return subset & spanset(repo) # drop "null" if any |
|
994 | return subset & spanset(repo) # drop "null" if any | |
1000 |
|
995 | |||
1001 | def grep(repo, subset, x): |
|
996 | def grep(repo, subset, x): | |
1002 | """``grep(regex)`` |
|
997 | """``grep(regex)`` | |
1003 | Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` |
|
998 | Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` | |
1004 | to ensure special escape characters are handled correctly. Unlike |
|
999 | to ensure special escape characters are handled correctly. Unlike | |
1005 | ``keyword(string)``, the match is case-sensitive. |
|
1000 | ``keyword(string)``, the match is case-sensitive. | |
1006 | """ |
|
1001 | """ | |
1007 | try: |
|
1002 | try: | |
1008 | # i18n: "grep" is a keyword |
|
1003 | # i18n: "grep" is a keyword | |
1009 | gr = re.compile(getstring(x, _("grep requires a string"))) |
|
1004 | gr = re.compile(getstring(x, _("grep requires a string"))) | |
1010 | except re.error, e: |
|
1005 | except re.error, e: | |
1011 | raise error.ParseError(_('invalid match pattern: %s') % e) |
|
1006 | raise error.ParseError(_('invalid match pattern: %s') % e) | |
1012 |
|
1007 | |||
1013 | def matches(x): |
|
1008 | def matches(x): | |
1014 | c = repo[x] |
|
1009 | c = repo[x] | |
1015 | for e in c.files() + [c.user(), c.description()]: |
|
1010 | for e in c.files() + [c.user(), c.description()]: | |
1016 | if gr.search(e): |
|
1011 | if gr.search(e): | |
1017 | return True |
|
1012 | return True | |
1018 | return False |
|
1013 | return False | |
1019 |
|
1014 | |||
1020 | return subset.filter(matches) |
|
1015 | return subset.filter(matches) | |
1021 |
|
1016 | |||
1022 | def _matchfiles(repo, subset, x): |
|
1017 | def _matchfiles(repo, subset, x): | |
1023 | # _matchfiles takes a revset list of prefixed arguments: |
|
1018 | # _matchfiles takes a revset list of prefixed arguments: | |
1024 | # |
|
1019 | # | |
1025 | # [p:foo, i:bar, x:baz] |
|
1020 | # [p:foo, i:bar, x:baz] | |
1026 | # |
|
1021 | # | |
1027 | # builds a match object from them and filters subset. Allowed |
|
1022 | # builds a match object from them and filters subset. Allowed | |
1028 | # prefixes are 'p:' for regular patterns, 'i:' for include |
|
1023 | # prefixes are 'p:' for regular patterns, 'i:' for include | |
1029 | # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass |
|
1024 | # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass | |
1030 | # a revision identifier, or the empty string to reference the |
|
1025 | # a revision identifier, or the empty string to reference the | |
1031 | # working directory, from which the match object is |
|
1026 | # working directory, from which the match object is | |
1032 | # initialized. Use 'd:' to set the default matching mode, default |
|
1027 | # initialized. Use 'd:' to set the default matching mode, default | |
1033 | # to 'glob'. At most one 'r:' and 'd:' argument can be passed. |
|
1028 | # to 'glob'. At most one 'r:' and 'd:' argument can be passed. | |
1034 |
|
1029 | |||
1035 | # i18n: "_matchfiles" is a keyword |
|
1030 | # i18n: "_matchfiles" is a keyword | |
1036 | l = getargs(x, 1, -1, _("_matchfiles requires at least one argument")) |
|
1031 | l = getargs(x, 1, -1, _("_matchfiles requires at least one argument")) | |
1037 | pats, inc, exc = [], [], [] |
|
1032 | pats, inc, exc = [], [], [] | |
1038 | rev, default = None, None |
|
1033 | rev, default = None, None | |
1039 | for arg in l: |
|
1034 | for arg in l: | |
1040 | # i18n: "_matchfiles" is a keyword |
|
1035 | # i18n: "_matchfiles" is a keyword | |
1041 | s = getstring(arg, _("_matchfiles requires string arguments")) |
|
1036 | s = getstring(arg, _("_matchfiles requires string arguments")) | |
1042 | prefix, value = s[:2], s[2:] |
|
1037 | prefix, value = s[:2], s[2:] | |
1043 | if prefix == 'p:': |
|
1038 | if prefix == 'p:': | |
1044 | pats.append(value) |
|
1039 | pats.append(value) | |
1045 | elif prefix == 'i:': |
|
1040 | elif prefix == 'i:': | |
1046 | inc.append(value) |
|
1041 | inc.append(value) | |
1047 | elif prefix == 'x:': |
|
1042 | elif prefix == 'x:': | |
1048 | exc.append(value) |
|
1043 | exc.append(value) | |
1049 | elif prefix == 'r:': |
|
1044 | elif prefix == 'r:': | |
1050 | if rev is not None: |
|
1045 | if rev is not None: | |
1051 | # i18n: "_matchfiles" is a keyword |
|
1046 | # i18n: "_matchfiles" is a keyword | |
1052 | raise error.ParseError(_('_matchfiles expected at most one ' |
|
1047 | raise error.ParseError(_('_matchfiles expected at most one ' | |
1053 | 'revision')) |
|
1048 | 'revision')) | |
1054 | if value != '': # empty means working directory; leave rev as None |
|
1049 | if value != '': # empty means working directory; leave rev as None | |
1055 | rev = value |
|
1050 | rev = value | |
1056 | elif prefix == 'd:': |
|
1051 | elif prefix == 'd:': | |
1057 | if default is not None: |
|
1052 | if default is not None: | |
1058 | # i18n: "_matchfiles" is a keyword |
|
1053 | # i18n: "_matchfiles" is a keyword | |
1059 | raise error.ParseError(_('_matchfiles expected at most one ' |
|
1054 | raise error.ParseError(_('_matchfiles expected at most one ' | |
1060 | 'default mode')) |
|
1055 | 'default mode')) | |
1061 | default = value |
|
1056 | default = value | |
1062 | else: |
|
1057 | else: | |
1063 | # i18n: "_matchfiles" is a keyword |
|
1058 | # i18n: "_matchfiles" is a keyword | |
1064 | raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix) |
|
1059 | raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix) | |
1065 | if not default: |
|
1060 | if not default: | |
1066 | default = 'glob' |
|
1061 | default = 'glob' | |
1067 |
|
1062 | |||
1068 | m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, |
|
1063 | m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, | |
1069 | exclude=exc, ctx=repo[rev], default=default) |
|
1064 | exclude=exc, ctx=repo[rev], default=default) | |
1070 |
|
1065 | |||
1071 | def matches(x): |
|
1066 | def matches(x): | |
1072 | for f in repo[x].files(): |
|
1067 | for f in repo[x].files(): | |
1073 | if m(f): |
|
1068 | if m(f): | |
1074 | return True |
|
1069 | return True | |
1075 | return False |
|
1070 | return False | |
1076 |
|
1071 | |||
1077 | return subset.filter(matches) |
|
1072 | return subset.filter(matches) | |
1078 |
|
1073 | |||
1079 | def hasfile(repo, subset, x): |
|
1074 | def hasfile(repo, subset, x): | |
1080 | """``file(pattern)`` |
|
1075 | """``file(pattern)`` | |
1081 | Changesets affecting files matched by pattern. |
|
1076 | Changesets affecting files matched by pattern. | |
1082 |
|
1077 | |||
1083 | For a faster but less accurate result, consider using ``filelog()`` |
|
1078 | For a faster but less accurate result, consider using ``filelog()`` | |
1084 | instead. |
|
1079 | instead. | |
1085 |
|
1080 | |||
1086 | This predicate uses ``glob:`` as the default kind of pattern. |
|
1081 | This predicate uses ``glob:`` as the default kind of pattern. | |
1087 | """ |
|
1082 | """ | |
1088 | # i18n: "file" is a keyword |
|
1083 | # i18n: "file" is a keyword | |
1089 | pat = getstring(x, _("file requires a pattern")) |
|
1084 | pat = getstring(x, _("file requires a pattern")) | |
1090 | return _matchfiles(repo, subset, ('string', 'p:' + pat)) |
|
1085 | return _matchfiles(repo, subset, ('string', 'p:' + pat)) | |
1091 |
|
1086 | |||
1092 | def head(repo, subset, x): |
|
1087 | def head(repo, subset, x): | |
1093 | """``head()`` |
|
1088 | """``head()`` | |
1094 | Changeset is a named branch head. |
|
1089 | Changeset is a named branch head. | |
1095 | """ |
|
1090 | """ | |
1096 | # i18n: "head" is a keyword |
|
1091 | # i18n: "head" is a keyword | |
1097 | getargs(x, 0, 0, _("head takes no arguments")) |
|
1092 | getargs(x, 0, 0, _("head takes no arguments")) | |
1098 | hs = set() |
|
1093 | hs = set() | |
1099 | for b, ls in repo.branchmap().iteritems(): |
|
1094 | for b, ls in repo.branchmap().iteritems(): | |
1100 | hs.update(repo[h].rev() for h in ls) |
|
1095 | hs.update(repo[h].rev() for h in ls) | |
1101 | return baseset(hs).filter(subset.__contains__) |
|
1096 | return baseset(hs).filter(subset.__contains__) | |
1102 |
|
1097 | |||
1103 | def heads(repo, subset, x): |
|
1098 | def heads(repo, subset, x): | |
1104 | """``heads(set)`` |
|
1099 | """``heads(set)`` | |
1105 | Members of set with no children in set. |
|
1100 | Members of set with no children in set. | |
1106 | """ |
|
1101 | """ | |
1107 | s = getset(repo, subset, x) |
|
1102 | s = getset(repo, subset, x) | |
1108 | ps = parents(repo, subset, x) |
|
1103 | ps = parents(repo, subset, x) | |
1109 | return s - ps |
|
1104 | return s - ps | |
1110 |
|
1105 | |||
1111 | def hidden(repo, subset, x): |
|
1106 | def hidden(repo, subset, x): | |
1112 | """``hidden()`` |
|
1107 | """``hidden()`` | |
1113 | Hidden changesets. |
|
1108 | Hidden changesets. | |
1114 | """ |
|
1109 | """ | |
1115 | # i18n: "hidden" is a keyword |
|
1110 | # i18n: "hidden" is a keyword | |
1116 | getargs(x, 0, 0, _("hidden takes no arguments")) |
|
1111 | getargs(x, 0, 0, _("hidden takes no arguments")) | |
1117 | hiddenrevs = repoview.filterrevs(repo, 'visible') |
|
1112 | hiddenrevs = repoview.filterrevs(repo, 'visible') | |
1118 | return subset & hiddenrevs |
|
1113 | return subset & hiddenrevs | |
1119 |
|
1114 | |||
1120 | def keyword(repo, subset, x): |
|
1115 | def keyword(repo, subset, x): | |
1121 | """``keyword(string)`` |
|
1116 | """``keyword(string)`` | |
1122 | Search commit message, user name, and names of changed files for |
|
1117 | Search commit message, user name, and names of changed files for | |
1123 | string. The match is case-insensitive. |
|
1118 | string. The match is case-insensitive. | |
1124 | """ |
|
1119 | """ | |
1125 | # i18n: "keyword" is a keyword |
|
1120 | # i18n: "keyword" is a keyword | |
1126 | kw = encoding.lower(getstring(x, _("keyword requires a string"))) |
|
1121 | kw = encoding.lower(getstring(x, _("keyword requires a string"))) | |
1127 |
|
1122 | |||
1128 | def matches(r): |
|
1123 | def matches(r): | |
1129 | c = repo[r] |
|
1124 | c = repo[r] | |
1130 | return util.any(kw in encoding.lower(t) for t in c.files() + [c.user(), |
|
1125 | return util.any(kw in encoding.lower(t) for t in c.files() + [c.user(), | |
1131 | c.description()]) |
|
1126 | c.description()]) | |
1132 |
|
1127 | |||
1133 | return subset.filter(matches) |
|
1128 | return subset.filter(matches) | |
1134 |
|
1129 | |||
1135 | def limit(repo, subset, x): |
|
1130 | def limit(repo, subset, x): | |
1136 | """``limit(set, [n])`` |
|
1131 | """``limit(set, [n])`` | |
1137 | First n members of set, defaulting to 1. |
|
1132 | First n members of set, defaulting to 1. | |
1138 | """ |
|
1133 | """ | |
1139 | # i18n: "limit" is a keyword |
|
1134 | # i18n: "limit" is a keyword | |
1140 | l = getargs(x, 1, 2, _("limit requires one or two arguments")) |
|
1135 | l = getargs(x, 1, 2, _("limit requires one or two arguments")) | |
1141 | try: |
|
1136 | try: | |
1142 | lim = 1 |
|
1137 | lim = 1 | |
1143 | if len(l) == 2: |
|
1138 | if len(l) == 2: | |
1144 | # i18n: "limit" is a keyword |
|
1139 | # i18n: "limit" is a keyword | |
1145 | lim = int(getstring(l[1], _("limit requires a number"))) |
|
1140 | lim = int(getstring(l[1], _("limit requires a number"))) | |
1146 | except (TypeError, ValueError): |
|
1141 | except (TypeError, ValueError): | |
1147 | # i18n: "limit" is a keyword |
|
1142 | # i18n: "limit" is a keyword | |
1148 | raise error.ParseError(_("limit expects a number")) |
|
1143 | raise error.ParseError(_("limit expects a number")) | |
1149 | ss = subset |
|
1144 | ss = subset | |
1150 | os = getset(repo, fullreposet(repo), l[0]) |
|
1145 | os = getset(repo, fullreposet(repo), l[0]) | |
1151 | result = [] |
|
1146 | result = [] | |
1152 | it = iter(os) |
|
1147 | it = iter(os) | |
1153 | for x in xrange(lim): |
|
1148 | for x in xrange(lim): | |
1154 | try: |
|
1149 | try: | |
1155 | y = it.next() |
|
1150 | y = it.next() | |
1156 | if y in ss: |
|
1151 | if y in ss: | |
1157 | result.append(y) |
|
1152 | result.append(y) | |
1158 | except (StopIteration): |
|
1153 | except (StopIteration): | |
1159 | break |
|
1154 | break | |
1160 | return baseset(result) |
|
1155 | return baseset(result) | |
1161 |
|
1156 | |||
1162 | def last(repo, subset, x): |
|
1157 | def last(repo, subset, x): | |
1163 | """``last(set, [n])`` |
|
1158 | """``last(set, [n])`` | |
1164 | Last n members of set, defaulting to 1. |
|
1159 | Last n members of set, defaulting to 1. | |
1165 | """ |
|
1160 | """ | |
1166 | # i18n: "last" is a keyword |
|
1161 | # i18n: "last" is a keyword | |
1167 | l = getargs(x, 1, 2, _("last requires one or two arguments")) |
|
1162 | l = getargs(x, 1, 2, _("last requires one or two arguments")) | |
1168 | try: |
|
1163 | try: | |
1169 | lim = 1 |
|
1164 | lim = 1 | |
1170 | if len(l) == 2: |
|
1165 | if len(l) == 2: | |
1171 | # i18n: "last" is a keyword |
|
1166 | # i18n: "last" is a keyword | |
1172 | lim = int(getstring(l[1], _("last requires a number"))) |
|
1167 | lim = int(getstring(l[1], _("last requires a number"))) | |
1173 | except (TypeError, ValueError): |
|
1168 | except (TypeError, ValueError): | |
1174 | # i18n: "last" is a keyword |
|
1169 | # i18n: "last" is a keyword | |
1175 | raise error.ParseError(_("last expects a number")) |
|
1170 | raise error.ParseError(_("last expects a number")) | |
1176 | ss = subset |
|
1171 | ss = subset | |
1177 | os = getset(repo, fullreposet(repo), l[0]) |
|
1172 | os = getset(repo, fullreposet(repo), l[0]) | |
1178 | os.reverse() |
|
1173 | os.reverse() | |
1179 | result = [] |
|
1174 | result = [] | |
1180 | it = iter(os) |
|
1175 | it = iter(os) | |
1181 | for x in xrange(lim): |
|
1176 | for x in xrange(lim): | |
1182 | try: |
|
1177 | try: | |
1183 | y = it.next() |
|
1178 | y = it.next() | |
1184 | if y in ss: |
|
1179 | if y in ss: | |
1185 | result.append(y) |
|
1180 | result.append(y) | |
1186 | except (StopIteration): |
|
1181 | except (StopIteration): | |
1187 | break |
|
1182 | break | |
1188 | return baseset(result) |
|
1183 | return baseset(result) | |
1189 |
|
1184 | |||
1190 | def maxrev(repo, subset, x): |
|
1185 | def maxrev(repo, subset, x): | |
1191 | """``max(set)`` |
|
1186 | """``max(set)`` | |
1192 | Changeset with highest revision number in set. |
|
1187 | Changeset with highest revision number in set. | |
1193 | """ |
|
1188 | """ | |
1194 | os = getset(repo, fullreposet(repo), x) |
|
1189 | os = getset(repo, fullreposet(repo), x) | |
1195 | if os: |
|
1190 | if os: | |
1196 | m = os.max() |
|
1191 | m = os.max() | |
1197 | if m in subset: |
|
1192 | if m in subset: | |
1198 | return baseset([m]) |
|
1193 | return baseset([m]) | |
1199 | return baseset() |
|
1194 | return baseset() | |
1200 |
|
1195 | |||
1201 | def merge(repo, subset, x): |
|
1196 | def merge(repo, subset, x): | |
1202 | """``merge()`` |
|
1197 | """``merge()`` | |
1203 | Changeset is a merge changeset. |
|
1198 | Changeset is a merge changeset. | |
1204 | """ |
|
1199 | """ | |
1205 | # i18n: "merge" is a keyword |
|
1200 | # i18n: "merge" is a keyword | |
1206 | getargs(x, 0, 0, _("merge takes no arguments")) |
|
1201 | getargs(x, 0, 0, _("merge takes no arguments")) | |
1207 | cl = repo.changelog |
|
1202 | cl = repo.changelog | |
1208 | return subset.filter(lambda r: cl.parentrevs(r)[1] != -1) |
|
1203 | return subset.filter(lambda r: cl.parentrevs(r)[1] != -1) | |
1209 |
|
1204 | |||
1210 | def branchpoint(repo, subset, x): |
|
1205 | def branchpoint(repo, subset, x): | |
1211 | """``branchpoint()`` |
|
1206 | """``branchpoint()`` | |
1212 | Changesets with more than one child. |
|
1207 | Changesets with more than one child. | |
1213 | """ |
|
1208 | """ | |
1214 | # i18n: "branchpoint" is a keyword |
|
1209 | # i18n: "branchpoint" is a keyword | |
1215 | getargs(x, 0, 0, _("branchpoint takes no arguments")) |
|
1210 | getargs(x, 0, 0, _("branchpoint takes no arguments")) | |
1216 | cl = repo.changelog |
|
1211 | cl = repo.changelog | |
1217 | if not subset: |
|
1212 | if not subset: | |
1218 | return baseset() |
|
1213 | return baseset() | |
1219 | baserev = min(subset) |
|
1214 | baserev = min(subset) | |
1220 | parentscount = [0]*(len(repo) - baserev) |
|
1215 | parentscount = [0]*(len(repo) - baserev) | |
1221 | for r in cl.revs(start=baserev + 1): |
|
1216 | for r in cl.revs(start=baserev + 1): | |
1222 | for p in cl.parentrevs(r): |
|
1217 | for p in cl.parentrevs(r): | |
1223 | if p >= baserev: |
|
1218 | if p >= baserev: | |
1224 | parentscount[p - baserev] += 1 |
|
1219 | parentscount[p - baserev] += 1 | |
1225 | return subset.filter(lambda r: parentscount[r - baserev] > 1) |
|
1220 | return subset.filter(lambda r: parentscount[r - baserev] > 1) | |
1226 |
|
1221 | |||
1227 | def minrev(repo, subset, x): |
|
1222 | def minrev(repo, subset, x): | |
1228 | """``min(set)`` |
|
1223 | """``min(set)`` | |
1229 | Changeset with lowest revision number in set. |
|
1224 | Changeset with lowest revision number in set. | |
1230 | """ |
|
1225 | """ | |
1231 | os = getset(repo, fullreposet(repo), x) |
|
1226 | os = getset(repo, fullreposet(repo), x) | |
1232 | if os: |
|
1227 | if os: | |
1233 | m = os.min() |
|
1228 | m = os.min() | |
1234 | if m in subset: |
|
1229 | if m in subset: | |
1235 | return baseset([m]) |
|
1230 | return baseset([m]) | |
1236 | return baseset() |
|
1231 | return baseset() | |
1237 |
|
1232 | |||
1238 | def modifies(repo, subset, x): |
|
1233 | def modifies(repo, subset, x): | |
1239 | """``modifies(pattern)`` |
|
1234 | """``modifies(pattern)`` | |
1240 | Changesets modifying files matched by pattern. |
|
1235 | Changesets modifying files matched by pattern. | |
1241 |
|
1236 | |||
1242 | The pattern without explicit kind like ``glob:`` is expected to be |
|
1237 | The pattern without explicit kind like ``glob:`` is expected to be | |
1243 | relative to the current directory and match against a file or a |
|
1238 | relative to the current directory and match against a file or a | |
1244 | directory. |
|
1239 | directory. | |
1245 | """ |
|
1240 | """ | |
1246 | # i18n: "modifies" is a keyword |
|
1241 | # i18n: "modifies" is a keyword | |
1247 | pat = getstring(x, _("modifies requires a pattern")) |
|
1242 | pat = getstring(x, _("modifies requires a pattern")) | |
1248 | return checkstatus(repo, subset, pat, 0) |
|
1243 | return checkstatus(repo, subset, pat, 0) | |
1249 |
|
1244 | |||
1250 | def named(repo, subset, x): |
|
1245 | def named(repo, subset, x): | |
1251 | """``named(namespace)`` |
|
1246 | """``named(namespace)`` | |
1252 | The changesets in a given namespace. |
|
1247 | The changesets in a given namespace. | |
1253 |
|
1248 | |||
1254 | If `namespace` starts with `re:`, the remainder of the string is treated as |
|
1249 | If `namespace` starts with `re:`, the remainder of the string is treated as | |
1255 | a regular expression. To match a namespace that actually starts with `re:`, |
|
1250 | a regular expression. To match a namespace that actually starts with `re:`, | |
1256 | use the prefix `literal:`. |
|
1251 | use the prefix `literal:`. | |
1257 | """ |
|
1252 | """ | |
1258 | # i18n: "named" is a keyword |
|
1253 | # i18n: "named" is a keyword | |
1259 | args = getargs(x, 1, 1, _('named requires a namespace argument')) |
|
1254 | args = getargs(x, 1, 1, _('named requires a namespace argument')) | |
1260 |
|
1255 | |||
1261 | ns = getstring(args[0], |
|
1256 | ns = getstring(args[0], | |
1262 | # i18n: "named" is a keyword |
|
1257 | # i18n: "named" is a keyword | |
1263 | _('the argument to named must be a string')) |
|
1258 | _('the argument to named must be a string')) | |
1264 | kind, pattern, matcher = _stringmatcher(ns) |
|
1259 | kind, pattern, matcher = _stringmatcher(ns) | |
1265 | namespaces = set() |
|
1260 | namespaces = set() | |
1266 | if kind == 'literal': |
|
1261 | if kind == 'literal': | |
1267 | if pattern not in repo.names: |
|
1262 | if pattern not in repo.names: | |
1268 | raise error.RepoLookupError(_("namespace '%s' does not exist") |
|
1263 | raise error.RepoLookupError(_("namespace '%s' does not exist") | |
1269 | % ns) |
|
1264 | % ns) | |
1270 | namespaces.add(repo.names[pattern]) |
|
1265 | namespaces.add(repo.names[pattern]) | |
1271 | else: |
|
1266 | else: | |
1272 | for name, ns in repo.names.iteritems(): |
|
1267 | for name, ns in repo.names.iteritems(): | |
1273 | if matcher(name): |
|
1268 | if matcher(name): | |
1274 | namespaces.add(ns) |
|
1269 | namespaces.add(ns) | |
1275 | if not namespaces: |
|
1270 | if not namespaces: | |
1276 | raise error.RepoLookupError(_("no namespace exists" |
|
1271 | raise error.RepoLookupError(_("no namespace exists" | |
1277 | " that match '%s'") % pattern) |
|
1272 | " that match '%s'") % pattern) | |
1278 |
|
1273 | |||
1279 | names = set() |
|
1274 | names = set() | |
1280 | for ns in namespaces: |
|
1275 | for ns in namespaces: | |
1281 | for name in ns.listnames(repo): |
|
1276 | for name in ns.listnames(repo): | |
1282 | if name not in ns.deprecated: |
|
1277 | if name not in ns.deprecated: | |
1283 | names.update(repo[n].rev() for n in ns.nodes(repo, name)) |
|
1278 | names.update(repo[n].rev() for n in ns.nodes(repo, name)) | |
1284 |
|
1279 | |||
1285 | names -= set([node.nullrev]) |
|
1280 | names -= set([node.nullrev]) | |
1286 | return subset & names |
|
1281 | return subset & names | |
1287 |
|
1282 | |||
1288 | def node_(repo, subset, x): |
|
1283 | def node_(repo, subset, x): | |
1289 | """``id(string)`` |
|
1284 | """``id(string)`` | |
1290 | Revision non-ambiguously specified by the given hex string prefix. |
|
1285 | Revision non-ambiguously specified by the given hex string prefix. | |
1291 | """ |
|
1286 | """ | |
1292 | # i18n: "id" is a keyword |
|
1287 | # i18n: "id" is a keyword | |
1293 | l = getargs(x, 1, 1, _("id requires one argument")) |
|
1288 | l = getargs(x, 1, 1, _("id requires one argument")) | |
1294 | # i18n: "id" is a keyword |
|
1289 | # i18n: "id" is a keyword | |
1295 | n = getstring(l[0], _("id requires a string")) |
|
1290 | n = getstring(l[0], _("id requires a string")) | |
1296 | if len(n) == 40: |
|
1291 | if len(n) == 40: | |
1297 | try: |
|
1292 | try: | |
1298 | rn = repo.changelog.rev(node.bin(n)) |
|
1293 | rn = repo.changelog.rev(node.bin(n)) | |
1299 | except (LookupError, TypeError): |
|
1294 | except (LookupError, TypeError): | |
1300 | rn = None |
|
1295 | rn = None | |
1301 | else: |
|
1296 | else: | |
1302 | rn = None |
|
1297 | rn = None | |
1303 | pm = repo.changelog._partialmatch(n) |
|
1298 | pm = repo.changelog._partialmatch(n) | |
1304 | if pm is not None: |
|
1299 | if pm is not None: | |
1305 | rn = repo.changelog.rev(pm) |
|
1300 | rn = repo.changelog.rev(pm) | |
1306 |
|
1301 | |||
1307 | if rn is None: |
|
1302 | if rn is None: | |
1308 | return baseset() |
|
1303 | return baseset() | |
1309 | result = baseset([rn]) |
|
1304 | result = baseset([rn]) | |
1310 | return result & subset |
|
1305 | return result & subset | |
1311 |
|
1306 | |||
1312 | def obsolete(repo, subset, x): |
|
1307 | def obsolete(repo, subset, x): | |
1313 | """``obsolete()`` |
|
1308 | """``obsolete()`` | |
1314 | Mutable changeset with a newer version.""" |
|
1309 | Mutable changeset with a newer version.""" | |
1315 | # i18n: "obsolete" is a keyword |
|
1310 | # i18n: "obsolete" is a keyword | |
1316 | getargs(x, 0, 0, _("obsolete takes no arguments")) |
|
1311 | getargs(x, 0, 0, _("obsolete takes no arguments")) | |
1317 | obsoletes = obsmod.getrevs(repo, 'obsolete') |
|
1312 | obsoletes = obsmod.getrevs(repo, 'obsolete') | |
1318 | return subset & obsoletes |
|
1313 | return subset & obsoletes | |
1319 |
|
1314 | |||
1320 | def only(repo, subset, x): |
|
1315 | def only(repo, subset, x): | |
1321 | """``only(set, [set])`` |
|
1316 | """``only(set, [set])`` | |
1322 | Changesets that are ancestors of the first set that are not ancestors |
|
1317 | Changesets that are ancestors of the first set that are not ancestors | |
1323 | of any other head in the repo. If a second set is specified, the result |
|
1318 | of any other head in the repo. If a second set is specified, the result | |
1324 | is ancestors of the first set that are not ancestors of the second set |
|
1319 | is ancestors of the first set that are not ancestors of the second set | |
1325 | (i.e. ::<set1> - ::<set2>). |
|
1320 | (i.e. ::<set1> - ::<set2>). | |
1326 | """ |
|
1321 | """ | |
1327 | cl = repo.changelog |
|
1322 | cl = repo.changelog | |
1328 | # i18n: "only" is a keyword |
|
1323 | # i18n: "only" is a keyword | |
1329 | args = getargs(x, 1, 2, _('only takes one or two arguments')) |
|
1324 | args = getargs(x, 1, 2, _('only takes one or two arguments')) | |
1330 | include = getset(repo, fullreposet(repo), args[0]) |
|
1325 | include = getset(repo, fullreposet(repo), args[0]) | |
1331 | if len(args) == 1: |
|
1326 | if len(args) == 1: | |
1332 | if not include: |
|
1327 | if not include: | |
1333 | return baseset() |
|
1328 | return baseset() | |
1334 |
|
1329 | |||
1335 | descendants = set(_revdescendants(repo, include, False)) |
|
1330 | descendants = set(_revdescendants(repo, include, False)) | |
1336 | exclude = [rev for rev in cl.headrevs() |
|
1331 | exclude = [rev for rev in cl.headrevs() | |
1337 | if not rev in descendants and not rev in include] |
|
1332 | if not rev in descendants and not rev in include] | |
1338 | else: |
|
1333 | else: | |
1339 | exclude = getset(repo, fullreposet(repo), args[1]) |
|
1334 | exclude = getset(repo, fullreposet(repo), args[1]) | |
1340 |
|
1335 | |||
1341 | results = set(cl.findmissingrevs(common=exclude, heads=include)) |
|
1336 | results = set(cl.findmissingrevs(common=exclude, heads=include)) | |
1342 | return subset & results |
|
1337 | return subset & results | |
1343 |
|
1338 | |||
1344 | def origin(repo, subset, x): |
|
1339 | def origin(repo, subset, x): | |
1345 | """``origin([set])`` |
|
1340 | """``origin([set])`` | |
1346 | Changesets that were specified as a source for the grafts, transplants or |
|
1341 | Changesets that were specified as a source for the grafts, transplants or | |
1347 | rebases that created the given revisions. Omitting the optional set is the |
|
1342 | rebases that created the given revisions. Omitting the optional set is the | |
1348 | same as passing all(). If a changeset created by these operations is itself |
|
1343 | same as passing all(). If a changeset created by these operations is itself | |
1349 | specified as a source for one of these operations, only the source changeset |
|
1344 | specified as a source for one of these operations, only the source changeset | |
1350 | for the first operation is selected. |
|
1345 | for the first operation is selected. | |
1351 | """ |
|
1346 | """ | |
1352 | if x is not None: |
|
1347 | if x is not None: | |
1353 | dests = getset(repo, fullreposet(repo), x) |
|
1348 | dests = getset(repo, fullreposet(repo), x) | |
1354 | else: |
|
1349 | else: | |
1355 | dests = fullreposet(repo) |
|
1350 | dests = fullreposet(repo) | |
1356 |
|
1351 | |||
1357 | def _firstsrc(rev): |
|
1352 | def _firstsrc(rev): | |
1358 | src = _getrevsource(repo, rev) |
|
1353 | src = _getrevsource(repo, rev) | |
1359 | if src is None: |
|
1354 | if src is None: | |
1360 | return None |
|
1355 | return None | |
1361 |
|
1356 | |||
1362 | while True: |
|
1357 | while True: | |
1363 | prev = _getrevsource(repo, src) |
|
1358 | prev = _getrevsource(repo, src) | |
1364 |
|
1359 | |||
1365 | if prev is None: |
|
1360 | if prev is None: | |
1366 | return src |
|
1361 | return src | |
1367 | src = prev |
|
1362 | src = prev | |
1368 |
|
1363 | |||
1369 | o = set([_firstsrc(r) for r in dests]) |
|
1364 | o = set([_firstsrc(r) for r in dests]) | |
1370 | o -= set([None]) |
|
1365 | o -= set([None]) | |
1371 | return subset & o |
|
1366 | return subset & o | |
1372 |
|
1367 | |||
1373 | def outgoing(repo, subset, x): |
|
1368 | def outgoing(repo, subset, x): | |
1374 | """``outgoing([path])`` |
|
1369 | """``outgoing([path])`` | |
1375 | Changesets not found in the specified destination repository, or the |
|
1370 | Changesets not found in the specified destination repository, or the | |
1376 | default push location. |
|
1371 | default push location. | |
1377 | """ |
|
1372 | """ | |
1378 | # Avoid cycles. |
|
1373 | # Avoid cycles. | |
1379 | import discovery |
|
1374 | import discovery | |
1380 | import hg |
|
1375 | import hg | |
1381 | # i18n: "outgoing" is a keyword |
|
1376 | # i18n: "outgoing" is a keyword | |
1382 | l = getargs(x, 0, 1, _("outgoing takes one or no arguments")) |
|
1377 | l = getargs(x, 0, 1, _("outgoing takes one or no arguments")) | |
1383 | # i18n: "outgoing" is a keyword |
|
1378 | # i18n: "outgoing" is a keyword | |
1384 | dest = l and getstring(l[0], _("outgoing requires a repository path")) or '' |
|
1379 | dest = l and getstring(l[0], _("outgoing requires a repository path")) or '' | |
1385 | dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') |
|
1380 | dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') | |
1386 | dest, branches = hg.parseurl(dest) |
|
1381 | dest, branches = hg.parseurl(dest) | |
1387 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) |
|
1382 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) | |
1388 | if revs: |
|
1383 | if revs: | |
1389 | revs = [repo.lookup(rev) for rev in revs] |
|
1384 | revs = [repo.lookup(rev) for rev in revs] | |
1390 | other = hg.peer(repo, {}, dest) |
|
1385 | other = hg.peer(repo, {}, dest) | |
1391 | repo.ui.pushbuffer() |
|
1386 | repo.ui.pushbuffer() | |
1392 | outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) |
|
1387 | outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) | |
1393 | repo.ui.popbuffer() |
|
1388 | repo.ui.popbuffer() | |
1394 | cl = repo.changelog |
|
1389 | cl = repo.changelog | |
1395 | o = set([cl.rev(r) for r in outgoing.missing]) |
|
1390 | o = set([cl.rev(r) for r in outgoing.missing]) | |
1396 | return subset & o |
|
1391 | return subset & o | |
1397 |
|
1392 | |||
1398 | def p1(repo, subset, x): |
|
1393 | def p1(repo, subset, x): | |
1399 | """``p1([set])`` |
|
1394 | """``p1([set])`` | |
1400 | First parent of changesets in set, or the working directory. |
|
1395 | First parent of changesets in set, or the working directory. | |
1401 | """ |
|
1396 | """ | |
1402 | if x is None: |
|
1397 | if x is None: | |
1403 | p = repo[x].p1().rev() |
|
1398 | p = repo[x].p1().rev() | |
1404 | if p >= 0: |
|
1399 | if p >= 0: | |
1405 | return subset & baseset([p]) |
|
1400 | return subset & baseset([p]) | |
1406 | return baseset() |
|
1401 | return baseset() | |
1407 |
|
1402 | |||
1408 | ps = set() |
|
1403 | ps = set() | |
1409 | cl = repo.changelog |
|
1404 | cl = repo.changelog | |
1410 | for r in getset(repo, fullreposet(repo), x): |
|
1405 | for r in getset(repo, fullreposet(repo), x): | |
1411 | ps.add(cl.parentrevs(r)[0]) |
|
1406 | ps.add(cl.parentrevs(r)[0]) | |
1412 | ps -= set([node.nullrev]) |
|
1407 | ps -= set([node.nullrev]) | |
1413 | return subset & ps |
|
1408 | return subset & ps | |
1414 |
|
1409 | |||
1415 | def p2(repo, subset, x): |
|
1410 | def p2(repo, subset, x): | |
1416 | """``p2([set])`` |
|
1411 | """``p2([set])`` | |
1417 | Second parent of changesets in set, or the working directory. |
|
1412 | Second parent of changesets in set, or the working directory. | |
1418 | """ |
|
1413 | """ | |
1419 | if x is None: |
|
1414 | if x is None: | |
1420 | ps = repo[x].parents() |
|
1415 | ps = repo[x].parents() | |
1421 | try: |
|
1416 | try: | |
1422 | p = ps[1].rev() |
|
1417 | p = ps[1].rev() | |
1423 | if p >= 0: |
|
1418 | if p >= 0: | |
1424 | return subset & baseset([p]) |
|
1419 | return subset & baseset([p]) | |
1425 | return baseset() |
|
1420 | return baseset() | |
1426 | except IndexError: |
|
1421 | except IndexError: | |
1427 | return baseset() |
|
1422 | return baseset() | |
1428 |
|
1423 | |||
1429 | ps = set() |
|
1424 | ps = set() | |
1430 | cl = repo.changelog |
|
1425 | cl = repo.changelog | |
1431 | for r in getset(repo, fullreposet(repo), x): |
|
1426 | for r in getset(repo, fullreposet(repo), x): | |
1432 | ps.add(cl.parentrevs(r)[1]) |
|
1427 | ps.add(cl.parentrevs(r)[1]) | |
1433 | ps -= set([node.nullrev]) |
|
1428 | ps -= set([node.nullrev]) | |
1434 | return subset & ps |
|
1429 | return subset & ps | |
1435 |
|
1430 | |||
1436 | def parents(repo, subset, x): |
|
1431 | def parents(repo, subset, x): | |
1437 | """``parents([set])`` |
|
1432 | """``parents([set])`` | |
1438 | The set of all parents for all changesets in set, or the working directory. |
|
1433 | The set of all parents for all changesets in set, or the working directory. | |
1439 | """ |
|
1434 | """ | |
1440 | if x is None: |
|
1435 | if x is None: | |
1441 | ps = set(p.rev() for p in repo[x].parents()) |
|
1436 | ps = set(p.rev() for p in repo[x].parents()) | |
1442 | else: |
|
1437 | else: | |
1443 | ps = set() |
|
1438 | ps = set() | |
1444 | cl = repo.changelog |
|
1439 | cl = repo.changelog | |
1445 | for r in getset(repo, fullreposet(repo), x): |
|
1440 | for r in getset(repo, fullreposet(repo), x): | |
1446 | ps.update(cl.parentrevs(r)) |
|
1441 | ps.update(cl.parentrevs(r)) | |
1447 | ps -= set([node.nullrev]) |
|
1442 | ps -= set([node.nullrev]) | |
1448 | return subset & ps |
|
1443 | return subset & ps | |
1449 |
|
1444 | |||
1450 | def parentspec(repo, subset, x, n): |
|
1445 | def parentspec(repo, subset, x, n): | |
1451 | """``set^0`` |
|
1446 | """``set^0`` | |
1452 | The set. |
|
1447 | The set. | |
1453 | ``set^1`` (or ``set^``), ``set^2`` |
|
1448 | ``set^1`` (or ``set^``), ``set^2`` | |
1454 | First or second parent, respectively, of all changesets in set. |
|
1449 | First or second parent, respectively, of all changesets in set. | |
1455 | """ |
|
1450 | """ | |
1456 | try: |
|
1451 | try: | |
1457 | n = int(n[1]) |
|
1452 | n = int(n[1]) | |
1458 | if n not in (0, 1, 2): |
|
1453 | if n not in (0, 1, 2): | |
1459 | raise ValueError |
|
1454 | raise ValueError | |
1460 | except (TypeError, ValueError): |
|
1455 | except (TypeError, ValueError): | |
1461 | raise error.ParseError(_("^ expects a number 0, 1, or 2")) |
|
1456 | raise error.ParseError(_("^ expects a number 0, 1, or 2")) | |
1462 | ps = set() |
|
1457 | ps = set() | |
1463 | cl = repo.changelog |
|
1458 | cl = repo.changelog | |
1464 | for r in getset(repo, fullreposet(repo), x): |
|
1459 | for r in getset(repo, fullreposet(repo), x): | |
1465 | if n == 0: |
|
1460 | if n == 0: | |
1466 | ps.add(r) |
|
1461 | ps.add(r) | |
1467 | elif n == 1: |
|
1462 | elif n == 1: | |
1468 | ps.add(cl.parentrevs(r)[0]) |
|
1463 | ps.add(cl.parentrevs(r)[0]) | |
1469 | elif n == 2: |
|
1464 | elif n == 2: | |
1470 | parents = cl.parentrevs(r) |
|
1465 | parents = cl.parentrevs(r) | |
1471 | if len(parents) > 1: |
|
1466 | if len(parents) > 1: | |
1472 | ps.add(parents[1]) |
|
1467 | ps.add(parents[1]) | |
1473 | return subset & ps |
|
1468 | return subset & ps | |
1474 |
|
1469 | |||
1475 | def present(repo, subset, x): |
|
1470 | def present(repo, subset, x): | |
1476 | """``present(set)`` |
|
1471 | """``present(set)`` | |
1477 | An empty set, if any revision in set isn't found; otherwise, |
|
1472 | An empty set, if any revision in set isn't found; otherwise, | |
1478 | all revisions in set. |
|
1473 | all revisions in set. | |
1479 |
|
1474 | |||
1480 | If any of specified revisions is not present in the local repository, |
|
1475 | If any of specified revisions is not present in the local repository, | |
1481 | the query is normally aborted. But this predicate allows the query |
|
1476 | the query is normally aborted. But this predicate allows the query | |
1482 | to continue even in such cases. |
|
1477 | to continue even in such cases. | |
1483 | """ |
|
1478 | """ | |
1484 | try: |
|
1479 | try: | |
1485 | return getset(repo, subset, x) |
|
1480 | return getset(repo, subset, x) | |
1486 | except error.RepoLookupError: |
|
1481 | except error.RepoLookupError: | |
1487 | return baseset() |
|
1482 | return baseset() | |
1488 |
|
1483 | |||
1489 | def public(repo, subset, x): |
|
1484 | def public(repo, subset, x): | |
1490 | """``public()`` |
|
1485 | """``public()`` | |
1491 | Changeset in public phase.""" |
|
1486 | Changeset in public phase.""" | |
1492 | # i18n: "public" is a keyword |
|
1487 | # i18n: "public" is a keyword | |
1493 | getargs(x, 0, 0, _("public takes no arguments")) |
|
1488 | getargs(x, 0, 0, _("public takes no arguments")) | |
1494 | phase = repo._phasecache.phase |
|
1489 | phase = repo._phasecache.phase | |
1495 | target = phases.public |
|
1490 | target = phases.public | |
1496 | condition = lambda r: phase(repo, r) == target |
|
1491 | condition = lambda r: phase(repo, r) == target | |
1497 | return subset.filter(condition, cache=False) |
|
1492 | return subset.filter(condition, cache=False) | |
1498 |
|
1493 | |||
1499 | def remote(repo, subset, x): |
|
1494 | def remote(repo, subset, x): | |
1500 | """``remote([id [,path]])`` |
|
1495 | """``remote([id [,path]])`` | |
1501 | Local revision that corresponds to the given identifier in a |
|
1496 | Local revision that corresponds to the given identifier in a | |
1502 | remote repository, if present. Here, the '.' identifier is a |
|
1497 | remote repository, if present. Here, the '.' identifier is a | |
1503 | synonym for the current local branch. |
|
1498 | synonym for the current local branch. | |
1504 | """ |
|
1499 | """ | |
1505 |
|
1500 | |||
1506 | import hg # avoid start-up nasties |
|
1501 | import hg # avoid start-up nasties | |
1507 | # i18n: "remote" is a keyword |
|
1502 | # i18n: "remote" is a keyword | |
1508 | l = getargs(x, 0, 2, _("remote takes one, two or no arguments")) |
|
1503 | l = getargs(x, 0, 2, _("remote takes one, two or no arguments")) | |
1509 |
|
1504 | |||
1510 | q = '.' |
|
1505 | q = '.' | |
1511 | if len(l) > 0: |
|
1506 | if len(l) > 0: | |
1512 | # i18n: "remote" is a keyword |
|
1507 | # i18n: "remote" is a keyword | |
1513 | q = getstring(l[0], _("remote requires a string id")) |
|
1508 | q = getstring(l[0], _("remote requires a string id")) | |
1514 | if q == '.': |
|
1509 | if q == '.': | |
1515 | q = repo['.'].branch() |
|
1510 | q = repo['.'].branch() | |
1516 |
|
1511 | |||
1517 | dest = '' |
|
1512 | dest = '' | |
1518 | if len(l) > 1: |
|
1513 | if len(l) > 1: | |
1519 | # i18n: "remote" is a keyword |
|
1514 | # i18n: "remote" is a keyword | |
1520 | dest = getstring(l[1], _("remote requires a repository path")) |
|
1515 | dest = getstring(l[1], _("remote requires a repository path")) | |
1521 | dest = repo.ui.expandpath(dest or 'default') |
|
1516 | dest = repo.ui.expandpath(dest or 'default') | |
1522 | dest, branches = hg.parseurl(dest) |
|
1517 | dest, branches = hg.parseurl(dest) | |
1523 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) |
|
1518 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) | |
1524 | if revs: |
|
1519 | if revs: | |
1525 | revs = [repo.lookup(rev) for rev in revs] |
|
1520 | revs = [repo.lookup(rev) for rev in revs] | |
1526 | other = hg.peer(repo, {}, dest) |
|
1521 | other = hg.peer(repo, {}, dest) | |
1527 | n = other.lookup(q) |
|
1522 | n = other.lookup(q) | |
1528 | if n in repo: |
|
1523 | if n in repo: | |
1529 | r = repo[n].rev() |
|
1524 | r = repo[n].rev() | |
1530 | if r in subset: |
|
1525 | if r in subset: | |
1531 | return baseset([r]) |
|
1526 | return baseset([r]) | |
1532 | return baseset() |
|
1527 | return baseset() | |
1533 |
|
1528 | |||
1534 | def removes(repo, subset, x): |
|
1529 | def removes(repo, subset, x): | |
1535 | """``removes(pattern)`` |
|
1530 | """``removes(pattern)`` | |
1536 | Changesets which remove files matching pattern. |
|
1531 | Changesets which remove files matching pattern. | |
1537 |
|
1532 | |||
1538 | The pattern without explicit kind like ``glob:`` is expected to be |
|
1533 | The pattern without explicit kind like ``glob:`` is expected to be | |
1539 | relative to the current directory and match against a file or a |
|
1534 | relative to the current directory and match against a file or a | |
1540 | directory. |
|
1535 | directory. | |
1541 | """ |
|
1536 | """ | |
1542 | # i18n: "removes" is a keyword |
|
1537 | # i18n: "removes" is a keyword | |
1543 | pat = getstring(x, _("removes requires a pattern")) |
|
1538 | pat = getstring(x, _("removes requires a pattern")) | |
1544 | return checkstatus(repo, subset, pat, 2) |
|
1539 | return checkstatus(repo, subset, pat, 2) | |
1545 |
|
1540 | |||
1546 | def rev(repo, subset, x): |
|
1541 | def rev(repo, subset, x): | |
1547 | """``rev(number)`` |
|
1542 | """``rev(number)`` | |
1548 | Revision with the given numeric identifier. |
|
1543 | Revision with the given numeric identifier. | |
1549 | """ |
|
1544 | """ | |
1550 | # i18n: "rev" is a keyword |
|
1545 | # i18n: "rev" is a keyword | |
1551 | l = getargs(x, 1, 1, _("rev requires one argument")) |
|
1546 | l = getargs(x, 1, 1, _("rev requires one argument")) | |
1552 | try: |
|
1547 | try: | |
1553 | # i18n: "rev" is a keyword |
|
1548 | # i18n: "rev" is a keyword | |
1554 | l = int(getstring(l[0], _("rev requires a number"))) |
|
1549 | l = int(getstring(l[0], _("rev requires a number"))) | |
1555 | except (TypeError, ValueError): |
|
1550 | except (TypeError, ValueError): | |
1556 | # i18n: "rev" is a keyword |
|
1551 | # i18n: "rev" is a keyword | |
1557 | raise error.ParseError(_("rev expects a number")) |
|
1552 | raise error.ParseError(_("rev expects a number")) | |
1558 | if l not in repo.changelog and l != node.nullrev: |
|
1553 | if l not in repo.changelog and l != node.nullrev: | |
1559 | return baseset() |
|
1554 | return baseset() | |
1560 | return subset & baseset([l]) |
|
1555 | return subset & baseset([l]) | |
1561 |
|
1556 | |||
1562 | def matching(repo, subset, x): |
|
1557 | def matching(repo, subset, x): | |
1563 | """``matching(revision [, field])`` |
|
1558 | """``matching(revision [, field])`` | |
1564 | Changesets in which a given set of fields match the set of fields in the |
|
1559 | Changesets in which a given set of fields match the set of fields in the | |
1565 | selected revision or set. |
|
1560 | selected revision or set. | |
1566 |
|
1561 | |||
1567 | To match more than one field pass the list of fields to match separated |
|
1562 | To match more than one field pass the list of fields to match separated | |
1568 | by spaces (e.g. ``author description``). |
|
1563 | by spaces (e.g. ``author description``). | |
1569 |
|
1564 | |||
1570 | Valid fields are most regular revision fields and some special fields. |
|
1565 | Valid fields are most regular revision fields and some special fields. | |
1571 |
|
1566 | |||
1572 | Regular revision fields are ``description``, ``author``, ``branch``, |
|
1567 | Regular revision fields are ``description``, ``author``, ``branch``, | |
1573 | ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` |
|
1568 | ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` | |
1574 | and ``diff``. |
|
1569 | and ``diff``. | |
1575 | Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the |
|
1570 | Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the | |
1576 | contents of the revision. Two revisions matching their ``diff`` will |
|
1571 | contents of the revision. Two revisions matching their ``diff`` will | |
1577 | also match their ``files``. |
|
1572 | also match their ``files``. | |
1578 |
|
1573 | |||
1579 | Special fields are ``summary`` and ``metadata``: |
|
1574 | Special fields are ``summary`` and ``metadata``: | |
1580 | ``summary`` matches the first line of the description. |
|
1575 | ``summary`` matches the first line of the description. | |
1581 | ``metadata`` is equivalent to matching ``description user date`` |
|
1576 | ``metadata`` is equivalent to matching ``description user date`` | |
1582 | (i.e. it matches the main metadata fields). |
|
1577 | (i.e. it matches the main metadata fields). | |
1583 |
|
1578 | |||
1584 | ``metadata`` is the default field which is used when no fields are |
|
1579 | ``metadata`` is the default field which is used when no fields are | |
1585 | specified. You can match more than one field at a time. |
|
1580 | specified. You can match more than one field at a time. | |
1586 | """ |
|
1581 | """ | |
1587 | # i18n: "matching" is a keyword |
|
1582 | # i18n: "matching" is a keyword | |
1588 | l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments")) |
|
1583 | l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments")) | |
1589 |
|
1584 | |||
1590 | revs = getset(repo, fullreposet(repo), l[0]) |
|
1585 | revs = getset(repo, fullreposet(repo), l[0]) | |
1591 |
|
1586 | |||
1592 | fieldlist = ['metadata'] |
|
1587 | fieldlist = ['metadata'] | |
1593 | if len(l) > 1: |
|
1588 | if len(l) > 1: | |
1594 | fieldlist = getstring(l[1], |
|
1589 | fieldlist = getstring(l[1], | |
1595 | # i18n: "matching" is a keyword |
|
1590 | # i18n: "matching" is a keyword | |
1596 | _("matching requires a string " |
|
1591 | _("matching requires a string " | |
1597 | "as its second argument")).split() |
|
1592 | "as its second argument")).split() | |
1598 |
|
1593 | |||
1599 | # Make sure that there are no repeated fields, |
|
1594 | # Make sure that there are no repeated fields, | |
1600 | # expand the 'special' 'metadata' field type |
|
1595 | # expand the 'special' 'metadata' field type | |
1601 | # and check the 'files' whenever we check the 'diff' |
|
1596 | # and check the 'files' whenever we check the 'diff' | |
1602 | fields = [] |
|
1597 | fields = [] | |
1603 | for field in fieldlist: |
|
1598 | for field in fieldlist: | |
1604 | if field == 'metadata': |
|
1599 | if field == 'metadata': | |
1605 | fields += ['user', 'description', 'date'] |
|
1600 | fields += ['user', 'description', 'date'] | |
1606 | elif field == 'diff': |
|
1601 | elif field == 'diff': | |
1607 | # a revision matching the diff must also match the files |
|
1602 | # a revision matching the diff must also match the files | |
1608 | # since matching the diff is very costly, make sure to |
|
1603 | # since matching the diff is very costly, make sure to | |
1609 | # also match the files first |
|
1604 | # also match the files first | |
1610 | fields += ['files', 'diff'] |
|
1605 | fields += ['files', 'diff'] | |
1611 | else: |
|
1606 | else: | |
1612 | if field == 'author': |
|
1607 | if field == 'author': | |
1613 | field = 'user' |
|
1608 | field = 'user' | |
1614 | fields.append(field) |
|
1609 | fields.append(field) | |
1615 | fields = set(fields) |
|
1610 | fields = set(fields) | |
1616 | if 'summary' in fields and 'description' in fields: |
|
1611 | if 'summary' in fields and 'description' in fields: | |
1617 | # If a revision matches its description it also matches its summary |
|
1612 | # If a revision matches its description it also matches its summary | |
1618 | fields.discard('summary') |
|
1613 | fields.discard('summary') | |
1619 |
|
1614 | |||
1620 | # We may want to match more than one field |
|
1615 | # We may want to match more than one field | |
1621 | # Not all fields take the same amount of time to be matched |
|
1616 | # Not all fields take the same amount of time to be matched | |
1622 | # Sort the selected fields in order of increasing matching cost |
|
1617 | # Sort the selected fields in order of increasing matching cost | |
1623 | fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary', |
|
1618 | fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary', | |
1624 | 'files', 'description', 'substate', 'diff'] |
|
1619 | 'files', 'description', 'substate', 'diff'] | |
1625 | def fieldkeyfunc(f): |
|
1620 | def fieldkeyfunc(f): | |
1626 | try: |
|
1621 | try: | |
1627 | return fieldorder.index(f) |
|
1622 | return fieldorder.index(f) | |
1628 | except ValueError: |
|
1623 | except ValueError: | |
1629 | # assume an unknown field is very costly |
|
1624 | # assume an unknown field is very costly | |
1630 | return len(fieldorder) |
|
1625 | return len(fieldorder) | |
1631 | fields = list(fields) |
|
1626 | fields = list(fields) | |
1632 | fields.sort(key=fieldkeyfunc) |
|
1627 | fields.sort(key=fieldkeyfunc) | |
1633 |
|
1628 | |||
1634 | # Each field will be matched with its own "getfield" function |
|
1629 | # Each field will be matched with its own "getfield" function | |
1635 | # which will be added to the getfieldfuncs array of functions |
|
1630 | # which will be added to the getfieldfuncs array of functions | |
1636 | getfieldfuncs = [] |
|
1631 | getfieldfuncs = [] | |
1637 | _funcs = { |
|
1632 | _funcs = { | |
1638 | 'user': lambda r: repo[r].user(), |
|
1633 | 'user': lambda r: repo[r].user(), | |
1639 | 'branch': lambda r: repo[r].branch(), |
|
1634 | 'branch': lambda r: repo[r].branch(), | |
1640 | 'date': lambda r: repo[r].date(), |
|
1635 | 'date': lambda r: repo[r].date(), | |
1641 | 'description': lambda r: repo[r].description(), |
|
1636 | 'description': lambda r: repo[r].description(), | |
1642 | 'files': lambda r: repo[r].files(), |
|
1637 | 'files': lambda r: repo[r].files(), | |
1643 | 'parents': lambda r: repo[r].parents(), |
|
1638 | 'parents': lambda r: repo[r].parents(), | |
1644 | 'phase': lambda r: repo[r].phase(), |
|
1639 | 'phase': lambda r: repo[r].phase(), | |
1645 | 'substate': lambda r: repo[r].substate, |
|
1640 | 'substate': lambda r: repo[r].substate, | |
1646 | 'summary': lambda r: repo[r].description().splitlines()[0], |
|
1641 | 'summary': lambda r: repo[r].description().splitlines()[0], | |
1647 | 'diff': lambda r: list(repo[r].diff(git=True),) |
|
1642 | 'diff': lambda r: list(repo[r].diff(git=True),) | |
1648 | } |
|
1643 | } | |
1649 | for info in fields: |
|
1644 | for info in fields: | |
1650 | getfield = _funcs.get(info, None) |
|
1645 | getfield = _funcs.get(info, None) | |
1651 | if getfield is None: |
|
1646 | if getfield is None: | |
1652 | raise error.ParseError( |
|
1647 | raise error.ParseError( | |
1653 | # i18n: "matching" is a keyword |
|
1648 | # i18n: "matching" is a keyword | |
1654 | _("unexpected field name passed to matching: %s") % info) |
|
1649 | _("unexpected field name passed to matching: %s") % info) | |
1655 | getfieldfuncs.append(getfield) |
|
1650 | getfieldfuncs.append(getfield) | |
1656 | # convert the getfield array of functions into a "getinfo" function |
|
1651 | # convert the getfield array of functions into a "getinfo" function | |
1657 | # which returns an array of field values (or a single value if there |
|
1652 | # which returns an array of field values (or a single value if there | |
1658 | # is only one field to match) |
|
1653 | # is only one field to match) | |
1659 | getinfo = lambda r: [f(r) for f in getfieldfuncs] |
|
1654 | getinfo = lambda r: [f(r) for f in getfieldfuncs] | |
1660 |
|
1655 | |||
1661 | def matches(x): |
|
1656 | def matches(x): | |
1662 | for rev in revs: |
|
1657 | for rev in revs: | |
1663 | target = getinfo(rev) |
|
1658 | target = getinfo(rev) | |
1664 | match = True |
|
1659 | match = True | |
1665 | for n, f in enumerate(getfieldfuncs): |
|
1660 | for n, f in enumerate(getfieldfuncs): | |
1666 | if target[n] != f(x): |
|
1661 | if target[n] != f(x): | |
1667 | match = False |
|
1662 | match = False | |
1668 | if match: |
|
1663 | if match: | |
1669 | return True |
|
1664 | return True | |
1670 | return False |
|
1665 | return False | |
1671 |
|
1666 | |||
1672 | return subset.filter(matches) |
|
1667 | return subset.filter(matches) | |
1673 |
|
1668 | |||
1674 | def reverse(repo, subset, x): |
|
1669 | def reverse(repo, subset, x): | |
1675 | """``reverse(set)`` |
|
1670 | """``reverse(set)`` | |
1676 | Reverse order of set. |
|
1671 | Reverse order of set. | |
1677 | """ |
|
1672 | """ | |
1678 | l = getset(repo, subset, x) |
|
1673 | l = getset(repo, subset, x) | |
1679 | l.reverse() |
|
1674 | l.reverse() | |
1680 | return l |
|
1675 | return l | |
1681 |
|
1676 | |||
1682 | def roots(repo, subset, x): |
|
1677 | def roots(repo, subset, x): | |
1683 | """``roots(set)`` |
|
1678 | """``roots(set)`` | |
1684 | Changesets in set with no parent changeset in set. |
|
1679 | Changesets in set with no parent changeset in set. | |
1685 | """ |
|
1680 | """ | |
1686 | s = getset(repo, fullreposet(repo), x) |
|
1681 | s = getset(repo, fullreposet(repo), x) | |
1687 | subset = subset & s# baseset([r for r in s if r in subset]) |
|
1682 | subset = subset & s# baseset([r for r in s if r in subset]) | |
1688 | cs = _children(repo, subset, s) |
|
1683 | cs = _children(repo, subset, s) | |
1689 | return subset - cs |
|
1684 | return subset - cs | |
1690 |
|
1685 | |||
1691 | def secret(repo, subset, x): |
|
1686 | def secret(repo, subset, x): | |
1692 | """``secret()`` |
|
1687 | """``secret()`` | |
1693 | Changeset in secret phase.""" |
|
1688 | Changeset in secret phase.""" | |
1694 | # i18n: "secret" is a keyword |
|
1689 | # i18n: "secret" is a keyword | |
1695 | getargs(x, 0, 0, _("secret takes no arguments")) |
|
1690 | getargs(x, 0, 0, _("secret takes no arguments")) | |
1696 | phase = repo._phasecache.phase |
|
1691 | phase = repo._phasecache.phase | |
1697 | target = phases.secret |
|
1692 | target = phases.secret | |
1698 | condition = lambda r: phase(repo, r) == target |
|
1693 | condition = lambda r: phase(repo, r) == target | |
1699 | return subset.filter(condition, cache=False) |
|
1694 | return subset.filter(condition, cache=False) | |
1700 |
|
1695 | |||
1701 | def sort(repo, subset, x): |
|
1696 | def sort(repo, subset, x): | |
1702 | """``sort(set[, [-]key...])`` |
|
1697 | """``sort(set[, [-]key...])`` | |
1703 | Sort set by keys. The default sort order is ascending, specify a key |
|
1698 | Sort set by keys. The default sort order is ascending, specify a key | |
1704 | as ``-key`` to sort in descending order. |
|
1699 | as ``-key`` to sort in descending order. | |
1705 |
|
1700 | |||
1706 | The keys can be: |
|
1701 | The keys can be: | |
1707 |
|
1702 | |||
1708 | - ``rev`` for the revision number, |
|
1703 | - ``rev`` for the revision number, | |
1709 | - ``branch`` for the branch name, |
|
1704 | - ``branch`` for the branch name, | |
1710 | - ``desc`` for the commit message (description), |
|
1705 | - ``desc`` for the commit message (description), | |
1711 | - ``user`` for user name (``author`` can be used as an alias), |
|
1706 | - ``user`` for user name (``author`` can be used as an alias), | |
1712 | - ``date`` for the commit date |
|
1707 | - ``date`` for the commit date | |
1713 | """ |
|
1708 | """ | |
1714 | # i18n: "sort" is a keyword |
|
1709 | # i18n: "sort" is a keyword | |
1715 | l = getargs(x, 1, 2, _("sort requires one or two arguments")) |
|
1710 | l = getargs(x, 1, 2, _("sort requires one or two arguments")) | |
1716 | keys = "rev" |
|
1711 | keys = "rev" | |
1717 | if len(l) == 2: |
|
1712 | if len(l) == 2: | |
1718 | # i18n: "sort" is a keyword |
|
1713 | # i18n: "sort" is a keyword | |
1719 | keys = getstring(l[1], _("sort spec must be a string")) |
|
1714 | keys = getstring(l[1], _("sort spec must be a string")) | |
1720 |
|
1715 | |||
1721 | s = l[0] |
|
1716 | s = l[0] | |
1722 | keys = keys.split() |
|
1717 | keys = keys.split() | |
1723 | l = [] |
|
1718 | l = [] | |
1724 | def invert(s): |
|
1719 | def invert(s): | |
1725 | return "".join(chr(255 - ord(c)) for c in s) |
|
1720 | return "".join(chr(255 - ord(c)) for c in s) | |
1726 | revs = getset(repo, subset, s) |
|
1721 | revs = getset(repo, subset, s) | |
1727 | if keys == ["rev"]: |
|
1722 | if keys == ["rev"]: | |
1728 | revs.sort() |
|
1723 | revs.sort() | |
1729 | return revs |
|
1724 | return revs | |
1730 | elif keys == ["-rev"]: |
|
1725 | elif keys == ["-rev"]: | |
1731 | revs.sort(reverse=True) |
|
1726 | revs.sort(reverse=True) | |
1732 | return revs |
|
1727 | return revs | |
1733 | for r in revs: |
|
1728 | for r in revs: | |
1734 | c = repo[r] |
|
1729 | c = repo[r] | |
1735 | e = [] |
|
1730 | e = [] | |
1736 | for k in keys: |
|
1731 | for k in keys: | |
1737 | if k == 'rev': |
|
1732 | if k == 'rev': | |
1738 | e.append(r) |
|
1733 | e.append(r) | |
1739 | elif k == '-rev': |
|
1734 | elif k == '-rev': | |
1740 | e.append(-r) |
|
1735 | e.append(-r) | |
1741 | elif k == 'branch': |
|
1736 | elif k == 'branch': | |
1742 | e.append(c.branch()) |
|
1737 | e.append(c.branch()) | |
1743 | elif k == '-branch': |
|
1738 | elif k == '-branch': | |
1744 | e.append(invert(c.branch())) |
|
1739 | e.append(invert(c.branch())) | |
1745 | elif k == 'desc': |
|
1740 | elif k == 'desc': | |
1746 | e.append(c.description()) |
|
1741 | e.append(c.description()) | |
1747 | elif k == '-desc': |
|
1742 | elif k == '-desc': | |
1748 | e.append(invert(c.description())) |
|
1743 | e.append(invert(c.description())) | |
1749 | elif k in 'user author': |
|
1744 | elif k in 'user author': | |
1750 | e.append(c.user()) |
|
1745 | e.append(c.user()) | |
1751 | elif k in '-user -author': |
|
1746 | elif k in '-user -author': | |
1752 | e.append(invert(c.user())) |
|
1747 | e.append(invert(c.user())) | |
1753 | elif k == 'date': |
|
1748 | elif k == 'date': | |
1754 | e.append(c.date()[0]) |
|
1749 | e.append(c.date()[0]) | |
1755 | elif k == '-date': |
|
1750 | elif k == '-date': | |
1756 | e.append(-c.date()[0]) |
|
1751 | e.append(-c.date()[0]) | |
1757 | else: |
|
1752 | else: | |
1758 | raise error.ParseError(_("unknown sort key %r") % k) |
|
1753 | raise error.ParseError(_("unknown sort key %r") % k) | |
1759 | e.append(r) |
|
1754 | e.append(r) | |
1760 | l.append(e) |
|
1755 | l.append(e) | |
1761 | l.sort() |
|
1756 | l.sort() | |
1762 | return baseset([e[-1] for e in l]) |
|
1757 | return baseset([e[-1] for e in l]) | |
1763 |
|
1758 | |||
1764 | def subrepo(repo, subset, x): |
|
1759 | def subrepo(repo, subset, x): | |
1765 | """``subrepo([pattern])`` |
|
1760 | """``subrepo([pattern])`` | |
1766 | Changesets that add, modify or remove the given subrepo. If no subrepo |
|
1761 | Changesets that add, modify or remove the given subrepo. If no subrepo | |
1767 | pattern is named, any subrepo changes are returned. |
|
1762 | pattern is named, any subrepo changes are returned. | |
1768 | """ |
|
1763 | """ | |
1769 | # i18n: "subrepo" is a keyword |
|
1764 | # i18n: "subrepo" is a keyword | |
1770 | args = getargs(x, 0, 1, _('subrepo takes at most one argument')) |
|
1765 | args = getargs(x, 0, 1, _('subrepo takes at most one argument')) | |
1771 | if len(args) != 0: |
|
1766 | if len(args) != 0: | |
1772 | pat = getstring(args[0], _("subrepo requires a pattern")) |
|
1767 | pat = getstring(args[0], _("subrepo requires a pattern")) | |
1773 |
|
1768 | |||
1774 | m = matchmod.exact(repo.root, repo.root, ['.hgsubstate']) |
|
1769 | m = matchmod.exact(repo.root, repo.root, ['.hgsubstate']) | |
1775 |
|
1770 | |||
1776 | def submatches(names): |
|
1771 | def submatches(names): | |
1777 | k, p, m = _stringmatcher(pat) |
|
1772 | k, p, m = _stringmatcher(pat) | |
1778 | for name in names: |
|
1773 | for name in names: | |
1779 | if m(name): |
|
1774 | if m(name): | |
1780 | yield name |
|
1775 | yield name | |
1781 |
|
1776 | |||
1782 | def matches(x): |
|
1777 | def matches(x): | |
1783 | c = repo[x] |
|
1778 | c = repo[x] | |
1784 | s = repo.status(c.p1().node(), c.node(), match=m) |
|
1779 | s = repo.status(c.p1().node(), c.node(), match=m) | |
1785 |
|
1780 | |||
1786 | if len(args) == 0: |
|
1781 | if len(args) == 0: | |
1787 | return s.added or s.modified or s.removed |
|
1782 | return s.added or s.modified or s.removed | |
1788 |
|
1783 | |||
1789 | if s.added: |
|
1784 | if s.added: | |
1790 | return util.any(submatches(c.substate.keys())) |
|
1785 | return util.any(submatches(c.substate.keys())) | |
1791 |
|
1786 | |||
1792 | if s.modified: |
|
1787 | if s.modified: | |
1793 | subs = set(c.p1().substate.keys()) |
|
1788 | subs = set(c.p1().substate.keys()) | |
1794 | subs.update(c.substate.keys()) |
|
1789 | subs.update(c.substate.keys()) | |
1795 |
|
1790 | |||
1796 | for path in submatches(subs): |
|
1791 | for path in submatches(subs): | |
1797 | if c.p1().substate.get(path) != c.substate.get(path): |
|
1792 | if c.p1().substate.get(path) != c.substate.get(path): | |
1798 | return True |
|
1793 | return True | |
1799 |
|
1794 | |||
1800 | if s.removed: |
|
1795 | if s.removed: | |
1801 | return util.any(submatches(c.p1().substate.keys())) |
|
1796 | return util.any(submatches(c.p1().substate.keys())) | |
1802 |
|
1797 | |||
1803 | return False |
|
1798 | return False | |
1804 |
|
1799 | |||
1805 | return subset.filter(matches) |
|
1800 | return subset.filter(matches) | |
1806 |
|
1801 | |||
1807 | def _stringmatcher(pattern): |
|
1802 | def _stringmatcher(pattern): | |
1808 | """ |
|
1803 | """ | |
1809 | accepts a string, possibly starting with 're:' or 'literal:' prefix. |
|
1804 | accepts a string, possibly starting with 're:' or 'literal:' prefix. | |
1810 | returns the matcher name, pattern, and matcher function. |
|
1805 | returns the matcher name, pattern, and matcher function. | |
1811 | missing or unknown prefixes are treated as literal matches. |
|
1806 | missing or unknown prefixes are treated as literal matches. | |
1812 |
|
1807 | |||
1813 | helper for tests: |
|
1808 | helper for tests: | |
1814 | >>> def test(pattern, *tests): |
|
1809 | >>> def test(pattern, *tests): | |
1815 | ... kind, pattern, matcher = _stringmatcher(pattern) |
|
1810 | ... kind, pattern, matcher = _stringmatcher(pattern) | |
1816 | ... return (kind, pattern, [bool(matcher(t)) for t in tests]) |
|
1811 | ... return (kind, pattern, [bool(matcher(t)) for t in tests]) | |
1817 |
|
1812 | |||
1818 | exact matching (no prefix): |
|
1813 | exact matching (no prefix): | |
1819 | >>> test('abcdefg', 'abc', 'def', 'abcdefg') |
|
1814 | >>> test('abcdefg', 'abc', 'def', 'abcdefg') | |
1820 | ('literal', 'abcdefg', [False, False, True]) |
|
1815 | ('literal', 'abcdefg', [False, False, True]) | |
1821 |
|
1816 | |||
1822 | regex matching ('re:' prefix) |
|
1817 | regex matching ('re:' prefix) | |
1823 | >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar') |
|
1818 | >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar') | |
1824 | ('re', 'a.+b', [False, False, True]) |
|
1819 | ('re', 'a.+b', [False, False, True]) | |
1825 |
|
1820 | |||
1826 | force exact matches ('literal:' prefix) |
|
1821 | force exact matches ('literal:' prefix) | |
1827 | >>> test('literal:re:foobar', 'foobar', 're:foobar') |
|
1822 | >>> test('literal:re:foobar', 'foobar', 're:foobar') | |
1828 | ('literal', 're:foobar', [False, True]) |
|
1823 | ('literal', 're:foobar', [False, True]) | |
1829 |
|
1824 | |||
1830 | unknown prefixes are ignored and treated as literals |
|
1825 | unknown prefixes are ignored and treated as literals | |
1831 | >>> test('foo:bar', 'foo', 'bar', 'foo:bar') |
|
1826 | >>> test('foo:bar', 'foo', 'bar', 'foo:bar') | |
1832 | ('literal', 'foo:bar', [False, False, True]) |
|
1827 | ('literal', 'foo:bar', [False, False, True]) | |
1833 | """ |
|
1828 | """ | |
1834 | if pattern.startswith('re:'): |
|
1829 | if pattern.startswith('re:'): | |
1835 | pattern = pattern[3:] |
|
1830 | pattern = pattern[3:] | |
1836 | try: |
|
1831 | try: | |
1837 | regex = re.compile(pattern) |
|
1832 | regex = re.compile(pattern) | |
1838 | except re.error, e: |
|
1833 | except re.error, e: | |
1839 | raise error.ParseError(_('invalid regular expression: %s') |
|
1834 | raise error.ParseError(_('invalid regular expression: %s') | |
1840 | % e) |
|
1835 | % e) | |
1841 | return 're', pattern, regex.search |
|
1836 | return 're', pattern, regex.search | |
1842 | elif pattern.startswith('literal:'): |
|
1837 | elif pattern.startswith('literal:'): | |
1843 | pattern = pattern[8:] |
|
1838 | pattern = pattern[8:] | |
1844 | return 'literal', pattern, pattern.__eq__ |
|
1839 | return 'literal', pattern, pattern.__eq__ | |
1845 |
|
1840 | |||
1846 | def _substringmatcher(pattern): |
|
1841 | def _substringmatcher(pattern): | |
1847 | kind, pattern, matcher = _stringmatcher(pattern) |
|
1842 | kind, pattern, matcher = _stringmatcher(pattern) | |
1848 | if kind == 'literal': |
|
1843 | if kind == 'literal': | |
1849 | matcher = lambda s: pattern in s |
|
1844 | matcher = lambda s: pattern in s | |
1850 | return kind, pattern, matcher |
|
1845 | return kind, pattern, matcher | |
1851 |
|
1846 | |||
1852 | def tag(repo, subset, x): |
|
1847 | def tag(repo, subset, x): | |
1853 | """``tag([name])`` |
|
1848 | """``tag([name])`` | |
1854 | The specified tag by name, or all tagged revisions if no name is given. |
|
1849 | The specified tag by name, or all tagged revisions if no name is given. | |
1855 |
|
1850 | |||
1856 | If `name` starts with `re:`, the remainder of the name is treated as |
|
1851 | If `name` starts with `re:`, the remainder of the name is treated as | |
1857 | a regular expression. To match a tag that actually starts with `re:`, |
|
1852 | a regular expression. To match a tag that actually starts with `re:`, | |
1858 | use the prefix `literal:`. |
|
1853 | use the prefix `literal:`. | |
1859 | """ |
|
1854 | """ | |
1860 | # i18n: "tag" is a keyword |
|
1855 | # i18n: "tag" is a keyword | |
1861 | args = getargs(x, 0, 1, _("tag takes one or no arguments")) |
|
1856 | args = getargs(x, 0, 1, _("tag takes one or no arguments")) | |
1862 | cl = repo.changelog |
|
1857 | cl = repo.changelog | |
1863 | if args: |
|
1858 | if args: | |
1864 | pattern = getstring(args[0], |
|
1859 | pattern = getstring(args[0], | |
1865 | # i18n: "tag" is a keyword |
|
1860 | # i18n: "tag" is a keyword | |
1866 | _('the argument to tag must be a string')) |
|
1861 | _('the argument to tag must be a string')) | |
1867 | kind, pattern, matcher = _stringmatcher(pattern) |
|
1862 | kind, pattern, matcher = _stringmatcher(pattern) | |
1868 | if kind == 'literal': |
|
1863 | if kind == 'literal': | |
1869 | # avoid resolving all tags |
|
1864 | # avoid resolving all tags | |
1870 | tn = repo._tagscache.tags.get(pattern, None) |
|
1865 | tn = repo._tagscache.tags.get(pattern, None) | |
1871 | if tn is None: |
|
1866 | if tn is None: | |
1872 | raise error.RepoLookupError(_("tag '%s' does not exist") |
|
1867 | raise error.RepoLookupError(_("tag '%s' does not exist") | |
1873 | % pattern) |
|
1868 | % pattern) | |
1874 | s = set([repo[tn].rev()]) |
|
1869 | s = set([repo[tn].rev()]) | |
1875 | else: |
|
1870 | else: | |
1876 | s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)]) |
|
1871 | s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)]) | |
1877 | else: |
|
1872 | else: | |
1878 | s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) |
|
1873 | s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) | |
1879 | return subset & s |
|
1874 | return subset & s | |
1880 |
|
1875 | |||
1881 | def tagged(repo, subset, x): |
|
1876 | def tagged(repo, subset, x): | |
1882 | return tag(repo, subset, x) |
|
1877 | return tag(repo, subset, x) | |
1883 |
|
1878 | |||
1884 | def unstable(repo, subset, x): |
|
1879 | def unstable(repo, subset, x): | |
1885 | """``unstable()`` |
|
1880 | """``unstable()`` | |
1886 | Non-obsolete changesets with obsolete ancestors. |
|
1881 | Non-obsolete changesets with obsolete ancestors. | |
1887 | """ |
|
1882 | """ | |
1888 | # i18n: "unstable" is a keyword |
|
1883 | # i18n: "unstable" is a keyword | |
1889 | getargs(x, 0, 0, _("unstable takes no arguments")) |
|
1884 | getargs(x, 0, 0, _("unstable takes no arguments")) | |
1890 | unstables = obsmod.getrevs(repo, 'unstable') |
|
1885 | unstables = obsmod.getrevs(repo, 'unstable') | |
1891 | return subset & unstables |
|
1886 | return subset & unstables | |
1892 |
|
1887 | |||
1893 |
|
1888 | |||
1894 | def user(repo, subset, x): |
|
1889 | def user(repo, subset, x): | |
1895 | """``user(string)`` |
|
1890 | """``user(string)`` | |
1896 | User name contains string. The match is case-insensitive. |
|
1891 | User name contains string. The match is case-insensitive. | |
1897 |
|
1892 | |||
1898 | If `string` starts with `re:`, the remainder of the string is treated as |
|
1893 | If `string` starts with `re:`, the remainder of the string is treated as | |
1899 | a regular expression. To match a user that actually contains `re:`, use |
|
1894 | a regular expression. To match a user that actually contains `re:`, use | |
1900 | the prefix `literal:`. |
|
1895 | the prefix `literal:`. | |
1901 | """ |
|
1896 | """ | |
1902 | return author(repo, subset, x) |
|
1897 | return author(repo, subset, x) | |
1903 |
|
1898 | |||
1904 | # experimental |
|
1899 | # experimental | |
1905 | def wdir(repo, subset, x): |
|
1900 | def wdir(repo, subset, x): | |
1906 | # i18n: "wdir" is a keyword |
|
1901 | # i18n: "wdir" is a keyword | |
1907 | getargs(x, 0, 0, _("wdir takes no arguments")) |
|
1902 | getargs(x, 0, 0, _("wdir takes no arguments")) | |
1908 | if None in subset: |
|
1903 | if None in subset: | |
1909 | return baseset([None]) |
|
1904 | return baseset([None]) | |
1910 | return baseset() |
|
1905 | return baseset() | |
1911 |
|
1906 | |||
1912 | # for internal use |
|
1907 | # for internal use | |
1913 | def _list(repo, subset, x): |
|
1908 | def _list(repo, subset, x): | |
1914 | s = getstring(x, "internal error") |
|
1909 | s = getstring(x, "internal error") | |
1915 | if not s: |
|
1910 | if not s: | |
1916 | return baseset() |
|
1911 | return baseset() | |
1917 | ls = [repo[r].rev() for r in s.split('\0')] |
|
1912 | ls = [repo[r].rev() for r in s.split('\0')] | |
1918 | s = subset |
|
1913 | s = subset | |
1919 | return baseset([r for r in ls if r in s]) |
|
1914 | return baseset([r for r in ls if r in s]) | |
1920 |
|
1915 | |||
1921 | # for internal use |
|
1916 | # for internal use | |
1922 | def _intlist(repo, subset, x): |
|
1917 | def _intlist(repo, subset, x): | |
1923 | s = getstring(x, "internal error") |
|
1918 | s = getstring(x, "internal error") | |
1924 | if not s: |
|
1919 | if not s: | |
1925 | return baseset() |
|
1920 | return baseset() | |
1926 | ls = [int(r) for r in s.split('\0')] |
|
1921 | ls = [int(r) for r in s.split('\0')] | |
1927 | s = subset |
|
1922 | s = subset | |
1928 | return baseset([r for r in ls if r in s]) |
|
1923 | return baseset([r for r in ls if r in s]) | |
1929 |
|
1924 | |||
1930 | # for internal use |
|
1925 | # for internal use | |
1931 | def _hexlist(repo, subset, x): |
|
1926 | def _hexlist(repo, subset, x): | |
1932 | s = getstring(x, "internal error") |
|
1927 | s = getstring(x, "internal error") | |
1933 | if not s: |
|
1928 | if not s: | |
1934 | return baseset() |
|
1929 | return baseset() | |
1935 | cl = repo.changelog |
|
1930 | cl = repo.changelog | |
1936 | ls = [cl.rev(node.bin(r)) for r in s.split('\0')] |
|
1931 | ls = [cl.rev(node.bin(r)) for r in s.split('\0')] | |
1937 | s = subset |
|
1932 | s = subset | |
1938 | return baseset([r for r in ls if r in s]) |
|
1933 | return baseset([r for r in ls if r in s]) | |
1939 |
|
1934 | |||
1940 | symbols = { |
|
1935 | symbols = { | |
1941 | "adds": adds, |
|
1936 | "adds": adds, | |
1942 | "all": getall, |
|
1937 | "all": getall, | |
1943 | "ancestor": ancestor, |
|
1938 | "ancestor": ancestor, | |
1944 | "ancestors": ancestors, |
|
1939 | "ancestors": ancestors, | |
1945 | "_firstancestors": _firstancestors, |
|
1940 | "_firstancestors": _firstancestors, | |
1946 | "author": author, |
|
1941 | "author": author, | |
1947 | "bisect": bisect, |
|
1942 | "bisect": bisect, | |
1948 | "bisected": bisected, |
|
1943 | "bisected": bisected, | |
1949 | "bookmark": bookmark, |
|
1944 | "bookmark": bookmark, | |
1950 | "branch": branch, |
|
1945 | "branch": branch, | |
1951 | "branchpoint": branchpoint, |
|
1946 | "branchpoint": branchpoint, | |
1952 | "bumped": bumped, |
|
1947 | "bumped": bumped, | |
1953 | "bundle": bundle, |
|
1948 | "bundle": bundle, | |
1954 | "children": children, |
|
1949 | "children": children, | |
1955 | "closed": closed, |
|
1950 | "closed": closed, | |
1956 | "contains": contains, |
|
1951 | "contains": contains, | |
1957 | "converted": converted, |
|
1952 | "converted": converted, | |
1958 | "date": date, |
|
1953 | "date": date, | |
1959 | "desc": desc, |
|
1954 | "desc": desc, | |
1960 | "descendants": descendants, |
|
1955 | "descendants": descendants, | |
1961 | "_firstdescendants": _firstdescendants, |
|
1956 | "_firstdescendants": _firstdescendants, | |
1962 | "destination": destination, |
|
1957 | "destination": destination, | |
1963 | "divergent": divergent, |
|
1958 | "divergent": divergent, | |
1964 | "draft": draft, |
|
1959 | "draft": draft, | |
1965 | "extinct": extinct, |
|
1960 | "extinct": extinct, | |
1966 | "extra": extra, |
|
1961 | "extra": extra, | |
1967 | "file": hasfile, |
|
1962 | "file": hasfile, | |
1968 | "filelog": filelog, |
|
1963 | "filelog": filelog, | |
1969 | "first": first, |
|
1964 | "first": first, | |
1970 | "follow": follow, |
|
1965 | "follow": follow, | |
1971 | "_followfirst": _followfirst, |
|
1966 | "_followfirst": _followfirst, | |
1972 | "grep": grep, |
|
1967 | "grep": grep, | |
1973 | "head": head, |
|
1968 | "head": head, | |
1974 | "heads": heads, |
|
1969 | "heads": heads, | |
1975 | "hidden": hidden, |
|
1970 | "hidden": hidden, | |
1976 | "id": node_, |
|
1971 | "id": node_, | |
1977 | "keyword": keyword, |
|
1972 | "keyword": keyword, | |
1978 | "last": last, |
|
1973 | "last": last, | |
1979 | "limit": limit, |
|
1974 | "limit": limit, | |
1980 | "_matchfiles": _matchfiles, |
|
1975 | "_matchfiles": _matchfiles, | |
1981 | "max": maxrev, |
|
1976 | "max": maxrev, | |
1982 | "merge": merge, |
|
1977 | "merge": merge, | |
1983 | "min": minrev, |
|
1978 | "min": minrev, | |
1984 | "modifies": modifies, |
|
1979 | "modifies": modifies, | |
1985 | "named": named, |
|
1980 | "named": named, | |
1986 | "obsolete": obsolete, |
|
1981 | "obsolete": obsolete, | |
1987 | "only": only, |
|
1982 | "only": only, | |
1988 | "origin": origin, |
|
1983 | "origin": origin, | |
1989 | "outgoing": outgoing, |
|
1984 | "outgoing": outgoing, | |
1990 | "p1": p1, |
|
1985 | "p1": p1, | |
1991 | "p2": p2, |
|
1986 | "p2": p2, | |
1992 | "parents": parents, |
|
1987 | "parents": parents, | |
1993 | "present": present, |
|
1988 | "present": present, | |
1994 | "public": public, |
|
1989 | "public": public, | |
1995 | "remote": remote, |
|
1990 | "remote": remote, | |
1996 | "removes": removes, |
|
1991 | "removes": removes, | |
1997 | "rev": rev, |
|
1992 | "rev": rev, | |
1998 | "reverse": reverse, |
|
1993 | "reverse": reverse, | |
1999 | "roots": roots, |
|
1994 | "roots": roots, | |
2000 | "sort": sort, |
|
1995 | "sort": sort, | |
2001 | "secret": secret, |
|
1996 | "secret": secret, | |
2002 | "subrepo": subrepo, |
|
1997 | "subrepo": subrepo, | |
2003 | "matching": matching, |
|
1998 | "matching": matching, | |
2004 | "tag": tag, |
|
1999 | "tag": tag, | |
2005 | "tagged": tagged, |
|
2000 | "tagged": tagged, | |
2006 | "user": user, |
|
2001 | "user": user, | |
2007 | "unstable": unstable, |
|
2002 | "unstable": unstable, | |
2008 | "wdir": wdir, |
|
2003 | "wdir": wdir, | |
2009 | "_list": _list, |
|
2004 | "_list": _list, | |
2010 | "_intlist": _intlist, |
|
2005 | "_intlist": _intlist, | |
2011 | "_hexlist": _hexlist, |
|
2006 | "_hexlist": _hexlist, | |
2012 | } |
|
2007 | } | |
2013 |
|
2008 | |||
2014 | # symbols which can't be used for a DoS attack for any given input |
|
2009 | # symbols which can't be used for a DoS attack for any given input | |
2015 | # (e.g. those which accept regexes as plain strings shouldn't be included) |
|
2010 | # (e.g. those which accept regexes as plain strings shouldn't be included) | |
2016 | # functions that just return a lot of changesets (like all) don't count here |
|
2011 | # functions that just return a lot of changesets (like all) don't count here | |
2017 | safesymbols = set([ |
|
2012 | safesymbols = set([ | |
2018 | "adds", |
|
2013 | "adds", | |
2019 | "all", |
|
2014 | "all", | |
2020 | "ancestor", |
|
2015 | "ancestor", | |
2021 | "ancestors", |
|
2016 | "ancestors", | |
2022 | "_firstancestors", |
|
2017 | "_firstancestors", | |
2023 | "author", |
|
2018 | "author", | |
2024 | "bisect", |
|
2019 | "bisect", | |
2025 | "bisected", |
|
2020 | "bisected", | |
2026 | "bookmark", |
|
2021 | "bookmark", | |
2027 | "branch", |
|
2022 | "branch", | |
2028 | "branchpoint", |
|
2023 | "branchpoint", | |
2029 | "bumped", |
|
2024 | "bumped", | |
2030 | "bundle", |
|
2025 | "bundle", | |
2031 | "children", |
|
2026 | "children", | |
2032 | "closed", |
|
2027 | "closed", | |
2033 | "converted", |
|
2028 | "converted", | |
2034 | "date", |
|
2029 | "date", | |
2035 | "desc", |
|
2030 | "desc", | |
2036 | "descendants", |
|
2031 | "descendants", | |
2037 | "_firstdescendants", |
|
2032 | "_firstdescendants", | |
2038 | "destination", |
|
2033 | "destination", | |
2039 | "divergent", |
|
2034 | "divergent", | |
2040 | "draft", |
|
2035 | "draft", | |
2041 | "extinct", |
|
2036 | "extinct", | |
2042 | "extra", |
|
2037 | "extra", | |
2043 | "file", |
|
2038 | "file", | |
2044 | "filelog", |
|
2039 | "filelog", | |
2045 | "first", |
|
2040 | "first", | |
2046 | "follow", |
|
2041 | "follow", | |
2047 | "_followfirst", |
|
2042 | "_followfirst", | |
2048 | "head", |
|
2043 | "head", | |
2049 | "heads", |
|
2044 | "heads", | |
2050 | "hidden", |
|
2045 | "hidden", | |
2051 | "id", |
|
2046 | "id", | |
2052 | "keyword", |
|
2047 | "keyword", | |
2053 | "last", |
|
2048 | "last", | |
2054 | "limit", |
|
2049 | "limit", | |
2055 | "_matchfiles", |
|
2050 | "_matchfiles", | |
2056 | "max", |
|
2051 | "max", | |
2057 | "merge", |
|
2052 | "merge", | |
2058 | "min", |
|
2053 | "min", | |
2059 | "modifies", |
|
2054 | "modifies", | |
2060 | "obsolete", |
|
2055 | "obsolete", | |
2061 | "only", |
|
2056 | "only", | |
2062 | "origin", |
|
2057 | "origin", | |
2063 | "outgoing", |
|
2058 | "outgoing", | |
2064 | "p1", |
|
2059 | "p1", | |
2065 | "p2", |
|
2060 | "p2", | |
2066 | "parents", |
|
2061 | "parents", | |
2067 | "present", |
|
2062 | "present", | |
2068 | "public", |
|
2063 | "public", | |
2069 | "remote", |
|
2064 | "remote", | |
2070 | "removes", |
|
2065 | "removes", | |
2071 | "rev", |
|
2066 | "rev", | |
2072 | "reverse", |
|
2067 | "reverse", | |
2073 | "roots", |
|
2068 | "roots", | |
2074 | "sort", |
|
2069 | "sort", | |
2075 | "secret", |
|
2070 | "secret", | |
2076 | "matching", |
|
2071 | "matching", | |
2077 | "tag", |
|
2072 | "tag", | |
2078 | "tagged", |
|
2073 | "tagged", | |
2079 | "user", |
|
2074 | "user", | |
2080 | "unstable", |
|
2075 | "unstable", | |
2081 | "wdir", |
|
2076 | "wdir", | |
2082 | "_list", |
|
2077 | "_list", | |
2083 | "_intlist", |
|
2078 | "_intlist", | |
2084 | "_hexlist", |
|
2079 | "_hexlist", | |
2085 | ]) |
|
2080 | ]) | |
2086 |
|
2081 | |||
2087 | methods = { |
|
2082 | methods = { | |
2088 | "range": rangeset, |
|
2083 | "range": rangeset, | |
2089 | "dagrange": dagrange, |
|
2084 | "dagrange": dagrange, | |
2090 | "string": stringset, |
|
2085 | "string": stringset, | |
2091 |
"symbol": s |
|
2086 | "symbol": stringset, | |
2092 | "and": andset, |
|
2087 | "and": andset, | |
2093 | "or": orset, |
|
2088 | "or": orset, | |
2094 | "not": notset, |
|
2089 | "not": notset, | |
2095 | "list": listset, |
|
2090 | "list": listset, | |
2096 | "func": func, |
|
2091 | "func": func, | |
2097 | "ancestor": ancestorspec, |
|
2092 | "ancestor": ancestorspec, | |
2098 | "parent": parentspec, |
|
2093 | "parent": parentspec, | |
2099 | "parentpost": p1, |
|
2094 | "parentpost": p1, | |
2100 | "only": only, |
|
2095 | "only": only, | |
2101 | "onlypost": only, |
|
2096 | "onlypost": only, | |
2102 | } |
|
2097 | } | |
2103 |
|
2098 | |||
2104 | def optimize(x, small): |
|
2099 | def optimize(x, small): | |
2105 | if x is None: |
|
2100 | if x is None: | |
2106 | return 0, x |
|
2101 | return 0, x | |
2107 |
|
2102 | |||
2108 | smallbonus = 1 |
|
2103 | smallbonus = 1 | |
2109 | if small: |
|
2104 | if small: | |
2110 | smallbonus = .5 |
|
2105 | smallbonus = .5 | |
2111 |
|
2106 | |||
2112 | op = x[0] |
|
2107 | op = x[0] | |
2113 | if op == 'minus': |
|
2108 | if op == 'minus': | |
2114 | return optimize(('and', x[1], ('not', x[2])), small) |
|
2109 | return optimize(('and', x[1], ('not', x[2])), small) | |
2115 | elif op == 'only': |
|
2110 | elif op == 'only': | |
2116 | return optimize(('func', ('symbol', 'only'), |
|
2111 | return optimize(('func', ('symbol', 'only'), | |
2117 | ('list', x[1], x[2])), small) |
|
2112 | ('list', x[1], x[2])), small) | |
2118 | elif op == 'dagrangepre': |
|
2113 | elif op == 'dagrangepre': | |
2119 | return optimize(('func', ('symbol', 'ancestors'), x[1]), small) |
|
2114 | return optimize(('func', ('symbol', 'ancestors'), x[1]), small) | |
2120 | elif op == 'dagrangepost': |
|
2115 | elif op == 'dagrangepost': | |
2121 | return optimize(('func', ('symbol', 'descendants'), x[1]), small) |
|
2116 | return optimize(('func', ('symbol', 'descendants'), x[1]), small) | |
2122 | elif op == 'rangepre': |
|
2117 | elif op == 'rangepre': | |
2123 | return optimize(('range', ('string', '0'), x[1]), small) |
|
2118 | return optimize(('range', ('string', '0'), x[1]), small) | |
2124 | elif op == 'rangepost': |
|
2119 | elif op == 'rangepost': | |
2125 | return optimize(('range', x[1], ('string', 'tip')), small) |
|
2120 | return optimize(('range', x[1], ('string', 'tip')), small) | |
2126 | elif op == 'negate': |
|
2121 | elif op == 'negate': | |
2127 | return optimize(('string', |
|
2122 | return optimize(('string', | |
2128 | '-' + getstring(x[1], _("can't negate that"))), small) |
|
2123 | '-' + getstring(x[1], _("can't negate that"))), small) | |
2129 | elif op in 'string symbol negate': |
|
2124 | elif op in 'string symbol negate': | |
2130 | return smallbonus, x # single revisions are small |
|
2125 | return smallbonus, x # single revisions are small | |
2131 | elif op == 'and': |
|
2126 | elif op == 'and': | |
2132 | wa, ta = optimize(x[1], True) |
|
2127 | wa, ta = optimize(x[1], True) | |
2133 | wb, tb = optimize(x[2], True) |
|
2128 | wb, tb = optimize(x[2], True) | |
2134 |
|
2129 | |||
2135 | # (::x and not ::y)/(not ::y and ::x) have a fast path |
|
2130 | # (::x and not ::y)/(not ::y and ::x) have a fast path | |
2136 | def isonly(revs, bases): |
|
2131 | def isonly(revs, bases): | |
2137 | return ( |
|
2132 | return ( | |
2138 | revs[0] == 'func' |
|
2133 | revs[0] == 'func' | |
2139 | and getstring(revs[1], _('not a symbol')) == 'ancestors' |
|
2134 | and getstring(revs[1], _('not a symbol')) == 'ancestors' | |
2140 | and bases[0] == 'not' |
|
2135 | and bases[0] == 'not' | |
2141 | and bases[1][0] == 'func' |
|
2136 | and bases[1][0] == 'func' | |
2142 | and getstring(bases[1][1], _('not a symbol')) == 'ancestors') |
|
2137 | and getstring(bases[1][1], _('not a symbol')) == 'ancestors') | |
2143 |
|
2138 | |||
2144 | w = min(wa, wb) |
|
2139 | w = min(wa, wb) | |
2145 | if isonly(ta, tb): |
|
2140 | if isonly(ta, tb): | |
2146 | return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2])) |
|
2141 | return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2])) | |
2147 | if isonly(tb, ta): |
|
2142 | if isonly(tb, ta): | |
2148 | return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2])) |
|
2143 | return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2])) | |
2149 |
|
2144 | |||
2150 | if wa > wb: |
|
2145 | if wa > wb: | |
2151 | return w, (op, tb, ta) |
|
2146 | return w, (op, tb, ta) | |
2152 | return w, (op, ta, tb) |
|
2147 | return w, (op, ta, tb) | |
2153 | elif op == 'or': |
|
2148 | elif op == 'or': | |
2154 | wa, ta = optimize(x[1], False) |
|
2149 | wa, ta = optimize(x[1], False) | |
2155 | wb, tb = optimize(x[2], False) |
|
2150 | wb, tb = optimize(x[2], False) | |
2156 | if wb < wa: |
|
2151 | if wb < wa: | |
2157 | wb, wa = wa, wb |
|
2152 | wb, wa = wa, wb | |
2158 | return max(wa, wb), (op, ta, tb) |
|
2153 | return max(wa, wb), (op, ta, tb) | |
2159 | elif op == 'not': |
|
2154 | elif op == 'not': | |
2160 | o = optimize(x[1], not small) |
|
2155 | o = optimize(x[1], not small) | |
2161 | return o[0], (op, o[1]) |
|
2156 | return o[0], (op, o[1]) | |
2162 | elif op == 'parentpost': |
|
2157 | elif op == 'parentpost': | |
2163 | o = optimize(x[1], small) |
|
2158 | o = optimize(x[1], small) | |
2164 | return o[0], (op, o[1]) |
|
2159 | return o[0], (op, o[1]) | |
2165 | elif op == 'group': |
|
2160 | elif op == 'group': | |
2166 | return optimize(x[1], small) |
|
2161 | return optimize(x[1], small) | |
2167 | elif op in 'dagrange range list parent ancestorspec': |
|
2162 | elif op in 'dagrange range list parent ancestorspec': | |
2168 | if op == 'parent': |
|
2163 | if op == 'parent': | |
2169 | # x^:y means (x^) : y, not x ^ (:y) |
|
2164 | # x^:y means (x^) : y, not x ^ (:y) | |
2170 | post = ('parentpost', x[1]) |
|
2165 | post = ('parentpost', x[1]) | |
2171 | if x[2][0] == 'dagrangepre': |
|
2166 | if x[2][0] == 'dagrangepre': | |
2172 | return optimize(('dagrange', post, x[2][1]), small) |
|
2167 | return optimize(('dagrange', post, x[2][1]), small) | |
2173 | elif x[2][0] == 'rangepre': |
|
2168 | elif x[2][0] == 'rangepre': | |
2174 | return optimize(('range', post, x[2][1]), small) |
|
2169 | return optimize(('range', post, x[2][1]), small) | |
2175 |
|
2170 | |||
2176 | wa, ta = optimize(x[1], small) |
|
2171 | wa, ta = optimize(x[1], small) | |
2177 | wb, tb = optimize(x[2], small) |
|
2172 | wb, tb = optimize(x[2], small) | |
2178 | return wa + wb, (op, ta, tb) |
|
2173 | return wa + wb, (op, ta, tb) | |
2179 | elif op == 'func': |
|
2174 | elif op == 'func': | |
2180 | f = getstring(x[1], _("not a symbol")) |
|
2175 | f = getstring(x[1], _("not a symbol")) | |
2181 | wa, ta = optimize(x[2], small) |
|
2176 | wa, ta = optimize(x[2], small) | |
2182 | if f in ("author branch closed date desc file grep keyword " |
|
2177 | if f in ("author branch closed date desc file grep keyword " | |
2183 | "outgoing user"): |
|
2178 | "outgoing user"): | |
2184 | w = 10 # slow |
|
2179 | w = 10 # slow | |
2185 | elif f in "modifies adds removes": |
|
2180 | elif f in "modifies adds removes": | |
2186 | w = 30 # slower |
|
2181 | w = 30 # slower | |
2187 | elif f == "contains": |
|
2182 | elif f == "contains": | |
2188 | w = 100 # very slow |
|
2183 | w = 100 # very slow | |
2189 | elif f == "ancestor": |
|
2184 | elif f == "ancestor": | |
2190 | w = 1 * smallbonus |
|
2185 | w = 1 * smallbonus | |
2191 | elif f in "reverse limit first _intlist": |
|
2186 | elif f in "reverse limit first _intlist": | |
2192 | w = 0 |
|
2187 | w = 0 | |
2193 | elif f in "sort": |
|
2188 | elif f in "sort": | |
2194 | w = 10 # assume most sorts look at changelog |
|
2189 | w = 10 # assume most sorts look at changelog | |
2195 | else: |
|
2190 | else: | |
2196 | w = 1 |
|
2191 | w = 1 | |
2197 | return w + wa, (op, x[1], ta) |
|
2192 | return w + wa, (op, x[1], ta) | |
2198 | return 1, x |
|
2193 | return 1, x | |
2199 |
|
2194 | |||
2200 | _aliasarg = ('func', ('symbol', '_aliasarg')) |
|
2195 | _aliasarg = ('func', ('symbol', '_aliasarg')) | |
2201 | def _getaliasarg(tree): |
|
2196 | def _getaliasarg(tree): | |
2202 | """If tree matches ('func', ('symbol', '_aliasarg'), ('string', X)) |
|
2197 | """If tree matches ('func', ('symbol', '_aliasarg'), ('string', X)) | |
2203 | return X, None otherwise. |
|
2198 | return X, None otherwise. | |
2204 | """ |
|
2199 | """ | |
2205 | if (len(tree) == 3 and tree[:2] == _aliasarg |
|
2200 | if (len(tree) == 3 and tree[:2] == _aliasarg | |
2206 | and tree[2][0] == 'string'): |
|
2201 | and tree[2][0] == 'string'): | |
2207 | return tree[2][1] |
|
2202 | return tree[2][1] | |
2208 | return None |
|
2203 | return None | |
2209 |
|
2204 | |||
2210 | def _checkaliasarg(tree, known=None): |
|
2205 | def _checkaliasarg(tree, known=None): | |
2211 | """Check tree contains no _aliasarg construct or only ones which |
|
2206 | """Check tree contains no _aliasarg construct or only ones which | |
2212 | value is in known. Used to avoid alias placeholders injection. |
|
2207 | value is in known. Used to avoid alias placeholders injection. | |
2213 | """ |
|
2208 | """ | |
2214 | if isinstance(tree, tuple): |
|
2209 | if isinstance(tree, tuple): | |
2215 | arg = _getaliasarg(tree) |
|
2210 | arg = _getaliasarg(tree) | |
2216 | if arg is not None and (not known or arg not in known): |
|
2211 | if arg is not None and (not known or arg not in known): | |
2217 | raise error.UnknownIdentifier('_aliasarg', []) |
|
2212 | raise error.UnknownIdentifier('_aliasarg', []) | |
2218 | for t in tree: |
|
2213 | for t in tree: | |
2219 | _checkaliasarg(t, known) |
|
2214 | _checkaliasarg(t, known) | |
2220 |
|
2215 | |||
2221 | # the set of valid characters for the initial letter of symbols in |
|
2216 | # the set of valid characters for the initial letter of symbols in | |
2222 | # alias declarations and definitions |
|
2217 | # alias declarations and definitions | |
2223 | _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)] |
|
2218 | _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)] | |
2224 | if c.isalnum() or c in '._@$' or ord(c) > 127) |
|
2219 | if c.isalnum() or c in '._@$' or ord(c) > 127) | |
2225 |
|
2220 | |||
2226 | def _tokenizealias(program, lookup=None): |
|
2221 | def _tokenizealias(program, lookup=None): | |
2227 | """Parse alias declaration/definition into a stream of tokens |
|
2222 | """Parse alias declaration/definition into a stream of tokens | |
2228 |
|
2223 | |||
2229 | This allows symbol names to use also ``$`` as an initial letter |
|
2224 | This allows symbol names to use also ``$`` as an initial letter | |
2230 | (for backward compatibility), and callers of this function should |
|
2225 | (for backward compatibility), and callers of this function should | |
2231 | examine whether ``$`` is used also for unexpected symbols or not. |
|
2226 | examine whether ``$`` is used also for unexpected symbols or not. | |
2232 | """ |
|
2227 | """ | |
2233 | return tokenize(program, lookup=lookup, |
|
2228 | return tokenize(program, lookup=lookup, | |
2234 | syminitletters=_aliassyminitletters) |
|
2229 | syminitletters=_aliassyminitletters) | |
2235 |
|
2230 | |||
2236 | def _parsealiasdecl(decl): |
|
2231 | def _parsealiasdecl(decl): | |
2237 | """Parse alias declaration ``decl`` |
|
2232 | """Parse alias declaration ``decl`` | |
2238 |
|
2233 | |||
2239 | This returns ``(name, tree, args, errorstr)`` tuple: |
|
2234 | This returns ``(name, tree, args, errorstr)`` tuple: | |
2240 |
|
2235 | |||
2241 | - ``name``: of declared alias (may be ``decl`` itself at error) |
|
2236 | - ``name``: of declared alias (may be ``decl`` itself at error) | |
2242 | - ``tree``: parse result (or ``None`` at error) |
|
2237 | - ``tree``: parse result (or ``None`` at error) | |
2243 | - ``args``: list of alias argument names (or None for symbol declaration) |
|
2238 | - ``args``: list of alias argument names (or None for symbol declaration) | |
2244 | - ``errorstr``: detail about detected error (or None) |
|
2239 | - ``errorstr``: detail about detected error (or None) | |
2245 |
|
2240 | |||
2246 | >>> _parsealiasdecl('foo') |
|
2241 | >>> _parsealiasdecl('foo') | |
2247 | ('foo', ('symbol', 'foo'), None, None) |
|
2242 | ('foo', ('symbol', 'foo'), None, None) | |
2248 | >>> _parsealiasdecl('$foo') |
|
2243 | >>> _parsealiasdecl('$foo') | |
2249 | ('$foo', None, None, "'$' not for alias arguments") |
|
2244 | ('$foo', None, None, "'$' not for alias arguments") | |
2250 | >>> _parsealiasdecl('foo::bar') |
|
2245 | >>> _parsealiasdecl('foo::bar') | |
2251 | ('foo::bar', None, None, 'invalid format') |
|
2246 | ('foo::bar', None, None, 'invalid format') | |
2252 | >>> _parsealiasdecl('foo bar') |
|
2247 | >>> _parsealiasdecl('foo bar') | |
2253 | ('foo bar', None, None, 'at 4: invalid token') |
|
2248 | ('foo bar', None, None, 'at 4: invalid token') | |
2254 | >>> _parsealiasdecl('foo()') |
|
2249 | >>> _parsealiasdecl('foo()') | |
2255 | ('foo', ('func', ('symbol', 'foo')), [], None) |
|
2250 | ('foo', ('func', ('symbol', 'foo')), [], None) | |
2256 | >>> _parsealiasdecl('$foo()') |
|
2251 | >>> _parsealiasdecl('$foo()') | |
2257 | ('$foo()', None, None, "'$' not for alias arguments") |
|
2252 | ('$foo()', None, None, "'$' not for alias arguments") | |
2258 | >>> _parsealiasdecl('foo($1, $2)') |
|
2253 | >>> _parsealiasdecl('foo($1, $2)') | |
2259 | ('foo', ('func', ('symbol', 'foo')), ['$1', '$2'], None) |
|
2254 | ('foo', ('func', ('symbol', 'foo')), ['$1', '$2'], None) | |
2260 | >>> _parsealiasdecl('foo(bar_bar, baz.baz)') |
|
2255 | >>> _parsealiasdecl('foo(bar_bar, baz.baz)') | |
2261 | ('foo', ('func', ('symbol', 'foo')), ['bar_bar', 'baz.baz'], None) |
|
2256 | ('foo', ('func', ('symbol', 'foo')), ['bar_bar', 'baz.baz'], None) | |
2262 | >>> _parsealiasdecl('foo($1, $2, nested($1, $2))') |
|
2257 | >>> _parsealiasdecl('foo($1, $2, nested($1, $2))') | |
2263 | ('foo($1, $2, nested($1, $2))', None, None, 'invalid argument list') |
|
2258 | ('foo($1, $2, nested($1, $2))', None, None, 'invalid argument list') | |
2264 | >>> _parsealiasdecl('foo(bar($1, $2))') |
|
2259 | >>> _parsealiasdecl('foo(bar($1, $2))') | |
2265 | ('foo(bar($1, $2))', None, None, 'invalid argument list') |
|
2260 | ('foo(bar($1, $2))', None, None, 'invalid argument list') | |
2266 | >>> _parsealiasdecl('foo("string")') |
|
2261 | >>> _parsealiasdecl('foo("string")') | |
2267 | ('foo("string")', None, None, 'invalid argument list') |
|
2262 | ('foo("string")', None, None, 'invalid argument list') | |
2268 | >>> _parsealiasdecl('foo($1, $2') |
|
2263 | >>> _parsealiasdecl('foo($1, $2') | |
2269 | ('foo($1, $2', None, None, 'at 10: unexpected token: end') |
|
2264 | ('foo($1, $2', None, None, 'at 10: unexpected token: end') | |
2270 | >>> _parsealiasdecl('foo("string') |
|
2265 | >>> _parsealiasdecl('foo("string') | |
2271 | ('foo("string', None, None, 'at 5: unterminated string') |
|
2266 | ('foo("string', None, None, 'at 5: unterminated string') | |
2272 | >>> _parsealiasdecl('foo($1, $2, $1)') |
|
2267 | >>> _parsealiasdecl('foo($1, $2, $1)') | |
2273 | ('foo', None, None, 'argument names collide with each other') |
|
2268 | ('foo', None, None, 'argument names collide with each other') | |
2274 | """ |
|
2269 | """ | |
2275 | p = parser.parser(_tokenizealias, elements) |
|
2270 | p = parser.parser(_tokenizealias, elements) | |
2276 | try: |
|
2271 | try: | |
2277 | tree, pos = p.parse(decl) |
|
2272 | tree, pos = p.parse(decl) | |
2278 | if (pos != len(decl)): |
|
2273 | if (pos != len(decl)): | |
2279 | raise error.ParseError(_('invalid token'), pos) |
|
2274 | raise error.ParseError(_('invalid token'), pos) | |
2280 |
|
2275 | |||
2281 | if isvalidsymbol(tree): |
|
2276 | if isvalidsymbol(tree): | |
2282 | # "name = ...." style |
|
2277 | # "name = ...." style | |
2283 | name = getsymbol(tree) |
|
2278 | name = getsymbol(tree) | |
2284 | if name.startswith('$'): |
|
2279 | if name.startswith('$'): | |
2285 | return (decl, None, None, _("'$' not for alias arguments")) |
|
2280 | return (decl, None, None, _("'$' not for alias arguments")) | |
2286 | return (name, ('symbol', name), None, None) |
|
2281 | return (name, ('symbol', name), None, None) | |
2287 |
|
2282 | |||
2288 | if isvalidfunc(tree): |
|
2283 | if isvalidfunc(tree): | |
2289 | # "name(arg, ....) = ...." style |
|
2284 | # "name(arg, ....) = ...." style | |
2290 | name = getfuncname(tree) |
|
2285 | name = getfuncname(tree) | |
2291 | if name.startswith('$'): |
|
2286 | if name.startswith('$'): | |
2292 | return (decl, None, None, _("'$' not for alias arguments")) |
|
2287 | return (decl, None, None, _("'$' not for alias arguments")) | |
2293 | args = [] |
|
2288 | args = [] | |
2294 | for arg in getfuncargs(tree): |
|
2289 | for arg in getfuncargs(tree): | |
2295 | if not isvalidsymbol(arg): |
|
2290 | if not isvalidsymbol(arg): | |
2296 | return (decl, None, None, _("invalid argument list")) |
|
2291 | return (decl, None, None, _("invalid argument list")) | |
2297 | args.append(getsymbol(arg)) |
|
2292 | args.append(getsymbol(arg)) | |
2298 | if len(args) != len(set(args)): |
|
2293 | if len(args) != len(set(args)): | |
2299 | return (name, None, None, |
|
2294 | return (name, None, None, | |
2300 | _("argument names collide with each other")) |
|
2295 | _("argument names collide with each other")) | |
2301 | return (name, ('func', ('symbol', name)), args, None) |
|
2296 | return (name, ('func', ('symbol', name)), args, None) | |
2302 |
|
2297 | |||
2303 | return (decl, None, None, _("invalid format")) |
|
2298 | return (decl, None, None, _("invalid format")) | |
2304 | except error.ParseError, inst: |
|
2299 | except error.ParseError, inst: | |
2305 | return (decl, None, None, parseerrordetail(inst)) |
|
2300 | return (decl, None, None, parseerrordetail(inst)) | |
2306 |
|
2301 | |||
2307 | def _parsealiasdefn(defn, args): |
|
2302 | def _parsealiasdefn(defn, args): | |
2308 | """Parse alias definition ``defn`` |
|
2303 | """Parse alias definition ``defn`` | |
2309 |
|
2304 | |||
2310 | This function also replaces alias argument references in the |
|
2305 | This function also replaces alias argument references in the | |
2311 | specified definition by ``_aliasarg(ARGNAME)``. |
|
2306 | specified definition by ``_aliasarg(ARGNAME)``. | |
2312 |
|
2307 | |||
2313 | ``args`` is a list of alias argument names, or None if the alias |
|
2308 | ``args`` is a list of alias argument names, or None if the alias | |
2314 | is declared as a symbol. |
|
2309 | is declared as a symbol. | |
2315 |
|
2310 | |||
2316 | This returns "tree" as parsing result. |
|
2311 | This returns "tree" as parsing result. | |
2317 |
|
2312 | |||
2318 | >>> args = ['$1', '$2', 'foo'] |
|
2313 | >>> args = ['$1', '$2', 'foo'] | |
2319 | >>> print prettyformat(_parsealiasdefn('$1 or foo', args)) |
|
2314 | >>> print prettyformat(_parsealiasdefn('$1 or foo', args)) | |
2320 | (or |
|
2315 | (or | |
2321 | (func |
|
2316 | (func | |
2322 | ('symbol', '_aliasarg') |
|
2317 | ('symbol', '_aliasarg') | |
2323 | ('string', '$1')) |
|
2318 | ('string', '$1')) | |
2324 | (func |
|
2319 | (func | |
2325 | ('symbol', '_aliasarg') |
|
2320 | ('symbol', '_aliasarg') | |
2326 | ('string', 'foo'))) |
|
2321 | ('string', 'foo'))) | |
2327 | >>> try: |
|
2322 | >>> try: | |
2328 | ... _parsealiasdefn('$1 or $bar', args) |
|
2323 | ... _parsealiasdefn('$1 or $bar', args) | |
2329 | ... except error.ParseError, inst: |
|
2324 | ... except error.ParseError, inst: | |
2330 | ... print parseerrordetail(inst) |
|
2325 | ... print parseerrordetail(inst) | |
2331 | at 6: '$' not for alias arguments |
|
2326 | at 6: '$' not for alias arguments | |
2332 | >>> args = ['$1', '$10', 'foo'] |
|
2327 | >>> args = ['$1', '$10', 'foo'] | |
2333 | >>> print prettyformat(_parsealiasdefn('$10 or foobar', args)) |
|
2328 | >>> print prettyformat(_parsealiasdefn('$10 or foobar', args)) | |
2334 | (or |
|
2329 | (or | |
2335 | (func |
|
2330 | (func | |
2336 | ('symbol', '_aliasarg') |
|
2331 | ('symbol', '_aliasarg') | |
2337 | ('string', '$10')) |
|
2332 | ('string', '$10')) | |
2338 | ('symbol', 'foobar')) |
|
2333 | ('symbol', 'foobar')) | |
2339 | >>> print prettyformat(_parsealiasdefn('"$1" or "foo"', args)) |
|
2334 | >>> print prettyformat(_parsealiasdefn('"$1" or "foo"', args)) | |
2340 | (or |
|
2335 | (or | |
2341 | ('string', '$1') |
|
2336 | ('string', '$1') | |
2342 | ('string', 'foo')) |
|
2337 | ('string', 'foo')) | |
2343 | """ |
|
2338 | """ | |
2344 | def tokenizedefn(program, lookup=None): |
|
2339 | def tokenizedefn(program, lookup=None): | |
2345 | if args: |
|
2340 | if args: | |
2346 | argset = set(args) |
|
2341 | argset = set(args) | |
2347 | else: |
|
2342 | else: | |
2348 | argset = set() |
|
2343 | argset = set() | |
2349 |
|
2344 | |||
2350 | for t, value, pos in _tokenizealias(program, lookup=lookup): |
|
2345 | for t, value, pos in _tokenizealias(program, lookup=lookup): | |
2351 | if t == 'symbol': |
|
2346 | if t == 'symbol': | |
2352 | if value in argset: |
|
2347 | if value in argset: | |
2353 | # emulate tokenization of "_aliasarg('ARGNAME')": |
|
2348 | # emulate tokenization of "_aliasarg('ARGNAME')": | |
2354 | # "_aliasarg()" is an unknown symbol only used separate |
|
2349 | # "_aliasarg()" is an unknown symbol only used separate | |
2355 | # alias argument placeholders from regular strings. |
|
2350 | # alias argument placeholders from regular strings. | |
2356 | yield ('symbol', '_aliasarg', pos) |
|
2351 | yield ('symbol', '_aliasarg', pos) | |
2357 | yield ('(', None, pos) |
|
2352 | yield ('(', None, pos) | |
2358 | yield ('string', value, pos) |
|
2353 | yield ('string', value, pos) | |
2359 | yield (')', None, pos) |
|
2354 | yield (')', None, pos) | |
2360 | continue |
|
2355 | continue | |
2361 | elif value.startswith('$'): |
|
2356 | elif value.startswith('$'): | |
2362 | raise error.ParseError(_("'$' not for alias arguments"), |
|
2357 | raise error.ParseError(_("'$' not for alias arguments"), | |
2363 | pos) |
|
2358 | pos) | |
2364 | yield (t, value, pos) |
|
2359 | yield (t, value, pos) | |
2365 |
|
2360 | |||
2366 | p = parser.parser(tokenizedefn, elements) |
|
2361 | p = parser.parser(tokenizedefn, elements) | |
2367 | tree, pos = p.parse(defn) |
|
2362 | tree, pos = p.parse(defn) | |
2368 | if pos != len(defn): |
|
2363 | if pos != len(defn): | |
2369 | raise error.ParseError(_('invalid token'), pos) |
|
2364 | raise error.ParseError(_('invalid token'), pos) | |
2370 | return tree |
|
2365 | return tree | |
2371 |
|
2366 | |||
2372 | class revsetalias(object): |
|
2367 | class revsetalias(object): | |
2373 | # whether own `error` information is already shown or not. |
|
2368 | # whether own `error` information is already shown or not. | |
2374 | # this avoids showing same warning multiple times at each `findaliases`. |
|
2369 | # this avoids showing same warning multiple times at each `findaliases`. | |
2375 | warned = False |
|
2370 | warned = False | |
2376 |
|
2371 | |||
2377 | def __init__(self, name, value): |
|
2372 | def __init__(self, name, value): | |
2378 | '''Aliases like: |
|
2373 | '''Aliases like: | |
2379 |
|
2374 | |||
2380 | h = heads(default) |
|
2375 | h = heads(default) | |
2381 | b($1) = ancestors($1) - ancestors(default) |
|
2376 | b($1) = ancestors($1) - ancestors(default) | |
2382 | ''' |
|
2377 | ''' | |
2383 | self.name, self.tree, self.args, self.error = _parsealiasdecl(name) |
|
2378 | self.name, self.tree, self.args, self.error = _parsealiasdecl(name) | |
2384 | if self.error: |
|
2379 | if self.error: | |
2385 | self.error = _('failed to parse the declaration of revset alias' |
|
2380 | self.error = _('failed to parse the declaration of revset alias' | |
2386 | ' "%s": %s') % (self.name, self.error) |
|
2381 | ' "%s": %s') % (self.name, self.error) | |
2387 | return |
|
2382 | return | |
2388 |
|
2383 | |||
2389 | try: |
|
2384 | try: | |
2390 | self.replacement = _parsealiasdefn(value, self.args) |
|
2385 | self.replacement = _parsealiasdefn(value, self.args) | |
2391 | # Check for placeholder injection |
|
2386 | # Check for placeholder injection | |
2392 | _checkaliasarg(self.replacement, self.args) |
|
2387 | _checkaliasarg(self.replacement, self.args) | |
2393 | except error.ParseError, inst: |
|
2388 | except error.ParseError, inst: | |
2394 | self.error = _('failed to parse the definition of revset alias' |
|
2389 | self.error = _('failed to parse the definition of revset alias' | |
2395 | ' "%s": %s') % (self.name, parseerrordetail(inst)) |
|
2390 | ' "%s": %s') % (self.name, parseerrordetail(inst)) | |
2396 |
|
2391 | |||
2397 | def _getalias(aliases, tree): |
|
2392 | def _getalias(aliases, tree): | |
2398 | """If tree looks like an unexpanded alias, return it. Return None |
|
2393 | """If tree looks like an unexpanded alias, return it. Return None | |
2399 | otherwise. |
|
2394 | otherwise. | |
2400 | """ |
|
2395 | """ | |
2401 | if isinstance(tree, tuple) and tree: |
|
2396 | if isinstance(tree, tuple) and tree: | |
2402 | if tree[0] == 'symbol' and len(tree) == 2: |
|
2397 | if tree[0] == 'symbol' and len(tree) == 2: | |
2403 | name = tree[1] |
|
2398 | name = tree[1] | |
2404 | alias = aliases.get(name) |
|
2399 | alias = aliases.get(name) | |
2405 | if alias and alias.args is None and alias.tree == tree: |
|
2400 | if alias and alias.args is None and alias.tree == tree: | |
2406 | return alias |
|
2401 | return alias | |
2407 | if tree[0] == 'func' and len(tree) > 1: |
|
2402 | if tree[0] == 'func' and len(tree) > 1: | |
2408 | if tree[1][0] == 'symbol' and len(tree[1]) == 2: |
|
2403 | if tree[1][0] == 'symbol' and len(tree[1]) == 2: | |
2409 | name = tree[1][1] |
|
2404 | name = tree[1][1] | |
2410 | alias = aliases.get(name) |
|
2405 | alias = aliases.get(name) | |
2411 | if alias and alias.args is not None and alias.tree == tree[:2]: |
|
2406 | if alias and alias.args is not None and alias.tree == tree[:2]: | |
2412 | return alias |
|
2407 | return alias | |
2413 | return None |
|
2408 | return None | |
2414 |
|
2409 | |||
2415 | def _expandargs(tree, args): |
|
2410 | def _expandargs(tree, args): | |
2416 | """Replace _aliasarg instances with the substitution value of the |
|
2411 | """Replace _aliasarg instances with the substitution value of the | |
2417 | same name in args, recursively. |
|
2412 | same name in args, recursively. | |
2418 | """ |
|
2413 | """ | |
2419 | if not tree or not isinstance(tree, tuple): |
|
2414 | if not tree or not isinstance(tree, tuple): | |
2420 | return tree |
|
2415 | return tree | |
2421 | arg = _getaliasarg(tree) |
|
2416 | arg = _getaliasarg(tree) | |
2422 | if arg is not None: |
|
2417 | if arg is not None: | |
2423 | return args[arg] |
|
2418 | return args[arg] | |
2424 | return tuple(_expandargs(t, args) for t in tree) |
|
2419 | return tuple(_expandargs(t, args) for t in tree) | |
2425 |
|
2420 | |||
2426 | def _expandaliases(aliases, tree, expanding, cache): |
|
2421 | def _expandaliases(aliases, tree, expanding, cache): | |
2427 | """Expand aliases in tree, recursively. |
|
2422 | """Expand aliases in tree, recursively. | |
2428 |
|
2423 | |||
2429 | 'aliases' is a dictionary mapping user defined aliases to |
|
2424 | 'aliases' is a dictionary mapping user defined aliases to | |
2430 | revsetalias objects. |
|
2425 | revsetalias objects. | |
2431 | """ |
|
2426 | """ | |
2432 | if not isinstance(tree, tuple): |
|
2427 | if not isinstance(tree, tuple): | |
2433 | # Do not expand raw strings |
|
2428 | # Do not expand raw strings | |
2434 | return tree |
|
2429 | return tree | |
2435 | alias = _getalias(aliases, tree) |
|
2430 | alias = _getalias(aliases, tree) | |
2436 | if alias is not None: |
|
2431 | if alias is not None: | |
2437 | if alias.error: |
|
2432 | if alias.error: | |
2438 | raise util.Abort(alias.error) |
|
2433 | raise util.Abort(alias.error) | |
2439 | if alias in expanding: |
|
2434 | if alias in expanding: | |
2440 | raise error.ParseError(_('infinite expansion of revset alias "%s" ' |
|
2435 | raise error.ParseError(_('infinite expansion of revset alias "%s" ' | |
2441 | 'detected') % alias.name) |
|
2436 | 'detected') % alias.name) | |
2442 | expanding.append(alias) |
|
2437 | expanding.append(alias) | |
2443 | if alias.name not in cache: |
|
2438 | if alias.name not in cache: | |
2444 | cache[alias.name] = _expandaliases(aliases, alias.replacement, |
|
2439 | cache[alias.name] = _expandaliases(aliases, alias.replacement, | |
2445 | expanding, cache) |
|
2440 | expanding, cache) | |
2446 | result = cache[alias.name] |
|
2441 | result = cache[alias.name] | |
2447 | expanding.pop() |
|
2442 | expanding.pop() | |
2448 | if alias.args is not None: |
|
2443 | if alias.args is not None: | |
2449 | l = getlist(tree[2]) |
|
2444 | l = getlist(tree[2]) | |
2450 | if len(l) != len(alias.args): |
|
2445 | if len(l) != len(alias.args): | |
2451 | raise error.ParseError( |
|
2446 | raise error.ParseError( | |
2452 | _('invalid number of arguments: %s') % len(l)) |
|
2447 | _('invalid number of arguments: %s') % len(l)) | |
2453 | l = [_expandaliases(aliases, a, [], cache) for a in l] |
|
2448 | l = [_expandaliases(aliases, a, [], cache) for a in l] | |
2454 | result = _expandargs(result, dict(zip(alias.args, l))) |
|
2449 | result = _expandargs(result, dict(zip(alias.args, l))) | |
2455 | else: |
|
2450 | else: | |
2456 | result = tuple(_expandaliases(aliases, t, expanding, cache) |
|
2451 | result = tuple(_expandaliases(aliases, t, expanding, cache) | |
2457 | for t in tree) |
|
2452 | for t in tree) | |
2458 | return result |
|
2453 | return result | |
2459 |
|
2454 | |||
2460 | def findaliases(ui, tree, showwarning=None): |
|
2455 | def findaliases(ui, tree, showwarning=None): | |
2461 | _checkaliasarg(tree) |
|
2456 | _checkaliasarg(tree) | |
2462 | aliases = {} |
|
2457 | aliases = {} | |
2463 | for k, v in ui.configitems('revsetalias'): |
|
2458 | for k, v in ui.configitems('revsetalias'): | |
2464 | alias = revsetalias(k, v) |
|
2459 | alias = revsetalias(k, v) | |
2465 | aliases[alias.name] = alias |
|
2460 | aliases[alias.name] = alias | |
2466 | tree = _expandaliases(aliases, tree, [], {}) |
|
2461 | tree = _expandaliases(aliases, tree, [], {}) | |
2467 | if showwarning: |
|
2462 | if showwarning: | |
2468 | # warn about problematic (but not referred) aliases |
|
2463 | # warn about problematic (but not referred) aliases | |
2469 | for name, alias in sorted(aliases.iteritems()): |
|
2464 | for name, alias in sorted(aliases.iteritems()): | |
2470 | if alias.error and not alias.warned: |
|
2465 | if alias.error and not alias.warned: | |
2471 | showwarning(_('warning: %s\n') % (alias.error)) |
|
2466 | showwarning(_('warning: %s\n') % (alias.error)) | |
2472 | alias.warned = True |
|
2467 | alias.warned = True | |
2473 | return tree |
|
2468 | return tree | |
2474 |
|
2469 | |||
2475 | def foldconcat(tree): |
|
2470 | def foldconcat(tree): | |
2476 | """Fold elements to be concatenated by `##` |
|
2471 | """Fold elements to be concatenated by `##` | |
2477 | """ |
|
2472 | """ | |
2478 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): |
|
2473 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): | |
2479 | return tree |
|
2474 | return tree | |
2480 | if tree[0] == '_concat': |
|
2475 | if tree[0] == '_concat': | |
2481 | pending = [tree] |
|
2476 | pending = [tree] | |
2482 | l = [] |
|
2477 | l = [] | |
2483 | while pending: |
|
2478 | while pending: | |
2484 | e = pending.pop() |
|
2479 | e = pending.pop() | |
2485 | if e[0] == '_concat': |
|
2480 | if e[0] == '_concat': | |
2486 | pending.extend(reversed(e[1:])) |
|
2481 | pending.extend(reversed(e[1:])) | |
2487 | elif e[0] in ('string', 'symbol'): |
|
2482 | elif e[0] in ('string', 'symbol'): | |
2488 | l.append(e[1]) |
|
2483 | l.append(e[1]) | |
2489 | else: |
|
2484 | else: | |
2490 | msg = _("\"##\" can't concatenate \"%s\" element") % (e[0]) |
|
2485 | msg = _("\"##\" can't concatenate \"%s\" element") % (e[0]) | |
2491 | raise error.ParseError(msg) |
|
2486 | raise error.ParseError(msg) | |
2492 | return ('string', ''.join(l)) |
|
2487 | return ('string', ''.join(l)) | |
2493 | else: |
|
2488 | else: | |
2494 | return tuple(foldconcat(t) for t in tree) |
|
2489 | return tuple(foldconcat(t) for t in tree) | |
2495 |
|
2490 | |||
2496 | def parse(spec, lookup=None): |
|
2491 | def parse(spec, lookup=None): | |
2497 | p = parser.parser(tokenize, elements) |
|
2492 | p = parser.parser(tokenize, elements) | |
2498 | return p.parse(spec, lookup=lookup) |
|
2493 | return p.parse(spec, lookup=lookup) | |
2499 |
|
2494 | |||
2500 | def posttreebuilthook(tree, repo): |
|
2495 | def posttreebuilthook(tree, repo): | |
2501 | # hook for extensions to execute code on the optimized tree |
|
2496 | # hook for extensions to execute code on the optimized tree | |
2502 | pass |
|
2497 | pass | |
2503 |
|
2498 | |||
2504 | def match(ui, spec, repo=None): |
|
2499 | def match(ui, spec, repo=None): | |
2505 | if not spec: |
|
2500 | if not spec: | |
2506 | raise error.ParseError(_("empty query")) |
|
2501 | raise error.ParseError(_("empty query")) | |
2507 | lookup = None |
|
2502 | lookup = None | |
2508 | if repo: |
|
2503 | if repo: | |
2509 | lookup = repo.__contains__ |
|
2504 | lookup = repo.__contains__ | |
2510 | tree, pos = parse(spec, lookup) |
|
2505 | tree, pos = parse(spec, lookup) | |
2511 | if (pos != len(spec)): |
|
2506 | if (pos != len(spec)): | |
2512 | raise error.ParseError(_("invalid token"), pos) |
|
2507 | raise error.ParseError(_("invalid token"), pos) | |
2513 | if ui: |
|
2508 | if ui: | |
2514 | tree = findaliases(ui, tree, showwarning=ui.warn) |
|
2509 | tree = findaliases(ui, tree, showwarning=ui.warn) | |
2515 | tree = foldconcat(tree) |
|
2510 | tree = foldconcat(tree) | |
2516 | weight, tree = optimize(tree, True) |
|
2511 | weight, tree = optimize(tree, True) | |
2517 | posttreebuilthook(tree, repo) |
|
2512 | posttreebuilthook(tree, repo) | |
2518 | def mfunc(repo, subset=None): |
|
2513 | def mfunc(repo, subset=None): | |
2519 | if subset is None: |
|
2514 | if subset is None: | |
2520 | subset = fullreposet(repo) |
|
2515 | subset = fullreposet(repo) | |
2521 | if util.safehasattr(subset, 'isascending'): |
|
2516 | if util.safehasattr(subset, 'isascending'): | |
2522 | result = getset(repo, subset, tree) |
|
2517 | result = getset(repo, subset, tree) | |
2523 | else: |
|
2518 | else: | |
2524 | result = getset(repo, baseset(subset), tree) |
|
2519 | result = getset(repo, baseset(subset), tree) | |
2525 | return result |
|
2520 | return result | |
2526 | return mfunc |
|
2521 | return mfunc | |
2527 |
|
2522 | |||
2528 | def formatspec(expr, *args): |
|
2523 | def formatspec(expr, *args): | |
2529 | ''' |
|
2524 | ''' | |
2530 | This is a convenience function for using revsets internally, and |
|
2525 | This is a convenience function for using revsets internally, and | |
2531 | escapes arguments appropriately. Aliases are intentionally ignored |
|
2526 | escapes arguments appropriately. Aliases are intentionally ignored | |
2532 | so that intended expression behavior isn't accidentally subverted. |
|
2527 | so that intended expression behavior isn't accidentally subverted. | |
2533 |
|
2528 | |||
2534 | Supported arguments: |
|
2529 | Supported arguments: | |
2535 |
|
2530 | |||
2536 | %r = revset expression, parenthesized |
|
2531 | %r = revset expression, parenthesized | |
2537 | %d = int(arg), no quoting |
|
2532 | %d = int(arg), no quoting | |
2538 | %s = string(arg), escaped and single-quoted |
|
2533 | %s = string(arg), escaped and single-quoted | |
2539 | %b = arg.branch(), escaped and single-quoted |
|
2534 | %b = arg.branch(), escaped and single-quoted | |
2540 | %n = hex(arg), single-quoted |
|
2535 | %n = hex(arg), single-quoted | |
2541 | %% = a literal '%' |
|
2536 | %% = a literal '%' | |
2542 |
|
2537 | |||
2543 | Prefixing the type with 'l' specifies a parenthesized list of that type. |
|
2538 | Prefixing the type with 'l' specifies a parenthesized list of that type. | |
2544 |
|
2539 | |||
2545 | >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()")) |
|
2540 | >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()")) | |
2546 | '(10 or 11):: and ((this()) or (that()))' |
|
2541 | '(10 or 11):: and ((this()) or (that()))' | |
2547 | >>> formatspec('%d:: and not %d::', 10, 20) |
|
2542 | >>> formatspec('%d:: and not %d::', 10, 20) | |
2548 | '10:: and not 20::' |
|
2543 | '10:: and not 20::' | |
2549 | >>> formatspec('%ld or %ld', [], [1]) |
|
2544 | >>> formatspec('%ld or %ld', [], [1]) | |
2550 | "_list('') or 1" |
|
2545 | "_list('') or 1" | |
2551 | >>> formatspec('keyword(%s)', 'foo\\xe9') |
|
2546 | >>> formatspec('keyword(%s)', 'foo\\xe9') | |
2552 | "keyword('foo\\\\xe9')" |
|
2547 | "keyword('foo\\\\xe9')" | |
2553 | >>> b = lambda: 'default' |
|
2548 | >>> b = lambda: 'default' | |
2554 | >>> b.branch = b |
|
2549 | >>> b.branch = b | |
2555 | >>> formatspec('branch(%b)', b) |
|
2550 | >>> formatspec('branch(%b)', b) | |
2556 | "branch('default')" |
|
2551 | "branch('default')" | |
2557 | >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) |
|
2552 | >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) | |
2558 | "root(_list('a\\x00b\\x00c\\x00d'))" |
|
2553 | "root(_list('a\\x00b\\x00c\\x00d'))" | |
2559 | ''' |
|
2554 | ''' | |
2560 |
|
2555 | |||
2561 | def quote(s): |
|
2556 | def quote(s): | |
2562 | return repr(str(s)) |
|
2557 | return repr(str(s)) | |
2563 |
|
2558 | |||
2564 | def argtype(c, arg): |
|
2559 | def argtype(c, arg): | |
2565 | if c == 'd': |
|
2560 | if c == 'd': | |
2566 | return str(int(arg)) |
|
2561 | return str(int(arg)) | |
2567 | elif c == 's': |
|
2562 | elif c == 's': | |
2568 | return quote(arg) |
|
2563 | return quote(arg) | |
2569 | elif c == 'r': |
|
2564 | elif c == 'r': | |
2570 | parse(arg) # make sure syntax errors are confined |
|
2565 | parse(arg) # make sure syntax errors are confined | |
2571 | return '(%s)' % arg |
|
2566 | return '(%s)' % arg | |
2572 | elif c == 'n': |
|
2567 | elif c == 'n': | |
2573 | return quote(node.hex(arg)) |
|
2568 | return quote(node.hex(arg)) | |
2574 | elif c == 'b': |
|
2569 | elif c == 'b': | |
2575 | return quote(arg.branch()) |
|
2570 | return quote(arg.branch()) | |
2576 |
|
2571 | |||
2577 | def listexp(s, t): |
|
2572 | def listexp(s, t): | |
2578 | l = len(s) |
|
2573 | l = len(s) | |
2579 | if l == 0: |
|
2574 | if l == 0: | |
2580 | return "_list('')" |
|
2575 | return "_list('')" | |
2581 | elif l == 1: |
|
2576 | elif l == 1: | |
2582 | return argtype(t, s[0]) |
|
2577 | return argtype(t, s[0]) | |
2583 | elif t == 'd': |
|
2578 | elif t == 'd': | |
2584 | return "_intlist('%s')" % "\0".join(str(int(a)) for a in s) |
|
2579 | return "_intlist('%s')" % "\0".join(str(int(a)) for a in s) | |
2585 | elif t == 's': |
|
2580 | elif t == 's': | |
2586 | return "_list('%s')" % "\0".join(s) |
|
2581 | return "_list('%s')" % "\0".join(s) | |
2587 | elif t == 'n': |
|
2582 | elif t == 'n': | |
2588 | return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s) |
|
2583 | return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s) | |
2589 | elif t == 'b': |
|
2584 | elif t == 'b': | |
2590 | return "_list('%s')" % "\0".join(a.branch() for a in s) |
|
2585 | return "_list('%s')" % "\0".join(a.branch() for a in s) | |
2591 |
|
2586 | |||
2592 | m = l // 2 |
|
2587 | m = l // 2 | |
2593 | return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) |
|
2588 | return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) | |
2594 |
|
2589 | |||
2595 | ret = '' |
|
2590 | ret = '' | |
2596 | pos = 0 |
|
2591 | pos = 0 | |
2597 | arg = 0 |
|
2592 | arg = 0 | |
2598 | while pos < len(expr): |
|
2593 | while pos < len(expr): | |
2599 | c = expr[pos] |
|
2594 | c = expr[pos] | |
2600 | if c == '%': |
|
2595 | if c == '%': | |
2601 | pos += 1 |
|
2596 | pos += 1 | |
2602 | d = expr[pos] |
|
2597 | d = expr[pos] | |
2603 | if d == '%': |
|
2598 | if d == '%': | |
2604 | ret += d |
|
2599 | ret += d | |
2605 | elif d in 'dsnbr': |
|
2600 | elif d in 'dsnbr': | |
2606 | ret += argtype(d, args[arg]) |
|
2601 | ret += argtype(d, args[arg]) | |
2607 | arg += 1 |
|
2602 | arg += 1 | |
2608 | elif d == 'l': |
|
2603 | elif d == 'l': | |
2609 | # a list of some type |
|
2604 | # a list of some type | |
2610 | pos += 1 |
|
2605 | pos += 1 | |
2611 | d = expr[pos] |
|
2606 | d = expr[pos] | |
2612 | ret += listexp(list(args[arg]), d) |
|
2607 | ret += listexp(list(args[arg]), d) | |
2613 | arg += 1 |
|
2608 | arg += 1 | |
2614 | else: |
|
2609 | else: | |
2615 | raise util.Abort('unexpected revspec format character %s' % d) |
|
2610 | raise util.Abort('unexpected revspec format character %s' % d) | |
2616 | else: |
|
2611 | else: | |
2617 | ret += c |
|
2612 | ret += c | |
2618 | pos += 1 |
|
2613 | pos += 1 | |
2619 |
|
2614 | |||
2620 | return ret |
|
2615 | return ret | |
2621 |
|
2616 | |||
2622 | def prettyformat(tree): |
|
2617 | def prettyformat(tree): | |
2623 | def _prettyformat(tree, level, lines): |
|
2618 | def _prettyformat(tree, level, lines): | |
2624 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): |
|
2619 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): | |
2625 | lines.append((level, str(tree))) |
|
2620 | lines.append((level, str(tree))) | |
2626 | else: |
|
2621 | else: | |
2627 | lines.append((level, '(%s' % tree[0])) |
|
2622 | lines.append((level, '(%s' % tree[0])) | |
2628 | for s in tree[1:]: |
|
2623 | for s in tree[1:]: | |
2629 | _prettyformat(s, level + 1, lines) |
|
2624 | _prettyformat(s, level + 1, lines) | |
2630 | lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] |
|
2625 | lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] | |
2631 |
|
2626 | |||
2632 | lines = [] |
|
2627 | lines = [] | |
2633 | _prettyformat(tree, 0, lines) |
|
2628 | _prettyformat(tree, 0, lines) | |
2634 | output = '\n'.join((' '*l + s) for l, s in lines) |
|
2629 | output = '\n'.join((' '*l + s) for l, s in lines) | |
2635 | return output |
|
2630 | return output | |
2636 |
|
2631 | |||
2637 | def depth(tree): |
|
2632 | def depth(tree): | |
2638 | if isinstance(tree, tuple): |
|
2633 | if isinstance(tree, tuple): | |
2639 | return max(map(depth, tree)) + 1 |
|
2634 | return max(map(depth, tree)) + 1 | |
2640 | else: |
|
2635 | else: | |
2641 | return 0 |
|
2636 | return 0 | |
2642 |
|
2637 | |||
2643 | def funcsused(tree): |
|
2638 | def funcsused(tree): | |
2644 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): |
|
2639 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): | |
2645 | return set() |
|
2640 | return set() | |
2646 | else: |
|
2641 | else: | |
2647 | funcs = set() |
|
2642 | funcs = set() | |
2648 | for s in tree[1:]: |
|
2643 | for s in tree[1:]: | |
2649 | funcs |= funcsused(s) |
|
2644 | funcs |= funcsused(s) | |
2650 | if tree[0] == 'func': |
|
2645 | if tree[0] == 'func': | |
2651 | funcs.add(tree[1][1]) |
|
2646 | funcs.add(tree[1][1]) | |
2652 | return funcs |
|
2647 | return funcs | |
2653 |
|
2648 | |||
2654 | class abstractsmartset(object): |
|
2649 | class abstractsmartset(object): | |
2655 |
|
2650 | |||
2656 | def __nonzero__(self): |
|
2651 | def __nonzero__(self): | |
2657 | """True if the smartset is not empty""" |
|
2652 | """True if the smartset is not empty""" | |
2658 | raise NotImplementedError() |
|
2653 | raise NotImplementedError() | |
2659 |
|
2654 | |||
2660 | def __contains__(self, rev): |
|
2655 | def __contains__(self, rev): | |
2661 | """provide fast membership testing""" |
|
2656 | """provide fast membership testing""" | |
2662 | raise NotImplementedError() |
|
2657 | raise NotImplementedError() | |
2663 |
|
2658 | |||
2664 | def __iter__(self): |
|
2659 | def __iter__(self): | |
2665 | """iterate the set in the order it is supposed to be iterated""" |
|
2660 | """iterate the set in the order it is supposed to be iterated""" | |
2666 | raise NotImplementedError() |
|
2661 | raise NotImplementedError() | |
2667 |
|
2662 | |||
2668 | # Attributes containing a function to perform a fast iteration in a given |
|
2663 | # Attributes containing a function to perform a fast iteration in a given | |
2669 | # direction. A smartset can have none, one, or both defined. |
|
2664 | # direction. A smartset can have none, one, or both defined. | |
2670 | # |
|
2665 | # | |
2671 | # Default value is None instead of a function returning None to avoid |
|
2666 | # Default value is None instead of a function returning None to avoid | |
2672 | # initializing an iterator just for testing if a fast method exists. |
|
2667 | # initializing an iterator just for testing if a fast method exists. | |
2673 | fastasc = None |
|
2668 | fastasc = None | |
2674 | fastdesc = None |
|
2669 | fastdesc = None | |
2675 |
|
2670 | |||
2676 | def isascending(self): |
|
2671 | def isascending(self): | |
2677 | """True if the set will iterate in ascending order""" |
|
2672 | """True if the set will iterate in ascending order""" | |
2678 | raise NotImplementedError() |
|
2673 | raise NotImplementedError() | |
2679 |
|
2674 | |||
2680 | def isdescending(self): |
|
2675 | def isdescending(self): | |
2681 | """True if the set will iterate in descending order""" |
|
2676 | """True if the set will iterate in descending order""" | |
2682 | raise NotImplementedError() |
|
2677 | raise NotImplementedError() | |
2683 |
|
2678 | |||
2684 | def min(self): |
|
2679 | def min(self): | |
2685 | """return the minimum element in the set""" |
|
2680 | """return the minimum element in the set""" | |
2686 | if self.fastasc is not None: |
|
2681 | if self.fastasc is not None: | |
2687 | for r in self.fastasc(): |
|
2682 | for r in self.fastasc(): | |
2688 | return r |
|
2683 | return r | |
2689 | raise ValueError('arg is an empty sequence') |
|
2684 | raise ValueError('arg is an empty sequence') | |
2690 | return min(self) |
|
2685 | return min(self) | |
2691 |
|
2686 | |||
2692 | def max(self): |
|
2687 | def max(self): | |
2693 | """return the maximum element in the set""" |
|
2688 | """return the maximum element in the set""" | |
2694 | if self.fastdesc is not None: |
|
2689 | if self.fastdesc is not None: | |
2695 | for r in self.fastdesc(): |
|
2690 | for r in self.fastdesc(): | |
2696 | return r |
|
2691 | return r | |
2697 | raise ValueError('arg is an empty sequence') |
|
2692 | raise ValueError('arg is an empty sequence') | |
2698 | return max(self) |
|
2693 | return max(self) | |
2699 |
|
2694 | |||
2700 | def first(self): |
|
2695 | def first(self): | |
2701 | """return the first element in the set (user iteration perspective) |
|
2696 | """return the first element in the set (user iteration perspective) | |
2702 |
|
2697 | |||
2703 | Return None if the set is empty""" |
|
2698 | Return None if the set is empty""" | |
2704 | raise NotImplementedError() |
|
2699 | raise NotImplementedError() | |
2705 |
|
2700 | |||
2706 | def last(self): |
|
2701 | def last(self): | |
2707 | """return the last element in the set (user iteration perspective) |
|
2702 | """return the last element in the set (user iteration perspective) | |
2708 |
|
2703 | |||
2709 | Return None if the set is empty""" |
|
2704 | Return None if the set is empty""" | |
2710 | raise NotImplementedError() |
|
2705 | raise NotImplementedError() | |
2711 |
|
2706 | |||
2712 | def __len__(self): |
|
2707 | def __len__(self): | |
2713 | """return the length of the smartsets |
|
2708 | """return the length of the smartsets | |
2714 |
|
2709 | |||
2715 | This can be expensive on smartset that could be lazy otherwise.""" |
|
2710 | This can be expensive on smartset that could be lazy otherwise.""" | |
2716 | raise NotImplementedError() |
|
2711 | raise NotImplementedError() | |
2717 |
|
2712 | |||
2718 | def reverse(self): |
|
2713 | def reverse(self): | |
2719 | """reverse the expected iteration order""" |
|
2714 | """reverse the expected iteration order""" | |
2720 | raise NotImplementedError() |
|
2715 | raise NotImplementedError() | |
2721 |
|
2716 | |||
2722 | def sort(self, reverse=True): |
|
2717 | def sort(self, reverse=True): | |
2723 | """get the set to iterate in an ascending or descending order""" |
|
2718 | """get the set to iterate in an ascending or descending order""" | |
2724 | raise NotImplementedError() |
|
2719 | raise NotImplementedError() | |
2725 |
|
2720 | |||
2726 | def __and__(self, other): |
|
2721 | def __and__(self, other): | |
2727 | """Returns a new object with the intersection of the two collections. |
|
2722 | """Returns a new object with the intersection of the two collections. | |
2728 |
|
2723 | |||
2729 | This is part of the mandatory API for smartset.""" |
|
2724 | This is part of the mandatory API for smartset.""" | |
2730 | if isinstance(other, fullreposet): |
|
2725 | if isinstance(other, fullreposet): | |
2731 | return self |
|
2726 | return self | |
2732 | return self.filter(other.__contains__, cache=False) |
|
2727 | return self.filter(other.__contains__, cache=False) | |
2733 |
|
2728 | |||
2734 | def __add__(self, other): |
|
2729 | def __add__(self, other): | |
2735 | """Returns a new object with the union of the two collections. |
|
2730 | """Returns a new object with the union of the two collections. | |
2736 |
|
2731 | |||
2737 | This is part of the mandatory API for smartset.""" |
|
2732 | This is part of the mandatory API for smartset.""" | |
2738 | return addset(self, other) |
|
2733 | return addset(self, other) | |
2739 |
|
2734 | |||
2740 | def __sub__(self, other): |
|
2735 | def __sub__(self, other): | |
2741 | """Returns a new object with the substraction of the two collections. |
|
2736 | """Returns a new object with the substraction of the two collections. | |
2742 |
|
2737 | |||
2743 | This is part of the mandatory API for smartset.""" |
|
2738 | This is part of the mandatory API for smartset.""" | |
2744 | c = other.__contains__ |
|
2739 | c = other.__contains__ | |
2745 | return self.filter(lambda r: not c(r), cache=False) |
|
2740 | return self.filter(lambda r: not c(r), cache=False) | |
2746 |
|
2741 | |||
2747 | def filter(self, condition, cache=True): |
|
2742 | def filter(self, condition, cache=True): | |
2748 | """Returns this smartset filtered by condition as a new smartset. |
|
2743 | """Returns this smartset filtered by condition as a new smartset. | |
2749 |
|
2744 | |||
2750 | `condition` is a callable which takes a revision number and returns a |
|
2745 | `condition` is a callable which takes a revision number and returns a | |
2751 | boolean. |
|
2746 | boolean. | |
2752 |
|
2747 | |||
2753 | This is part of the mandatory API for smartset.""" |
|
2748 | This is part of the mandatory API for smartset.""" | |
2754 | # builtin cannot be cached. but do not needs to |
|
2749 | # builtin cannot be cached. but do not needs to | |
2755 | if cache and util.safehasattr(condition, 'func_code'): |
|
2750 | if cache and util.safehasattr(condition, 'func_code'): | |
2756 | condition = util.cachefunc(condition) |
|
2751 | condition = util.cachefunc(condition) | |
2757 | return filteredset(self, condition) |
|
2752 | return filteredset(self, condition) | |
2758 |
|
2753 | |||
2759 | class baseset(abstractsmartset): |
|
2754 | class baseset(abstractsmartset): | |
2760 | """Basic data structure that represents a revset and contains the basic |
|
2755 | """Basic data structure that represents a revset and contains the basic | |
2761 | operation that it should be able to perform. |
|
2756 | operation that it should be able to perform. | |
2762 |
|
2757 | |||
2763 | Every method in this class should be implemented by any smartset class. |
|
2758 | Every method in this class should be implemented by any smartset class. | |
2764 | """ |
|
2759 | """ | |
2765 | def __init__(self, data=()): |
|
2760 | def __init__(self, data=()): | |
2766 | if not isinstance(data, list): |
|
2761 | if not isinstance(data, list): | |
2767 | data = list(data) |
|
2762 | data = list(data) | |
2768 | self._list = data |
|
2763 | self._list = data | |
2769 | self._ascending = None |
|
2764 | self._ascending = None | |
2770 |
|
2765 | |||
2771 | @util.propertycache |
|
2766 | @util.propertycache | |
2772 | def _set(self): |
|
2767 | def _set(self): | |
2773 | return set(self._list) |
|
2768 | return set(self._list) | |
2774 |
|
2769 | |||
2775 | @util.propertycache |
|
2770 | @util.propertycache | |
2776 | def _asclist(self): |
|
2771 | def _asclist(self): | |
2777 | asclist = self._list[:] |
|
2772 | asclist = self._list[:] | |
2778 | asclist.sort() |
|
2773 | asclist.sort() | |
2779 | return asclist |
|
2774 | return asclist | |
2780 |
|
2775 | |||
2781 | def __iter__(self): |
|
2776 | def __iter__(self): | |
2782 | if self._ascending is None: |
|
2777 | if self._ascending is None: | |
2783 | return iter(self._list) |
|
2778 | return iter(self._list) | |
2784 | elif self._ascending: |
|
2779 | elif self._ascending: | |
2785 | return iter(self._asclist) |
|
2780 | return iter(self._asclist) | |
2786 | else: |
|
2781 | else: | |
2787 | return reversed(self._asclist) |
|
2782 | return reversed(self._asclist) | |
2788 |
|
2783 | |||
2789 | def fastasc(self): |
|
2784 | def fastasc(self): | |
2790 | return iter(self._asclist) |
|
2785 | return iter(self._asclist) | |
2791 |
|
2786 | |||
2792 | def fastdesc(self): |
|
2787 | def fastdesc(self): | |
2793 | return reversed(self._asclist) |
|
2788 | return reversed(self._asclist) | |
2794 |
|
2789 | |||
2795 | @util.propertycache |
|
2790 | @util.propertycache | |
2796 | def __contains__(self): |
|
2791 | def __contains__(self): | |
2797 | return self._set.__contains__ |
|
2792 | return self._set.__contains__ | |
2798 |
|
2793 | |||
2799 | def __nonzero__(self): |
|
2794 | def __nonzero__(self): | |
2800 | return bool(self._list) |
|
2795 | return bool(self._list) | |
2801 |
|
2796 | |||
2802 | def sort(self, reverse=False): |
|
2797 | def sort(self, reverse=False): | |
2803 | self._ascending = not bool(reverse) |
|
2798 | self._ascending = not bool(reverse) | |
2804 |
|
2799 | |||
2805 | def reverse(self): |
|
2800 | def reverse(self): | |
2806 | if self._ascending is None: |
|
2801 | if self._ascending is None: | |
2807 | self._list.reverse() |
|
2802 | self._list.reverse() | |
2808 | else: |
|
2803 | else: | |
2809 | self._ascending = not self._ascending |
|
2804 | self._ascending = not self._ascending | |
2810 |
|
2805 | |||
2811 | def __len__(self): |
|
2806 | def __len__(self): | |
2812 | return len(self._list) |
|
2807 | return len(self._list) | |
2813 |
|
2808 | |||
2814 | def isascending(self): |
|
2809 | def isascending(self): | |
2815 | """Returns True if the collection is ascending order, False if not. |
|
2810 | """Returns True if the collection is ascending order, False if not. | |
2816 |
|
2811 | |||
2817 | This is part of the mandatory API for smartset.""" |
|
2812 | This is part of the mandatory API for smartset.""" | |
2818 | if len(self) <= 1: |
|
2813 | if len(self) <= 1: | |
2819 | return True |
|
2814 | return True | |
2820 | return self._ascending is not None and self._ascending |
|
2815 | return self._ascending is not None and self._ascending | |
2821 |
|
2816 | |||
2822 | def isdescending(self): |
|
2817 | def isdescending(self): | |
2823 | """Returns True if the collection is descending order, False if not. |
|
2818 | """Returns True if the collection is descending order, False if not. | |
2824 |
|
2819 | |||
2825 | This is part of the mandatory API for smartset.""" |
|
2820 | This is part of the mandatory API for smartset.""" | |
2826 | if len(self) <= 1: |
|
2821 | if len(self) <= 1: | |
2827 | return True |
|
2822 | return True | |
2828 | return self._ascending is not None and not self._ascending |
|
2823 | return self._ascending is not None and not self._ascending | |
2829 |
|
2824 | |||
2830 | def first(self): |
|
2825 | def first(self): | |
2831 | if self: |
|
2826 | if self: | |
2832 | if self._ascending is None: |
|
2827 | if self._ascending is None: | |
2833 | return self._list[0] |
|
2828 | return self._list[0] | |
2834 | elif self._ascending: |
|
2829 | elif self._ascending: | |
2835 | return self._asclist[0] |
|
2830 | return self._asclist[0] | |
2836 | else: |
|
2831 | else: | |
2837 | return self._asclist[-1] |
|
2832 | return self._asclist[-1] | |
2838 | return None |
|
2833 | return None | |
2839 |
|
2834 | |||
2840 | def last(self): |
|
2835 | def last(self): | |
2841 | if self: |
|
2836 | if self: | |
2842 | if self._ascending is None: |
|
2837 | if self._ascending is None: | |
2843 | return self._list[-1] |
|
2838 | return self._list[-1] | |
2844 | elif self._ascending: |
|
2839 | elif self._ascending: | |
2845 | return self._asclist[-1] |
|
2840 | return self._asclist[-1] | |
2846 | else: |
|
2841 | else: | |
2847 | return self._asclist[0] |
|
2842 | return self._asclist[0] | |
2848 | return None |
|
2843 | return None | |
2849 |
|
2844 | |||
2850 | def __repr__(self): |
|
2845 | def __repr__(self): | |
2851 | d = {None: '', False: '-', True: '+'}[self._ascending] |
|
2846 | d = {None: '', False: '-', True: '+'}[self._ascending] | |
2852 | return '<%s%s %r>' % (type(self).__name__, d, self._list) |
|
2847 | return '<%s%s %r>' % (type(self).__name__, d, self._list) | |
2853 |
|
2848 | |||
2854 | class filteredset(abstractsmartset): |
|
2849 | class filteredset(abstractsmartset): | |
2855 | """Duck type for baseset class which iterates lazily over the revisions in |
|
2850 | """Duck type for baseset class which iterates lazily over the revisions in | |
2856 | the subset and contains a function which tests for membership in the |
|
2851 | the subset and contains a function which tests for membership in the | |
2857 | revset |
|
2852 | revset | |
2858 | """ |
|
2853 | """ | |
2859 | def __init__(self, subset, condition=lambda x: True): |
|
2854 | def __init__(self, subset, condition=lambda x: True): | |
2860 | """ |
|
2855 | """ | |
2861 | condition: a function that decide whether a revision in the subset |
|
2856 | condition: a function that decide whether a revision in the subset | |
2862 | belongs to the revset or not. |
|
2857 | belongs to the revset or not. | |
2863 | """ |
|
2858 | """ | |
2864 | self._subset = subset |
|
2859 | self._subset = subset | |
2865 | self._condition = condition |
|
2860 | self._condition = condition | |
2866 | self._cache = {} |
|
2861 | self._cache = {} | |
2867 |
|
2862 | |||
2868 | def __contains__(self, x): |
|
2863 | def __contains__(self, x): | |
2869 | c = self._cache |
|
2864 | c = self._cache | |
2870 | if x not in c: |
|
2865 | if x not in c: | |
2871 | v = c[x] = x in self._subset and self._condition(x) |
|
2866 | v = c[x] = x in self._subset and self._condition(x) | |
2872 | return v |
|
2867 | return v | |
2873 | return c[x] |
|
2868 | return c[x] | |
2874 |
|
2869 | |||
2875 | def __iter__(self): |
|
2870 | def __iter__(self): | |
2876 | return self._iterfilter(self._subset) |
|
2871 | return self._iterfilter(self._subset) | |
2877 |
|
2872 | |||
2878 | def _iterfilter(self, it): |
|
2873 | def _iterfilter(self, it): | |
2879 | cond = self._condition |
|
2874 | cond = self._condition | |
2880 | for x in it: |
|
2875 | for x in it: | |
2881 | if cond(x): |
|
2876 | if cond(x): | |
2882 | yield x |
|
2877 | yield x | |
2883 |
|
2878 | |||
2884 | @property |
|
2879 | @property | |
2885 | def fastasc(self): |
|
2880 | def fastasc(self): | |
2886 | it = self._subset.fastasc |
|
2881 | it = self._subset.fastasc | |
2887 | if it is None: |
|
2882 | if it is None: | |
2888 | return None |
|
2883 | return None | |
2889 | return lambda: self._iterfilter(it()) |
|
2884 | return lambda: self._iterfilter(it()) | |
2890 |
|
2885 | |||
2891 | @property |
|
2886 | @property | |
2892 | def fastdesc(self): |
|
2887 | def fastdesc(self): | |
2893 | it = self._subset.fastdesc |
|
2888 | it = self._subset.fastdesc | |
2894 | if it is None: |
|
2889 | if it is None: | |
2895 | return None |
|
2890 | return None | |
2896 | return lambda: self._iterfilter(it()) |
|
2891 | return lambda: self._iterfilter(it()) | |
2897 |
|
2892 | |||
2898 | def __nonzero__(self): |
|
2893 | def __nonzero__(self): | |
2899 | for r in self: |
|
2894 | for r in self: | |
2900 | return True |
|
2895 | return True | |
2901 | return False |
|
2896 | return False | |
2902 |
|
2897 | |||
2903 | def __len__(self): |
|
2898 | def __len__(self): | |
2904 | # Basic implementation to be changed in future patches. |
|
2899 | # Basic implementation to be changed in future patches. | |
2905 | l = baseset([r for r in self]) |
|
2900 | l = baseset([r for r in self]) | |
2906 | return len(l) |
|
2901 | return len(l) | |
2907 |
|
2902 | |||
2908 | def sort(self, reverse=False): |
|
2903 | def sort(self, reverse=False): | |
2909 | self._subset.sort(reverse=reverse) |
|
2904 | self._subset.sort(reverse=reverse) | |
2910 |
|
2905 | |||
2911 | def reverse(self): |
|
2906 | def reverse(self): | |
2912 | self._subset.reverse() |
|
2907 | self._subset.reverse() | |
2913 |
|
2908 | |||
2914 | def isascending(self): |
|
2909 | def isascending(self): | |
2915 | return self._subset.isascending() |
|
2910 | return self._subset.isascending() | |
2916 |
|
2911 | |||
2917 | def isdescending(self): |
|
2912 | def isdescending(self): | |
2918 | return self._subset.isdescending() |
|
2913 | return self._subset.isdescending() | |
2919 |
|
2914 | |||
2920 | def first(self): |
|
2915 | def first(self): | |
2921 | for x in self: |
|
2916 | for x in self: | |
2922 | return x |
|
2917 | return x | |
2923 | return None |
|
2918 | return None | |
2924 |
|
2919 | |||
2925 | def last(self): |
|
2920 | def last(self): | |
2926 | it = None |
|
2921 | it = None | |
2927 | if self._subset.isascending: |
|
2922 | if self._subset.isascending: | |
2928 | it = self.fastdesc |
|
2923 | it = self.fastdesc | |
2929 | elif self._subset.isdescending: |
|
2924 | elif self._subset.isdescending: | |
2930 | it = self.fastdesc |
|
2925 | it = self.fastdesc | |
2931 | if it is None: |
|
2926 | if it is None: | |
2932 | # slowly consume everything. This needs improvement |
|
2927 | # slowly consume everything. This needs improvement | |
2933 | it = lambda: reversed(list(self)) |
|
2928 | it = lambda: reversed(list(self)) | |
2934 | for x in it(): |
|
2929 | for x in it(): | |
2935 | return x |
|
2930 | return x | |
2936 | return None |
|
2931 | return None | |
2937 |
|
2932 | |||
2938 | def __repr__(self): |
|
2933 | def __repr__(self): | |
2939 | return '<%s %r>' % (type(self).__name__, self._subset) |
|
2934 | return '<%s %r>' % (type(self).__name__, self._subset) | |
2940 |
|
2935 | |||
2941 | class addset(abstractsmartset): |
|
2936 | class addset(abstractsmartset): | |
2942 | """Represent the addition of two sets |
|
2937 | """Represent the addition of two sets | |
2943 |
|
2938 | |||
2944 | Wrapper structure for lazily adding two structures without losing much |
|
2939 | Wrapper structure for lazily adding two structures without losing much | |
2945 | performance on the __contains__ method |
|
2940 | performance on the __contains__ method | |
2946 |
|
2941 | |||
2947 | If the ascending attribute is set, that means the two structures are |
|
2942 | If the ascending attribute is set, that means the two structures are | |
2948 | ordered in either an ascending or descending way. Therefore, we can add |
|
2943 | ordered in either an ascending or descending way. Therefore, we can add | |
2949 | them maintaining the order by iterating over both at the same time |
|
2944 | them maintaining the order by iterating over both at the same time | |
2950 | """ |
|
2945 | """ | |
2951 | def __init__(self, revs1, revs2, ascending=None): |
|
2946 | def __init__(self, revs1, revs2, ascending=None): | |
2952 | self._r1 = revs1 |
|
2947 | self._r1 = revs1 | |
2953 | self._r2 = revs2 |
|
2948 | self._r2 = revs2 | |
2954 | self._iter = None |
|
2949 | self._iter = None | |
2955 | self._ascending = ascending |
|
2950 | self._ascending = ascending | |
2956 | self._genlist = None |
|
2951 | self._genlist = None | |
2957 | self._asclist = None |
|
2952 | self._asclist = None | |
2958 |
|
2953 | |||
2959 | def __len__(self): |
|
2954 | def __len__(self): | |
2960 | return len(self._list) |
|
2955 | return len(self._list) | |
2961 |
|
2956 | |||
2962 | def __nonzero__(self): |
|
2957 | def __nonzero__(self): | |
2963 | return bool(self._r1) or bool(self._r2) |
|
2958 | return bool(self._r1) or bool(self._r2) | |
2964 |
|
2959 | |||
2965 | @util.propertycache |
|
2960 | @util.propertycache | |
2966 | def _list(self): |
|
2961 | def _list(self): | |
2967 | if not self._genlist: |
|
2962 | if not self._genlist: | |
2968 | self._genlist = baseset(self._iterator()) |
|
2963 | self._genlist = baseset(self._iterator()) | |
2969 | return self._genlist |
|
2964 | return self._genlist | |
2970 |
|
2965 | |||
2971 | def _iterator(self): |
|
2966 | def _iterator(self): | |
2972 | """Iterate over both collections without repeating elements |
|
2967 | """Iterate over both collections without repeating elements | |
2973 |
|
2968 | |||
2974 | If the ascending attribute is not set, iterate over the first one and |
|
2969 | If the ascending attribute is not set, iterate over the first one and | |
2975 | then over the second one checking for membership on the first one so we |
|
2970 | then over the second one checking for membership on the first one so we | |
2976 | dont yield any duplicates. |
|
2971 | dont yield any duplicates. | |
2977 |
|
2972 | |||
2978 | If the ascending attribute is set, iterate over both collections at the |
|
2973 | If the ascending attribute is set, iterate over both collections at the | |
2979 | same time, yielding only one value at a time in the given order. |
|
2974 | same time, yielding only one value at a time in the given order. | |
2980 | """ |
|
2975 | """ | |
2981 | if self._ascending is None: |
|
2976 | if self._ascending is None: | |
2982 | def gen(): |
|
2977 | def gen(): | |
2983 | for r in self._r1: |
|
2978 | for r in self._r1: | |
2984 | yield r |
|
2979 | yield r | |
2985 | inr1 = self._r1.__contains__ |
|
2980 | inr1 = self._r1.__contains__ | |
2986 | for r in self._r2: |
|
2981 | for r in self._r2: | |
2987 | if not inr1(r): |
|
2982 | if not inr1(r): | |
2988 | yield r |
|
2983 | yield r | |
2989 | gen = gen() |
|
2984 | gen = gen() | |
2990 | else: |
|
2985 | else: | |
2991 | iter1 = iter(self._r1) |
|
2986 | iter1 = iter(self._r1) | |
2992 | iter2 = iter(self._r2) |
|
2987 | iter2 = iter(self._r2) | |
2993 | gen = self._iterordered(self._ascending, iter1, iter2) |
|
2988 | gen = self._iterordered(self._ascending, iter1, iter2) | |
2994 | return gen |
|
2989 | return gen | |
2995 |
|
2990 | |||
2996 | def __iter__(self): |
|
2991 | def __iter__(self): | |
2997 | if self._ascending is None: |
|
2992 | if self._ascending is None: | |
2998 | if self._genlist: |
|
2993 | if self._genlist: | |
2999 | return iter(self._genlist) |
|
2994 | return iter(self._genlist) | |
3000 | return iter(self._iterator()) |
|
2995 | return iter(self._iterator()) | |
3001 | self._trysetasclist() |
|
2996 | self._trysetasclist() | |
3002 | if self._ascending: |
|
2997 | if self._ascending: | |
3003 | it = self.fastasc |
|
2998 | it = self.fastasc | |
3004 | else: |
|
2999 | else: | |
3005 | it = self.fastdesc |
|
3000 | it = self.fastdesc | |
3006 | if it is None: |
|
3001 | if it is None: | |
3007 | # consume the gen and try again |
|
3002 | # consume the gen and try again | |
3008 | self._list |
|
3003 | self._list | |
3009 | return iter(self) |
|
3004 | return iter(self) | |
3010 | return it() |
|
3005 | return it() | |
3011 |
|
3006 | |||
3012 | def _trysetasclist(self): |
|
3007 | def _trysetasclist(self): | |
3013 | """populate the _asclist attribute if possible and necessary""" |
|
3008 | """populate the _asclist attribute if possible and necessary""" | |
3014 | if self._genlist is not None and self._asclist is None: |
|
3009 | if self._genlist is not None and self._asclist is None: | |
3015 | self._asclist = sorted(self._genlist) |
|
3010 | self._asclist = sorted(self._genlist) | |
3016 |
|
3011 | |||
3017 | @property |
|
3012 | @property | |
3018 | def fastasc(self): |
|
3013 | def fastasc(self): | |
3019 | self._trysetasclist() |
|
3014 | self._trysetasclist() | |
3020 | if self._asclist is not None: |
|
3015 | if self._asclist is not None: | |
3021 | return self._asclist.__iter__ |
|
3016 | return self._asclist.__iter__ | |
3022 | iter1 = self._r1.fastasc |
|
3017 | iter1 = self._r1.fastasc | |
3023 | iter2 = self._r2.fastasc |
|
3018 | iter2 = self._r2.fastasc | |
3024 | if None in (iter1, iter2): |
|
3019 | if None in (iter1, iter2): | |
3025 | return None |
|
3020 | return None | |
3026 | return lambda: self._iterordered(True, iter1(), iter2()) |
|
3021 | return lambda: self._iterordered(True, iter1(), iter2()) | |
3027 |
|
3022 | |||
3028 | @property |
|
3023 | @property | |
3029 | def fastdesc(self): |
|
3024 | def fastdesc(self): | |
3030 | self._trysetasclist() |
|
3025 | self._trysetasclist() | |
3031 | if self._asclist is not None: |
|
3026 | if self._asclist is not None: | |
3032 | return self._asclist.__reversed__ |
|
3027 | return self._asclist.__reversed__ | |
3033 | iter1 = self._r1.fastdesc |
|
3028 | iter1 = self._r1.fastdesc | |
3034 | iter2 = self._r2.fastdesc |
|
3029 | iter2 = self._r2.fastdesc | |
3035 | if None in (iter1, iter2): |
|
3030 | if None in (iter1, iter2): | |
3036 | return None |
|
3031 | return None | |
3037 | return lambda: self._iterordered(False, iter1(), iter2()) |
|
3032 | return lambda: self._iterordered(False, iter1(), iter2()) | |
3038 |
|
3033 | |||
3039 | def _iterordered(self, ascending, iter1, iter2): |
|
3034 | def _iterordered(self, ascending, iter1, iter2): | |
3040 | """produce an ordered iteration from two iterators with the same order |
|
3035 | """produce an ordered iteration from two iterators with the same order | |
3041 |
|
3036 | |||
3042 | The ascending is used to indicated the iteration direction. |
|
3037 | The ascending is used to indicated the iteration direction. | |
3043 | """ |
|
3038 | """ | |
3044 | choice = max |
|
3039 | choice = max | |
3045 | if ascending: |
|
3040 | if ascending: | |
3046 | choice = min |
|
3041 | choice = min | |
3047 |
|
3042 | |||
3048 | val1 = None |
|
3043 | val1 = None | |
3049 | val2 = None |
|
3044 | val2 = None | |
3050 |
|
3045 | |||
3051 | choice = max |
|
3046 | choice = max | |
3052 | if ascending: |
|
3047 | if ascending: | |
3053 | choice = min |
|
3048 | choice = min | |
3054 | try: |
|
3049 | try: | |
3055 | # Consume both iterators in an ordered way until one is |
|
3050 | # Consume both iterators in an ordered way until one is | |
3056 | # empty |
|
3051 | # empty | |
3057 | while True: |
|
3052 | while True: | |
3058 | if val1 is None: |
|
3053 | if val1 is None: | |
3059 | val1 = iter1.next() |
|
3054 | val1 = iter1.next() | |
3060 | if val2 is None: |
|
3055 | if val2 is None: | |
3061 | val2 = iter2.next() |
|
3056 | val2 = iter2.next() | |
3062 | next = choice(val1, val2) |
|
3057 | next = choice(val1, val2) | |
3063 | yield next |
|
3058 | yield next | |
3064 | if val1 == next: |
|
3059 | if val1 == next: | |
3065 | val1 = None |
|
3060 | val1 = None | |
3066 | if val2 == next: |
|
3061 | if val2 == next: | |
3067 | val2 = None |
|
3062 | val2 = None | |
3068 | except StopIteration: |
|
3063 | except StopIteration: | |
3069 | # Flush any remaining values and consume the other one |
|
3064 | # Flush any remaining values and consume the other one | |
3070 | it = iter2 |
|
3065 | it = iter2 | |
3071 | if val1 is not None: |
|
3066 | if val1 is not None: | |
3072 | yield val1 |
|
3067 | yield val1 | |
3073 | it = iter1 |
|
3068 | it = iter1 | |
3074 | elif val2 is not None: |
|
3069 | elif val2 is not None: | |
3075 | # might have been equality and both are empty |
|
3070 | # might have been equality and both are empty | |
3076 | yield val2 |
|
3071 | yield val2 | |
3077 | for val in it: |
|
3072 | for val in it: | |
3078 | yield val |
|
3073 | yield val | |
3079 |
|
3074 | |||
3080 | def __contains__(self, x): |
|
3075 | def __contains__(self, x): | |
3081 | return x in self._r1 or x in self._r2 |
|
3076 | return x in self._r1 or x in self._r2 | |
3082 |
|
3077 | |||
3083 | def sort(self, reverse=False): |
|
3078 | def sort(self, reverse=False): | |
3084 | """Sort the added set |
|
3079 | """Sort the added set | |
3085 |
|
3080 | |||
3086 | For this we use the cached list with all the generated values and if we |
|
3081 | For this we use the cached list with all the generated values and if we | |
3087 | know they are ascending or descending we can sort them in a smart way. |
|
3082 | know they are ascending or descending we can sort them in a smart way. | |
3088 | """ |
|
3083 | """ | |
3089 | self._ascending = not reverse |
|
3084 | self._ascending = not reverse | |
3090 |
|
3085 | |||
3091 | def isascending(self): |
|
3086 | def isascending(self): | |
3092 | return self._ascending is not None and self._ascending |
|
3087 | return self._ascending is not None and self._ascending | |
3093 |
|
3088 | |||
3094 | def isdescending(self): |
|
3089 | def isdescending(self): | |
3095 | return self._ascending is not None and not self._ascending |
|
3090 | return self._ascending is not None and not self._ascending | |
3096 |
|
3091 | |||
3097 | def reverse(self): |
|
3092 | def reverse(self): | |
3098 | if self._ascending is None: |
|
3093 | if self._ascending is None: | |
3099 | self._list.reverse() |
|
3094 | self._list.reverse() | |
3100 | else: |
|
3095 | else: | |
3101 | self._ascending = not self._ascending |
|
3096 | self._ascending = not self._ascending | |
3102 |
|
3097 | |||
3103 | def first(self): |
|
3098 | def first(self): | |
3104 | for x in self: |
|
3099 | for x in self: | |
3105 | return x |
|
3100 | return x | |
3106 | return None |
|
3101 | return None | |
3107 |
|
3102 | |||
3108 | def last(self): |
|
3103 | def last(self): | |
3109 | self.reverse() |
|
3104 | self.reverse() | |
3110 | val = self.first() |
|
3105 | val = self.first() | |
3111 | self.reverse() |
|
3106 | self.reverse() | |
3112 | return val |
|
3107 | return val | |
3113 |
|
3108 | |||
3114 | def __repr__(self): |
|
3109 | def __repr__(self): | |
3115 | d = {None: '', False: '-', True: '+'}[self._ascending] |
|
3110 | d = {None: '', False: '-', True: '+'}[self._ascending] | |
3116 | return '<%s%s %r, %r>' % (type(self).__name__, d, self._r1, self._r2) |
|
3111 | return '<%s%s %r, %r>' % (type(self).__name__, d, self._r1, self._r2) | |
3117 |
|
3112 | |||
3118 | class generatorset(abstractsmartset): |
|
3113 | class generatorset(abstractsmartset): | |
3119 | """Wrap a generator for lazy iteration |
|
3114 | """Wrap a generator for lazy iteration | |
3120 |
|
3115 | |||
3121 | Wrapper structure for generators that provides lazy membership and can |
|
3116 | Wrapper structure for generators that provides lazy membership and can | |
3122 | be iterated more than once. |
|
3117 | be iterated more than once. | |
3123 | When asked for membership it generates values until either it finds the |
|
3118 | When asked for membership it generates values until either it finds the | |
3124 | requested one or has gone through all the elements in the generator |
|
3119 | requested one or has gone through all the elements in the generator | |
3125 | """ |
|
3120 | """ | |
3126 | def __init__(self, gen, iterasc=None): |
|
3121 | def __init__(self, gen, iterasc=None): | |
3127 | """ |
|
3122 | """ | |
3128 | gen: a generator producing the values for the generatorset. |
|
3123 | gen: a generator producing the values for the generatorset. | |
3129 | """ |
|
3124 | """ | |
3130 | self._gen = gen |
|
3125 | self._gen = gen | |
3131 | self._asclist = None |
|
3126 | self._asclist = None | |
3132 | self._cache = {} |
|
3127 | self._cache = {} | |
3133 | self._genlist = [] |
|
3128 | self._genlist = [] | |
3134 | self._finished = False |
|
3129 | self._finished = False | |
3135 | self._ascending = True |
|
3130 | self._ascending = True | |
3136 | if iterasc is not None: |
|
3131 | if iterasc is not None: | |
3137 | if iterasc: |
|
3132 | if iterasc: | |
3138 | self.fastasc = self._iterator |
|
3133 | self.fastasc = self._iterator | |
3139 | self.__contains__ = self._asccontains |
|
3134 | self.__contains__ = self._asccontains | |
3140 | else: |
|
3135 | else: | |
3141 | self.fastdesc = self._iterator |
|
3136 | self.fastdesc = self._iterator | |
3142 | self.__contains__ = self._desccontains |
|
3137 | self.__contains__ = self._desccontains | |
3143 |
|
3138 | |||
3144 | def __nonzero__(self): |
|
3139 | def __nonzero__(self): | |
3145 | for r in self: |
|
3140 | for r in self: | |
3146 | return True |
|
3141 | return True | |
3147 | return False |
|
3142 | return False | |
3148 |
|
3143 | |||
3149 | def __contains__(self, x): |
|
3144 | def __contains__(self, x): | |
3150 | if x in self._cache: |
|
3145 | if x in self._cache: | |
3151 | return self._cache[x] |
|
3146 | return self._cache[x] | |
3152 |
|
3147 | |||
3153 | # Use new values only, as existing values would be cached. |
|
3148 | # Use new values only, as existing values would be cached. | |
3154 | for l in self._consumegen(): |
|
3149 | for l in self._consumegen(): | |
3155 | if l == x: |
|
3150 | if l == x: | |
3156 | return True |
|
3151 | return True | |
3157 |
|
3152 | |||
3158 | self._cache[x] = False |
|
3153 | self._cache[x] = False | |
3159 | return False |
|
3154 | return False | |
3160 |
|
3155 | |||
3161 | def _asccontains(self, x): |
|
3156 | def _asccontains(self, x): | |
3162 | """version of contains optimised for ascending generator""" |
|
3157 | """version of contains optimised for ascending generator""" | |
3163 | if x in self._cache: |
|
3158 | if x in self._cache: | |
3164 | return self._cache[x] |
|
3159 | return self._cache[x] | |
3165 |
|
3160 | |||
3166 | # Use new values only, as existing values would be cached. |
|
3161 | # Use new values only, as existing values would be cached. | |
3167 | for l in self._consumegen(): |
|
3162 | for l in self._consumegen(): | |
3168 | if l == x: |
|
3163 | if l == x: | |
3169 | return True |
|
3164 | return True | |
3170 | if l > x: |
|
3165 | if l > x: | |
3171 | break |
|
3166 | break | |
3172 |
|
3167 | |||
3173 | self._cache[x] = False |
|
3168 | self._cache[x] = False | |
3174 | return False |
|
3169 | return False | |
3175 |
|
3170 | |||
3176 | def _desccontains(self, x): |
|
3171 | def _desccontains(self, x): | |
3177 | """version of contains optimised for descending generator""" |
|
3172 | """version of contains optimised for descending generator""" | |
3178 | if x in self._cache: |
|
3173 | if x in self._cache: | |
3179 | return self._cache[x] |
|
3174 | return self._cache[x] | |
3180 |
|
3175 | |||
3181 | # Use new values only, as existing values would be cached. |
|
3176 | # Use new values only, as existing values would be cached. | |
3182 | for l in self._consumegen(): |
|
3177 | for l in self._consumegen(): | |
3183 | if l == x: |
|
3178 | if l == x: | |
3184 | return True |
|
3179 | return True | |
3185 | if l < x: |
|
3180 | if l < x: | |
3186 | break |
|
3181 | break | |
3187 |
|
3182 | |||
3188 | self._cache[x] = False |
|
3183 | self._cache[x] = False | |
3189 | return False |
|
3184 | return False | |
3190 |
|
3185 | |||
3191 | def __iter__(self): |
|
3186 | def __iter__(self): | |
3192 | if self._ascending: |
|
3187 | if self._ascending: | |
3193 | it = self.fastasc |
|
3188 | it = self.fastasc | |
3194 | else: |
|
3189 | else: | |
3195 | it = self.fastdesc |
|
3190 | it = self.fastdesc | |
3196 | if it is not None: |
|
3191 | if it is not None: | |
3197 | return it() |
|
3192 | return it() | |
3198 | # we need to consume the iterator |
|
3193 | # we need to consume the iterator | |
3199 | for x in self._consumegen(): |
|
3194 | for x in self._consumegen(): | |
3200 | pass |
|
3195 | pass | |
3201 | # recall the same code |
|
3196 | # recall the same code | |
3202 | return iter(self) |
|
3197 | return iter(self) | |
3203 |
|
3198 | |||
3204 | def _iterator(self): |
|
3199 | def _iterator(self): | |
3205 | if self._finished: |
|
3200 | if self._finished: | |
3206 | return iter(self._genlist) |
|
3201 | return iter(self._genlist) | |
3207 |
|
3202 | |||
3208 | # We have to use this complex iteration strategy to allow multiple |
|
3203 | # We have to use this complex iteration strategy to allow multiple | |
3209 | # iterations at the same time. We need to be able to catch revision |
|
3204 | # iterations at the same time. We need to be able to catch revision | |
3210 | # removed from _consumegen and added to genlist in another instance. |
|
3205 | # removed from _consumegen and added to genlist in another instance. | |
3211 | # |
|
3206 | # | |
3212 | # Getting rid of it would provide an about 15% speed up on this |
|
3207 | # Getting rid of it would provide an about 15% speed up on this | |
3213 | # iteration. |
|
3208 | # iteration. | |
3214 | genlist = self._genlist |
|
3209 | genlist = self._genlist | |
3215 | nextrev = self._consumegen().next |
|
3210 | nextrev = self._consumegen().next | |
3216 | _len = len # cache global lookup |
|
3211 | _len = len # cache global lookup | |
3217 | def gen(): |
|
3212 | def gen(): | |
3218 | i = 0 |
|
3213 | i = 0 | |
3219 | while True: |
|
3214 | while True: | |
3220 | if i < _len(genlist): |
|
3215 | if i < _len(genlist): | |
3221 | yield genlist[i] |
|
3216 | yield genlist[i] | |
3222 | else: |
|
3217 | else: | |
3223 | yield nextrev() |
|
3218 | yield nextrev() | |
3224 | i += 1 |
|
3219 | i += 1 | |
3225 | return gen() |
|
3220 | return gen() | |
3226 |
|
3221 | |||
3227 | def _consumegen(self): |
|
3222 | def _consumegen(self): | |
3228 | cache = self._cache |
|
3223 | cache = self._cache | |
3229 | genlist = self._genlist.append |
|
3224 | genlist = self._genlist.append | |
3230 | for item in self._gen: |
|
3225 | for item in self._gen: | |
3231 | cache[item] = True |
|
3226 | cache[item] = True | |
3232 | genlist(item) |
|
3227 | genlist(item) | |
3233 | yield item |
|
3228 | yield item | |
3234 | if not self._finished: |
|
3229 | if not self._finished: | |
3235 | self._finished = True |
|
3230 | self._finished = True | |
3236 | asc = self._genlist[:] |
|
3231 | asc = self._genlist[:] | |
3237 | asc.sort() |
|
3232 | asc.sort() | |
3238 | self._asclist = asc |
|
3233 | self._asclist = asc | |
3239 | self.fastasc = asc.__iter__ |
|
3234 | self.fastasc = asc.__iter__ | |
3240 | self.fastdesc = asc.__reversed__ |
|
3235 | self.fastdesc = asc.__reversed__ | |
3241 |
|
3236 | |||
3242 | def __len__(self): |
|
3237 | def __len__(self): | |
3243 | for x in self._consumegen(): |
|
3238 | for x in self._consumegen(): | |
3244 | pass |
|
3239 | pass | |
3245 | return len(self._genlist) |
|
3240 | return len(self._genlist) | |
3246 |
|
3241 | |||
3247 | def sort(self, reverse=False): |
|
3242 | def sort(self, reverse=False): | |
3248 | self._ascending = not reverse |
|
3243 | self._ascending = not reverse | |
3249 |
|
3244 | |||
3250 | def reverse(self): |
|
3245 | def reverse(self): | |
3251 | self._ascending = not self._ascending |
|
3246 | self._ascending = not self._ascending | |
3252 |
|
3247 | |||
3253 | def isascending(self): |
|
3248 | def isascending(self): | |
3254 | return self._ascending |
|
3249 | return self._ascending | |
3255 |
|
3250 | |||
3256 | def isdescending(self): |
|
3251 | def isdescending(self): | |
3257 | return not self._ascending |
|
3252 | return not self._ascending | |
3258 |
|
3253 | |||
3259 | def first(self): |
|
3254 | def first(self): | |
3260 | if self._ascending: |
|
3255 | if self._ascending: | |
3261 | it = self.fastasc |
|
3256 | it = self.fastasc | |
3262 | else: |
|
3257 | else: | |
3263 | it = self.fastdesc |
|
3258 | it = self.fastdesc | |
3264 | if it is None: |
|
3259 | if it is None: | |
3265 | # we need to consume all and try again |
|
3260 | # we need to consume all and try again | |
3266 | for x in self._consumegen(): |
|
3261 | for x in self._consumegen(): | |
3267 | pass |
|
3262 | pass | |
3268 | return self.first() |
|
3263 | return self.first() | |
3269 | if self: |
|
3264 | if self: | |
3270 | return it().next() |
|
3265 | return it().next() | |
3271 | return None |
|
3266 | return None | |
3272 |
|
3267 | |||
3273 | def last(self): |
|
3268 | def last(self): | |
3274 | if self._ascending: |
|
3269 | if self._ascending: | |
3275 | it = self.fastdesc |
|
3270 | it = self.fastdesc | |
3276 | else: |
|
3271 | else: | |
3277 | it = self.fastasc |
|
3272 | it = self.fastasc | |
3278 | if it is None: |
|
3273 | if it is None: | |
3279 | # we need to consume all and try again |
|
3274 | # we need to consume all and try again | |
3280 | for x in self._consumegen(): |
|
3275 | for x in self._consumegen(): | |
3281 | pass |
|
3276 | pass | |
3282 | return self.first() |
|
3277 | return self.first() | |
3283 | if self: |
|
3278 | if self: | |
3284 | return it().next() |
|
3279 | return it().next() | |
3285 | return None |
|
3280 | return None | |
3286 |
|
3281 | |||
3287 | def __repr__(self): |
|
3282 | def __repr__(self): | |
3288 | d = {False: '-', True: '+'}[self._ascending] |
|
3283 | d = {False: '-', True: '+'}[self._ascending] | |
3289 | return '<%s%s>' % (type(self).__name__, d) |
|
3284 | return '<%s%s>' % (type(self).__name__, d) | |
3290 |
|
3285 | |||
3291 | class spanset(abstractsmartset): |
|
3286 | class spanset(abstractsmartset): | |
3292 | """Duck type for baseset class which represents a range of revisions and |
|
3287 | """Duck type for baseset class which represents a range of revisions and | |
3293 | can work lazily and without having all the range in memory |
|
3288 | can work lazily and without having all the range in memory | |
3294 |
|
3289 | |||
3295 | Note that spanset(x, y) behave almost like xrange(x, y) except for two |
|
3290 | Note that spanset(x, y) behave almost like xrange(x, y) except for two | |
3296 | notable points: |
|
3291 | notable points: | |
3297 | - when x < y it will be automatically descending, |
|
3292 | - when x < y it will be automatically descending, | |
3298 | - revision filtered with this repoview will be skipped. |
|
3293 | - revision filtered with this repoview will be skipped. | |
3299 |
|
3294 | |||
3300 | """ |
|
3295 | """ | |
3301 | def __init__(self, repo, start=0, end=None): |
|
3296 | def __init__(self, repo, start=0, end=None): | |
3302 | """ |
|
3297 | """ | |
3303 | start: first revision included the set |
|
3298 | start: first revision included the set | |
3304 | (default to 0) |
|
3299 | (default to 0) | |
3305 | end: first revision excluded (last+1) |
|
3300 | end: first revision excluded (last+1) | |
3306 | (default to len(repo) |
|
3301 | (default to len(repo) | |
3307 |
|
3302 | |||
3308 | Spanset will be descending if `end` < `start`. |
|
3303 | Spanset will be descending if `end` < `start`. | |
3309 | """ |
|
3304 | """ | |
3310 | if end is None: |
|
3305 | if end is None: | |
3311 | end = len(repo) |
|
3306 | end = len(repo) | |
3312 | self._ascending = start <= end |
|
3307 | self._ascending = start <= end | |
3313 | if not self._ascending: |
|
3308 | if not self._ascending: | |
3314 | start, end = end + 1, start +1 |
|
3309 | start, end = end + 1, start +1 | |
3315 | self._start = start |
|
3310 | self._start = start | |
3316 | self._end = end |
|
3311 | self._end = end | |
3317 | self._hiddenrevs = repo.changelog.filteredrevs |
|
3312 | self._hiddenrevs = repo.changelog.filteredrevs | |
3318 |
|
3313 | |||
3319 | def sort(self, reverse=False): |
|
3314 | def sort(self, reverse=False): | |
3320 | self._ascending = not reverse |
|
3315 | self._ascending = not reverse | |
3321 |
|
3316 | |||
3322 | def reverse(self): |
|
3317 | def reverse(self): | |
3323 | self._ascending = not self._ascending |
|
3318 | self._ascending = not self._ascending | |
3324 |
|
3319 | |||
3325 | def _iterfilter(self, iterrange): |
|
3320 | def _iterfilter(self, iterrange): | |
3326 | s = self._hiddenrevs |
|
3321 | s = self._hiddenrevs | |
3327 | for r in iterrange: |
|
3322 | for r in iterrange: | |
3328 | if r not in s: |
|
3323 | if r not in s: | |
3329 | yield r |
|
3324 | yield r | |
3330 |
|
3325 | |||
3331 | def __iter__(self): |
|
3326 | def __iter__(self): | |
3332 | if self._ascending: |
|
3327 | if self._ascending: | |
3333 | return self.fastasc() |
|
3328 | return self.fastasc() | |
3334 | else: |
|
3329 | else: | |
3335 | return self.fastdesc() |
|
3330 | return self.fastdesc() | |
3336 |
|
3331 | |||
3337 | def fastasc(self): |
|
3332 | def fastasc(self): | |
3338 | iterrange = xrange(self._start, self._end) |
|
3333 | iterrange = xrange(self._start, self._end) | |
3339 | if self._hiddenrevs: |
|
3334 | if self._hiddenrevs: | |
3340 | return self._iterfilter(iterrange) |
|
3335 | return self._iterfilter(iterrange) | |
3341 | return iter(iterrange) |
|
3336 | return iter(iterrange) | |
3342 |
|
3337 | |||
3343 | def fastdesc(self): |
|
3338 | def fastdesc(self): | |
3344 | iterrange = xrange(self._end - 1, self._start - 1, -1) |
|
3339 | iterrange = xrange(self._end - 1, self._start - 1, -1) | |
3345 | if self._hiddenrevs: |
|
3340 | if self._hiddenrevs: | |
3346 | return self._iterfilter(iterrange) |
|
3341 | return self._iterfilter(iterrange) | |
3347 | return iter(iterrange) |
|
3342 | return iter(iterrange) | |
3348 |
|
3343 | |||
3349 | def __contains__(self, rev): |
|
3344 | def __contains__(self, rev): | |
3350 | hidden = self._hiddenrevs |
|
3345 | hidden = self._hiddenrevs | |
3351 | return ((self._start <= rev < self._end) |
|
3346 | return ((self._start <= rev < self._end) | |
3352 | and not (hidden and rev in hidden)) |
|
3347 | and not (hidden and rev in hidden)) | |
3353 |
|
3348 | |||
3354 | def __nonzero__(self): |
|
3349 | def __nonzero__(self): | |
3355 | for r in self: |
|
3350 | for r in self: | |
3356 | return True |
|
3351 | return True | |
3357 | return False |
|
3352 | return False | |
3358 |
|
3353 | |||
3359 | def __len__(self): |
|
3354 | def __len__(self): | |
3360 | if not self._hiddenrevs: |
|
3355 | if not self._hiddenrevs: | |
3361 | return abs(self._end - self._start) |
|
3356 | return abs(self._end - self._start) | |
3362 | else: |
|
3357 | else: | |
3363 | count = 0 |
|
3358 | count = 0 | |
3364 | start = self._start |
|
3359 | start = self._start | |
3365 | end = self._end |
|
3360 | end = self._end | |
3366 | for rev in self._hiddenrevs: |
|
3361 | for rev in self._hiddenrevs: | |
3367 | if (end < rev <= start) or (start <= rev < end): |
|
3362 | if (end < rev <= start) or (start <= rev < end): | |
3368 | count += 1 |
|
3363 | count += 1 | |
3369 | return abs(self._end - self._start) - count |
|
3364 | return abs(self._end - self._start) - count | |
3370 |
|
3365 | |||
3371 | def isascending(self): |
|
3366 | def isascending(self): | |
3372 | return self._ascending |
|
3367 | return self._ascending | |
3373 |
|
3368 | |||
3374 | def isdescending(self): |
|
3369 | def isdescending(self): | |
3375 | return not self._ascending |
|
3370 | return not self._ascending | |
3376 |
|
3371 | |||
3377 | def first(self): |
|
3372 | def first(self): | |
3378 | if self._ascending: |
|
3373 | if self._ascending: | |
3379 | it = self.fastasc |
|
3374 | it = self.fastasc | |
3380 | else: |
|
3375 | else: | |
3381 | it = self.fastdesc |
|
3376 | it = self.fastdesc | |
3382 | for x in it(): |
|
3377 | for x in it(): | |
3383 | return x |
|
3378 | return x | |
3384 | return None |
|
3379 | return None | |
3385 |
|
3380 | |||
3386 | def last(self): |
|
3381 | def last(self): | |
3387 | if self._ascending: |
|
3382 | if self._ascending: | |
3388 | it = self.fastdesc |
|
3383 | it = self.fastdesc | |
3389 | else: |
|
3384 | else: | |
3390 | it = self.fastasc |
|
3385 | it = self.fastasc | |
3391 | for x in it(): |
|
3386 | for x in it(): | |
3392 | return x |
|
3387 | return x | |
3393 | return None |
|
3388 | return None | |
3394 |
|
3389 | |||
3395 | def __repr__(self): |
|
3390 | def __repr__(self): | |
3396 | d = {False: '-', True: '+'}[self._ascending] |
|
3391 | d = {False: '-', True: '+'}[self._ascending] | |
3397 | return '<%s%s %d:%d>' % (type(self).__name__, d, |
|
3392 | return '<%s%s %d:%d>' % (type(self).__name__, d, | |
3398 | self._start, self._end - 1) |
|
3393 | self._start, self._end - 1) | |
3399 |
|
3394 | |||
3400 | class fullreposet(spanset): |
|
3395 | class fullreposet(spanset): | |
3401 | """a set containing all revisions in the repo |
|
3396 | """a set containing all revisions in the repo | |
3402 |
|
3397 | |||
3403 | This class exists to host special optimization and magic to handle virtual |
|
3398 | This class exists to host special optimization and magic to handle virtual | |
3404 | revisions such as "null". |
|
3399 | revisions such as "null". | |
3405 | """ |
|
3400 | """ | |
3406 |
|
3401 | |||
3407 | def __init__(self, repo): |
|
3402 | def __init__(self, repo): | |
3408 | super(fullreposet, self).__init__(repo) |
|
3403 | super(fullreposet, self).__init__(repo) | |
3409 |
|
3404 | |||
3410 | def __contains__(self, rev): |
|
3405 | def __contains__(self, rev): | |
3411 | # assumes the given rev is valid |
|
3406 | # assumes the given rev is valid | |
3412 | hidden = self._hiddenrevs |
|
3407 | hidden = self._hiddenrevs | |
3413 | return not (hidden and rev in hidden) |
|
3408 | return not (hidden and rev in hidden) | |
3414 |
|
3409 | |||
3415 | def __and__(self, other): |
|
3410 | def __and__(self, other): | |
3416 | """As self contains the whole repo, all of the other set should also be |
|
3411 | """As self contains the whole repo, all of the other set should also be | |
3417 | in self. Therefore `self & other = other`. |
|
3412 | in self. Therefore `self & other = other`. | |
3418 |
|
3413 | |||
3419 | This boldly assumes the other contains valid revs only. |
|
3414 | This boldly assumes the other contains valid revs only. | |
3420 | """ |
|
3415 | """ | |
3421 | # other not a smartset, make is so |
|
3416 | # other not a smartset, make is so | |
3422 | if not util.safehasattr(other, 'isascending'): |
|
3417 | if not util.safehasattr(other, 'isascending'): | |
3423 | # filter out hidden revision |
|
3418 | # filter out hidden revision | |
3424 | # (this boldly assumes all smartset are pure) |
|
3419 | # (this boldly assumes all smartset are pure) | |
3425 | # |
|
3420 | # | |
3426 | # `other` was used with "&", let's assume this is a set like |
|
3421 | # `other` was used with "&", let's assume this is a set like | |
3427 | # object. |
|
3422 | # object. | |
3428 | other = baseset(other - self._hiddenrevs) |
|
3423 | other = baseset(other - self._hiddenrevs) | |
3429 |
|
3424 | |||
3430 | other.sort(reverse=self.isdescending()) |
|
3425 | other.sort(reverse=self.isdescending()) | |
3431 | return other |
|
3426 | return other | |
3432 |
|
3427 | |||
3433 | def prettyformatset(revs): |
|
3428 | def prettyformatset(revs): | |
3434 | lines = [] |
|
3429 | lines = [] | |
3435 | rs = repr(revs) |
|
3430 | rs = repr(revs) | |
3436 | p = 0 |
|
3431 | p = 0 | |
3437 | while p < len(rs): |
|
3432 | while p < len(rs): | |
3438 | q = rs.find('<', p + 1) |
|
3433 | q = rs.find('<', p + 1) | |
3439 | if q < 0: |
|
3434 | if q < 0: | |
3440 | q = len(rs) |
|
3435 | q = len(rs) | |
3441 | l = rs.count('<', 0, p) - rs.count('>', 0, p) |
|
3436 | l = rs.count('<', 0, p) - rs.count('>', 0, p) | |
3442 | assert l >= 0 |
|
3437 | assert l >= 0 | |
3443 | lines.append((l, rs[p:q].rstrip())) |
|
3438 | lines.append((l, rs[p:q].rstrip())) | |
3444 | p = q |
|
3439 | p = q | |
3445 | return '\n'.join(' ' * l + s for l, s in lines) |
|
3440 | return '\n'.join(' ' * l + s for l, s in lines) | |
3446 |
|
3441 | |||
3447 | # tell hggettext to extract docstrings from these functions: |
|
3442 | # tell hggettext to extract docstrings from these functions: | |
3448 | i18nfunctions = symbols.values() |
|
3443 | i18nfunctions = symbols.values() |
@@ -1,1619 +1,1648 b'' | |||||
1 | $ HGENCODING=utf-8 |
|
1 | $ HGENCODING=utf-8 | |
2 | $ export HGENCODING |
|
2 | $ export HGENCODING | |
3 |
|
3 | |||
4 | $ try() { |
|
4 | $ try() { | |
5 | > hg debugrevspec --debug "$@" |
|
5 | > hg debugrevspec --debug "$@" | |
6 | > } |
|
6 | > } | |
7 |
|
7 | |||
8 | $ log() { |
|
8 | $ log() { | |
9 | > hg log --template '{rev}\n' -r "$1" |
|
9 | > hg log --template '{rev}\n' -r "$1" | |
10 | > } |
|
10 | > } | |
11 |
|
11 | |||
12 | $ hg init repo |
|
12 | $ hg init repo | |
13 | $ cd repo |
|
13 | $ cd repo | |
14 |
|
14 | |||
15 | $ echo a > a |
|
15 | $ echo a > a | |
16 | $ hg branch a |
|
16 | $ hg branch a | |
17 | marked working directory as branch a |
|
17 | marked working directory as branch a | |
18 | (branches are permanent and global, did you want a bookmark?) |
|
18 | (branches are permanent and global, did you want a bookmark?) | |
19 | $ hg ci -Aqm0 |
|
19 | $ hg ci -Aqm0 | |
20 |
|
20 | |||
21 | $ echo b > b |
|
21 | $ echo b > b | |
22 | $ hg branch b |
|
22 | $ hg branch b | |
23 | marked working directory as branch b |
|
23 | marked working directory as branch b | |
24 | (branches are permanent and global, did you want a bookmark?) |
|
24 | (branches are permanent and global, did you want a bookmark?) | |
25 | $ hg ci -Aqm1 |
|
25 | $ hg ci -Aqm1 | |
26 |
|
26 | |||
27 | $ rm a |
|
27 | $ rm a | |
28 | $ hg branch a-b-c- |
|
28 | $ hg branch a-b-c- | |
29 | marked working directory as branch a-b-c- |
|
29 | marked working directory as branch a-b-c- | |
30 | (branches are permanent and global, did you want a bookmark?) |
|
30 | (branches are permanent and global, did you want a bookmark?) | |
31 | $ hg ci -Aqm2 -u Bob |
|
31 | $ hg ci -Aqm2 -u Bob | |
32 |
|
32 | |||
33 | $ hg log -r "extra('branch', 'a-b-c-')" --template '{rev}\n' |
|
33 | $ hg log -r "extra('branch', 'a-b-c-')" --template '{rev}\n' | |
34 | 2 |
|
34 | 2 | |
35 | $ hg log -r "extra('branch')" --template '{rev}\n' |
|
35 | $ hg log -r "extra('branch')" --template '{rev}\n' | |
36 | 0 |
|
36 | 0 | |
37 | 1 |
|
37 | 1 | |
38 | 2 |
|
38 | 2 | |
39 | $ hg log -r "extra('branch', 're:a')" --template '{rev} {branch}\n' |
|
39 | $ hg log -r "extra('branch', 're:a')" --template '{rev} {branch}\n' | |
40 | 0 a |
|
40 | 0 a | |
41 | 2 a-b-c- |
|
41 | 2 a-b-c- | |
42 |
|
42 | |||
43 | $ hg co 1 |
|
43 | $ hg co 1 | |
44 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
44 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
45 | $ hg branch +a+b+c+ |
|
45 | $ hg branch +a+b+c+ | |
46 | marked working directory as branch +a+b+c+ |
|
46 | marked working directory as branch +a+b+c+ | |
47 | (branches are permanent and global, did you want a bookmark?) |
|
47 | (branches are permanent and global, did you want a bookmark?) | |
48 | $ hg ci -Aqm3 |
|
48 | $ hg ci -Aqm3 | |
49 |
|
49 | |||
50 | $ hg co 2 # interleave |
|
50 | $ hg co 2 # interleave | |
51 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
51 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
52 | $ echo bb > b |
|
52 | $ echo bb > b | |
53 | $ hg branch -- -a-b-c- |
|
53 | $ hg branch -- -a-b-c- | |
54 | marked working directory as branch -a-b-c- |
|
54 | marked working directory as branch -a-b-c- | |
55 | (branches are permanent and global, did you want a bookmark?) |
|
55 | (branches are permanent and global, did you want a bookmark?) | |
56 | $ hg ci -Aqm4 -d "May 12 2005" |
|
56 | $ hg ci -Aqm4 -d "May 12 2005" | |
57 |
|
57 | |||
58 | $ hg co 3 |
|
58 | $ hg co 3 | |
59 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
59 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
60 | $ hg branch !a/b/c/ |
|
60 | $ hg branch !a/b/c/ | |
61 | marked working directory as branch !a/b/c/ |
|
61 | marked working directory as branch !a/b/c/ | |
62 | (branches are permanent and global, did you want a bookmark?) |
|
62 | (branches are permanent and global, did you want a bookmark?) | |
63 | $ hg ci -Aqm"5 bug" |
|
63 | $ hg ci -Aqm"5 bug" | |
64 |
|
64 | |||
65 | $ hg merge 4 |
|
65 | $ hg merge 4 | |
66 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
66 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
67 | (branch merge, don't forget to commit) |
|
67 | (branch merge, don't forget to commit) | |
68 | $ hg branch _a_b_c_ |
|
68 | $ hg branch _a_b_c_ | |
69 | marked working directory as branch _a_b_c_ |
|
69 | marked working directory as branch _a_b_c_ | |
70 | (branches are permanent and global, did you want a bookmark?) |
|
70 | (branches are permanent and global, did you want a bookmark?) | |
71 | $ hg ci -Aqm"6 issue619" |
|
71 | $ hg ci -Aqm"6 issue619" | |
72 |
|
72 | |||
73 | $ hg branch .a.b.c. |
|
73 | $ hg branch .a.b.c. | |
74 | marked working directory as branch .a.b.c. |
|
74 | marked working directory as branch .a.b.c. | |
75 | (branches are permanent and global, did you want a bookmark?) |
|
75 | (branches are permanent and global, did you want a bookmark?) | |
76 | $ hg ci -Aqm7 |
|
76 | $ hg ci -Aqm7 | |
77 |
|
77 | |||
78 | $ hg branch all |
|
78 | $ hg branch all | |
79 | marked working directory as branch all |
|
79 | marked working directory as branch all | |
80 | (branches are permanent and global, did you want a bookmark?) |
|
80 | (branches are permanent and global, did you want a bookmark?) | |
81 |
|
81 | |||
82 | $ hg co 4 |
|
82 | $ hg co 4 | |
83 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
83 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
84 | $ hg branch é |
|
84 | $ hg branch é | |
85 | marked working directory as branch \xc3\xa9 (esc) |
|
85 | marked working directory as branch \xc3\xa9 (esc) | |
86 | (branches are permanent and global, did you want a bookmark?) |
|
86 | (branches are permanent and global, did you want a bookmark?) | |
87 | $ hg ci -Aqm9 |
|
87 | $ hg ci -Aqm9 | |
88 |
|
88 | |||
89 | $ hg tag -r6 1.0 |
|
89 | $ hg tag -r6 1.0 | |
90 | $ hg bookmark -r6 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
90 | $ hg bookmark -r6 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
91 |
|
91 | |||
92 | $ hg clone --quiet -U -r 7 . ../remote1 |
|
92 | $ hg clone --quiet -U -r 7 . ../remote1 | |
93 | $ hg clone --quiet -U -r 8 . ../remote2 |
|
93 | $ hg clone --quiet -U -r 8 . ../remote2 | |
94 | $ echo "[paths]" >> .hg/hgrc |
|
94 | $ echo "[paths]" >> .hg/hgrc | |
95 | $ echo "default = ../remote1" >> .hg/hgrc |
|
95 | $ echo "default = ../remote1" >> .hg/hgrc | |
96 |
|
96 | |||
97 | trivial |
|
97 | trivial | |
98 |
|
98 | |||
99 | $ try 0:1 |
|
99 | $ try 0:1 | |
100 | (range |
|
100 | (range | |
101 | ('symbol', '0') |
|
101 | ('symbol', '0') | |
102 | ('symbol', '1')) |
|
102 | ('symbol', '1')) | |
103 | * set: |
|
103 | * set: | |
104 | <spanset+ 0:1> |
|
104 | <spanset+ 0:1> | |
105 | 0 |
|
105 | 0 | |
106 | 1 |
|
106 | 1 | |
107 | $ try 3::6 |
|
107 | $ try 3::6 | |
108 | (dagrange |
|
108 | (dagrange | |
109 | ('symbol', '3') |
|
109 | ('symbol', '3') | |
110 | ('symbol', '6')) |
|
110 | ('symbol', '6')) | |
111 | * set: |
|
111 | * set: | |
112 | <baseset [3, 5, 6]> |
|
112 | <baseset [3, 5, 6]> | |
113 | 3 |
|
113 | 3 | |
114 | 5 |
|
114 | 5 | |
115 | 6 |
|
115 | 6 | |
116 | $ try '0|1|2' |
|
116 | $ try '0|1|2' | |
117 | (or |
|
117 | (or | |
118 | (or |
|
118 | (or | |
119 | ('symbol', '0') |
|
119 | ('symbol', '0') | |
120 | ('symbol', '1')) |
|
120 | ('symbol', '1')) | |
121 | ('symbol', '2')) |
|
121 | ('symbol', '2')) | |
122 | * set: |
|
122 | * set: | |
123 | <addset |
|
123 | <addset | |
124 | <addset |
|
124 | <addset | |
125 | <baseset [0]>, |
|
125 | <baseset [0]>, | |
126 | <baseset [1]>>, |
|
126 | <baseset [1]>>, | |
127 | <baseset [2]>> |
|
127 | <baseset [2]>> | |
128 | 0 |
|
128 | 0 | |
129 | 1 |
|
129 | 1 | |
130 | 2 |
|
130 | 2 | |
131 |
|
131 | |||
132 | names that should work without quoting |
|
132 | names that should work without quoting | |
133 |
|
133 | |||
134 | $ try a |
|
134 | $ try a | |
135 | ('symbol', 'a') |
|
135 | ('symbol', 'a') | |
136 | * set: |
|
136 | * set: | |
137 | <baseset [0]> |
|
137 | <baseset [0]> | |
138 | 0 |
|
138 | 0 | |
139 | $ try b-a |
|
139 | $ try b-a | |
140 | (minus |
|
140 | (minus | |
141 | ('symbol', 'b') |
|
141 | ('symbol', 'b') | |
142 | ('symbol', 'a')) |
|
142 | ('symbol', 'a')) | |
143 | * set: |
|
143 | * set: | |
144 | <filteredset |
|
144 | <filteredset | |
145 | <baseset [1]>> |
|
145 | <baseset [1]>> | |
146 | 1 |
|
146 | 1 | |
147 | $ try _a_b_c_ |
|
147 | $ try _a_b_c_ | |
148 | ('symbol', '_a_b_c_') |
|
148 | ('symbol', '_a_b_c_') | |
149 | * set: |
|
149 | * set: | |
150 | <baseset [6]> |
|
150 | <baseset [6]> | |
151 | 6 |
|
151 | 6 | |
152 | $ try _a_b_c_-a |
|
152 | $ try _a_b_c_-a | |
153 | (minus |
|
153 | (minus | |
154 | ('symbol', '_a_b_c_') |
|
154 | ('symbol', '_a_b_c_') | |
155 | ('symbol', 'a')) |
|
155 | ('symbol', 'a')) | |
156 | * set: |
|
156 | * set: | |
157 | <filteredset |
|
157 | <filteredset | |
158 | <baseset [6]>> |
|
158 | <baseset [6]>> | |
159 | 6 |
|
159 | 6 | |
160 | $ try .a.b.c. |
|
160 | $ try .a.b.c. | |
161 | ('symbol', '.a.b.c.') |
|
161 | ('symbol', '.a.b.c.') | |
162 | * set: |
|
162 | * set: | |
163 | <baseset [7]> |
|
163 | <baseset [7]> | |
164 | 7 |
|
164 | 7 | |
165 | $ try .a.b.c.-a |
|
165 | $ try .a.b.c.-a | |
166 | (minus |
|
166 | (minus | |
167 | ('symbol', '.a.b.c.') |
|
167 | ('symbol', '.a.b.c.') | |
168 | ('symbol', 'a')) |
|
168 | ('symbol', 'a')) | |
169 | * set: |
|
169 | * set: | |
170 | <filteredset |
|
170 | <filteredset | |
171 | <baseset [7]>> |
|
171 | <baseset [7]>> | |
172 | 7 |
|
172 | 7 | |
173 | $ try -- '-a-b-c-' # complains |
|
173 | $ try -- '-a-b-c-' # complains | |
174 | hg: parse error at 7: not a prefix: end |
|
174 | hg: parse error at 7: not a prefix: end | |
175 | [255] |
|
175 | [255] | |
176 | $ log -a-b-c- # succeeds with fallback |
|
176 | $ log -a-b-c- # succeeds with fallback | |
177 | 4 |
|
177 | 4 | |
178 |
|
178 | |||
179 | $ try -- -a-b-c--a # complains |
|
179 | $ try -- -a-b-c--a # complains | |
180 | (minus |
|
180 | (minus | |
181 | (minus |
|
181 | (minus | |
182 | (minus |
|
182 | (minus | |
183 | (negate |
|
183 | (negate | |
184 | ('symbol', 'a')) |
|
184 | ('symbol', 'a')) | |
185 | ('symbol', 'b')) |
|
185 | ('symbol', 'b')) | |
186 | ('symbol', 'c')) |
|
186 | ('symbol', 'c')) | |
187 | (negate |
|
187 | (negate | |
188 | ('symbol', 'a'))) |
|
188 | ('symbol', 'a'))) | |
189 | abort: unknown revision '-a'! |
|
189 | abort: unknown revision '-a'! | |
190 | [255] |
|
190 | [255] | |
191 | $ try é |
|
191 | $ try é | |
192 | ('symbol', '\xc3\xa9') |
|
192 | ('symbol', '\xc3\xa9') | |
193 | * set: |
|
193 | * set: | |
194 | <baseset [9]> |
|
194 | <baseset [9]> | |
195 | 9 |
|
195 | 9 | |
196 |
|
196 | |||
197 | no quoting needed |
|
197 | no quoting needed | |
198 |
|
198 | |||
199 | $ log ::a-b-c- |
|
199 | $ log ::a-b-c- | |
200 | 0 |
|
200 | 0 | |
201 | 1 |
|
201 | 1 | |
202 | 2 |
|
202 | 2 | |
203 |
|
203 | |||
204 | quoting needed |
|
204 | quoting needed | |
205 |
|
205 | |||
206 | $ try '"-a-b-c-"-a' |
|
206 | $ try '"-a-b-c-"-a' | |
207 | (minus |
|
207 | (minus | |
208 | ('string', '-a-b-c-') |
|
208 | ('string', '-a-b-c-') | |
209 | ('symbol', 'a')) |
|
209 | ('symbol', 'a')) | |
210 | * set: |
|
210 | * set: | |
211 | <filteredset |
|
211 | <filteredset | |
212 | <baseset [4]>> |
|
212 | <baseset [4]>> | |
213 | 4 |
|
213 | 4 | |
214 |
|
214 | |||
215 | $ log '1 or 2' |
|
215 | $ log '1 or 2' | |
216 | 1 |
|
216 | 1 | |
217 | 2 |
|
217 | 2 | |
218 | $ log '1|2' |
|
218 | $ log '1|2' | |
219 | 1 |
|
219 | 1 | |
220 | 2 |
|
220 | 2 | |
221 | $ log '1 and 2' |
|
221 | $ log '1 and 2' | |
222 | $ log '1&2' |
|
222 | $ log '1&2' | |
223 | $ try '1&2|3' # precedence - and is higher |
|
223 | $ try '1&2|3' # precedence - and is higher | |
224 | (or |
|
224 | (or | |
225 | (and |
|
225 | (and | |
226 | ('symbol', '1') |
|
226 | ('symbol', '1') | |
227 | ('symbol', '2')) |
|
227 | ('symbol', '2')) | |
228 | ('symbol', '3')) |
|
228 | ('symbol', '3')) | |
229 | * set: |
|
229 | * set: | |
230 | <addset |
|
230 | <addset | |
231 | <baseset []>, |
|
231 | <baseset []>, | |
232 | <baseset [3]>> |
|
232 | <baseset [3]>> | |
233 | 3 |
|
233 | 3 | |
234 | $ try '1|2&3' |
|
234 | $ try '1|2&3' | |
235 | (or |
|
235 | (or | |
236 | ('symbol', '1') |
|
236 | ('symbol', '1') | |
237 | (and |
|
237 | (and | |
238 | ('symbol', '2') |
|
238 | ('symbol', '2') | |
239 | ('symbol', '3'))) |
|
239 | ('symbol', '3'))) | |
240 | * set: |
|
240 | * set: | |
241 | <addset |
|
241 | <addset | |
242 | <baseset [1]>, |
|
242 | <baseset [1]>, | |
243 | <baseset []>> |
|
243 | <baseset []>> | |
244 | 1 |
|
244 | 1 | |
245 | $ try '1&2&3' # associativity |
|
245 | $ try '1&2&3' # associativity | |
246 | (and |
|
246 | (and | |
247 | (and |
|
247 | (and | |
248 | ('symbol', '1') |
|
248 | ('symbol', '1') | |
249 | ('symbol', '2')) |
|
249 | ('symbol', '2')) | |
250 | ('symbol', '3')) |
|
250 | ('symbol', '3')) | |
251 | * set: |
|
251 | * set: | |
252 | <baseset []> |
|
252 | <baseset []> | |
253 | $ try '1|(2|3)' |
|
253 | $ try '1|(2|3)' | |
254 | (or |
|
254 | (or | |
255 | ('symbol', '1') |
|
255 | ('symbol', '1') | |
256 | (group |
|
256 | (group | |
257 | (or |
|
257 | (or | |
258 | ('symbol', '2') |
|
258 | ('symbol', '2') | |
259 | ('symbol', '3')))) |
|
259 | ('symbol', '3')))) | |
260 | * set: |
|
260 | * set: | |
261 | <addset |
|
261 | <addset | |
262 | <baseset [1]>, |
|
262 | <baseset [1]>, | |
263 | <addset |
|
263 | <addset | |
264 | <baseset [2]>, |
|
264 | <baseset [2]>, | |
265 | <baseset [3]>>> |
|
265 | <baseset [3]>>> | |
266 | 1 |
|
266 | 1 | |
267 | 2 |
|
267 | 2 | |
268 | 3 |
|
268 | 3 | |
269 | $ log '1.0' # tag |
|
269 | $ log '1.0' # tag | |
270 | 6 |
|
270 | 6 | |
271 | $ log 'a' # branch |
|
271 | $ log 'a' # branch | |
272 | 0 |
|
272 | 0 | |
273 | $ log '2785f51ee' |
|
273 | $ log '2785f51ee' | |
274 | 0 |
|
274 | 0 | |
275 | $ log 'date(2005)' |
|
275 | $ log 'date(2005)' | |
276 | 4 |
|
276 | 4 | |
277 | $ log 'date(this is a test)' |
|
277 | $ log 'date(this is a test)' | |
278 | hg: parse error at 10: unexpected token: symbol |
|
278 | hg: parse error at 10: unexpected token: symbol | |
279 | [255] |
|
279 | [255] | |
280 | $ log 'date()' |
|
280 | $ log 'date()' | |
281 | hg: parse error: date requires a string |
|
281 | hg: parse error: date requires a string | |
282 | [255] |
|
282 | [255] | |
283 | $ log 'date' |
|
283 | $ log 'date' | |
284 | hg: parse error: can't use date here |
|
284 | abort: unknown revision 'date'! | |
285 | [255] |
|
285 | [255] | |
286 | $ log 'date(' |
|
286 | $ log 'date(' | |
287 | hg: parse error at 5: not a prefix: end |
|
287 | hg: parse error at 5: not a prefix: end | |
288 | [255] |
|
288 | [255] | |
289 | $ log 'date(tip)' |
|
289 | $ log 'date(tip)' | |
290 | abort: invalid date: 'tip' |
|
290 | abort: invalid date: 'tip' | |
291 | [255] |
|
291 | [255] | |
292 |
$ log ' |
|
292 | $ log '0:date' | |
|
293 | abort: unknown revision 'date'! | |||
|
294 | [255] | |||
|
295 | $ log '::"date"' | |||
293 |
abort: unknown revision 'date'! |
|
296 | abort: unknown revision 'date'! | |
294 | [255] |
|
297 | [255] | |
|
298 | $ hg book date -r 4 | |||
|
299 | $ log '0:date' | |||
|
300 | 0 | |||
|
301 | 1 | |||
|
302 | 2 | |||
|
303 | 3 | |||
|
304 | 4 | |||
|
305 | $ log '::date' | |||
|
306 | 0 | |||
|
307 | 1 | |||
|
308 | 2 | |||
|
309 | 4 | |||
|
310 | $ log '::"date"' | |||
|
311 | 0 | |||
|
312 | 1 | |||
|
313 | 2 | |||
|
314 | 4 | |||
295 |
$ |
|
315 | $ log 'date(2005) and 1::' | |
296 | 4 |
|
316 | 4 | |
|
317 | $ hg book -d date | |||
|
318 | ||||
|
319 | Test that symbols only get parsed as functions if there's an opening | |||
|
320 | parenthesis. | |||
|
321 | ||||
|
322 | $ hg book only -r 9 | |||
|
323 | $ log 'only(only)' # Outer "only" is a function, inner "only" is the bookmark | |||
|
324 | 8 | |||
|
325 | 9 | |||
297 |
|
326 | |||
298 | ancestor can accept 0 or more arguments |
|
327 | ancestor can accept 0 or more arguments | |
299 |
|
328 | |||
300 | $ log 'ancestor()' |
|
329 | $ log 'ancestor()' | |
301 | $ log 'ancestor(1)' |
|
330 | $ log 'ancestor(1)' | |
302 | 1 |
|
331 | 1 | |
303 | $ log 'ancestor(4,5)' |
|
332 | $ log 'ancestor(4,5)' | |
304 | 1 |
|
333 | 1 | |
305 | $ log 'ancestor(4,5) and 4' |
|
334 | $ log 'ancestor(4,5) and 4' | |
306 | $ log 'ancestor(0,0,1,3)' |
|
335 | $ log 'ancestor(0,0,1,3)' | |
307 | 0 |
|
336 | 0 | |
308 | $ log 'ancestor(3,1,5,3,5,1)' |
|
337 | $ log 'ancestor(3,1,5,3,5,1)' | |
309 | 1 |
|
338 | 1 | |
310 | $ log 'ancestor(0,1,3,5)' |
|
339 | $ log 'ancestor(0,1,3,5)' | |
311 | 0 |
|
340 | 0 | |
312 | $ log 'ancestor(1,2,3,4,5)' |
|
341 | $ log 'ancestor(1,2,3,4,5)' | |
313 | 1 |
|
342 | 1 | |
314 | $ log 'ancestors(5)' |
|
343 | $ log 'ancestors(5)' | |
315 | 0 |
|
344 | 0 | |
316 | 1 |
|
345 | 1 | |
317 | 3 |
|
346 | 3 | |
318 | 5 |
|
347 | 5 | |
319 | $ log 'ancestor(ancestors(5))' |
|
348 | $ log 'ancestor(ancestors(5))' | |
320 | 0 |
|
349 | 0 | |
321 | $ log 'author(bob)' |
|
350 | $ log 'author(bob)' | |
322 | 2 |
|
351 | 2 | |
323 | $ log 'author("re:bob|test")' |
|
352 | $ log 'author("re:bob|test")' | |
324 | 0 |
|
353 | 0 | |
325 | 1 |
|
354 | 1 | |
326 | 2 |
|
355 | 2 | |
327 | 3 |
|
356 | 3 | |
328 | 4 |
|
357 | 4 | |
329 | 5 |
|
358 | 5 | |
330 | 6 |
|
359 | 6 | |
331 | 7 |
|
360 | 7 | |
332 | 8 |
|
361 | 8 | |
333 | 9 |
|
362 | 9 | |
334 | $ log 'branch(é)' |
|
363 | $ log 'branch(é)' | |
335 | 8 |
|
364 | 8 | |
336 | 9 |
|
365 | 9 | |
337 | $ log 'branch(a)' |
|
366 | $ log 'branch(a)' | |
338 | 0 |
|
367 | 0 | |
339 | $ hg log -r 'branch("re:a")' --template '{rev} {branch}\n' |
|
368 | $ hg log -r 'branch("re:a")' --template '{rev} {branch}\n' | |
340 | 0 a |
|
369 | 0 a | |
341 | 2 a-b-c- |
|
370 | 2 a-b-c- | |
342 | 3 +a+b+c+ |
|
371 | 3 +a+b+c+ | |
343 | 4 -a-b-c- |
|
372 | 4 -a-b-c- | |
344 | 5 !a/b/c/ |
|
373 | 5 !a/b/c/ | |
345 | 6 _a_b_c_ |
|
374 | 6 _a_b_c_ | |
346 | 7 .a.b.c. |
|
375 | 7 .a.b.c. | |
347 | $ log 'children(ancestor(4,5))' |
|
376 | $ log 'children(ancestor(4,5))' | |
348 | 2 |
|
377 | 2 | |
349 | 3 |
|
378 | 3 | |
350 | $ log 'closed()' |
|
379 | $ log 'closed()' | |
351 | $ log 'contains(a)' |
|
380 | $ log 'contains(a)' | |
352 | 0 |
|
381 | 0 | |
353 | 1 |
|
382 | 1 | |
354 | 3 |
|
383 | 3 | |
355 | 5 |
|
384 | 5 | |
356 | $ log 'contains("../repo/a")' |
|
385 | $ log 'contains("../repo/a")' | |
357 | 0 |
|
386 | 0 | |
358 | 1 |
|
387 | 1 | |
359 | 3 |
|
388 | 3 | |
360 | 5 |
|
389 | 5 | |
361 | $ log 'desc(B)' |
|
390 | $ log 'desc(B)' | |
362 | 5 |
|
391 | 5 | |
363 | $ log 'descendants(2 or 3)' |
|
392 | $ log 'descendants(2 or 3)' | |
364 | 2 |
|
393 | 2 | |
365 | 3 |
|
394 | 3 | |
366 | 4 |
|
395 | 4 | |
367 | 5 |
|
396 | 5 | |
368 | 6 |
|
397 | 6 | |
369 | 7 |
|
398 | 7 | |
370 | 8 |
|
399 | 8 | |
371 | 9 |
|
400 | 9 | |
372 | $ log 'file("b*")' |
|
401 | $ log 'file("b*")' | |
373 | 1 |
|
402 | 1 | |
374 | 4 |
|
403 | 4 | |
375 | $ log 'filelog("b")' |
|
404 | $ log 'filelog("b")' | |
376 | 1 |
|
405 | 1 | |
377 | 4 |
|
406 | 4 | |
378 | $ log 'filelog("../repo/b")' |
|
407 | $ log 'filelog("../repo/b")' | |
379 | 1 |
|
408 | 1 | |
380 | 4 |
|
409 | 4 | |
381 | $ log 'follow()' |
|
410 | $ log 'follow()' | |
382 | 0 |
|
411 | 0 | |
383 | 1 |
|
412 | 1 | |
384 | 2 |
|
413 | 2 | |
385 | 4 |
|
414 | 4 | |
386 | 8 |
|
415 | 8 | |
387 | 9 |
|
416 | 9 | |
388 | $ log 'grep("issue\d+")' |
|
417 | $ log 'grep("issue\d+")' | |
389 | 6 |
|
418 | 6 | |
390 | $ try 'grep("(")' # invalid regular expression |
|
419 | $ try 'grep("(")' # invalid regular expression | |
391 | (func |
|
420 | (func | |
392 | ('symbol', 'grep') |
|
421 | ('symbol', 'grep') | |
393 | ('string', '(')) |
|
422 | ('string', '(')) | |
394 | hg: parse error: invalid match pattern: unbalanced parenthesis |
|
423 | hg: parse error: invalid match pattern: unbalanced parenthesis | |
395 | [255] |
|
424 | [255] | |
396 | $ try 'grep("\bissue\d+")' |
|
425 | $ try 'grep("\bissue\d+")' | |
397 | (func |
|
426 | (func | |
398 | ('symbol', 'grep') |
|
427 | ('symbol', 'grep') | |
399 | ('string', '\x08issue\\d+')) |
|
428 | ('string', '\x08issue\\d+')) | |
400 | * set: |
|
429 | * set: | |
401 | <filteredset |
|
430 | <filteredset | |
402 | <fullreposet+ 0:9>> |
|
431 | <fullreposet+ 0:9>> | |
403 | $ try 'grep(r"\bissue\d+")' |
|
432 | $ try 'grep(r"\bissue\d+")' | |
404 | (func |
|
433 | (func | |
405 | ('symbol', 'grep') |
|
434 | ('symbol', 'grep') | |
406 | ('string', '\\bissue\\d+')) |
|
435 | ('string', '\\bissue\\d+')) | |
407 | * set: |
|
436 | * set: | |
408 | <filteredset |
|
437 | <filteredset | |
409 | <fullreposet+ 0:9>> |
|
438 | <fullreposet+ 0:9>> | |
410 | 6 |
|
439 | 6 | |
411 | $ try 'grep(r"\")' |
|
440 | $ try 'grep(r"\")' | |
412 | hg: parse error at 7: unterminated string |
|
441 | hg: parse error at 7: unterminated string | |
413 | [255] |
|
442 | [255] | |
414 | $ log 'head()' |
|
443 | $ log 'head()' | |
415 | 0 |
|
444 | 0 | |
416 | 1 |
|
445 | 1 | |
417 | 2 |
|
446 | 2 | |
418 | 3 |
|
447 | 3 | |
419 | 4 |
|
448 | 4 | |
420 | 5 |
|
449 | 5 | |
421 | 6 |
|
450 | 6 | |
422 | 7 |
|
451 | 7 | |
423 | 9 |
|
452 | 9 | |
424 | $ log 'heads(6::)' |
|
453 | $ log 'heads(6::)' | |
425 | 7 |
|
454 | 7 | |
426 | $ log 'keyword(issue)' |
|
455 | $ log 'keyword(issue)' | |
427 | 6 |
|
456 | 6 | |
428 | $ log 'keyword("test a")' |
|
457 | $ log 'keyword("test a")' | |
429 | $ log 'limit(head(), 1)' |
|
458 | $ log 'limit(head(), 1)' | |
430 | 0 |
|
459 | 0 | |
431 | $ log 'matching(6)' |
|
460 | $ log 'matching(6)' | |
432 | 6 |
|
461 | 6 | |
433 | $ log 'matching(6:7, "phase parents user date branch summary files description substate")' |
|
462 | $ log 'matching(6:7, "phase parents user date branch summary files description substate")' | |
434 | 6 |
|
463 | 6 | |
435 | 7 |
|
464 | 7 | |
436 |
|
465 | |||
437 | Testing min and max |
|
466 | Testing min and max | |
438 |
|
467 | |||
439 | max: simple |
|
468 | max: simple | |
440 |
|
469 | |||
441 | $ log 'max(contains(a))' |
|
470 | $ log 'max(contains(a))' | |
442 | 5 |
|
471 | 5 | |
443 |
|
472 | |||
444 | max: simple on unordered set) |
|
473 | max: simple on unordered set) | |
445 |
|
474 | |||
446 | $ log 'max((4+0+2+5+7) and contains(a))' |
|
475 | $ log 'max((4+0+2+5+7) and contains(a))' | |
447 | 5 |
|
476 | 5 | |
448 |
|
477 | |||
449 | max: no result |
|
478 | max: no result | |
450 |
|
479 | |||
451 | $ log 'max(contains(stringthatdoesnotappearanywhere))' |
|
480 | $ log 'max(contains(stringthatdoesnotappearanywhere))' | |
452 |
|
481 | |||
453 | max: no result on unordered set |
|
482 | max: no result on unordered set | |
454 |
|
483 | |||
455 | $ log 'max((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))' |
|
484 | $ log 'max((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))' | |
456 |
|
485 | |||
457 | min: simple |
|
486 | min: simple | |
458 |
|
487 | |||
459 | $ log 'min(contains(a))' |
|
488 | $ log 'min(contains(a))' | |
460 | 0 |
|
489 | 0 | |
461 |
|
490 | |||
462 | min: simple on unordered set |
|
491 | min: simple on unordered set | |
463 |
|
492 | |||
464 | $ log 'min((4+0+2+5+7) and contains(a))' |
|
493 | $ log 'min((4+0+2+5+7) and contains(a))' | |
465 | 0 |
|
494 | 0 | |
466 |
|
495 | |||
467 | min: empty |
|
496 | min: empty | |
468 |
|
497 | |||
469 | $ log 'min(contains(stringthatdoesnotappearanywhere))' |
|
498 | $ log 'min(contains(stringthatdoesnotappearanywhere))' | |
470 |
|
499 | |||
471 | min: empty on unordered set |
|
500 | min: empty on unordered set | |
472 |
|
501 | |||
473 | $ log 'min((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))' |
|
502 | $ log 'min((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))' | |
474 |
|
503 | |||
475 |
|
504 | |||
476 | $ log 'merge()' |
|
505 | $ log 'merge()' | |
477 | 6 |
|
506 | 6 | |
478 | $ log 'branchpoint()' |
|
507 | $ log 'branchpoint()' | |
479 | 1 |
|
508 | 1 | |
480 | 4 |
|
509 | 4 | |
481 | $ log 'modifies(b)' |
|
510 | $ log 'modifies(b)' | |
482 | 4 |
|
511 | 4 | |
483 | $ log 'modifies("path:b")' |
|
512 | $ log 'modifies("path:b")' | |
484 | 4 |
|
513 | 4 | |
485 | $ log 'modifies("*")' |
|
514 | $ log 'modifies("*")' | |
486 | 4 |
|
515 | 4 | |
487 | 6 |
|
516 | 6 | |
488 | $ log 'modifies("set:modified()")' |
|
517 | $ log 'modifies("set:modified()")' | |
489 | 4 |
|
518 | 4 | |
490 | $ log 'id(5)' |
|
519 | $ log 'id(5)' | |
491 | 2 |
|
520 | 2 | |
492 | $ log 'only(9)' |
|
521 | $ log 'only(9)' | |
493 | 8 |
|
522 | 8 | |
494 | 9 |
|
523 | 9 | |
495 | $ log 'only(8)' |
|
524 | $ log 'only(8)' | |
496 | 8 |
|
525 | 8 | |
497 | $ log 'only(9, 5)' |
|
526 | $ log 'only(9, 5)' | |
498 | 2 |
|
527 | 2 | |
499 | 4 |
|
528 | 4 | |
500 | 8 |
|
529 | 8 | |
501 | 9 |
|
530 | 9 | |
502 | $ log 'only(7 + 9, 5 + 2)' |
|
531 | $ log 'only(7 + 9, 5 + 2)' | |
503 | 4 |
|
532 | 4 | |
504 | 6 |
|
533 | 6 | |
505 | 7 |
|
534 | 7 | |
506 | 8 |
|
535 | 8 | |
507 | 9 |
|
536 | 9 | |
508 |
|
537 | |||
509 | Test empty set input |
|
538 | Test empty set input | |
510 | $ log 'only(p2())' |
|
539 | $ log 'only(p2())' | |
511 | $ log 'only(p1(), p2())' |
|
540 | $ log 'only(p1(), p2())' | |
512 | 0 |
|
541 | 0 | |
513 | 1 |
|
542 | 1 | |
514 | 2 |
|
543 | 2 | |
515 | 4 |
|
544 | 4 | |
516 | 8 |
|
545 | 8 | |
517 | 9 |
|
546 | 9 | |
518 |
|
547 | |||
519 | Test '%' operator |
|
548 | Test '%' operator | |
520 |
|
549 | |||
521 | $ log '9%' |
|
550 | $ log '9%' | |
522 | 8 |
|
551 | 8 | |
523 | 9 |
|
552 | 9 | |
524 | $ log '9%5' |
|
553 | $ log '9%5' | |
525 | 2 |
|
554 | 2 | |
526 | 4 |
|
555 | 4 | |
527 | 8 |
|
556 | 8 | |
528 | 9 |
|
557 | 9 | |
529 | $ log '(7 + 9)%(5 + 2)' |
|
558 | $ log '(7 + 9)%(5 + 2)' | |
530 | 4 |
|
559 | 4 | |
531 | 6 |
|
560 | 6 | |
532 | 7 |
|
561 | 7 | |
533 | 8 |
|
562 | 8 | |
534 | 9 |
|
563 | 9 | |
535 |
|
564 | |||
536 | Test the order of operations |
|
565 | Test the order of operations | |
537 |
|
566 | |||
538 | $ log '7 + 9%5 + 2' |
|
567 | $ log '7 + 9%5 + 2' | |
539 | 7 |
|
568 | 7 | |
540 | 2 |
|
569 | 2 | |
541 | 4 |
|
570 | 4 | |
542 | 8 |
|
571 | 8 | |
543 | 9 |
|
572 | 9 | |
544 |
|
573 | |||
545 | Test explicit numeric revision |
|
574 | Test explicit numeric revision | |
546 | $ log 'rev(-2)' |
|
575 | $ log 'rev(-2)' | |
547 | $ log 'rev(-1)' |
|
576 | $ log 'rev(-1)' | |
548 | -1 |
|
577 | -1 | |
549 | $ log 'rev(0)' |
|
578 | $ log 'rev(0)' | |
550 | 0 |
|
579 | 0 | |
551 | $ log 'rev(9)' |
|
580 | $ log 'rev(9)' | |
552 | 9 |
|
581 | 9 | |
553 | $ log 'rev(10)' |
|
582 | $ log 'rev(10)' | |
554 | $ log 'rev(tip)' |
|
583 | $ log 'rev(tip)' | |
555 | hg: parse error: rev expects a number |
|
584 | hg: parse error: rev expects a number | |
556 | [255] |
|
585 | [255] | |
557 |
|
586 | |||
558 | Test hexadecimal revision |
|
587 | Test hexadecimal revision | |
559 | $ log 'id(2)' |
|
588 | $ log 'id(2)' | |
560 | abort: 00changelog.i@2: ambiguous identifier! |
|
589 | abort: 00changelog.i@2: ambiguous identifier! | |
561 | [255] |
|
590 | [255] | |
562 | $ log 'id(23268)' |
|
591 | $ log 'id(23268)' | |
563 | 4 |
|
592 | 4 | |
564 | $ log 'id(2785f51eece)' |
|
593 | $ log 'id(2785f51eece)' | |
565 | 0 |
|
594 | 0 | |
566 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532c)' |
|
595 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532c)' | |
567 | 8 |
|
596 | 8 | |
568 | $ log 'id(d5d0dcbdc4a)' |
|
597 | $ log 'id(d5d0dcbdc4a)' | |
569 | $ log 'id(d5d0dcbdc4w)' |
|
598 | $ log 'id(d5d0dcbdc4w)' | |
570 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532d)' |
|
599 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532d)' | |
571 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532q)' |
|
600 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532q)' | |
572 | $ log 'id(1.0)' |
|
601 | $ log 'id(1.0)' | |
573 | $ log 'id(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)' |
|
602 | $ log 'id(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)' | |
574 |
|
603 | |||
575 | Test null revision |
|
604 | Test null revision | |
576 | $ log '(null)' |
|
605 | $ log '(null)' | |
577 | -1 |
|
606 | -1 | |
578 | $ log '(null:0)' |
|
607 | $ log '(null:0)' | |
579 | -1 |
|
608 | -1 | |
580 | 0 |
|
609 | 0 | |
581 | $ log '(0:null)' |
|
610 | $ log '(0:null)' | |
582 | 0 |
|
611 | 0 | |
583 | -1 |
|
612 | -1 | |
584 | $ log 'null::0' |
|
613 | $ log 'null::0' | |
585 | -1 |
|
614 | -1 | |
586 | 0 |
|
615 | 0 | |
587 | $ log 'null:tip - 0:' |
|
616 | $ log 'null:tip - 0:' | |
588 | -1 |
|
617 | -1 | |
589 | $ log 'null: and null::' | head -1 |
|
618 | $ log 'null: and null::' | head -1 | |
590 | -1 |
|
619 | -1 | |
591 | $ log 'null: or 0:' | head -2 |
|
620 | $ log 'null: or 0:' | head -2 | |
592 | -1 |
|
621 | -1 | |
593 | 0 |
|
622 | 0 | |
594 | $ log 'ancestors(null)' |
|
623 | $ log 'ancestors(null)' | |
595 | -1 |
|
624 | -1 | |
596 | $ log 'reverse(null:)' | tail -2 |
|
625 | $ log 'reverse(null:)' | tail -2 | |
597 | 0 |
|
626 | 0 | |
598 | -1 |
|
627 | -1 | |
599 | $ log 'first(null:)' |
|
628 | $ log 'first(null:)' | |
600 | -1 |
|
629 | -1 | |
601 | $ log 'min(null:)' |
|
630 | $ log 'min(null:)' | |
602 | -1 |
|
631 | -1 | |
603 | $ log 'tip:null and all()' | tail -2 |
|
632 | $ log 'tip:null and all()' | tail -2 | |
604 | 1 |
|
633 | 1 | |
605 | 0 |
|
634 | 0 | |
606 |
|
635 | |||
607 | Test working-directory revision |
|
636 | Test working-directory revision | |
608 | $ hg debugrevspec 'wdir()' |
|
637 | $ hg debugrevspec 'wdir()' | |
609 | None |
|
638 | None | |
610 | $ hg debugrevspec 'tip or wdir()' |
|
639 | $ hg debugrevspec 'tip or wdir()' | |
611 | 9 |
|
640 | 9 | |
612 | None |
|
641 | None | |
613 | $ hg debugrevspec '0:tip and wdir()' |
|
642 | $ hg debugrevspec '0:tip and wdir()' | |
614 |
|
643 | |||
615 | $ log 'outgoing()' |
|
644 | $ log 'outgoing()' | |
616 | 8 |
|
645 | 8 | |
617 | 9 |
|
646 | 9 | |
618 | $ log 'outgoing("../remote1")' |
|
647 | $ log 'outgoing("../remote1")' | |
619 | 8 |
|
648 | 8 | |
620 | 9 |
|
649 | 9 | |
621 | $ log 'outgoing("../remote2")' |
|
650 | $ log 'outgoing("../remote2")' | |
622 | 3 |
|
651 | 3 | |
623 | 5 |
|
652 | 5 | |
624 | 6 |
|
653 | 6 | |
625 | 7 |
|
654 | 7 | |
626 | 9 |
|
655 | 9 | |
627 | $ log 'p1(merge())' |
|
656 | $ log 'p1(merge())' | |
628 | 5 |
|
657 | 5 | |
629 | $ log 'p2(merge())' |
|
658 | $ log 'p2(merge())' | |
630 | 4 |
|
659 | 4 | |
631 | $ log 'parents(merge())' |
|
660 | $ log 'parents(merge())' | |
632 | 4 |
|
661 | 4 | |
633 | 5 |
|
662 | 5 | |
634 | $ log 'p1(branchpoint())' |
|
663 | $ log 'p1(branchpoint())' | |
635 | 0 |
|
664 | 0 | |
636 | 2 |
|
665 | 2 | |
637 | $ log 'p2(branchpoint())' |
|
666 | $ log 'p2(branchpoint())' | |
638 | $ log 'parents(branchpoint())' |
|
667 | $ log 'parents(branchpoint())' | |
639 | 0 |
|
668 | 0 | |
640 | 2 |
|
669 | 2 | |
641 | $ log 'removes(a)' |
|
670 | $ log 'removes(a)' | |
642 | 2 |
|
671 | 2 | |
643 | 6 |
|
672 | 6 | |
644 | $ log 'roots(all())' |
|
673 | $ log 'roots(all())' | |
645 | 0 |
|
674 | 0 | |
646 | $ log 'reverse(2 or 3 or 4 or 5)' |
|
675 | $ log 'reverse(2 or 3 or 4 or 5)' | |
647 | 5 |
|
676 | 5 | |
648 | 4 |
|
677 | 4 | |
649 | 3 |
|
678 | 3 | |
650 | 2 |
|
679 | 2 | |
651 | $ log 'reverse(all())' |
|
680 | $ log 'reverse(all())' | |
652 | 9 |
|
681 | 9 | |
653 | 8 |
|
682 | 8 | |
654 | 7 |
|
683 | 7 | |
655 | 6 |
|
684 | 6 | |
656 | 5 |
|
685 | 5 | |
657 | 4 |
|
686 | 4 | |
658 | 3 |
|
687 | 3 | |
659 | 2 |
|
688 | 2 | |
660 | 1 |
|
689 | 1 | |
661 | 0 |
|
690 | 0 | |
662 | $ log 'reverse(all()) & filelog(b)' |
|
691 | $ log 'reverse(all()) & filelog(b)' | |
663 | 4 |
|
692 | 4 | |
664 | 1 |
|
693 | 1 | |
665 | $ log 'rev(5)' |
|
694 | $ log 'rev(5)' | |
666 | 5 |
|
695 | 5 | |
667 | $ log 'sort(limit(reverse(all()), 3))' |
|
696 | $ log 'sort(limit(reverse(all()), 3))' | |
668 | 7 |
|
697 | 7 | |
669 | 8 |
|
698 | 8 | |
670 | 9 |
|
699 | 9 | |
671 | $ log 'sort(2 or 3 or 4 or 5, date)' |
|
700 | $ log 'sort(2 or 3 or 4 or 5, date)' | |
672 | 2 |
|
701 | 2 | |
673 | 3 |
|
702 | 3 | |
674 | 5 |
|
703 | 5 | |
675 | 4 |
|
704 | 4 | |
676 | $ log 'tagged()' |
|
705 | $ log 'tagged()' | |
677 | 6 |
|
706 | 6 | |
678 | $ log 'tag()' |
|
707 | $ log 'tag()' | |
679 | 6 |
|
708 | 6 | |
680 | $ log 'tag(1.0)' |
|
709 | $ log 'tag(1.0)' | |
681 | 6 |
|
710 | 6 | |
682 | $ log 'tag(tip)' |
|
711 | $ log 'tag(tip)' | |
683 | 9 |
|
712 | 9 | |
684 |
|
713 | |||
685 | test sort revset |
|
714 | test sort revset | |
686 | -------------------------------------------- |
|
715 | -------------------------------------------- | |
687 |
|
716 | |||
688 | test when adding two unordered revsets |
|
717 | test when adding two unordered revsets | |
689 |
|
718 | |||
690 | $ log 'sort(keyword(issue) or modifies(b))' |
|
719 | $ log 'sort(keyword(issue) or modifies(b))' | |
691 | 4 |
|
720 | 4 | |
692 | 6 |
|
721 | 6 | |
693 |
|
722 | |||
694 | test when sorting a reversed collection in the same way it is |
|
723 | test when sorting a reversed collection in the same way it is | |
695 |
|
724 | |||
696 | $ log 'sort(reverse(all()), -rev)' |
|
725 | $ log 'sort(reverse(all()), -rev)' | |
697 | 9 |
|
726 | 9 | |
698 | 8 |
|
727 | 8 | |
699 | 7 |
|
728 | 7 | |
700 | 6 |
|
729 | 6 | |
701 | 5 |
|
730 | 5 | |
702 | 4 |
|
731 | 4 | |
703 | 3 |
|
732 | 3 | |
704 | 2 |
|
733 | 2 | |
705 | 1 |
|
734 | 1 | |
706 | 0 |
|
735 | 0 | |
707 |
|
736 | |||
708 | test when sorting a reversed collection |
|
737 | test when sorting a reversed collection | |
709 |
|
738 | |||
710 | $ log 'sort(reverse(all()), rev)' |
|
739 | $ log 'sort(reverse(all()), rev)' | |
711 | 0 |
|
740 | 0 | |
712 | 1 |
|
741 | 1 | |
713 | 2 |
|
742 | 2 | |
714 | 3 |
|
743 | 3 | |
715 | 4 |
|
744 | 4 | |
716 | 5 |
|
745 | 5 | |
717 | 6 |
|
746 | 6 | |
718 | 7 |
|
747 | 7 | |
719 | 8 |
|
748 | 8 | |
720 | 9 |
|
749 | 9 | |
721 |
|
750 | |||
722 |
|
751 | |||
723 | test sorting two sorted collections in different orders |
|
752 | test sorting two sorted collections in different orders | |
724 |
|
753 | |||
725 | $ log 'sort(outgoing() or reverse(removes(a)), rev)' |
|
754 | $ log 'sort(outgoing() or reverse(removes(a)), rev)' | |
726 | 2 |
|
755 | 2 | |
727 | 6 |
|
756 | 6 | |
728 | 8 |
|
757 | 8 | |
729 | 9 |
|
758 | 9 | |
730 |
|
759 | |||
731 | test sorting two sorted collections in different orders backwards |
|
760 | test sorting two sorted collections in different orders backwards | |
732 |
|
761 | |||
733 | $ log 'sort(outgoing() or reverse(removes(a)), -rev)' |
|
762 | $ log 'sort(outgoing() or reverse(removes(a)), -rev)' | |
734 | 9 |
|
763 | 9 | |
735 | 8 |
|
764 | 8 | |
736 | 6 |
|
765 | 6 | |
737 | 2 |
|
766 | 2 | |
738 |
|
767 | |||
739 | test subtracting something from an addset |
|
768 | test subtracting something from an addset | |
740 |
|
769 | |||
741 | $ log '(outgoing() or removes(a)) - removes(a)' |
|
770 | $ log '(outgoing() or removes(a)) - removes(a)' | |
742 | 8 |
|
771 | 8 | |
743 | 9 |
|
772 | 9 | |
744 |
|
773 | |||
745 | test intersecting something with an addset |
|
774 | test intersecting something with an addset | |
746 |
|
775 | |||
747 | $ log 'parents(outgoing() or removes(a))' |
|
776 | $ log 'parents(outgoing() or removes(a))' | |
748 | 1 |
|
777 | 1 | |
749 | 4 |
|
778 | 4 | |
750 | 5 |
|
779 | 5 | |
751 | 8 |
|
780 | 8 | |
752 |
|
781 | |||
753 | test that `or` operation combines elements in the right order: |
|
782 | test that `or` operation combines elements in the right order: | |
754 |
|
783 | |||
755 | $ log '3:4 or 2:5' |
|
784 | $ log '3:4 or 2:5' | |
756 | 3 |
|
785 | 3 | |
757 | 4 |
|
786 | 4 | |
758 | 2 |
|
787 | 2 | |
759 | 5 |
|
788 | 5 | |
760 | $ log '3:4 or 5:2' |
|
789 | $ log '3:4 or 5:2' | |
761 | 3 |
|
790 | 3 | |
762 | 4 |
|
791 | 4 | |
763 | 5 |
|
792 | 5 | |
764 | 2 |
|
793 | 2 | |
765 | $ log 'sort(3:4 or 2:5)' |
|
794 | $ log 'sort(3:4 or 2:5)' | |
766 | 2 |
|
795 | 2 | |
767 | 3 |
|
796 | 3 | |
768 | 4 |
|
797 | 4 | |
769 | 5 |
|
798 | 5 | |
770 | $ log 'sort(3:4 or 5:2)' |
|
799 | $ log 'sort(3:4 or 5:2)' | |
771 | 2 |
|
800 | 2 | |
772 | 3 |
|
801 | 3 | |
773 | 4 |
|
802 | 4 | |
774 | 5 |
|
803 | 5 | |
775 |
|
804 | |||
776 | check that conversion to only works |
|
805 | check that conversion to only works | |
777 | $ try --optimize '::3 - ::1' |
|
806 | $ try --optimize '::3 - ::1' | |
778 | (minus |
|
807 | (minus | |
779 | (dagrangepre |
|
808 | (dagrangepre | |
780 | ('symbol', '3')) |
|
809 | ('symbol', '3')) | |
781 | (dagrangepre |
|
810 | (dagrangepre | |
782 | ('symbol', '1'))) |
|
811 | ('symbol', '1'))) | |
783 | * optimized: |
|
812 | * optimized: | |
784 | (func |
|
813 | (func | |
785 | ('symbol', 'only') |
|
814 | ('symbol', 'only') | |
786 | (list |
|
815 | (list | |
787 | ('symbol', '3') |
|
816 | ('symbol', '3') | |
788 | ('symbol', '1'))) |
|
817 | ('symbol', '1'))) | |
789 | * set: |
|
818 | * set: | |
790 | <baseset+ [3]> |
|
819 | <baseset+ [3]> | |
791 | 3 |
|
820 | 3 | |
792 | $ try --optimize 'ancestors(1) - ancestors(3)' |
|
821 | $ try --optimize 'ancestors(1) - ancestors(3)' | |
793 | (minus |
|
822 | (minus | |
794 | (func |
|
823 | (func | |
795 | ('symbol', 'ancestors') |
|
824 | ('symbol', 'ancestors') | |
796 | ('symbol', '1')) |
|
825 | ('symbol', '1')) | |
797 | (func |
|
826 | (func | |
798 | ('symbol', 'ancestors') |
|
827 | ('symbol', 'ancestors') | |
799 | ('symbol', '3'))) |
|
828 | ('symbol', '3'))) | |
800 | * optimized: |
|
829 | * optimized: | |
801 | (func |
|
830 | (func | |
802 | ('symbol', 'only') |
|
831 | ('symbol', 'only') | |
803 | (list |
|
832 | (list | |
804 | ('symbol', '1') |
|
833 | ('symbol', '1') | |
805 | ('symbol', '3'))) |
|
834 | ('symbol', '3'))) | |
806 | * set: |
|
835 | * set: | |
807 | <baseset+ []> |
|
836 | <baseset+ []> | |
808 | $ try --optimize 'not ::2 and ::6' |
|
837 | $ try --optimize 'not ::2 and ::6' | |
809 | (and |
|
838 | (and | |
810 | (not |
|
839 | (not | |
811 | (dagrangepre |
|
840 | (dagrangepre | |
812 | ('symbol', '2'))) |
|
841 | ('symbol', '2'))) | |
813 | (dagrangepre |
|
842 | (dagrangepre | |
814 | ('symbol', '6'))) |
|
843 | ('symbol', '6'))) | |
815 | * optimized: |
|
844 | * optimized: | |
816 | (func |
|
845 | (func | |
817 | ('symbol', 'only') |
|
846 | ('symbol', 'only') | |
818 | (list |
|
847 | (list | |
819 | ('symbol', '6') |
|
848 | ('symbol', '6') | |
820 | ('symbol', '2'))) |
|
849 | ('symbol', '2'))) | |
821 | * set: |
|
850 | * set: | |
822 | <baseset+ [3, 4, 5, 6]> |
|
851 | <baseset+ [3, 4, 5, 6]> | |
823 | 3 |
|
852 | 3 | |
824 | 4 |
|
853 | 4 | |
825 | 5 |
|
854 | 5 | |
826 | 6 |
|
855 | 6 | |
827 | $ try --optimize 'ancestors(6) and not ancestors(4)' |
|
856 | $ try --optimize 'ancestors(6) and not ancestors(4)' | |
828 | (and |
|
857 | (and | |
829 | (func |
|
858 | (func | |
830 | ('symbol', 'ancestors') |
|
859 | ('symbol', 'ancestors') | |
831 | ('symbol', '6')) |
|
860 | ('symbol', '6')) | |
832 | (not |
|
861 | (not | |
833 | (func |
|
862 | (func | |
834 | ('symbol', 'ancestors') |
|
863 | ('symbol', 'ancestors') | |
835 | ('symbol', '4')))) |
|
864 | ('symbol', '4')))) | |
836 | * optimized: |
|
865 | * optimized: | |
837 | (func |
|
866 | (func | |
838 | ('symbol', 'only') |
|
867 | ('symbol', 'only') | |
839 | (list |
|
868 | (list | |
840 | ('symbol', '6') |
|
869 | ('symbol', '6') | |
841 | ('symbol', '4'))) |
|
870 | ('symbol', '4'))) | |
842 | * set: |
|
871 | * set: | |
843 | <baseset+ [3, 5, 6]> |
|
872 | <baseset+ [3, 5, 6]> | |
844 | 3 |
|
873 | 3 | |
845 | 5 |
|
874 | 5 | |
846 | 6 |
|
875 | 6 | |
847 |
|
876 | |||
848 | we can use patterns when searching for tags |
|
877 | we can use patterns when searching for tags | |
849 |
|
878 | |||
850 | $ log 'tag("1..*")' |
|
879 | $ log 'tag("1..*")' | |
851 | abort: tag '1..*' does not exist! |
|
880 | abort: tag '1..*' does not exist! | |
852 | [255] |
|
881 | [255] | |
853 | $ log 'tag("re:1..*")' |
|
882 | $ log 'tag("re:1..*")' | |
854 | 6 |
|
883 | 6 | |
855 | $ log 'tag("re:[0-9].[0-9]")' |
|
884 | $ log 'tag("re:[0-9].[0-9]")' | |
856 | 6 |
|
885 | 6 | |
857 | $ log 'tag("literal:1.0")' |
|
886 | $ log 'tag("literal:1.0")' | |
858 | 6 |
|
887 | 6 | |
859 | $ log 'tag("re:0..*")' |
|
888 | $ log 'tag("re:0..*")' | |
860 |
|
889 | |||
861 | $ log 'tag(unknown)' |
|
890 | $ log 'tag(unknown)' | |
862 | abort: tag 'unknown' does not exist! |
|
891 | abort: tag 'unknown' does not exist! | |
863 | [255] |
|
892 | [255] | |
864 | $ log 'tag("re:unknown")' |
|
893 | $ log 'tag("re:unknown")' | |
865 | $ log 'present(tag("unknown"))' |
|
894 | $ log 'present(tag("unknown"))' | |
866 | $ log 'present(tag("re:unknown"))' |
|
895 | $ log 'present(tag("re:unknown"))' | |
867 | $ log 'branch(unknown)' |
|
896 | $ log 'branch(unknown)' | |
868 | abort: unknown revision 'unknown'! |
|
897 | abort: unknown revision 'unknown'! | |
869 | [255] |
|
898 | [255] | |
870 | $ log 'branch("re:unknown")' |
|
899 | $ log 'branch("re:unknown")' | |
871 | $ log 'present(branch("unknown"))' |
|
900 | $ log 'present(branch("unknown"))' | |
872 | $ log 'present(branch("re:unknown"))' |
|
901 | $ log 'present(branch("re:unknown"))' | |
873 | $ log 'user(bob)' |
|
902 | $ log 'user(bob)' | |
874 | 2 |
|
903 | 2 | |
875 |
|
904 | |||
876 | $ log '4::8' |
|
905 | $ log '4::8' | |
877 | 4 |
|
906 | 4 | |
878 | 8 |
|
907 | 8 | |
879 | $ log '4:8' |
|
908 | $ log '4:8' | |
880 | 4 |
|
909 | 4 | |
881 | 5 |
|
910 | 5 | |
882 | 6 |
|
911 | 6 | |
883 | 7 |
|
912 | 7 | |
884 | 8 |
|
913 | 8 | |
885 |
|
914 | |||
886 | $ log 'sort(!merge() & (modifies(b) | user(bob) | keyword(bug) | keyword(issue) & 1::9), "-date")' |
|
915 | $ log 'sort(!merge() & (modifies(b) | user(bob) | keyword(bug) | keyword(issue) & 1::9), "-date")' | |
887 | 4 |
|
916 | 4 | |
888 | 2 |
|
917 | 2 | |
889 | 5 |
|
918 | 5 | |
890 |
|
919 | |||
891 | $ log 'not 0 and 0:2' |
|
920 | $ log 'not 0 and 0:2' | |
892 | 1 |
|
921 | 1 | |
893 | 2 |
|
922 | 2 | |
894 | $ log 'not 1 and 0:2' |
|
923 | $ log 'not 1 and 0:2' | |
895 | 0 |
|
924 | 0 | |
896 | 2 |
|
925 | 2 | |
897 | $ log 'not 2 and 0:2' |
|
926 | $ log 'not 2 and 0:2' | |
898 | 0 |
|
927 | 0 | |
899 | 1 |
|
928 | 1 | |
900 | $ log '(1 and 2)::' |
|
929 | $ log '(1 and 2)::' | |
901 | $ log '(1 and 2):' |
|
930 | $ log '(1 and 2):' | |
902 | $ log '(1 and 2):3' |
|
931 | $ log '(1 and 2):3' | |
903 | $ log 'sort(head(), -rev)' |
|
932 | $ log 'sort(head(), -rev)' | |
904 | 9 |
|
933 | 9 | |
905 | 7 |
|
934 | 7 | |
906 | 6 |
|
935 | 6 | |
907 | 5 |
|
936 | 5 | |
908 | 4 |
|
937 | 4 | |
909 | 3 |
|
938 | 3 | |
910 | 2 |
|
939 | 2 | |
911 | 1 |
|
940 | 1 | |
912 | 0 |
|
941 | 0 | |
913 | $ log '4::8 - 8' |
|
942 | $ log '4::8 - 8' | |
914 | 4 |
|
943 | 4 | |
915 | $ log 'matching(1 or 2 or 3) and (2 or 3 or 1)' |
|
944 | $ log 'matching(1 or 2 or 3) and (2 or 3 or 1)' | |
916 | 2 |
|
945 | 2 | |
917 | 3 |
|
946 | 3 | |
918 | 1 |
|
947 | 1 | |
919 |
|
948 | |||
920 | $ log 'named("unknown")' |
|
949 | $ log 'named("unknown")' | |
921 | abort: namespace 'unknown' does not exist! |
|
950 | abort: namespace 'unknown' does not exist! | |
922 | [255] |
|
951 | [255] | |
923 | $ log 'named("re:unknown")' |
|
952 | $ log 'named("re:unknown")' | |
924 | abort: no namespace exists that match 'unknown'! |
|
953 | abort: no namespace exists that match 'unknown'! | |
925 | [255] |
|
954 | [255] | |
926 | $ log 'present(named("unknown"))' |
|
955 | $ log 'present(named("unknown"))' | |
927 | $ log 'present(named("re:unknown"))' |
|
956 | $ log 'present(named("re:unknown"))' | |
928 |
|
957 | |||
929 | $ log 'tag()' |
|
958 | $ log 'tag()' | |
930 | 6 |
|
959 | 6 | |
931 | $ log 'named("tags")' |
|
960 | $ log 'named("tags")' | |
932 | 6 |
|
961 | 6 | |
933 |
|
962 | |||
934 | issue2437 |
|
963 | issue2437 | |
935 |
|
964 | |||
936 | $ log '3 and p1(5)' |
|
965 | $ log '3 and p1(5)' | |
937 | 3 |
|
966 | 3 | |
938 | $ log '4 and p2(6)' |
|
967 | $ log '4 and p2(6)' | |
939 | 4 |
|
968 | 4 | |
940 | $ log '1 and parents(:2)' |
|
969 | $ log '1 and parents(:2)' | |
941 | 1 |
|
970 | 1 | |
942 | $ log '2 and children(1:)' |
|
971 | $ log '2 and children(1:)' | |
943 | 2 |
|
972 | 2 | |
944 | $ log 'roots(all()) or roots(all())' |
|
973 | $ log 'roots(all()) or roots(all())' | |
945 | 0 |
|
974 | 0 | |
946 | $ hg debugrevspec 'roots(all()) or roots(all())' |
|
975 | $ hg debugrevspec 'roots(all()) or roots(all())' | |
947 | 0 |
|
976 | 0 | |
948 | $ log 'heads(branch(é)) or heads(branch(é))' |
|
977 | $ log 'heads(branch(é)) or heads(branch(é))' | |
949 | 9 |
|
978 | 9 | |
950 | $ log 'ancestors(8) and (heads(branch("-a-b-c-")) or heads(branch(é)))' |
|
979 | $ log 'ancestors(8) and (heads(branch("-a-b-c-")) or heads(branch(é)))' | |
951 | 4 |
|
980 | 4 | |
952 |
|
981 | |||
953 | issue2654: report a parse error if the revset was not completely parsed |
|
982 | issue2654: report a parse error if the revset was not completely parsed | |
954 |
|
983 | |||
955 | $ log '1 OR 2' |
|
984 | $ log '1 OR 2' | |
956 | hg: parse error at 2: invalid token |
|
985 | hg: parse error at 2: invalid token | |
957 | [255] |
|
986 | [255] | |
958 |
|
987 | |||
959 | or operator should preserve ordering: |
|
988 | or operator should preserve ordering: | |
960 | $ log 'reverse(2::4) or tip' |
|
989 | $ log 'reverse(2::4) or tip' | |
961 | 4 |
|
990 | 4 | |
962 | 2 |
|
991 | 2 | |
963 | 9 |
|
992 | 9 | |
964 |
|
993 | |||
965 | parentrevspec |
|
994 | parentrevspec | |
966 |
|
995 | |||
967 | $ log 'merge()^0' |
|
996 | $ log 'merge()^0' | |
968 | 6 |
|
997 | 6 | |
969 | $ log 'merge()^' |
|
998 | $ log 'merge()^' | |
970 | 5 |
|
999 | 5 | |
971 | $ log 'merge()^1' |
|
1000 | $ log 'merge()^1' | |
972 | 5 |
|
1001 | 5 | |
973 | $ log 'merge()^2' |
|
1002 | $ log 'merge()^2' | |
974 | 4 |
|
1003 | 4 | |
975 | $ log 'merge()^^' |
|
1004 | $ log 'merge()^^' | |
976 | 3 |
|
1005 | 3 | |
977 | $ log 'merge()^1^' |
|
1006 | $ log 'merge()^1^' | |
978 | 3 |
|
1007 | 3 | |
979 | $ log 'merge()^^^' |
|
1008 | $ log 'merge()^^^' | |
980 | 1 |
|
1009 | 1 | |
981 |
|
1010 | |||
982 | $ log 'merge()~0' |
|
1011 | $ log 'merge()~0' | |
983 | 6 |
|
1012 | 6 | |
984 | $ log 'merge()~1' |
|
1013 | $ log 'merge()~1' | |
985 | 5 |
|
1014 | 5 | |
986 | $ log 'merge()~2' |
|
1015 | $ log 'merge()~2' | |
987 | 3 |
|
1016 | 3 | |
988 | $ log 'merge()~2^1' |
|
1017 | $ log 'merge()~2^1' | |
989 | 1 |
|
1018 | 1 | |
990 | $ log 'merge()~3' |
|
1019 | $ log 'merge()~3' | |
991 | 1 |
|
1020 | 1 | |
992 |
|
1021 | |||
993 | $ log '(-3:tip)^' |
|
1022 | $ log '(-3:tip)^' | |
994 | 4 |
|
1023 | 4 | |
995 | 6 |
|
1024 | 6 | |
996 | 8 |
|
1025 | 8 | |
997 |
|
1026 | |||
998 | $ log 'tip^foo' |
|
1027 | $ log 'tip^foo' | |
999 | hg: parse error: ^ expects a number 0, 1, or 2 |
|
1028 | hg: parse error: ^ expects a number 0, 1, or 2 | |
1000 | [255] |
|
1029 | [255] | |
1001 |
|
1030 | |||
1002 | Bogus function gets suggestions |
|
1031 | Bogus function gets suggestions | |
1003 | $ log 'add()' |
|
1032 | $ log 'add()' | |
1004 | hg: parse error: unknown identifier: add |
|
1033 | hg: parse error: unknown identifier: add | |
1005 | (did you mean 'adds'?) |
|
1034 | (did you mean 'adds'?) | |
1006 | [255] |
|
1035 | [255] | |
1007 | $ log 'added()' |
|
1036 | $ log 'added()' | |
1008 | hg: parse error: unknown identifier: added |
|
1037 | hg: parse error: unknown identifier: added | |
1009 | (did you mean 'adds'?) |
|
1038 | (did you mean 'adds'?) | |
1010 | [255] |
|
1039 | [255] | |
1011 | $ log 'remo()' |
|
1040 | $ log 'remo()' | |
1012 | hg: parse error: unknown identifier: remo |
|
1041 | hg: parse error: unknown identifier: remo | |
1013 | (did you mean one of remote, removes?) |
|
1042 | (did you mean one of remote, removes?) | |
1014 | [255] |
|
1043 | [255] | |
1015 | $ log 'babar()' |
|
1044 | $ log 'babar()' | |
1016 | hg: parse error: unknown identifier: babar |
|
1045 | hg: parse error: unknown identifier: babar | |
1017 | [255] |
|
1046 | [255] | |
1018 |
|
1047 | |||
1019 | multiple revspecs |
|
1048 | multiple revspecs | |
1020 |
|
1049 | |||
1021 | $ hg log -r 'tip~1:tip' -r 'tip~2:tip~1' --template '{rev}\n' |
|
1050 | $ hg log -r 'tip~1:tip' -r 'tip~2:tip~1' --template '{rev}\n' | |
1022 | 8 |
|
1051 | 8 | |
1023 | 9 |
|
1052 | 9 | |
1024 | 4 |
|
1053 | 4 | |
1025 | 5 |
|
1054 | 5 | |
1026 | 6 |
|
1055 | 6 | |
1027 | 7 |
|
1056 | 7 | |
1028 |
|
1057 | |||
1029 | test usage in revpair (with "+") |
|
1058 | test usage in revpair (with "+") | |
1030 |
|
1059 | |||
1031 | (real pair) |
|
1060 | (real pair) | |
1032 |
|
1061 | |||
1033 | $ hg diff -r 'tip^^' -r 'tip' |
|
1062 | $ hg diff -r 'tip^^' -r 'tip' | |
1034 | diff -r 2326846efdab -r 24286f4ae135 .hgtags |
|
1063 | diff -r 2326846efdab -r 24286f4ae135 .hgtags | |
1035 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
1064 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
1036 | +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000 |
|
1065 | +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000 | |
1037 | @@ -0,0 +1,1 @@ |
|
1066 | @@ -0,0 +1,1 @@ | |
1038 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 |
|
1067 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 | |
1039 | $ hg diff -r 'tip^^::tip' |
|
1068 | $ hg diff -r 'tip^^::tip' | |
1040 | diff -r 2326846efdab -r 24286f4ae135 .hgtags |
|
1069 | diff -r 2326846efdab -r 24286f4ae135 .hgtags | |
1041 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
1070 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
1042 | +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000 |
|
1071 | +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000 | |
1043 | @@ -0,0 +1,1 @@ |
|
1072 | @@ -0,0 +1,1 @@ | |
1044 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 |
|
1073 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 | |
1045 |
|
1074 | |||
1046 | (single rev) |
|
1075 | (single rev) | |
1047 |
|
1076 | |||
1048 | $ hg diff -r 'tip^' -r 'tip^' |
|
1077 | $ hg diff -r 'tip^' -r 'tip^' | |
1049 | $ hg diff -r 'tip^::tip^ or tip^' |
|
1078 | $ hg diff -r 'tip^::tip^ or tip^' | |
1050 |
|
1079 | |||
1051 | (single rev that does not looks like a range) |
|
1080 | (single rev that does not looks like a range) | |
1052 |
|
1081 | |||
1053 | $ hg diff -r 'tip^ or tip^' |
|
1082 | $ hg diff -r 'tip^ or tip^' | |
1054 | diff -r d5d0dcbdc4d9 .hgtags |
|
1083 | diff -r d5d0dcbdc4d9 .hgtags | |
1055 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
1084 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
1056 | +++ b/.hgtags * (glob) |
|
1085 | +++ b/.hgtags * (glob) | |
1057 | @@ -0,0 +1,1 @@ |
|
1086 | @@ -0,0 +1,1 @@ | |
1058 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 |
|
1087 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 | |
1059 |
|
1088 | |||
1060 | (no rev) |
|
1089 | (no rev) | |
1061 |
|
1090 | |||
1062 | $ hg diff -r 'author("babar") or author("celeste")' |
|
1091 | $ hg diff -r 'author("babar") or author("celeste")' | |
1063 | abort: empty revision range |
|
1092 | abort: empty revision range | |
1064 | [255] |
|
1093 | [255] | |
1065 |
|
1094 | |||
1066 | aliases: |
|
1095 | aliases: | |
1067 |
|
1096 | |||
1068 | $ echo '[revsetalias]' >> .hg/hgrc |
|
1097 | $ echo '[revsetalias]' >> .hg/hgrc | |
1069 | $ echo 'm = merge()' >> .hg/hgrc |
|
1098 | $ echo 'm = merge()' >> .hg/hgrc | |
1070 | (revset aliases can override builtin revsets) |
|
1099 | (revset aliases can override builtin revsets) | |
1071 | $ echo 'p2($1) = p1($1)' >> .hg/hgrc |
|
1100 | $ echo 'p2($1) = p1($1)' >> .hg/hgrc | |
1072 | $ echo 'sincem = descendants(m)' >> .hg/hgrc |
|
1101 | $ echo 'sincem = descendants(m)' >> .hg/hgrc | |
1073 | $ echo 'd($1) = reverse(sort($1, date))' >> .hg/hgrc |
|
1102 | $ echo 'd($1) = reverse(sort($1, date))' >> .hg/hgrc | |
1074 | $ echo 'rs(ARG1, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc |
|
1103 | $ echo 'rs(ARG1, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc | |
1075 | $ echo 'rs4(ARG1, ARGA, ARGB, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc |
|
1104 | $ echo 'rs4(ARG1, ARGA, ARGB, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc | |
1076 |
|
1105 | |||
1077 | $ try m |
|
1106 | $ try m | |
1078 | ('symbol', 'm') |
|
1107 | ('symbol', 'm') | |
1079 | (func |
|
1108 | (func | |
1080 | ('symbol', 'merge') |
|
1109 | ('symbol', 'merge') | |
1081 | None) |
|
1110 | None) | |
1082 | * set: |
|
1111 | * set: | |
1083 | <filteredset |
|
1112 | <filteredset | |
1084 | <fullreposet+ 0:9>> |
|
1113 | <fullreposet+ 0:9>> | |
1085 | 6 |
|
1114 | 6 | |
1086 |
|
1115 | |||
1087 | $ HGPLAIN=1 |
|
1116 | $ HGPLAIN=1 | |
1088 | $ export HGPLAIN |
|
1117 | $ export HGPLAIN | |
1089 | $ try m |
|
1118 | $ try m | |
1090 | ('symbol', 'm') |
|
1119 | ('symbol', 'm') | |
1091 | abort: unknown revision 'm'! |
|
1120 | abort: unknown revision 'm'! | |
1092 | [255] |
|
1121 | [255] | |
1093 |
|
1122 | |||
1094 | $ HGPLAINEXCEPT=revsetalias |
|
1123 | $ HGPLAINEXCEPT=revsetalias | |
1095 | $ export HGPLAINEXCEPT |
|
1124 | $ export HGPLAINEXCEPT | |
1096 | $ try m |
|
1125 | $ try m | |
1097 | ('symbol', 'm') |
|
1126 | ('symbol', 'm') | |
1098 | (func |
|
1127 | (func | |
1099 | ('symbol', 'merge') |
|
1128 | ('symbol', 'merge') | |
1100 | None) |
|
1129 | None) | |
1101 | * set: |
|
1130 | * set: | |
1102 | <filteredset |
|
1131 | <filteredset | |
1103 | <fullreposet+ 0:9>> |
|
1132 | <fullreposet+ 0:9>> | |
1104 | 6 |
|
1133 | 6 | |
1105 |
|
1134 | |||
1106 | $ unset HGPLAIN |
|
1135 | $ unset HGPLAIN | |
1107 | $ unset HGPLAINEXCEPT |
|
1136 | $ unset HGPLAINEXCEPT | |
1108 |
|
1137 | |||
1109 | $ try 'p2(.)' |
|
1138 | $ try 'p2(.)' | |
1110 | (func |
|
1139 | (func | |
1111 | ('symbol', 'p2') |
|
1140 | ('symbol', 'p2') | |
1112 | ('symbol', '.')) |
|
1141 | ('symbol', '.')) | |
1113 | (func |
|
1142 | (func | |
1114 | ('symbol', 'p1') |
|
1143 | ('symbol', 'p1') | |
1115 | ('symbol', '.')) |
|
1144 | ('symbol', '.')) | |
1116 | * set: |
|
1145 | * set: | |
1117 | <baseset+ [8]> |
|
1146 | <baseset+ [8]> | |
1118 | 8 |
|
1147 | 8 | |
1119 |
|
1148 | |||
1120 | $ HGPLAIN=1 |
|
1149 | $ HGPLAIN=1 | |
1121 | $ export HGPLAIN |
|
1150 | $ export HGPLAIN | |
1122 | $ try 'p2(.)' |
|
1151 | $ try 'p2(.)' | |
1123 | (func |
|
1152 | (func | |
1124 | ('symbol', 'p2') |
|
1153 | ('symbol', 'p2') | |
1125 | ('symbol', '.')) |
|
1154 | ('symbol', '.')) | |
1126 | * set: |
|
1155 | * set: | |
1127 | <baseset+ []> |
|
1156 | <baseset+ []> | |
1128 |
|
1157 | |||
1129 | $ HGPLAINEXCEPT=revsetalias |
|
1158 | $ HGPLAINEXCEPT=revsetalias | |
1130 | $ export HGPLAINEXCEPT |
|
1159 | $ export HGPLAINEXCEPT | |
1131 | $ try 'p2(.)' |
|
1160 | $ try 'p2(.)' | |
1132 | (func |
|
1161 | (func | |
1133 | ('symbol', 'p2') |
|
1162 | ('symbol', 'p2') | |
1134 | ('symbol', '.')) |
|
1163 | ('symbol', '.')) | |
1135 | (func |
|
1164 | (func | |
1136 | ('symbol', 'p1') |
|
1165 | ('symbol', 'p1') | |
1137 | ('symbol', '.')) |
|
1166 | ('symbol', '.')) | |
1138 | * set: |
|
1167 | * set: | |
1139 | <baseset+ [8]> |
|
1168 | <baseset+ [8]> | |
1140 | 8 |
|
1169 | 8 | |
1141 |
|
1170 | |||
1142 | $ unset HGPLAIN |
|
1171 | $ unset HGPLAIN | |
1143 | $ unset HGPLAINEXCEPT |
|
1172 | $ unset HGPLAINEXCEPT | |
1144 |
|
1173 | |||
1145 | test alias recursion |
|
1174 | test alias recursion | |
1146 |
|
1175 | |||
1147 | $ try sincem |
|
1176 | $ try sincem | |
1148 | ('symbol', 'sincem') |
|
1177 | ('symbol', 'sincem') | |
1149 | (func |
|
1178 | (func | |
1150 | ('symbol', 'descendants') |
|
1179 | ('symbol', 'descendants') | |
1151 | (func |
|
1180 | (func | |
1152 | ('symbol', 'merge') |
|
1181 | ('symbol', 'merge') | |
1153 | None)) |
|
1182 | None)) | |
1154 | * set: |
|
1183 | * set: | |
1155 | <addset+ |
|
1184 | <addset+ | |
1156 | <filteredset |
|
1185 | <filteredset | |
1157 | <fullreposet+ 0:9>>, |
|
1186 | <fullreposet+ 0:9>>, | |
1158 | <generatorset+>> |
|
1187 | <generatorset+>> | |
1159 | 6 |
|
1188 | 6 | |
1160 | 7 |
|
1189 | 7 | |
1161 |
|
1190 | |||
1162 | test infinite recursion |
|
1191 | test infinite recursion | |
1163 |
|
1192 | |||
1164 | $ echo 'recurse1 = recurse2' >> .hg/hgrc |
|
1193 | $ echo 'recurse1 = recurse2' >> .hg/hgrc | |
1165 | $ echo 'recurse2 = recurse1' >> .hg/hgrc |
|
1194 | $ echo 'recurse2 = recurse1' >> .hg/hgrc | |
1166 | $ try recurse1 |
|
1195 | $ try recurse1 | |
1167 | ('symbol', 'recurse1') |
|
1196 | ('symbol', 'recurse1') | |
1168 | hg: parse error: infinite expansion of revset alias "recurse1" detected |
|
1197 | hg: parse error: infinite expansion of revset alias "recurse1" detected | |
1169 | [255] |
|
1198 | [255] | |
1170 |
|
1199 | |||
1171 | $ echo 'level1($1, $2) = $1 or $2' >> .hg/hgrc |
|
1200 | $ echo 'level1($1, $2) = $1 or $2' >> .hg/hgrc | |
1172 | $ echo 'level2($1, $2) = level1($2, $1)' >> .hg/hgrc |
|
1201 | $ echo 'level2($1, $2) = level1($2, $1)' >> .hg/hgrc | |
1173 | $ try "level2(level1(1, 2), 3)" |
|
1202 | $ try "level2(level1(1, 2), 3)" | |
1174 | (func |
|
1203 | (func | |
1175 | ('symbol', 'level2') |
|
1204 | ('symbol', 'level2') | |
1176 | (list |
|
1205 | (list | |
1177 | (func |
|
1206 | (func | |
1178 | ('symbol', 'level1') |
|
1207 | ('symbol', 'level1') | |
1179 | (list |
|
1208 | (list | |
1180 | ('symbol', '1') |
|
1209 | ('symbol', '1') | |
1181 | ('symbol', '2'))) |
|
1210 | ('symbol', '2'))) | |
1182 | ('symbol', '3'))) |
|
1211 | ('symbol', '3'))) | |
1183 | (or |
|
1212 | (or | |
1184 | ('symbol', '3') |
|
1213 | ('symbol', '3') | |
1185 | (or |
|
1214 | (or | |
1186 | ('symbol', '1') |
|
1215 | ('symbol', '1') | |
1187 | ('symbol', '2'))) |
|
1216 | ('symbol', '2'))) | |
1188 | * set: |
|
1217 | * set: | |
1189 | <addset |
|
1218 | <addset | |
1190 | <baseset [3]>, |
|
1219 | <baseset [3]>, | |
1191 | <addset |
|
1220 | <addset | |
1192 | <baseset [1]>, |
|
1221 | <baseset [1]>, | |
1193 | <baseset [2]>>> |
|
1222 | <baseset [2]>>> | |
1194 | 3 |
|
1223 | 3 | |
1195 | 1 |
|
1224 | 1 | |
1196 | 2 |
|
1225 | 2 | |
1197 |
|
1226 | |||
1198 | test nesting and variable passing |
|
1227 | test nesting and variable passing | |
1199 |
|
1228 | |||
1200 | $ echo 'nested($1) = nested2($1)' >> .hg/hgrc |
|
1229 | $ echo 'nested($1) = nested2($1)' >> .hg/hgrc | |
1201 | $ echo 'nested2($1) = nested3($1)' >> .hg/hgrc |
|
1230 | $ echo 'nested2($1) = nested3($1)' >> .hg/hgrc | |
1202 | $ echo 'nested3($1) = max($1)' >> .hg/hgrc |
|
1231 | $ echo 'nested3($1) = max($1)' >> .hg/hgrc | |
1203 | $ try 'nested(2:5)' |
|
1232 | $ try 'nested(2:5)' | |
1204 | (func |
|
1233 | (func | |
1205 | ('symbol', 'nested') |
|
1234 | ('symbol', 'nested') | |
1206 | (range |
|
1235 | (range | |
1207 | ('symbol', '2') |
|
1236 | ('symbol', '2') | |
1208 | ('symbol', '5'))) |
|
1237 | ('symbol', '5'))) | |
1209 | (func |
|
1238 | (func | |
1210 | ('symbol', 'max') |
|
1239 | ('symbol', 'max') | |
1211 | (range |
|
1240 | (range | |
1212 | ('symbol', '2') |
|
1241 | ('symbol', '2') | |
1213 | ('symbol', '5'))) |
|
1242 | ('symbol', '5'))) | |
1214 | * set: |
|
1243 | * set: | |
1215 | <baseset [5]> |
|
1244 | <baseset [5]> | |
1216 | 5 |
|
1245 | 5 | |
1217 |
|
1246 | |||
1218 | test variable isolation, variable placeholders are rewritten as string |
|
1247 | test variable isolation, variable placeholders are rewritten as string | |
1219 | then parsed and matched again as string. Check they do not leak too |
|
1248 | then parsed and matched again as string. Check they do not leak too | |
1220 | far away. |
|
1249 | far away. | |
1221 |
|
1250 | |||
1222 | $ echo 'injectparamasstring = max("$1")' >> .hg/hgrc |
|
1251 | $ echo 'injectparamasstring = max("$1")' >> .hg/hgrc | |
1223 | $ echo 'callinjection($1) = descendants(injectparamasstring)' >> .hg/hgrc |
|
1252 | $ echo 'callinjection($1) = descendants(injectparamasstring)' >> .hg/hgrc | |
1224 | $ try 'callinjection(2:5)' |
|
1253 | $ try 'callinjection(2:5)' | |
1225 | (func |
|
1254 | (func | |
1226 | ('symbol', 'callinjection') |
|
1255 | ('symbol', 'callinjection') | |
1227 | (range |
|
1256 | (range | |
1228 | ('symbol', '2') |
|
1257 | ('symbol', '2') | |
1229 | ('symbol', '5'))) |
|
1258 | ('symbol', '5'))) | |
1230 | (func |
|
1259 | (func | |
1231 | ('symbol', 'descendants') |
|
1260 | ('symbol', 'descendants') | |
1232 | (func |
|
1261 | (func | |
1233 | ('symbol', 'max') |
|
1262 | ('symbol', 'max') | |
1234 | ('string', '$1'))) |
|
1263 | ('string', '$1'))) | |
1235 | abort: unknown revision '$1'! |
|
1264 | abort: unknown revision '$1'! | |
1236 | [255] |
|
1265 | [255] | |
1237 |
|
1266 | |||
1238 | $ echo 'injectparamasstring2 = max(_aliasarg("$1"))' >> .hg/hgrc |
|
1267 | $ echo 'injectparamasstring2 = max(_aliasarg("$1"))' >> .hg/hgrc | |
1239 | $ echo 'callinjection2($1) = descendants(injectparamasstring2)' >> .hg/hgrc |
|
1268 | $ echo 'callinjection2($1) = descendants(injectparamasstring2)' >> .hg/hgrc | |
1240 | $ try 'callinjection2(2:5)' |
|
1269 | $ try 'callinjection2(2:5)' | |
1241 | (func |
|
1270 | (func | |
1242 | ('symbol', 'callinjection2') |
|
1271 | ('symbol', 'callinjection2') | |
1243 | (range |
|
1272 | (range | |
1244 | ('symbol', '2') |
|
1273 | ('symbol', '2') | |
1245 | ('symbol', '5'))) |
|
1274 | ('symbol', '5'))) | |
1246 | abort: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg |
|
1275 | abort: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg | |
1247 | [255] |
|
1276 | [255] | |
1248 | $ hg debugrevspec --debug --config revsetalias.anotherbadone='branch(' "tip" |
|
1277 | $ hg debugrevspec --debug --config revsetalias.anotherbadone='branch(' "tip" | |
1249 | ('symbol', 'tip') |
|
1278 | ('symbol', 'tip') | |
1250 | warning: failed to parse the definition of revset alias "anotherbadone": at 7: not a prefix: end |
|
1279 | warning: failed to parse the definition of revset alias "anotherbadone": at 7: not a prefix: end | |
1251 | warning: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg |
|
1280 | warning: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg | |
1252 | * set: |
|
1281 | * set: | |
1253 | <baseset [9]> |
|
1282 | <baseset [9]> | |
1254 | 9 |
|
1283 | 9 | |
1255 | >>> data = file('.hg/hgrc', 'rb').read() |
|
1284 | >>> data = file('.hg/hgrc', 'rb').read() | |
1256 | >>> file('.hg/hgrc', 'wb').write(data.replace('_aliasarg', '')) |
|
1285 | >>> file('.hg/hgrc', 'wb').write(data.replace('_aliasarg', '')) | |
1257 |
|
1286 | |||
1258 | $ try 'tip' |
|
1287 | $ try 'tip' | |
1259 | ('symbol', 'tip') |
|
1288 | ('symbol', 'tip') | |
1260 | * set: |
|
1289 | * set: | |
1261 | <baseset [9]> |
|
1290 | <baseset [9]> | |
1262 | 9 |
|
1291 | 9 | |
1263 |
|
1292 | |||
1264 | $ hg debugrevspec --debug --config revsetalias.'bad name'='tip' "tip" |
|
1293 | $ hg debugrevspec --debug --config revsetalias.'bad name'='tip' "tip" | |
1265 | ('symbol', 'tip') |
|
1294 | ('symbol', 'tip') | |
1266 | warning: failed to parse the declaration of revset alias "bad name": at 4: invalid token |
|
1295 | warning: failed to parse the declaration of revset alias "bad name": at 4: invalid token | |
1267 | * set: |
|
1296 | * set: | |
1268 | <baseset [9]> |
|
1297 | <baseset [9]> | |
1269 | 9 |
|
1298 | 9 | |
1270 | $ echo 'strictreplacing($1, $10) = $10 or desc("$1")' >> .hg/hgrc |
|
1299 | $ echo 'strictreplacing($1, $10) = $10 or desc("$1")' >> .hg/hgrc | |
1271 | $ try 'strictreplacing("foo", tip)' |
|
1300 | $ try 'strictreplacing("foo", tip)' | |
1272 | (func |
|
1301 | (func | |
1273 | ('symbol', 'strictreplacing') |
|
1302 | ('symbol', 'strictreplacing') | |
1274 | (list |
|
1303 | (list | |
1275 | ('string', 'foo') |
|
1304 | ('string', 'foo') | |
1276 | ('symbol', 'tip'))) |
|
1305 | ('symbol', 'tip'))) | |
1277 | (or |
|
1306 | (or | |
1278 | ('symbol', 'tip') |
|
1307 | ('symbol', 'tip') | |
1279 | (func |
|
1308 | (func | |
1280 | ('symbol', 'desc') |
|
1309 | ('symbol', 'desc') | |
1281 | ('string', '$1'))) |
|
1310 | ('string', '$1'))) | |
1282 | * set: |
|
1311 | * set: | |
1283 | <addset |
|
1312 | <addset | |
1284 | <baseset [9]>, |
|
1313 | <baseset [9]>, | |
1285 | <filteredset |
|
1314 | <filteredset | |
1286 | <filteredset |
|
1315 | <filteredset | |
1287 | <fullreposet+ 0:9>>>> |
|
1316 | <fullreposet+ 0:9>>>> | |
1288 | 9 |
|
1317 | 9 | |
1289 |
|
1318 | |||
1290 | $ try 'd(2:5)' |
|
1319 | $ try 'd(2:5)' | |
1291 | (func |
|
1320 | (func | |
1292 | ('symbol', 'd') |
|
1321 | ('symbol', 'd') | |
1293 | (range |
|
1322 | (range | |
1294 | ('symbol', '2') |
|
1323 | ('symbol', '2') | |
1295 | ('symbol', '5'))) |
|
1324 | ('symbol', '5'))) | |
1296 | (func |
|
1325 | (func | |
1297 | ('symbol', 'reverse') |
|
1326 | ('symbol', 'reverse') | |
1298 | (func |
|
1327 | (func | |
1299 | ('symbol', 'sort') |
|
1328 | ('symbol', 'sort') | |
1300 | (list |
|
1329 | (list | |
1301 | (range |
|
1330 | (range | |
1302 | ('symbol', '2') |
|
1331 | ('symbol', '2') | |
1303 | ('symbol', '5')) |
|
1332 | ('symbol', '5')) | |
1304 | ('symbol', 'date')))) |
|
1333 | ('symbol', 'date')))) | |
1305 | * set: |
|
1334 | * set: | |
1306 | <baseset [4, 5, 3, 2]> |
|
1335 | <baseset [4, 5, 3, 2]> | |
1307 | 4 |
|
1336 | 4 | |
1308 | 5 |
|
1337 | 5 | |
1309 | 3 |
|
1338 | 3 | |
1310 | 2 |
|
1339 | 2 | |
1311 | $ try 'rs(2 or 3, date)' |
|
1340 | $ try 'rs(2 or 3, date)' | |
1312 | (func |
|
1341 | (func | |
1313 | ('symbol', 'rs') |
|
1342 | ('symbol', 'rs') | |
1314 | (list |
|
1343 | (list | |
1315 | (or |
|
1344 | (or | |
1316 | ('symbol', '2') |
|
1345 | ('symbol', '2') | |
1317 | ('symbol', '3')) |
|
1346 | ('symbol', '3')) | |
1318 | ('symbol', 'date'))) |
|
1347 | ('symbol', 'date'))) | |
1319 | (func |
|
1348 | (func | |
1320 | ('symbol', 'reverse') |
|
1349 | ('symbol', 'reverse') | |
1321 | (func |
|
1350 | (func | |
1322 | ('symbol', 'sort') |
|
1351 | ('symbol', 'sort') | |
1323 | (list |
|
1352 | (list | |
1324 | (or |
|
1353 | (or | |
1325 | ('symbol', '2') |
|
1354 | ('symbol', '2') | |
1326 | ('symbol', '3')) |
|
1355 | ('symbol', '3')) | |
1327 | ('symbol', 'date')))) |
|
1356 | ('symbol', 'date')))) | |
1328 | * set: |
|
1357 | * set: | |
1329 | <baseset [3, 2]> |
|
1358 | <baseset [3, 2]> | |
1330 | 3 |
|
1359 | 3 | |
1331 | 2 |
|
1360 | 2 | |
1332 | $ try 'rs()' |
|
1361 | $ try 'rs()' | |
1333 | (func |
|
1362 | (func | |
1334 | ('symbol', 'rs') |
|
1363 | ('symbol', 'rs') | |
1335 | None) |
|
1364 | None) | |
1336 | hg: parse error: invalid number of arguments: 0 |
|
1365 | hg: parse error: invalid number of arguments: 0 | |
1337 | [255] |
|
1366 | [255] | |
1338 | $ try 'rs(2)' |
|
1367 | $ try 'rs(2)' | |
1339 | (func |
|
1368 | (func | |
1340 | ('symbol', 'rs') |
|
1369 | ('symbol', 'rs') | |
1341 | ('symbol', '2')) |
|
1370 | ('symbol', '2')) | |
1342 | hg: parse error: invalid number of arguments: 1 |
|
1371 | hg: parse error: invalid number of arguments: 1 | |
1343 | [255] |
|
1372 | [255] | |
1344 | $ try 'rs(2, data, 7)' |
|
1373 | $ try 'rs(2, data, 7)' | |
1345 | (func |
|
1374 | (func | |
1346 | ('symbol', 'rs') |
|
1375 | ('symbol', 'rs') | |
1347 | (list |
|
1376 | (list | |
1348 | (list |
|
1377 | (list | |
1349 | ('symbol', '2') |
|
1378 | ('symbol', '2') | |
1350 | ('symbol', 'data')) |
|
1379 | ('symbol', 'data')) | |
1351 | ('symbol', '7'))) |
|
1380 | ('symbol', '7'))) | |
1352 | hg: parse error: invalid number of arguments: 3 |
|
1381 | hg: parse error: invalid number of arguments: 3 | |
1353 | [255] |
|
1382 | [255] | |
1354 | $ try 'rs4(2 or 3, x, x, date)' |
|
1383 | $ try 'rs4(2 or 3, x, x, date)' | |
1355 | (func |
|
1384 | (func | |
1356 | ('symbol', 'rs4') |
|
1385 | ('symbol', 'rs4') | |
1357 | (list |
|
1386 | (list | |
1358 | (list |
|
1387 | (list | |
1359 | (list |
|
1388 | (list | |
1360 | (or |
|
1389 | (or | |
1361 | ('symbol', '2') |
|
1390 | ('symbol', '2') | |
1362 | ('symbol', '3')) |
|
1391 | ('symbol', '3')) | |
1363 | ('symbol', 'x')) |
|
1392 | ('symbol', 'x')) | |
1364 | ('symbol', 'x')) |
|
1393 | ('symbol', 'x')) | |
1365 | ('symbol', 'date'))) |
|
1394 | ('symbol', 'date'))) | |
1366 | (func |
|
1395 | (func | |
1367 | ('symbol', 'reverse') |
|
1396 | ('symbol', 'reverse') | |
1368 | (func |
|
1397 | (func | |
1369 | ('symbol', 'sort') |
|
1398 | ('symbol', 'sort') | |
1370 | (list |
|
1399 | (list | |
1371 | (or |
|
1400 | (or | |
1372 | ('symbol', '2') |
|
1401 | ('symbol', '2') | |
1373 | ('symbol', '3')) |
|
1402 | ('symbol', '3')) | |
1374 | ('symbol', 'date')))) |
|
1403 | ('symbol', 'date')))) | |
1375 | * set: |
|
1404 | * set: | |
1376 | <baseset [3, 2]> |
|
1405 | <baseset [3, 2]> | |
1377 | 3 |
|
1406 | 3 | |
1378 | 2 |
|
1407 | 2 | |
1379 |
|
1408 | |||
1380 | issue4553: check that revset aliases override existing hash prefix |
|
1409 | issue4553: check that revset aliases override existing hash prefix | |
1381 |
|
1410 | |||
1382 | $ hg log -qr e |
|
1411 | $ hg log -qr e | |
1383 | 6:e0cc66ef77e8 |
|
1412 | 6:e0cc66ef77e8 | |
1384 |
|
1413 | |||
1385 | $ hg log -qr e --config revsetalias.e="all()" |
|
1414 | $ hg log -qr e --config revsetalias.e="all()" | |
1386 | 0:2785f51eece5 |
|
1415 | 0:2785f51eece5 | |
1387 | 1:d75937da8da0 |
|
1416 | 1:d75937da8da0 | |
1388 | 2:5ed5505e9f1c |
|
1417 | 2:5ed5505e9f1c | |
1389 | 3:8528aa5637f2 |
|
1418 | 3:8528aa5637f2 | |
1390 | 4:2326846efdab |
|
1419 | 4:2326846efdab | |
1391 | 5:904fa392b941 |
|
1420 | 5:904fa392b941 | |
1392 | 6:e0cc66ef77e8 |
|
1421 | 6:e0cc66ef77e8 | |
1393 | 7:013af1973af4 |
|
1422 | 7:013af1973af4 | |
1394 | 8:d5d0dcbdc4d9 |
|
1423 | 8:d5d0dcbdc4d9 | |
1395 | 9:24286f4ae135 |
|
1424 | 9:24286f4ae135 | |
1396 |
|
1425 | |||
1397 | $ hg log -qr e: --config revsetalias.e="0" |
|
1426 | $ hg log -qr e: --config revsetalias.e="0" | |
1398 | 0:2785f51eece5 |
|
1427 | 0:2785f51eece5 | |
1399 | 1:d75937da8da0 |
|
1428 | 1:d75937da8da0 | |
1400 | 2:5ed5505e9f1c |
|
1429 | 2:5ed5505e9f1c | |
1401 | 3:8528aa5637f2 |
|
1430 | 3:8528aa5637f2 | |
1402 | 4:2326846efdab |
|
1431 | 4:2326846efdab | |
1403 | 5:904fa392b941 |
|
1432 | 5:904fa392b941 | |
1404 | 6:e0cc66ef77e8 |
|
1433 | 6:e0cc66ef77e8 | |
1405 | 7:013af1973af4 |
|
1434 | 7:013af1973af4 | |
1406 | 8:d5d0dcbdc4d9 |
|
1435 | 8:d5d0dcbdc4d9 | |
1407 | 9:24286f4ae135 |
|
1436 | 9:24286f4ae135 | |
1408 |
|
1437 | |||
1409 | $ hg log -qr :e --config revsetalias.e="9" |
|
1438 | $ hg log -qr :e --config revsetalias.e="9" | |
1410 | 0:2785f51eece5 |
|
1439 | 0:2785f51eece5 | |
1411 | 1:d75937da8da0 |
|
1440 | 1:d75937da8da0 | |
1412 | 2:5ed5505e9f1c |
|
1441 | 2:5ed5505e9f1c | |
1413 | 3:8528aa5637f2 |
|
1442 | 3:8528aa5637f2 | |
1414 | 4:2326846efdab |
|
1443 | 4:2326846efdab | |
1415 | 5:904fa392b941 |
|
1444 | 5:904fa392b941 | |
1416 | 6:e0cc66ef77e8 |
|
1445 | 6:e0cc66ef77e8 | |
1417 | 7:013af1973af4 |
|
1446 | 7:013af1973af4 | |
1418 | 8:d5d0dcbdc4d9 |
|
1447 | 8:d5d0dcbdc4d9 | |
1419 | 9:24286f4ae135 |
|
1448 | 9:24286f4ae135 | |
1420 |
|
1449 | |||
1421 | $ hg log -qr e: |
|
1450 | $ hg log -qr e: | |
1422 | 6:e0cc66ef77e8 |
|
1451 | 6:e0cc66ef77e8 | |
1423 | 7:013af1973af4 |
|
1452 | 7:013af1973af4 | |
1424 | 8:d5d0dcbdc4d9 |
|
1453 | 8:d5d0dcbdc4d9 | |
1425 | 9:24286f4ae135 |
|
1454 | 9:24286f4ae135 | |
1426 |
|
1455 | |||
1427 | $ hg log -qr :e |
|
1456 | $ hg log -qr :e | |
1428 | 0:2785f51eece5 |
|
1457 | 0:2785f51eece5 | |
1429 | 1:d75937da8da0 |
|
1458 | 1:d75937da8da0 | |
1430 | 2:5ed5505e9f1c |
|
1459 | 2:5ed5505e9f1c | |
1431 | 3:8528aa5637f2 |
|
1460 | 3:8528aa5637f2 | |
1432 | 4:2326846efdab |
|
1461 | 4:2326846efdab | |
1433 | 5:904fa392b941 |
|
1462 | 5:904fa392b941 | |
1434 | 6:e0cc66ef77e8 |
|
1463 | 6:e0cc66ef77e8 | |
1435 |
|
1464 | |||
1436 | issue2549 - correct optimizations |
|
1465 | issue2549 - correct optimizations | |
1437 |
|
1466 | |||
1438 | $ log 'limit(1 or 2 or 3, 2) and not 2' |
|
1467 | $ log 'limit(1 or 2 or 3, 2) and not 2' | |
1439 | 1 |
|
1468 | 1 | |
1440 | $ log 'max(1 or 2) and not 2' |
|
1469 | $ log 'max(1 or 2) and not 2' | |
1441 | $ log 'min(1 or 2) and not 1' |
|
1470 | $ log 'min(1 or 2) and not 1' | |
1442 | $ log 'last(1 or 2, 1) and not 2' |
|
1471 | $ log 'last(1 or 2, 1) and not 2' | |
1443 |
|
1472 | |||
1444 | issue4289 - ordering of built-ins |
|
1473 | issue4289 - ordering of built-ins | |
1445 | $ hg log -M -q -r 3:2 |
|
1474 | $ hg log -M -q -r 3:2 | |
1446 | 3:8528aa5637f2 |
|
1475 | 3:8528aa5637f2 | |
1447 | 2:5ed5505e9f1c |
|
1476 | 2:5ed5505e9f1c | |
1448 |
|
1477 | |||
1449 | test revsets started with 40-chars hash (issue3669) |
|
1478 | test revsets started with 40-chars hash (issue3669) | |
1450 |
|
1479 | |||
1451 | $ ISSUE3669_TIP=`hg tip --template '{node}'` |
|
1480 | $ ISSUE3669_TIP=`hg tip --template '{node}'` | |
1452 | $ hg log -r "${ISSUE3669_TIP}" --template '{rev}\n' |
|
1481 | $ hg log -r "${ISSUE3669_TIP}" --template '{rev}\n' | |
1453 | 9 |
|
1482 | 9 | |
1454 | $ hg log -r "${ISSUE3669_TIP}^" --template '{rev}\n' |
|
1483 | $ hg log -r "${ISSUE3669_TIP}^" --template '{rev}\n' | |
1455 | 8 |
|
1484 | 8 | |
1456 |
|
1485 | |||
1457 | test or-ed indirect predicates (issue3775) |
|
1486 | test or-ed indirect predicates (issue3775) | |
1458 |
|
1487 | |||
1459 | $ log '6 or 6^1' | sort |
|
1488 | $ log '6 or 6^1' | sort | |
1460 | 5 |
|
1489 | 5 | |
1461 | 6 |
|
1490 | 6 | |
1462 | $ log '6^1 or 6' | sort |
|
1491 | $ log '6^1 or 6' | sort | |
1463 | 5 |
|
1492 | 5 | |
1464 | 6 |
|
1493 | 6 | |
1465 | $ log '4 or 4~1' | sort |
|
1494 | $ log '4 or 4~1' | sort | |
1466 | 2 |
|
1495 | 2 | |
1467 | 4 |
|
1496 | 4 | |
1468 | $ log '4~1 or 4' | sort |
|
1497 | $ log '4~1 or 4' | sort | |
1469 | 2 |
|
1498 | 2 | |
1470 | 4 |
|
1499 | 4 | |
1471 | $ log '(0 or 2):(4 or 6) or 0 or 6' | sort |
|
1500 | $ log '(0 or 2):(4 or 6) or 0 or 6' | sort | |
1472 | 0 |
|
1501 | 0 | |
1473 | 1 |
|
1502 | 1 | |
1474 | 2 |
|
1503 | 2 | |
1475 | 3 |
|
1504 | 3 | |
1476 | 4 |
|
1505 | 4 | |
1477 | 5 |
|
1506 | 5 | |
1478 | 6 |
|
1507 | 6 | |
1479 | $ log '0 or 6 or (0 or 2):(4 or 6)' | sort |
|
1508 | $ log '0 or 6 or (0 or 2):(4 or 6)' | sort | |
1480 | 0 |
|
1509 | 0 | |
1481 | 1 |
|
1510 | 1 | |
1482 | 2 |
|
1511 | 2 | |
1483 | 3 |
|
1512 | 3 | |
1484 | 4 |
|
1513 | 4 | |
1485 | 5 |
|
1514 | 5 | |
1486 | 6 |
|
1515 | 6 | |
1487 |
|
1516 | |||
1488 | tests for 'remote()' predicate: |
|
1517 | tests for 'remote()' predicate: | |
1489 | #. (csets in remote) (id) (remote) |
|
1518 | #. (csets in remote) (id) (remote) | |
1490 | 1. less than local current branch "default" |
|
1519 | 1. less than local current branch "default" | |
1491 | 2. same with local specified "default" |
|
1520 | 2. same with local specified "default" | |
1492 | 3. more than local specified specified |
|
1521 | 3. more than local specified specified | |
1493 |
|
1522 | |||
1494 | $ hg clone --quiet -U . ../remote3 |
|
1523 | $ hg clone --quiet -U . ../remote3 | |
1495 | $ cd ../remote3 |
|
1524 | $ cd ../remote3 | |
1496 | $ hg update -q 7 |
|
1525 | $ hg update -q 7 | |
1497 | $ echo r > r |
|
1526 | $ echo r > r | |
1498 | $ hg ci -Aqm 10 |
|
1527 | $ hg ci -Aqm 10 | |
1499 | $ log 'remote()' |
|
1528 | $ log 'remote()' | |
1500 | 7 |
|
1529 | 7 | |
1501 | $ log 'remote("a-b-c-")' |
|
1530 | $ log 'remote("a-b-c-")' | |
1502 | 2 |
|
1531 | 2 | |
1503 | $ cd ../repo |
|
1532 | $ cd ../repo | |
1504 | $ log 'remote(".a.b.c.", "../remote3")' |
|
1533 | $ log 'remote(".a.b.c.", "../remote3")' | |
1505 |
|
1534 | |||
1506 | tests for concatenation of strings/symbols by "##" |
|
1535 | tests for concatenation of strings/symbols by "##" | |
1507 |
|
1536 | |||
1508 | $ try "278 ## '5f5' ## 1ee ## 'ce5'" |
|
1537 | $ try "278 ## '5f5' ## 1ee ## 'ce5'" | |
1509 | (_concat |
|
1538 | (_concat | |
1510 | (_concat |
|
1539 | (_concat | |
1511 | (_concat |
|
1540 | (_concat | |
1512 | ('symbol', '278') |
|
1541 | ('symbol', '278') | |
1513 | ('string', '5f5')) |
|
1542 | ('string', '5f5')) | |
1514 | ('symbol', '1ee')) |
|
1543 | ('symbol', '1ee')) | |
1515 | ('string', 'ce5')) |
|
1544 | ('string', 'ce5')) | |
1516 | ('string', '2785f51eece5') |
|
1545 | ('string', '2785f51eece5') | |
1517 | * set: |
|
1546 | * set: | |
1518 | <baseset [0]> |
|
1547 | <baseset [0]> | |
1519 | 0 |
|
1548 | 0 | |
1520 |
|
1549 | |||
1521 | $ echo 'cat4($1, $2, $3, $4) = $1 ## $2 ## $3 ## $4' >> .hg/hgrc |
|
1550 | $ echo 'cat4($1, $2, $3, $4) = $1 ## $2 ## $3 ## $4' >> .hg/hgrc | |
1522 | $ try "cat4(278, '5f5', 1ee, 'ce5')" |
|
1551 | $ try "cat4(278, '5f5', 1ee, 'ce5')" | |
1523 | (func |
|
1552 | (func | |
1524 | ('symbol', 'cat4') |
|
1553 | ('symbol', 'cat4') | |
1525 | (list |
|
1554 | (list | |
1526 | (list |
|
1555 | (list | |
1527 | (list |
|
1556 | (list | |
1528 | ('symbol', '278') |
|
1557 | ('symbol', '278') | |
1529 | ('string', '5f5')) |
|
1558 | ('string', '5f5')) | |
1530 | ('symbol', '1ee')) |
|
1559 | ('symbol', '1ee')) | |
1531 | ('string', 'ce5'))) |
|
1560 | ('string', 'ce5'))) | |
1532 | (_concat |
|
1561 | (_concat | |
1533 | (_concat |
|
1562 | (_concat | |
1534 | (_concat |
|
1563 | (_concat | |
1535 | ('symbol', '278') |
|
1564 | ('symbol', '278') | |
1536 | ('string', '5f5')) |
|
1565 | ('string', '5f5')) | |
1537 | ('symbol', '1ee')) |
|
1566 | ('symbol', '1ee')) | |
1538 | ('string', 'ce5')) |
|
1567 | ('string', 'ce5')) | |
1539 | ('string', '2785f51eece5') |
|
1568 | ('string', '2785f51eece5') | |
1540 | * set: |
|
1569 | * set: | |
1541 | <baseset [0]> |
|
1570 | <baseset [0]> | |
1542 | 0 |
|
1571 | 0 | |
1543 |
|
1572 | |||
1544 | (check concatenation in alias nesting) |
|
1573 | (check concatenation in alias nesting) | |
1545 |
|
1574 | |||
1546 | $ echo 'cat2($1, $2) = $1 ## $2' >> .hg/hgrc |
|
1575 | $ echo 'cat2($1, $2) = $1 ## $2' >> .hg/hgrc | |
1547 | $ echo 'cat2x2($1, $2, $3, $4) = cat2($1 ## $2, $3 ## $4)' >> .hg/hgrc |
|
1576 | $ echo 'cat2x2($1, $2, $3, $4) = cat2($1 ## $2, $3 ## $4)' >> .hg/hgrc | |
1548 | $ log "cat2x2(278, '5f5', 1ee, 'ce5')" |
|
1577 | $ log "cat2x2(278, '5f5', 1ee, 'ce5')" | |
1549 | 0 |
|
1578 | 0 | |
1550 |
|
1579 | |||
1551 | (check operator priority) |
|
1580 | (check operator priority) | |
1552 |
|
1581 | |||
1553 | $ echo 'cat2n2($1, $2, $3, $4) = $1 ## $2 or $3 ## $4~2' >> .hg/hgrc |
|
1582 | $ echo 'cat2n2($1, $2, $3, $4) = $1 ## $2 or $3 ## $4~2' >> .hg/hgrc | |
1554 | $ log "cat2n2(2785f5, 1eece5, 24286f, 4ae135)" |
|
1583 | $ log "cat2n2(2785f5, 1eece5, 24286f, 4ae135)" | |
1555 | 0 |
|
1584 | 0 | |
1556 | 4 |
|
1585 | 4 | |
1557 |
|
1586 | |||
1558 | $ cd .. |
|
1587 | $ cd .. | |
1559 |
|
1588 | |||
1560 | test author/desc/keyword in problematic encoding |
|
1589 | test author/desc/keyword in problematic encoding | |
1561 | # unicode: cp932: |
|
1590 | # unicode: cp932: | |
1562 | # u30A2 0x83 0x41(= 'A') |
|
1591 | # u30A2 0x83 0x41(= 'A') | |
1563 | # u30C2 0x83 0x61(= 'a') |
|
1592 | # u30C2 0x83 0x61(= 'a') | |
1564 |
|
1593 | |||
1565 | $ hg init problematicencoding |
|
1594 | $ hg init problematicencoding | |
1566 | $ cd problematicencoding |
|
1595 | $ cd problematicencoding | |
1567 |
|
1596 | |||
1568 | $ python > setup.sh <<EOF |
|
1597 | $ python > setup.sh <<EOF | |
1569 | > print u''' |
|
1598 | > print u''' | |
1570 | > echo a > text |
|
1599 | > echo a > text | |
1571 | > hg add text |
|
1600 | > hg add text | |
1572 | > hg --encoding utf-8 commit -u '\u30A2' -m none |
|
1601 | > hg --encoding utf-8 commit -u '\u30A2' -m none | |
1573 | > echo b > text |
|
1602 | > echo b > text | |
1574 | > hg --encoding utf-8 commit -u '\u30C2' -m none |
|
1603 | > hg --encoding utf-8 commit -u '\u30C2' -m none | |
1575 | > echo c > text |
|
1604 | > echo c > text | |
1576 | > hg --encoding utf-8 commit -u none -m '\u30A2' |
|
1605 | > hg --encoding utf-8 commit -u none -m '\u30A2' | |
1577 | > echo d > text |
|
1606 | > echo d > text | |
1578 | > hg --encoding utf-8 commit -u none -m '\u30C2' |
|
1607 | > hg --encoding utf-8 commit -u none -m '\u30C2' | |
1579 | > '''.encode('utf-8') |
|
1608 | > '''.encode('utf-8') | |
1580 | > EOF |
|
1609 | > EOF | |
1581 | $ sh < setup.sh |
|
1610 | $ sh < setup.sh | |
1582 |
|
1611 | |||
1583 | test in problematic encoding |
|
1612 | test in problematic encoding | |
1584 | $ python > test.sh <<EOF |
|
1613 | $ python > test.sh <<EOF | |
1585 | > print u''' |
|
1614 | > print u''' | |
1586 | > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30A2)' |
|
1615 | > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30A2)' | |
1587 | > echo ==== |
|
1616 | > echo ==== | |
1588 | > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30C2)' |
|
1617 | > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30C2)' | |
1589 | > echo ==== |
|
1618 | > echo ==== | |
1590 | > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30A2)' |
|
1619 | > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30A2)' | |
1591 | > echo ==== |
|
1620 | > echo ==== | |
1592 | > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30C2)' |
|
1621 | > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30C2)' | |
1593 | > echo ==== |
|
1622 | > echo ==== | |
1594 | > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30A2)' |
|
1623 | > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30A2)' | |
1595 | > echo ==== |
|
1624 | > echo ==== | |
1596 | > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30C2)' |
|
1625 | > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30C2)' | |
1597 | > '''.encode('cp932') |
|
1626 | > '''.encode('cp932') | |
1598 | > EOF |
|
1627 | > EOF | |
1599 | $ sh < test.sh |
|
1628 | $ sh < test.sh | |
1600 | 0 |
|
1629 | 0 | |
1601 | ==== |
|
1630 | ==== | |
1602 | 1 |
|
1631 | 1 | |
1603 | ==== |
|
1632 | ==== | |
1604 | 2 |
|
1633 | 2 | |
1605 | ==== |
|
1634 | ==== | |
1606 | 3 |
|
1635 | 3 | |
1607 | ==== |
|
1636 | ==== | |
1608 | 0 |
|
1637 | 0 | |
1609 | 2 |
|
1638 | 2 | |
1610 | ==== |
|
1639 | ==== | |
1611 | 1 |
|
1640 | 1 | |
1612 | 3 |
|
1641 | 3 | |
1613 |
|
1642 | |||
1614 | test error message of bad revset |
|
1643 | test error message of bad revset | |
1615 | $ hg log -r 'foo\\' |
|
1644 | $ hg log -r 'foo\\' | |
1616 | hg: parse error at 3: syntax error in revset 'foo\\' |
|
1645 | hg: parse error at 3: syntax error in revset 'foo\\' | |
1617 | [255] |
|
1646 | [255] | |
1618 |
|
1647 | |||
1619 | $ cd .. |
|
1648 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now