Show More
@@ -1,3445 +1,3448 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): |
|
337 | def symbolset(repo, subset, x): | |
338 | if x in symbols: |
|
338 | if x in symbols: | |
339 | raise error.ParseError(_("can't use %s here") % x) |
|
339 | raise error.ParseError(_("can't use %s here") % x) | |
340 | return stringset(repo, subset, x) |
|
340 | return stringset(repo, subset, x) | |
341 |
|
341 | |||
342 | def rangeset(repo, subset, x, y): |
|
342 | def rangeset(repo, subset, x, y): | |
343 | m = getset(repo, fullreposet(repo), x) |
|
343 | m = getset(repo, fullreposet(repo), x) | |
344 | n = getset(repo, fullreposet(repo), y) |
|
344 | n = getset(repo, fullreposet(repo), y) | |
345 |
|
345 | |||
346 | if not m or not n: |
|
346 | if not m or not n: | |
347 | return baseset() |
|
347 | return baseset() | |
348 | m, n = m.first(), n.last() |
|
348 | m, n = m.first(), n.last() | |
349 |
|
349 | |||
350 | if m < n: |
|
350 | if m < n: | |
351 | r = spanset(repo, m, n + 1) |
|
351 | r = spanset(repo, m, n + 1) | |
352 | else: |
|
352 | else: | |
353 | r = spanset(repo, m, n - 1) |
|
353 | r = spanset(repo, m, n - 1) | |
354 | return r & subset |
|
354 | return r & subset | |
355 |
|
355 | |||
356 | def dagrange(repo, subset, x, y): |
|
356 | def dagrange(repo, subset, x, y): | |
357 | r = fullreposet(repo) |
|
357 | r = fullreposet(repo) | |
358 | xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y)) |
|
358 | xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y)) | |
359 | return xs & subset |
|
359 | return xs & subset | |
360 |
|
360 | |||
361 | def andset(repo, subset, x, y): |
|
361 | def andset(repo, subset, x, y): | |
362 | return getset(repo, getset(repo, subset, x), y) |
|
362 | return getset(repo, getset(repo, subset, x), y) | |
363 |
|
363 | |||
364 | def orset(repo, subset, x, y): |
|
364 | def orset(repo, subset, x, y): | |
365 | xl = getset(repo, subset, x) |
|
365 | xl = getset(repo, subset, x) | |
366 | yl = getset(repo, subset - xl, y) |
|
366 | yl = getset(repo, subset - xl, y) | |
367 | return xl + yl |
|
367 | return xl + yl | |
368 |
|
368 | |||
369 | def notset(repo, subset, x): |
|
369 | def notset(repo, subset, x): | |
370 | return subset - getset(repo, subset, x) |
|
370 | return subset - getset(repo, subset, x) | |
371 |
|
371 | |||
372 | def listset(repo, subset, a, b): |
|
372 | def listset(repo, subset, a, b): | |
373 | raise error.ParseError(_("can't use a list in this context")) |
|
373 | raise error.ParseError(_("can't use a list in this context")) | |
374 |
|
374 | |||
375 | def func(repo, subset, a, b): |
|
375 | def func(repo, subset, a, b): | |
376 | if a[0] == 'symbol' and a[1] in symbols: |
|
376 | if a[0] == 'symbol' and a[1] in symbols: | |
377 | return symbols[a[1]](repo, subset, b) |
|
377 | return symbols[a[1]](repo, subset, b) | |
378 | raise error.UnknownIdentifier(a[1], symbols.keys()) |
|
378 | raise error.UnknownIdentifier(a[1], symbols.keys()) | |
379 |
|
379 | |||
380 | # functions |
|
380 | # functions | |
381 |
|
381 | |||
382 | def adds(repo, subset, x): |
|
382 | def adds(repo, subset, x): | |
383 | """``adds(pattern)`` |
|
383 | """``adds(pattern)`` | |
384 | Changesets that add a file matching pattern. |
|
384 | Changesets that add a file matching pattern. | |
385 |
|
385 | |||
386 | The pattern without explicit kind like ``glob:`` is expected to be |
|
386 | The pattern without explicit kind like ``glob:`` is expected to be | |
387 | relative to the current directory and match against a file or a |
|
387 | relative to the current directory and match against a file or a | |
388 | directory. |
|
388 | directory. | |
389 | """ |
|
389 | """ | |
390 | # i18n: "adds" is a keyword |
|
390 | # i18n: "adds" is a keyword | |
391 | pat = getstring(x, _("adds requires a pattern")) |
|
391 | pat = getstring(x, _("adds requires a pattern")) | |
392 | return checkstatus(repo, subset, pat, 1) |
|
392 | return checkstatus(repo, subset, pat, 1) | |
393 |
|
393 | |||
394 | def ancestor(repo, subset, x): |
|
394 | def ancestor(repo, subset, x): | |
395 | """``ancestor(*changeset)`` |
|
395 | """``ancestor(*changeset)`` | |
396 | A greatest common ancestor of the changesets. |
|
396 | A greatest common ancestor of the changesets. | |
397 |
|
397 | |||
398 | Accepts 0 or more changesets. |
|
398 | Accepts 0 or more changesets. | |
399 | Will return empty list when passed no args. |
|
399 | Will return empty list when passed no args. | |
400 | Greatest common ancestor of a single changeset is that changeset. |
|
400 | Greatest common ancestor of a single changeset is that changeset. | |
401 | """ |
|
401 | """ | |
402 | # i18n: "ancestor" is a keyword |
|
402 | # i18n: "ancestor" is a keyword | |
403 | l = getlist(x) |
|
403 | l = getlist(x) | |
404 | rl = fullreposet(repo) |
|
404 | rl = fullreposet(repo) | |
405 | anc = None |
|
405 | anc = None | |
406 |
|
406 | |||
407 | # (getset(repo, rl, i) for i in l) generates a list of lists |
|
407 | # (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): |
|
408 | for revs in (getset(repo, rl, i) for i in l): | |
409 | for r in revs: |
|
409 | for r in revs: | |
410 | if anc is None: |
|
410 | if anc is None: | |
411 | anc = repo[r] |
|
411 | anc = repo[r] | |
412 | else: |
|
412 | else: | |
413 | anc = anc.ancestor(repo[r]) |
|
413 | anc = anc.ancestor(repo[r]) | |
414 |
|
414 | |||
415 | if anc is not None and anc.rev() in subset: |
|
415 | if anc is not None and anc.rev() in subset: | |
416 | return baseset([anc.rev()]) |
|
416 | return baseset([anc.rev()]) | |
417 | return baseset() |
|
417 | return baseset() | |
418 |
|
418 | |||
419 | def _ancestors(repo, subset, x, followfirst=False): |
|
419 | def _ancestors(repo, subset, x, followfirst=False): | |
420 | heads = getset(repo, fullreposet(repo), x) |
|
420 | heads = getset(repo, fullreposet(repo), x) | |
421 | if not heads: |
|
421 | if not heads: | |
422 | return baseset() |
|
422 | return baseset() | |
423 | s = _revancestors(repo, heads, followfirst) |
|
423 | s = _revancestors(repo, heads, followfirst) | |
424 | return subset & s |
|
424 | return subset & s | |
425 |
|
425 | |||
426 | def ancestors(repo, subset, x): |
|
426 | def ancestors(repo, subset, x): | |
427 | """``ancestors(set)`` |
|
427 | """``ancestors(set)`` | |
428 | Changesets that are ancestors of a changeset in set. |
|
428 | Changesets that are ancestors of a changeset in set. | |
429 | """ |
|
429 | """ | |
430 | return _ancestors(repo, subset, x) |
|
430 | return _ancestors(repo, subset, x) | |
431 |
|
431 | |||
432 | def _firstancestors(repo, subset, x): |
|
432 | def _firstancestors(repo, subset, x): | |
433 | # ``_firstancestors(set)`` |
|
433 | # ``_firstancestors(set)`` | |
434 | # Like ``ancestors(set)`` but follows only the first parents. |
|
434 | # Like ``ancestors(set)`` but follows only the first parents. | |
435 | return _ancestors(repo, subset, x, followfirst=True) |
|
435 | return _ancestors(repo, subset, x, followfirst=True) | |
436 |
|
436 | |||
437 | def ancestorspec(repo, subset, x, n): |
|
437 | def ancestorspec(repo, subset, x, n): | |
438 | """``set~n`` |
|
438 | """``set~n`` | |
439 | Changesets that are the Nth ancestor (first parents only) of a changeset |
|
439 | Changesets that are the Nth ancestor (first parents only) of a changeset | |
440 | in set. |
|
440 | in set. | |
441 | """ |
|
441 | """ | |
442 | try: |
|
442 | try: | |
443 | n = int(n[1]) |
|
443 | n = int(n[1]) | |
444 | except (TypeError, ValueError): |
|
444 | except (TypeError, ValueError): | |
445 | raise error.ParseError(_("~ expects a number")) |
|
445 | raise error.ParseError(_("~ expects a number")) | |
446 | ps = set() |
|
446 | ps = set() | |
447 | cl = repo.changelog |
|
447 | cl = repo.changelog | |
448 | for r in getset(repo, fullreposet(repo), x): |
|
448 | for r in getset(repo, fullreposet(repo), x): | |
449 | for i in range(n): |
|
449 | for i in range(n): | |
450 | r = cl.parentrevs(r)[0] |
|
450 | r = cl.parentrevs(r)[0] | |
451 | ps.add(r) |
|
451 | ps.add(r) | |
452 | return subset & ps |
|
452 | return subset & ps | |
453 |
|
453 | |||
454 | def author(repo, subset, x): |
|
454 | def author(repo, subset, x): | |
455 | """``author(string)`` |
|
455 | """``author(string)`` | |
456 | Alias for ``user(string)``. |
|
456 | Alias for ``user(string)``. | |
457 | """ |
|
457 | """ | |
458 | # i18n: "author" is a keyword |
|
458 | # i18n: "author" is a keyword | |
459 | n = encoding.lower(getstring(x, _("author requires a string"))) |
|
459 | n = encoding.lower(getstring(x, _("author requires a string"))) | |
460 | kind, pattern, matcher = _substringmatcher(n) |
|
460 | kind, pattern, matcher = _substringmatcher(n) | |
461 | return subset.filter(lambda x: matcher(encoding.lower(repo[x].user()))) |
|
461 | return subset.filter(lambda x: matcher(encoding.lower(repo[x].user()))) | |
462 |
|
462 | |||
463 | def bisect(repo, subset, x): |
|
463 | def bisect(repo, subset, x): | |
464 | """``bisect(string)`` |
|
464 | """``bisect(string)`` | |
465 | Changesets marked in the specified bisect status: |
|
465 | Changesets marked in the specified bisect status: | |
466 |
|
466 | |||
467 | - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip |
|
467 | - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip | |
468 | - ``goods``, ``bads`` : csets topologically good/bad |
|
468 | - ``goods``, ``bads`` : csets topologically good/bad | |
469 | - ``range`` : csets taking part in the bisection |
|
469 | - ``range`` : csets taking part in the bisection | |
470 | - ``pruned`` : csets that are goods, bads or skipped |
|
470 | - ``pruned`` : csets that are goods, bads or skipped | |
471 | - ``untested`` : csets whose fate is yet unknown |
|
471 | - ``untested`` : csets whose fate is yet unknown | |
472 | - ``ignored`` : csets ignored due to DAG topology |
|
472 | - ``ignored`` : csets ignored due to DAG topology | |
473 | - ``current`` : the cset currently being bisected |
|
473 | - ``current`` : the cset currently being bisected | |
474 | """ |
|
474 | """ | |
475 | # i18n: "bisect" is a keyword |
|
475 | # i18n: "bisect" is a keyword | |
476 | status = getstring(x, _("bisect requires a string")).lower() |
|
476 | status = getstring(x, _("bisect requires a string")).lower() | |
477 | state = set(hbisect.get(repo, status)) |
|
477 | state = set(hbisect.get(repo, status)) | |
478 | return subset & state |
|
478 | return subset & state | |
479 |
|
479 | |||
480 | # Backward-compatibility |
|
480 | # Backward-compatibility | |
481 | # - no help entry so that we do not advertise it any more |
|
481 | # - no help entry so that we do not advertise it any more | |
482 | def bisected(repo, subset, x): |
|
482 | def bisected(repo, subset, x): | |
483 | return bisect(repo, subset, x) |
|
483 | return bisect(repo, subset, x) | |
484 |
|
484 | |||
485 | def bookmark(repo, subset, x): |
|
485 | def bookmark(repo, subset, x): | |
486 | """``bookmark([name])`` |
|
486 | """``bookmark([name])`` | |
487 | The named bookmark or all bookmarks. |
|
487 | The named bookmark or all bookmarks. | |
488 |
|
488 | |||
489 | If `name` starts with `re:`, the remainder of the name is treated as |
|
489 | 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:`, |
|
490 | a regular expression. To match a bookmark that actually starts with `re:`, | |
491 | use the prefix `literal:`. |
|
491 | use the prefix `literal:`. | |
492 | """ |
|
492 | """ | |
493 | # i18n: "bookmark" is a keyword |
|
493 | # i18n: "bookmark" is a keyword | |
494 | args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) |
|
494 | args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) | |
495 | if args: |
|
495 | if args: | |
496 | bm = getstring(args[0], |
|
496 | bm = getstring(args[0], | |
497 | # i18n: "bookmark" is a keyword |
|
497 | # i18n: "bookmark" is a keyword | |
498 | _('the argument to bookmark must be a string')) |
|
498 | _('the argument to bookmark must be a string')) | |
499 | kind, pattern, matcher = _stringmatcher(bm) |
|
499 | kind, pattern, matcher = _stringmatcher(bm) | |
500 | bms = set() |
|
500 | bms = set() | |
501 | if kind == 'literal': |
|
501 | if kind == 'literal': | |
502 | bmrev = repo._bookmarks.get(pattern, None) |
|
502 | bmrev = repo._bookmarks.get(pattern, None) | |
503 | if not bmrev: |
|
503 | if not bmrev: | |
504 | raise error.RepoLookupError(_("bookmark '%s' does not exist") |
|
504 | raise error.RepoLookupError(_("bookmark '%s' does not exist") | |
505 | % bm) |
|
505 | % bm) | |
506 | bms.add(repo[bmrev].rev()) |
|
506 | bms.add(repo[bmrev].rev()) | |
507 | else: |
|
507 | else: | |
508 | matchrevs = set() |
|
508 | matchrevs = set() | |
509 | for name, bmrev in repo._bookmarks.iteritems(): |
|
509 | for name, bmrev in repo._bookmarks.iteritems(): | |
510 | if matcher(name): |
|
510 | if matcher(name): | |
511 | matchrevs.add(bmrev) |
|
511 | matchrevs.add(bmrev) | |
512 | if not matchrevs: |
|
512 | if not matchrevs: | |
513 | raise error.RepoLookupError(_("no bookmarks exist" |
|
513 | raise error.RepoLookupError(_("no bookmarks exist" | |
514 | " that match '%s'") % pattern) |
|
514 | " that match '%s'") % pattern) | |
515 | for bmrev in matchrevs: |
|
515 | for bmrev in matchrevs: | |
516 | bms.add(repo[bmrev].rev()) |
|
516 | bms.add(repo[bmrev].rev()) | |
517 | else: |
|
517 | else: | |
518 | bms = set([repo[r].rev() |
|
518 | bms = set([repo[r].rev() | |
519 | for r in repo._bookmarks.values()]) |
|
519 | for r in repo._bookmarks.values()]) | |
520 | bms -= set([node.nullrev]) |
|
520 | bms -= set([node.nullrev]) | |
521 | return subset & bms |
|
521 | return subset & bms | |
522 |
|
522 | |||
523 | def branch(repo, subset, x): |
|
523 | def branch(repo, subset, x): | |
524 | """``branch(string or set)`` |
|
524 | """``branch(string or set)`` | |
525 | All changesets belonging to the given branch or the branches of the given |
|
525 | All changesets belonging to the given branch or the branches of the given | |
526 | changesets. |
|
526 | changesets. | |
527 |
|
527 | |||
528 | If `string` starts with `re:`, the remainder of the name is treated as |
|
528 | 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:`, |
|
529 | a regular expression. To match a branch that actually starts with `re:`, | |
530 | use the prefix `literal:`. |
|
530 | use the prefix `literal:`. | |
531 | """ |
|
531 | """ | |
532 | getbi = repo.revbranchcache().branchinfo |
|
532 | getbi = repo.revbranchcache().branchinfo | |
533 |
|
533 | |||
534 | try: |
|
534 | try: | |
535 | b = getstring(x, '') |
|
535 | b = getstring(x, '') | |
536 | except error.ParseError: |
|
536 | except error.ParseError: | |
537 | # not a string, but another revspec, e.g. tip() |
|
537 | # not a string, but another revspec, e.g. tip() | |
538 | pass |
|
538 | pass | |
539 | else: |
|
539 | else: | |
540 | kind, pattern, matcher = _stringmatcher(b) |
|
540 | kind, pattern, matcher = _stringmatcher(b) | |
541 | if kind == 'literal': |
|
541 | if kind == 'literal': | |
542 | # note: falls through to the revspec case if no branch with |
|
542 | # note: falls through to the revspec case if no branch with | |
543 | # this name exists |
|
543 | # this name exists | |
544 | if pattern in repo.branchmap(): |
|
544 | if pattern in repo.branchmap(): | |
545 | return subset.filter(lambda r: matcher(getbi(r)[0])) |
|
545 | return subset.filter(lambda r: matcher(getbi(r)[0])) | |
546 | else: |
|
546 | else: | |
547 | return subset.filter(lambda r: matcher(getbi(r)[0])) |
|
547 | return subset.filter(lambda r: matcher(getbi(r)[0])) | |
548 |
|
548 | |||
549 | s = getset(repo, fullreposet(repo), x) |
|
549 | s = getset(repo, fullreposet(repo), x) | |
550 | b = set() |
|
550 | b = set() | |
551 | for r in s: |
|
551 | for r in s: | |
552 | b.add(getbi(r)[0]) |
|
552 | b.add(getbi(r)[0]) | |
553 | c = s.__contains__ |
|
553 | c = s.__contains__ | |
554 | return subset.filter(lambda r: c(r) or getbi(r)[0] in b) |
|
554 | return subset.filter(lambda r: c(r) or getbi(r)[0] in b) | |
555 |
|
555 | |||
556 | def bumped(repo, subset, x): |
|
556 | def bumped(repo, subset, x): | |
557 | """``bumped()`` |
|
557 | """``bumped()`` | |
558 | Mutable changesets marked as successors of public changesets. |
|
558 | Mutable changesets marked as successors of public changesets. | |
559 |
|
559 | |||
560 | Only non-public and non-obsolete changesets can be `bumped`. |
|
560 | Only non-public and non-obsolete changesets can be `bumped`. | |
561 | """ |
|
561 | """ | |
562 | # i18n: "bumped" is a keyword |
|
562 | # i18n: "bumped" is a keyword | |
563 | getargs(x, 0, 0, _("bumped takes no arguments")) |
|
563 | getargs(x, 0, 0, _("bumped takes no arguments")) | |
564 | bumped = obsmod.getrevs(repo, 'bumped') |
|
564 | bumped = obsmod.getrevs(repo, 'bumped') | |
565 | return subset & bumped |
|
565 | return subset & bumped | |
566 |
|
566 | |||
567 | def bundle(repo, subset, x): |
|
567 | def bundle(repo, subset, x): | |
568 | """``bundle()`` |
|
568 | """``bundle()`` | |
569 | Changesets in the bundle. |
|
569 | Changesets in the bundle. | |
570 |
|
570 | |||
571 | Bundle must be specified by the -R option.""" |
|
571 | Bundle must be specified by the -R option.""" | |
572 |
|
572 | |||
573 | try: |
|
573 | try: | |
574 | bundlerevs = repo.changelog.bundlerevs |
|
574 | bundlerevs = repo.changelog.bundlerevs | |
575 | except AttributeError: |
|
575 | except AttributeError: | |
576 | raise util.Abort(_("no bundle provided - specify with -R")) |
|
576 | raise util.Abort(_("no bundle provided - specify with -R")) | |
577 | return subset & bundlerevs |
|
577 | return subset & bundlerevs | |
578 |
|
578 | |||
579 | def checkstatus(repo, subset, pat, field): |
|
579 | def checkstatus(repo, subset, pat, field): | |
580 | hasset = matchmod.patkind(pat) == 'set' |
|
580 | hasset = matchmod.patkind(pat) == 'set' | |
581 |
|
581 | |||
582 | mcache = [None] |
|
582 | mcache = [None] | |
583 | def matches(x): |
|
583 | def matches(x): | |
584 | c = repo[x] |
|
584 | c = repo[x] | |
585 | if not mcache[0] or hasset: |
|
585 | if not mcache[0] or hasset: | |
586 | mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) |
|
586 | mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) | |
587 | m = mcache[0] |
|
587 | m = mcache[0] | |
588 | fname = None |
|
588 | fname = None | |
589 | if not m.anypats() and len(m.files()) == 1: |
|
589 | if not m.anypats() and len(m.files()) == 1: | |
590 | fname = m.files()[0] |
|
590 | fname = m.files()[0] | |
591 | if fname is not None: |
|
591 | if fname is not None: | |
592 | if fname not in c.files(): |
|
592 | if fname not in c.files(): | |
593 | return False |
|
593 | return False | |
594 | else: |
|
594 | else: | |
595 | for f in c.files(): |
|
595 | for f in c.files(): | |
596 | if m(f): |
|
596 | if m(f): | |
597 | break |
|
597 | break | |
598 | else: |
|
598 | else: | |
599 | return False |
|
599 | return False | |
600 | files = repo.status(c.p1().node(), c.node())[field] |
|
600 | files = repo.status(c.p1().node(), c.node())[field] | |
601 | if fname is not None: |
|
601 | if fname is not None: | |
602 | if fname in files: |
|
602 | if fname in files: | |
603 | return True |
|
603 | return True | |
604 | else: |
|
604 | else: | |
605 | for f in files: |
|
605 | for f in files: | |
606 | if m(f): |
|
606 | if m(f): | |
607 | return True |
|
607 | return True | |
608 |
|
608 | |||
609 | return subset.filter(matches) |
|
609 | return subset.filter(matches) | |
610 |
|
610 | |||
611 | def _children(repo, narrow, parentset): |
|
611 | def _children(repo, narrow, parentset): | |
612 | cs = set() |
|
612 | cs = set() | |
613 | if not parentset: |
|
613 | if not parentset: | |
614 | return baseset(cs) |
|
614 | return baseset(cs) | |
615 | pr = repo.changelog.parentrevs |
|
615 | pr = repo.changelog.parentrevs | |
616 | minrev = min(parentset) |
|
616 | minrev = min(parentset) | |
617 | for r in narrow: |
|
617 | for r in narrow: | |
618 | if r <= minrev: |
|
618 | if r <= minrev: | |
619 | continue |
|
619 | continue | |
620 | for p in pr(r): |
|
620 | for p in pr(r): | |
621 | if p in parentset: |
|
621 | if p in parentset: | |
622 | cs.add(r) |
|
622 | cs.add(r) | |
623 | return baseset(cs) |
|
623 | return baseset(cs) | |
624 |
|
624 | |||
625 | def children(repo, subset, x): |
|
625 | def children(repo, subset, x): | |
626 | """``children(set)`` |
|
626 | """``children(set)`` | |
627 | Child changesets of changesets in set. |
|
627 | Child changesets of changesets in set. | |
628 | """ |
|
628 | """ | |
629 | s = getset(repo, fullreposet(repo), x) |
|
629 | s = getset(repo, fullreposet(repo), x) | |
630 | cs = _children(repo, subset, s) |
|
630 | cs = _children(repo, subset, s) | |
631 | return subset & cs |
|
631 | return subset & cs | |
632 |
|
632 | |||
633 | def closed(repo, subset, x): |
|
633 | def closed(repo, subset, x): | |
634 | """``closed()`` |
|
634 | """``closed()`` | |
635 | Changeset is closed. |
|
635 | Changeset is closed. | |
636 | """ |
|
636 | """ | |
637 | # i18n: "closed" is a keyword |
|
637 | # i18n: "closed" is a keyword | |
638 | getargs(x, 0, 0, _("closed takes no arguments")) |
|
638 | getargs(x, 0, 0, _("closed takes no arguments")) | |
639 | return subset.filter(lambda r: repo[r].closesbranch()) |
|
639 | return subset.filter(lambda r: repo[r].closesbranch()) | |
640 |
|
640 | |||
641 | def contains(repo, subset, x): |
|
641 | def contains(repo, subset, x): | |
642 | """``contains(pattern)`` |
|
642 | """``contains(pattern)`` | |
643 | The revision's manifest contains a file matching pattern (but might not |
|
643 | The revision's manifest contains a file matching pattern (but might not | |
644 | modify it). See :hg:`help patterns` for information about file patterns. |
|
644 | modify it). See :hg:`help patterns` for information about file patterns. | |
645 |
|
645 | |||
646 | The pattern without explicit kind like ``glob:`` is expected to be |
|
646 | The pattern without explicit kind like ``glob:`` is expected to be | |
647 | relative to the current directory and match against a file exactly |
|
647 | relative to the current directory and match against a file exactly | |
648 | for efficiency. |
|
648 | for efficiency. | |
649 | """ |
|
649 | """ | |
650 | # i18n: "contains" is a keyword |
|
650 | # i18n: "contains" is a keyword | |
651 | pat = getstring(x, _("contains requires a pattern")) |
|
651 | pat = getstring(x, _("contains requires a pattern")) | |
652 |
|
652 | |||
653 | def matches(x): |
|
653 | def matches(x): | |
654 | if not matchmod.patkind(pat): |
|
654 | if not matchmod.patkind(pat): | |
655 | pats = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
655 | pats = pathutil.canonpath(repo.root, repo.getcwd(), pat) | |
656 | if pats in repo[x]: |
|
656 | if pats in repo[x]: | |
657 | return True |
|
657 | return True | |
658 | else: |
|
658 | else: | |
659 | c = repo[x] |
|
659 | c = repo[x] | |
660 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) |
|
660 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) | |
661 | for f in c.manifest(): |
|
661 | for f in c.manifest(): | |
662 | if m(f): |
|
662 | if m(f): | |
663 | return True |
|
663 | return True | |
664 | return False |
|
664 | return False | |
665 |
|
665 | |||
666 | return subset.filter(matches) |
|
666 | return subset.filter(matches) | |
667 |
|
667 | |||
668 | def converted(repo, subset, x): |
|
668 | def converted(repo, subset, x): | |
669 | """``converted([id])`` |
|
669 | """``converted([id])`` | |
670 | Changesets converted from the given identifier in the old repository if |
|
670 | Changesets converted from the given identifier in the old repository if | |
671 | present, or all converted changesets if no identifier is specified. |
|
671 | present, or all converted changesets if no identifier is specified. | |
672 | """ |
|
672 | """ | |
673 |
|
673 | |||
674 | # There is exactly no chance of resolving the revision, so do a simple |
|
674 | # There is exactly no chance of resolving the revision, so do a simple | |
675 | # string compare and hope for the best |
|
675 | # string compare and hope for the best | |
676 |
|
676 | |||
677 | rev = None |
|
677 | rev = None | |
678 | # i18n: "converted" is a keyword |
|
678 | # i18n: "converted" is a keyword | |
679 | l = getargs(x, 0, 1, _('converted takes one or no arguments')) |
|
679 | l = getargs(x, 0, 1, _('converted takes one or no arguments')) | |
680 | if l: |
|
680 | if l: | |
681 | # i18n: "converted" is a keyword |
|
681 | # i18n: "converted" is a keyword | |
682 | rev = getstring(l[0], _('converted requires a revision')) |
|
682 | rev = getstring(l[0], _('converted requires a revision')) | |
683 |
|
683 | |||
684 | def _matchvalue(r): |
|
684 | def _matchvalue(r): | |
685 | source = repo[r].extra().get('convert_revision', None) |
|
685 | source = repo[r].extra().get('convert_revision', None) | |
686 | return source is not None and (rev is None or source.startswith(rev)) |
|
686 | return source is not None and (rev is None or source.startswith(rev)) | |
687 |
|
687 | |||
688 | return subset.filter(lambda r: _matchvalue(r)) |
|
688 | return subset.filter(lambda r: _matchvalue(r)) | |
689 |
|
689 | |||
690 | def date(repo, subset, x): |
|
690 | def date(repo, subset, x): | |
691 | """``date(interval)`` |
|
691 | """``date(interval)`` | |
692 | Changesets within the interval, see :hg:`help dates`. |
|
692 | Changesets within the interval, see :hg:`help dates`. | |
693 | """ |
|
693 | """ | |
694 | # i18n: "date" is a keyword |
|
694 | # i18n: "date" is a keyword | |
695 | ds = getstring(x, _("date requires a string")) |
|
695 | ds = getstring(x, _("date requires a string")) | |
696 | dm = util.matchdate(ds) |
|
696 | dm = util.matchdate(ds) | |
697 | return subset.filter(lambda x: dm(repo[x].date()[0])) |
|
697 | return subset.filter(lambda x: dm(repo[x].date()[0])) | |
698 |
|
698 | |||
699 | def desc(repo, subset, x): |
|
699 | def desc(repo, subset, x): | |
700 | """``desc(string)`` |
|
700 | """``desc(string)`` | |
701 | Search commit message for string. The match is case-insensitive. |
|
701 | Search commit message for string. The match is case-insensitive. | |
702 | """ |
|
702 | """ | |
703 | # i18n: "desc" is a keyword |
|
703 | # i18n: "desc" is a keyword | |
704 | ds = encoding.lower(getstring(x, _("desc requires a string"))) |
|
704 | ds = encoding.lower(getstring(x, _("desc requires a string"))) | |
705 |
|
705 | |||
706 | def matches(x): |
|
706 | def matches(x): | |
707 | c = repo[x] |
|
707 | c = repo[x] | |
708 | return ds in encoding.lower(c.description()) |
|
708 | return ds in encoding.lower(c.description()) | |
709 |
|
709 | |||
710 | return subset.filter(matches) |
|
710 | return subset.filter(matches) | |
711 |
|
711 | |||
712 | def _descendants(repo, subset, x, followfirst=False): |
|
712 | def _descendants(repo, subset, x, followfirst=False): | |
713 | roots = getset(repo, fullreposet(repo), x) |
|
713 | roots = getset(repo, fullreposet(repo), x) | |
714 | if not roots: |
|
714 | if not roots: | |
715 | return baseset() |
|
715 | return baseset() | |
716 | s = _revdescendants(repo, roots, followfirst) |
|
716 | s = _revdescendants(repo, roots, followfirst) | |
717 |
|
717 | |||
718 | # Both sets need to be ascending in order to lazily return the union |
|
718 | # Both sets need to be ascending in order to lazily return the union | |
719 | # in the correct order. |
|
719 | # in the correct order. | |
720 | base = subset & roots |
|
720 | base = subset & roots | |
721 | desc = subset & s |
|
721 | desc = subset & s | |
722 | result = base + desc |
|
722 | result = base + desc | |
723 | if subset.isascending(): |
|
723 | if subset.isascending(): | |
724 | result.sort() |
|
724 | result.sort() | |
725 | elif subset.isdescending(): |
|
725 | elif subset.isdescending(): | |
726 | result.sort(reverse=True) |
|
726 | result.sort(reverse=True) | |
727 | else: |
|
727 | else: | |
728 | result = subset & result |
|
728 | result = subset & result | |
729 | return result |
|
729 | return result | |
730 |
|
730 | |||
731 | def descendants(repo, subset, x): |
|
731 | def descendants(repo, subset, x): | |
732 | """``descendants(set)`` |
|
732 | """``descendants(set)`` | |
733 | Changesets which are descendants of changesets in set. |
|
733 | Changesets which are descendants of changesets in set. | |
734 | """ |
|
734 | """ | |
735 | return _descendants(repo, subset, x) |
|
735 | return _descendants(repo, subset, x) | |
736 |
|
736 | |||
737 | def _firstdescendants(repo, subset, x): |
|
737 | def _firstdescendants(repo, subset, x): | |
738 | # ``_firstdescendants(set)`` |
|
738 | # ``_firstdescendants(set)`` | |
739 | # Like ``descendants(set)`` but follows only the first parents. |
|
739 | # Like ``descendants(set)`` but follows only the first parents. | |
740 | return _descendants(repo, subset, x, followfirst=True) |
|
740 | return _descendants(repo, subset, x, followfirst=True) | |
741 |
|
741 | |||
742 | def destination(repo, subset, x): |
|
742 | def destination(repo, subset, x): | |
743 | """``destination([set])`` |
|
743 | """``destination([set])`` | |
744 | Changesets that were created by a graft, transplant or rebase operation, |
|
744 | Changesets that were created by a graft, transplant or rebase operation, | |
745 | with the given revisions specified as the source. Omitting the optional set |
|
745 | with the given revisions specified as the source. Omitting the optional set | |
746 | is the same as passing all(). |
|
746 | is the same as passing all(). | |
747 | """ |
|
747 | """ | |
748 | if x is not None: |
|
748 | if x is not None: | |
749 | sources = getset(repo, fullreposet(repo), x) |
|
749 | sources = getset(repo, fullreposet(repo), x) | |
750 | else: |
|
750 | else: | |
751 | sources = fullreposet(repo) |
|
751 | sources = fullreposet(repo) | |
752 |
|
752 | |||
753 | dests = set() |
|
753 | dests = set() | |
754 |
|
754 | |||
755 | # subset contains all of the possible destinations that can be returned, so |
|
755 | # 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. |
|
756 | # 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 |
|
757 | # 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 |
|
758 | # further back) may be. Scanning back further than the immediate src allows | |
759 | # transitive transplants and rebases to yield the same results as transitive |
|
759 | # transitive transplants and rebases to yield the same results as transitive | |
760 | # grafts. |
|
760 | # grafts. | |
761 | for r in subset: |
|
761 | for r in subset: | |
762 | src = _getrevsource(repo, r) |
|
762 | src = _getrevsource(repo, r) | |
763 | lineage = None |
|
763 | lineage = None | |
764 |
|
764 | |||
765 | while src is not None: |
|
765 | while src is not None: | |
766 | if lineage is None: |
|
766 | if lineage is None: | |
767 | lineage = list() |
|
767 | lineage = list() | |
768 |
|
768 | |||
769 | lineage.append(r) |
|
769 | lineage.append(r) | |
770 |
|
770 | |||
771 | # The visited lineage is a match if the current source is in the arg |
|
771 | # 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 |
|
772 | # 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 |
|
773 | # subset, any dests further back in the lineage will be tested by a | |
774 | # different iteration over subset. Likewise, if the src was already |
|
774 | # different iteration over subset. Likewise, if the src was already | |
775 | # selected, the current lineage can be selected without going back |
|
775 | # selected, the current lineage can be selected without going back | |
776 | # further. |
|
776 | # further. | |
777 | if src in sources or src in dests: |
|
777 | if src in sources or src in dests: | |
778 | dests.update(lineage) |
|
778 | dests.update(lineage) | |
779 | break |
|
779 | break | |
780 |
|
780 | |||
781 | r = src |
|
781 | r = src | |
782 | src = _getrevsource(repo, r) |
|
782 | src = _getrevsource(repo, r) | |
783 |
|
783 | |||
784 | return subset.filter(dests.__contains__) |
|
784 | return subset.filter(dests.__contains__) | |
785 |
|
785 | |||
786 | def divergent(repo, subset, x): |
|
786 | def divergent(repo, subset, x): | |
787 | """``divergent()`` |
|
787 | """``divergent()`` | |
788 | Final successors of changesets with an alternative set of final successors. |
|
788 | Final successors of changesets with an alternative set of final successors. | |
789 | """ |
|
789 | """ | |
790 | # i18n: "divergent" is a keyword |
|
790 | # i18n: "divergent" is a keyword | |
791 | getargs(x, 0, 0, _("divergent takes no arguments")) |
|
791 | getargs(x, 0, 0, _("divergent takes no arguments")) | |
792 | divergent = obsmod.getrevs(repo, 'divergent') |
|
792 | divergent = obsmod.getrevs(repo, 'divergent') | |
793 | return subset & divergent |
|
793 | return subset & divergent | |
794 |
|
794 | |||
795 | def draft(repo, subset, x): |
|
795 | def draft(repo, subset, x): | |
796 | """``draft()`` |
|
796 | """``draft()`` | |
797 | Changeset in draft phase.""" |
|
797 | Changeset in draft phase.""" | |
798 | # i18n: "draft" is a keyword |
|
798 | # i18n: "draft" is a keyword | |
799 | getargs(x, 0, 0, _("draft takes no arguments")) |
|
799 | getargs(x, 0, 0, _("draft takes no arguments")) | |
800 | phase = repo._phasecache.phase |
|
800 | phase = repo._phasecache.phase | |
801 | target = phases.draft |
|
801 | target = phases.draft | |
802 | condition = lambda r: phase(repo, r) == target |
|
802 | condition = lambda r: phase(repo, r) == target | |
803 | return subset.filter(condition, cache=False) |
|
803 | return subset.filter(condition, cache=False) | |
804 |
|
804 | |||
805 | def extinct(repo, subset, x): |
|
805 | def extinct(repo, subset, x): | |
806 | """``extinct()`` |
|
806 | """``extinct()`` | |
807 | Obsolete changesets with obsolete descendants only. |
|
807 | Obsolete changesets with obsolete descendants only. | |
808 | """ |
|
808 | """ | |
809 | # i18n: "extinct" is a keyword |
|
809 | # i18n: "extinct" is a keyword | |
810 | getargs(x, 0, 0, _("extinct takes no arguments")) |
|
810 | getargs(x, 0, 0, _("extinct takes no arguments")) | |
811 | extincts = obsmod.getrevs(repo, 'extinct') |
|
811 | extincts = obsmod.getrevs(repo, 'extinct') | |
812 | return subset & extincts |
|
812 | return subset & extincts | |
813 |
|
813 | |||
814 | def extra(repo, subset, x): |
|
814 | def extra(repo, subset, x): | |
815 | """``extra(label, [value])`` |
|
815 | """``extra(label, [value])`` | |
816 | Changesets with the given label in the extra metadata, with the given |
|
816 | Changesets with the given label in the extra metadata, with the given | |
817 | optional value. |
|
817 | optional value. | |
818 |
|
818 | |||
819 | If `value` starts with `re:`, the remainder of the value is treated as |
|
819 | 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:`, |
|
820 | a regular expression. To match a value that actually starts with `re:`, | |
821 | use the prefix `literal:`. |
|
821 | use the prefix `literal:`. | |
822 | """ |
|
822 | """ | |
823 |
|
823 | |||
824 | # i18n: "extra" is a keyword |
|
824 | # i18n: "extra" is a keyword | |
825 | l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments')) |
|
825 | l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments')) | |
826 | # i18n: "extra" is a keyword |
|
826 | # i18n: "extra" is a keyword | |
827 | label = getstring(l[0], _('first argument to extra must be a string')) |
|
827 | label = getstring(l[0], _('first argument to extra must be a string')) | |
828 | value = None |
|
828 | value = None | |
829 |
|
829 | |||
830 | if len(l) > 1: |
|
830 | if len(l) > 1: | |
831 | # i18n: "extra" is a keyword |
|
831 | # i18n: "extra" is a keyword | |
832 | value = getstring(l[1], _('second argument to extra must be a string')) |
|
832 | value = getstring(l[1], _('second argument to extra must be a string')) | |
833 | kind, value, matcher = _stringmatcher(value) |
|
833 | kind, value, matcher = _stringmatcher(value) | |
834 |
|
834 | |||
835 | def _matchvalue(r): |
|
835 | def _matchvalue(r): | |
836 | extra = repo[r].extra() |
|
836 | extra = repo[r].extra() | |
837 | return label in extra and (value is None or matcher(extra[label])) |
|
837 | return label in extra and (value is None or matcher(extra[label])) | |
838 |
|
838 | |||
839 | return subset.filter(lambda r: _matchvalue(r)) |
|
839 | return subset.filter(lambda r: _matchvalue(r)) | |
840 |
|
840 | |||
841 | def filelog(repo, subset, x): |
|
841 | def filelog(repo, subset, x): | |
842 | """``filelog(pattern)`` |
|
842 | """``filelog(pattern)`` | |
843 | Changesets connected to the specified filelog. |
|
843 | Changesets connected to the specified filelog. | |
844 |
|
844 | |||
845 | For performance reasons, visits only revisions mentioned in the file-level |
|
845 | For performance reasons, visits only revisions mentioned in the file-level | |
846 | filelog, rather than filtering through all changesets (much faster, but |
|
846 | filelog, rather than filtering through all changesets (much faster, but | |
847 | doesn't include deletes or duplicate changes). For a slower, more accurate |
|
847 | doesn't include deletes or duplicate changes). For a slower, more accurate | |
848 | result, use ``file()``. |
|
848 | result, use ``file()``. | |
849 |
|
849 | |||
850 | The pattern without explicit kind like ``glob:`` is expected to be |
|
850 | The pattern without explicit kind like ``glob:`` is expected to be | |
851 | relative to the current directory and match against a file exactly |
|
851 | relative to the current directory and match against a file exactly | |
852 | for efficiency. |
|
852 | for efficiency. | |
853 |
|
853 | |||
854 | If some linkrev points to revisions filtered by the current repoview, we'll |
|
854 | If some linkrev points to revisions filtered by the current repoview, we'll | |
855 | work around it to return a non-filtered value. |
|
855 | work around it to return a non-filtered value. | |
856 | """ |
|
856 | """ | |
857 |
|
857 | |||
858 | # i18n: "filelog" is a keyword |
|
858 | # i18n: "filelog" is a keyword | |
859 | pat = getstring(x, _("filelog requires a pattern")) |
|
859 | pat = getstring(x, _("filelog requires a pattern")) | |
860 | s = set() |
|
860 | s = set() | |
861 | cl = repo.changelog |
|
861 | cl = repo.changelog | |
862 |
|
862 | |||
863 | if not matchmod.patkind(pat): |
|
863 | if not matchmod.patkind(pat): | |
864 | f = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
864 | f = pathutil.canonpath(repo.root, repo.getcwd(), pat) | |
865 | files = [f] |
|
865 | files = [f] | |
866 | else: |
|
866 | else: | |
867 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None]) |
|
867 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None]) | |
868 | files = (f for f in repo[None] if m(f)) |
|
868 | files = (f for f in repo[None] if m(f)) | |
869 |
|
869 | |||
870 | for f in files: |
|
870 | for f in files: | |
871 | backrevref = {} # final value for: filerev -> changerev |
|
871 | backrevref = {} # final value for: filerev -> changerev | |
872 | lowestchild = {} # lowest known filerev child of a filerev |
|
872 | lowestchild = {} # lowest known filerev child of a filerev | |
873 | delayed = [] # filerev with filtered linkrev, for post-processing |
|
873 | delayed = [] # filerev with filtered linkrev, for post-processing | |
874 | lowesthead = None # cache for manifest content of all head revisions |
|
874 | lowesthead = None # cache for manifest content of all head revisions | |
875 | fl = repo.file(f) |
|
875 | fl = repo.file(f) | |
876 | for fr in list(fl): |
|
876 | for fr in list(fl): | |
877 | rev = fl.linkrev(fr) |
|
877 | rev = fl.linkrev(fr) | |
878 | if rev not in cl: |
|
878 | if rev not in cl: | |
879 | # changerev pointed in linkrev is filtered |
|
879 | # changerev pointed in linkrev is filtered | |
880 | # record it for post processing. |
|
880 | # record it for post processing. | |
881 | delayed.append((fr, rev)) |
|
881 | delayed.append((fr, rev)) | |
882 | continue |
|
882 | continue | |
883 | for p in fl.parentrevs(fr): |
|
883 | for p in fl.parentrevs(fr): | |
884 | if 0 <= p and p not in lowestchild: |
|
884 | if 0 <= p and p not in lowestchild: | |
885 | lowestchild[p] = fr |
|
885 | lowestchild[p] = fr | |
886 | backrevref[fr] = rev |
|
886 | backrevref[fr] = rev | |
887 | s.add(rev) |
|
887 | s.add(rev) | |
888 |
|
888 | |||
889 | # Post-processing of all filerevs we skipped because they were |
|
889 | # Post-processing of all filerevs we skipped because they were | |
890 | # filtered. If such filerevs have known and unfiltered children, this |
|
890 | # filtered. If such filerevs have known and unfiltered children, this | |
891 | # means they have an unfiltered appearance out there. We'll use linkrev |
|
891 | # means they have an unfiltered appearance out there. We'll use linkrev | |
892 | # adjustment to find one of these appearances. The lowest known child |
|
892 | # 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 |
|
893 | # will be used as a starting point because it is the best upper-bound we | |
894 | # have. |
|
894 | # have. | |
895 | # |
|
895 | # | |
896 | # This approach will fail when an unfiltered but linkrev-shadowed |
|
896 | # This approach will fail when an unfiltered but linkrev-shadowed | |
897 | # appearance exists in a head changeset without unfiltered filerev |
|
897 | # appearance exists in a head changeset without unfiltered filerev | |
898 | # children anywhere. |
|
898 | # children anywhere. | |
899 | while delayed: |
|
899 | while delayed: | |
900 | # must be a descending iteration. To slowly fill lowest child |
|
900 | # must be a descending iteration. To slowly fill lowest child | |
901 | # information that is of potential use by the next item. |
|
901 | # information that is of potential use by the next item. | |
902 | fr, rev = delayed.pop() |
|
902 | fr, rev = delayed.pop() | |
903 | lkr = rev |
|
903 | lkr = rev | |
904 |
|
904 | |||
905 | child = lowestchild.get(fr) |
|
905 | child = lowestchild.get(fr) | |
906 |
|
906 | |||
907 | if child is None: |
|
907 | if child is None: | |
908 | # search for existence of this file revision in a head revision. |
|
908 | # search for existence of this file revision in a head revision. | |
909 | # There are three possibilities: |
|
909 | # There are three possibilities: | |
910 | # - the revision exists in a head and we can find an |
|
910 | # - the revision exists in a head and we can find an | |
911 | # introduction from there, |
|
911 | # introduction from there, | |
912 | # - the revision does not exist in a head because it has been |
|
912 | # - the revision does not exist in a head because it has been | |
913 | # changed since its introduction: we would have found a child |
|
913 | # changed since its introduction: we would have found a child | |
914 | # and be in the other 'else' clause, |
|
914 | # and be in the other 'else' clause, | |
915 | # - all versions of the revision are hidden. |
|
915 | # - all versions of the revision are hidden. | |
916 | if lowesthead is None: |
|
916 | if lowesthead is None: | |
917 | lowesthead = {} |
|
917 | lowesthead = {} | |
918 | for h in repo.heads(): |
|
918 | for h in repo.heads(): | |
919 | fnode = repo[h].manifest().get(f) |
|
919 | fnode = repo[h].manifest().get(f) | |
920 | if fnode is not None: |
|
920 | if fnode is not None: | |
921 | lowesthead[fl.rev(fnode)] = h |
|
921 | lowesthead[fl.rev(fnode)] = h | |
922 | headrev = lowesthead.get(fr) |
|
922 | headrev = lowesthead.get(fr) | |
923 | if headrev is None: |
|
923 | if headrev is None: | |
924 | # content is nowhere unfiltered |
|
924 | # content is nowhere unfiltered | |
925 | continue |
|
925 | continue | |
926 | rev = repo[headrev][f].introrev() |
|
926 | rev = repo[headrev][f].introrev() | |
927 | else: |
|
927 | else: | |
928 | # the lowest known child is a good upper bound |
|
928 | # the lowest known child is a good upper bound | |
929 | childcrev = backrevref[child] |
|
929 | childcrev = backrevref[child] | |
930 | # XXX this does not guarantee returning the lowest |
|
930 | # XXX this does not guarantee returning the lowest | |
931 | # introduction of this revision, but this gives a |
|
931 | # introduction of this revision, but this gives a | |
932 | # result which is a good start and will fit in most |
|
932 | # result which is a good start and will fit in most | |
933 | # cases. We probably need to fix the multiple |
|
933 | # cases. We probably need to fix the multiple | |
934 | # introductions case properly (report each |
|
934 | # introductions case properly (report each | |
935 | # introduction, even for identical file revisions) |
|
935 | # introduction, even for identical file revisions) | |
936 | # once and for all at some point anyway. |
|
936 | # once and for all at some point anyway. | |
937 | for p in repo[childcrev][f].parents(): |
|
937 | for p in repo[childcrev][f].parents(): | |
938 | if p.filerev() == fr: |
|
938 | if p.filerev() == fr: | |
939 | rev = p.rev() |
|
939 | rev = p.rev() | |
940 | break |
|
940 | break | |
941 | if rev == lkr: # no shadowed entry found |
|
941 | if rev == lkr: # no shadowed entry found | |
942 | # XXX This should never happen unless some manifest points |
|
942 | # XXX This should never happen unless some manifest points | |
943 | # to biggish file revisions (like a revision that uses a |
|
943 | # to biggish file revisions (like a revision that uses a | |
944 | # parent that never appears in the manifest ancestors) |
|
944 | # parent that never appears in the manifest ancestors) | |
945 | continue |
|
945 | continue | |
946 |
|
946 | |||
947 | # Fill the data for the next iteration. |
|
947 | # Fill the data for the next iteration. | |
948 | for p in fl.parentrevs(fr): |
|
948 | for p in fl.parentrevs(fr): | |
949 | if 0 <= p and p not in lowestchild: |
|
949 | if 0 <= p and p not in lowestchild: | |
950 | lowestchild[p] = fr |
|
950 | lowestchild[p] = fr | |
951 | backrevref[fr] = rev |
|
951 | backrevref[fr] = rev | |
952 | s.add(rev) |
|
952 | s.add(rev) | |
953 |
|
953 | |||
954 | return subset & s |
|
954 | return subset & s | |
955 |
|
955 | |||
956 | def first(repo, subset, x): |
|
956 | def first(repo, subset, x): | |
957 | """``first(set, [n])`` |
|
957 | """``first(set, [n])`` | |
958 | An alias for limit(). |
|
958 | An alias for limit(). | |
959 | """ |
|
959 | """ | |
960 | return limit(repo, subset, x) |
|
960 | return limit(repo, subset, x) | |
961 |
|
961 | |||
962 | def _follow(repo, subset, x, name, followfirst=False): |
|
962 | def _follow(repo, subset, x, name, followfirst=False): | |
963 | l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name) |
|
963 | l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name) | |
964 | c = repo['.'] |
|
964 | c = repo['.'] | |
965 | if l: |
|
965 | if l: | |
966 | x = getstring(l[0], _("%s expected a filename") % name) |
|
966 | x = getstring(l[0], _("%s expected a filename") % name) | |
967 | if x in c: |
|
967 | if x in c: | |
968 | cx = c[x] |
|
968 | cx = c[x] | |
969 | s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst)) |
|
969 | s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst)) | |
970 | # include the revision responsible for the most recent version |
|
970 | # include the revision responsible for the most recent version | |
971 | s.add(cx.introrev()) |
|
971 | s.add(cx.introrev()) | |
972 | else: |
|
972 | else: | |
973 | return baseset() |
|
973 | return baseset() | |
974 | else: |
|
974 | else: | |
975 | s = _revancestors(repo, baseset([c.rev()]), followfirst) |
|
975 | s = _revancestors(repo, baseset([c.rev()]), followfirst) | |
976 |
|
976 | |||
977 | return subset & s |
|
977 | return subset & s | |
978 |
|
978 | |||
979 | def follow(repo, subset, x): |
|
979 | def follow(repo, subset, x): | |
980 | """``follow([file])`` |
|
980 | """``follow([file])`` | |
981 | An alias for ``::.`` (ancestors of the working directory's first parent). |
|
981 | 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, |
|
982 | If a filename is specified, the history of the given file is followed, | |
983 | including copies. |
|
983 | including copies. | |
984 | """ |
|
984 | """ | |
985 | return _follow(repo, subset, x, 'follow') |
|
985 | return _follow(repo, subset, x, 'follow') | |
986 |
|
986 | |||
987 | def _followfirst(repo, subset, x): |
|
987 | def _followfirst(repo, subset, x): | |
988 | # ``followfirst([file])`` |
|
988 | # ``followfirst([file])`` | |
989 | # Like ``follow([file])`` but follows only the first parent of |
|
989 | # Like ``follow([file])`` but follows only the first parent of | |
990 | # every revision or file revision. |
|
990 | # every revision or file revision. | |
991 | return _follow(repo, subset, x, '_followfirst', followfirst=True) |
|
991 | return _follow(repo, subset, x, '_followfirst', followfirst=True) | |
992 |
|
992 | |||
993 | def getall(repo, subset, x): |
|
993 | def getall(repo, subset, x): | |
994 | """``all()`` |
|
994 | """``all()`` | |
995 | All changesets, the same as ``0:tip``. |
|
995 | All changesets, the same as ``0:tip``. | |
996 | """ |
|
996 | """ | |
997 | # i18n: "all" is a keyword |
|
997 | # i18n: "all" is a keyword | |
998 | getargs(x, 0, 0, _("all takes no arguments")) |
|
998 | getargs(x, 0, 0, _("all takes no arguments")) | |
999 | return subset & spanset(repo) # drop "null" if any |
|
999 | return subset & spanset(repo) # drop "null" if any | |
1000 |
|
1000 | |||
1001 | def grep(repo, subset, x): |
|
1001 | def grep(repo, subset, x): | |
1002 | """``grep(regex)`` |
|
1002 | """``grep(regex)`` | |
1003 | Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` |
|
1003 | Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` | |
1004 | to ensure special escape characters are handled correctly. Unlike |
|
1004 | to ensure special escape characters are handled correctly. Unlike | |
1005 | ``keyword(string)``, the match is case-sensitive. |
|
1005 | ``keyword(string)``, the match is case-sensitive. | |
1006 | """ |
|
1006 | """ | |
1007 | try: |
|
1007 | try: | |
1008 | # i18n: "grep" is a keyword |
|
1008 | # i18n: "grep" is a keyword | |
1009 | gr = re.compile(getstring(x, _("grep requires a string"))) |
|
1009 | gr = re.compile(getstring(x, _("grep requires a string"))) | |
1010 | except re.error, e: |
|
1010 | except re.error, e: | |
1011 | raise error.ParseError(_('invalid match pattern: %s') % e) |
|
1011 | raise error.ParseError(_('invalid match pattern: %s') % e) | |
1012 |
|
1012 | |||
1013 | def matches(x): |
|
1013 | def matches(x): | |
1014 | c = repo[x] |
|
1014 | c = repo[x] | |
1015 | for e in c.files() + [c.user(), c.description()]: |
|
1015 | for e in c.files() + [c.user(), c.description()]: | |
1016 | if gr.search(e): |
|
1016 | if gr.search(e): | |
1017 | return True |
|
1017 | return True | |
1018 | return False |
|
1018 | return False | |
1019 |
|
1019 | |||
1020 | return subset.filter(matches) |
|
1020 | return subset.filter(matches) | |
1021 |
|
1021 | |||
1022 | def _matchfiles(repo, subset, x): |
|
1022 | def _matchfiles(repo, subset, x): | |
1023 | # _matchfiles takes a revset list of prefixed arguments: |
|
1023 | # _matchfiles takes a revset list of prefixed arguments: | |
1024 | # |
|
1024 | # | |
1025 | # [p:foo, i:bar, x:baz] |
|
1025 | # [p:foo, i:bar, x:baz] | |
1026 | # |
|
1026 | # | |
1027 | # builds a match object from them and filters subset. Allowed |
|
1027 | # builds a match object from them and filters subset. Allowed | |
1028 | # prefixes are 'p:' for regular patterns, 'i:' for include |
|
1028 | # prefixes are 'p:' for regular patterns, 'i:' for include | |
1029 | # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass |
|
1029 | # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass | |
1030 | # a revision identifier, or the empty string to reference the |
|
1030 | # a revision identifier, or the empty string to reference the | |
1031 | # working directory, from which the match object is |
|
1031 | # working directory, from which the match object is | |
1032 | # initialized. Use 'd:' to set the default matching mode, default |
|
1032 | # initialized. Use 'd:' to set the default matching mode, default | |
1033 | # to 'glob'. At most one 'r:' and 'd:' argument can be passed. |
|
1033 | # to 'glob'. At most one 'r:' and 'd:' argument can be passed. | |
1034 |
|
1034 | |||
1035 | # i18n: "_matchfiles" is a keyword |
|
1035 | # i18n: "_matchfiles" is a keyword | |
1036 | l = getargs(x, 1, -1, _("_matchfiles requires at least one argument")) |
|
1036 | l = getargs(x, 1, -1, _("_matchfiles requires at least one argument")) | |
1037 | pats, inc, exc = [], [], [] |
|
1037 | pats, inc, exc = [], [], [] | |
1038 | rev, default = None, None |
|
1038 | rev, default = None, None | |
1039 | for arg in l: |
|
1039 | for arg in l: | |
1040 | # i18n: "_matchfiles" is a keyword |
|
1040 | # i18n: "_matchfiles" is a keyword | |
1041 | s = getstring(arg, _("_matchfiles requires string arguments")) |
|
1041 | s = getstring(arg, _("_matchfiles requires string arguments")) | |
1042 | prefix, value = s[:2], s[2:] |
|
1042 | prefix, value = s[:2], s[2:] | |
1043 | if prefix == 'p:': |
|
1043 | if prefix == 'p:': | |
1044 | pats.append(value) |
|
1044 | pats.append(value) | |
1045 | elif prefix == 'i:': |
|
1045 | elif prefix == 'i:': | |
1046 | inc.append(value) |
|
1046 | inc.append(value) | |
1047 | elif prefix == 'x:': |
|
1047 | elif prefix == 'x:': | |
1048 | exc.append(value) |
|
1048 | exc.append(value) | |
1049 | elif prefix == 'r:': |
|
1049 | elif prefix == 'r:': | |
1050 | if rev is not None: |
|
1050 | if rev is not None: | |
1051 | # i18n: "_matchfiles" is a keyword |
|
1051 | # i18n: "_matchfiles" is a keyword | |
1052 | raise error.ParseError(_('_matchfiles expected at most one ' |
|
1052 | raise error.ParseError(_('_matchfiles expected at most one ' | |
1053 | 'revision')) |
|
1053 | 'revision')) | |
1054 | if value != '': # empty means working directory; leave rev as None |
|
1054 | if value != '': # empty means working directory; leave rev as None | |
1055 | rev = value |
|
1055 | rev = value | |
1056 | elif prefix == 'd:': |
|
1056 | elif prefix == 'd:': | |
1057 | if default is not None: |
|
1057 | if default is not None: | |
1058 | # i18n: "_matchfiles" is a keyword |
|
1058 | # i18n: "_matchfiles" is a keyword | |
1059 | raise error.ParseError(_('_matchfiles expected at most one ' |
|
1059 | raise error.ParseError(_('_matchfiles expected at most one ' | |
1060 | 'default mode')) |
|
1060 | 'default mode')) | |
1061 | default = value |
|
1061 | default = value | |
1062 | else: |
|
1062 | else: | |
1063 | # i18n: "_matchfiles" is a keyword |
|
1063 | # i18n: "_matchfiles" is a keyword | |
1064 | raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix) |
|
1064 | raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix) | |
1065 | if not default: |
|
1065 | if not default: | |
1066 | default = 'glob' |
|
1066 | default = 'glob' | |
1067 |
|
1067 | |||
1068 | m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, |
|
1068 | m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, | |
1069 | exclude=exc, ctx=repo[rev], default=default) |
|
1069 | exclude=exc, ctx=repo[rev], default=default) | |
1070 |
|
1070 | |||
1071 | def matches(x): |
|
1071 | def matches(x): | |
1072 | for f in repo[x].files(): |
|
1072 | for f in repo[x].files(): | |
1073 | if m(f): |
|
1073 | if m(f): | |
1074 | return True |
|
1074 | return True | |
1075 | return False |
|
1075 | return False | |
1076 |
|
1076 | |||
1077 | return subset.filter(matches) |
|
1077 | return subset.filter(matches) | |
1078 |
|
1078 | |||
1079 | def hasfile(repo, subset, x): |
|
1079 | def hasfile(repo, subset, x): | |
1080 | """``file(pattern)`` |
|
1080 | """``file(pattern)`` | |
1081 | Changesets affecting files matched by pattern. |
|
1081 | Changesets affecting files matched by pattern. | |
1082 |
|
1082 | |||
1083 | For a faster but less accurate result, consider using ``filelog()`` |
|
1083 | For a faster but less accurate result, consider using ``filelog()`` | |
1084 | instead. |
|
1084 | instead. | |
1085 |
|
1085 | |||
1086 | This predicate uses ``glob:`` as the default kind of pattern. |
|
1086 | This predicate uses ``glob:`` as the default kind of pattern. | |
1087 | """ |
|
1087 | """ | |
1088 | # i18n: "file" is a keyword |
|
1088 | # i18n: "file" is a keyword | |
1089 | pat = getstring(x, _("file requires a pattern")) |
|
1089 | pat = getstring(x, _("file requires a pattern")) | |
1090 | return _matchfiles(repo, subset, ('string', 'p:' + pat)) |
|
1090 | return _matchfiles(repo, subset, ('string', 'p:' + pat)) | |
1091 |
|
1091 | |||
1092 | def head(repo, subset, x): |
|
1092 | def head(repo, subset, x): | |
1093 | """``head()`` |
|
1093 | """``head()`` | |
1094 | Changeset is a named branch head. |
|
1094 | Changeset is a named branch head. | |
1095 | """ |
|
1095 | """ | |
1096 | # i18n: "head" is a keyword |
|
1096 | # i18n: "head" is a keyword | |
1097 | getargs(x, 0, 0, _("head takes no arguments")) |
|
1097 | getargs(x, 0, 0, _("head takes no arguments")) | |
1098 | hs = set() |
|
1098 | hs = set() | |
1099 | for b, ls in repo.branchmap().iteritems(): |
|
1099 | for b, ls in repo.branchmap().iteritems(): | |
1100 | hs.update(repo[h].rev() for h in ls) |
|
1100 | hs.update(repo[h].rev() for h in ls) | |
1101 | return baseset(hs).filter(subset.__contains__) |
|
1101 | return baseset(hs).filter(subset.__contains__) | |
1102 |
|
1102 | |||
1103 | def heads(repo, subset, x): |
|
1103 | def heads(repo, subset, x): | |
1104 | """``heads(set)`` |
|
1104 | """``heads(set)`` | |
1105 | Members of set with no children in set. |
|
1105 | Members of set with no children in set. | |
1106 | """ |
|
1106 | """ | |
1107 | s = getset(repo, subset, x) |
|
1107 | s = getset(repo, subset, x) | |
1108 | ps = parents(repo, subset, x) |
|
1108 | ps = parents(repo, subset, x) | |
1109 | return s - ps |
|
1109 | return s - ps | |
1110 |
|
1110 | |||
1111 | def hidden(repo, subset, x): |
|
1111 | def hidden(repo, subset, x): | |
1112 | """``hidden()`` |
|
1112 | """``hidden()`` | |
1113 | Hidden changesets. |
|
1113 | Hidden changesets. | |
1114 | """ |
|
1114 | """ | |
1115 | # i18n: "hidden" is a keyword |
|
1115 | # i18n: "hidden" is a keyword | |
1116 | getargs(x, 0, 0, _("hidden takes no arguments")) |
|
1116 | getargs(x, 0, 0, _("hidden takes no arguments")) | |
1117 | hiddenrevs = repoview.filterrevs(repo, 'visible') |
|
1117 | hiddenrevs = repoview.filterrevs(repo, 'visible') | |
1118 | return subset & hiddenrevs |
|
1118 | return subset & hiddenrevs | |
1119 |
|
1119 | |||
1120 | def keyword(repo, subset, x): |
|
1120 | def keyword(repo, subset, x): | |
1121 | """``keyword(string)`` |
|
1121 | """``keyword(string)`` | |
1122 | Search commit message, user name, and names of changed files for |
|
1122 | Search commit message, user name, and names of changed files for | |
1123 | string. The match is case-insensitive. |
|
1123 | string. The match is case-insensitive. | |
1124 | """ |
|
1124 | """ | |
1125 | # i18n: "keyword" is a keyword |
|
1125 | # i18n: "keyword" is a keyword | |
1126 | kw = encoding.lower(getstring(x, _("keyword requires a string"))) |
|
1126 | kw = encoding.lower(getstring(x, _("keyword requires a string"))) | |
1127 |
|
1127 | |||
1128 | def matches(r): |
|
1128 | def matches(r): | |
1129 | c = repo[r] |
|
1129 | c = repo[r] | |
1130 | return util.any(kw in encoding.lower(t) for t in c.files() + [c.user(), |
|
1130 | return util.any(kw in encoding.lower(t) for t in c.files() + [c.user(), | |
1131 | c.description()]) |
|
1131 | c.description()]) | |
1132 |
|
1132 | |||
1133 | return subset.filter(matches) |
|
1133 | return subset.filter(matches) | |
1134 |
|
1134 | |||
1135 | def limit(repo, subset, x): |
|
1135 | def limit(repo, subset, x): | |
1136 | """``limit(set, [n])`` |
|
1136 | """``limit(set, [n])`` | |
1137 | First n members of set, defaulting to 1. |
|
1137 | First n members of set, defaulting to 1. | |
1138 | """ |
|
1138 | """ | |
1139 | # i18n: "limit" is a keyword |
|
1139 | # i18n: "limit" is a keyword | |
1140 | l = getargs(x, 1, 2, _("limit requires one or two arguments")) |
|
1140 | l = getargs(x, 1, 2, _("limit requires one or two arguments")) | |
1141 | try: |
|
1141 | try: | |
1142 | lim = 1 |
|
1142 | lim = 1 | |
1143 | if len(l) == 2: |
|
1143 | if len(l) == 2: | |
1144 | # i18n: "limit" is a keyword |
|
1144 | # i18n: "limit" is a keyword | |
1145 | lim = int(getstring(l[1], _("limit requires a number"))) |
|
1145 | lim = int(getstring(l[1], _("limit requires a number"))) | |
1146 | except (TypeError, ValueError): |
|
1146 | except (TypeError, ValueError): | |
1147 | # i18n: "limit" is a keyword |
|
1147 | # i18n: "limit" is a keyword | |
1148 | raise error.ParseError(_("limit expects a number")) |
|
1148 | raise error.ParseError(_("limit expects a number")) | |
1149 | ss = subset |
|
1149 | ss = subset | |
1150 | os = getset(repo, fullreposet(repo), l[0]) |
|
1150 | os = getset(repo, fullreposet(repo), l[0]) | |
1151 | result = [] |
|
1151 | result = [] | |
1152 | it = iter(os) |
|
1152 | it = iter(os) | |
1153 | for x in xrange(lim): |
|
1153 | for x in xrange(lim): | |
1154 | try: |
|
1154 | try: | |
1155 | y = it.next() |
|
1155 | y = it.next() | |
1156 | if y in ss: |
|
1156 | if y in ss: | |
1157 | result.append(y) |
|
1157 | result.append(y) | |
1158 | except (StopIteration): |
|
1158 | except (StopIteration): | |
1159 | break |
|
1159 | break | |
1160 | return baseset(result) |
|
1160 | return baseset(result) | |
1161 |
|
1161 | |||
1162 | def last(repo, subset, x): |
|
1162 | def last(repo, subset, x): | |
1163 | """``last(set, [n])`` |
|
1163 | """``last(set, [n])`` | |
1164 | Last n members of set, defaulting to 1. |
|
1164 | Last n members of set, defaulting to 1. | |
1165 | """ |
|
1165 | """ | |
1166 | # i18n: "last" is a keyword |
|
1166 | # i18n: "last" is a keyword | |
1167 | l = getargs(x, 1, 2, _("last requires one or two arguments")) |
|
1167 | l = getargs(x, 1, 2, _("last requires one or two arguments")) | |
1168 | try: |
|
1168 | try: | |
1169 | lim = 1 |
|
1169 | lim = 1 | |
1170 | if len(l) == 2: |
|
1170 | if len(l) == 2: | |
1171 | # i18n: "last" is a keyword |
|
1171 | # i18n: "last" is a keyword | |
1172 | lim = int(getstring(l[1], _("last requires a number"))) |
|
1172 | lim = int(getstring(l[1], _("last requires a number"))) | |
1173 | except (TypeError, ValueError): |
|
1173 | except (TypeError, ValueError): | |
1174 | # i18n: "last" is a keyword |
|
1174 | # i18n: "last" is a keyword | |
1175 | raise error.ParseError(_("last expects a number")) |
|
1175 | raise error.ParseError(_("last expects a number")) | |
1176 | ss = subset |
|
1176 | ss = subset | |
1177 | os = getset(repo, fullreposet(repo), l[0]) |
|
1177 | os = getset(repo, fullreposet(repo), l[0]) | |
1178 | os.reverse() |
|
1178 | os.reverse() | |
1179 | result = [] |
|
1179 | result = [] | |
1180 | it = iter(os) |
|
1180 | it = iter(os) | |
1181 | for x in xrange(lim): |
|
1181 | for x in xrange(lim): | |
1182 | try: |
|
1182 | try: | |
1183 | y = it.next() |
|
1183 | y = it.next() | |
1184 | if y in ss: |
|
1184 | if y in ss: | |
1185 | result.append(y) |
|
1185 | result.append(y) | |
1186 | except (StopIteration): |
|
1186 | except (StopIteration): | |
1187 | break |
|
1187 | break | |
1188 | return baseset(result) |
|
1188 | return baseset(result) | |
1189 |
|
1189 | |||
1190 | def maxrev(repo, subset, x): |
|
1190 | def maxrev(repo, subset, x): | |
1191 | """``max(set)`` |
|
1191 | """``max(set)`` | |
1192 | Changeset with highest revision number in set. |
|
1192 | Changeset with highest revision number in set. | |
1193 | """ |
|
1193 | """ | |
1194 | os = getset(repo, fullreposet(repo), x) |
|
1194 | os = getset(repo, fullreposet(repo), x) | |
1195 | if os: |
|
1195 | if os: | |
1196 | m = os.max() |
|
1196 | m = os.max() | |
1197 | if m in subset: |
|
1197 | if m in subset: | |
1198 | return baseset([m]) |
|
1198 | return baseset([m]) | |
1199 | return baseset() |
|
1199 | return baseset() | |
1200 |
|
1200 | |||
1201 | def merge(repo, subset, x): |
|
1201 | def merge(repo, subset, x): | |
1202 | """``merge()`` |
|
1202 | """``merge()`` | |
1203 | Changeset is a merge changeset. |
|
1203 | Changeset is a merge changeset. | |
1204 | """ |
|
1204 | """ | |
1205 | # i18n: "merge" is a keyword |
|
1205 | # i18n: "merge" is a keyword | |
1206 | getargs(x, 0, 0, _("merge takes no arguments")) |
|
1206 | getargs(x, 0, 0, _("merge takes no arguments")) | |
1207 | cl = repo.changelog |
|
1207 | cl = repo.changelog | |
1208 | return subset.filter(lambda r: cl.parentrevs(r)[1] != -1) |
|
1208 | return subset.filter(lambda r: cl.parentrevs(r)[1] != -1) | |
1209 |
|
1209 | |||
1210 | def branchpoint(repo, subset, x): |
|
1210 | def branchpoint(repo, subset, x): | |
1211 | """``branchpoint()`` |
|
1211 | """``branchpoint()`` | |
1212 | Changesets with more than one child. |
|
1212 | Changesets with more than one child. | |
1213 | """ |
|
1213 | """ | |
1214 | # i18n: "branchpoint" is a keyword |
|
1214 | # i18n: "branchpoint" is a keyword | |
1215 | getargs(x, 0, 0, _("branchpoint takes no arguments")) |
|
1215 | getargs(x, 0, 0, _("branchpoint takes no arguments")) | |
1216 | cl = repo.changelog |
|
1216 | cl = repo.changelog | |
1217 | if not subset: |
|
1217 | if not subset: | |
1218 | return baseset() |
|
1218 | return baseset() | |
1219 | baserev = min(subset) |
|
1219 | baserev = min(subset) | |
1220 | parentscount = [0]*(len(repo) - baserev) |
|
1220 | parentscount = [0]*(len(repo) - baserev) | |
1221 | for r in cl.revs(start=baserev + 1): |
|
1221 | for r in cl.revs(start=baserev + 1): | |
1222 | for p in cl.parentrevs(r): |
|
1222 | for p in cl.parentrevs(r): | |
1223 | if p >= baserev: |
|
1223 | if p >= baserev: | |
1224 | parentscount[p - baserev] += 1 |
|
1224 | parentscount[p - baserev] += 1 | |
1225 | return subset.filter(lambda r: parentscount[r - baserev] > 1) |
|
1225 | return subset.filter(lambda r: parentscount[r - baserev] > 1) | |
1226 |
|
1226 | |||
1227 | def minrev(repo, subset, x): |
|
1227 | def minrev(repo, subset, x): | |
1228 | """``min(set)`` |
|
1228 | """``min(set)`` | |
1229 | Changeset with lowest revision number in set. |
|
1229 | Changeset with lowest revision number in set. | |
1230 | """ |
|
1230 | """ | |
1231 | os = getset(repo, fullreposet(repo), x) |
|
1231 | os = getset(repo, fullreposet(repo), x) | |
1232 | if os: |
|
1232 | if os: | |
1233 | m = os.min() |
|
1233 | m = os.min() | |
1234 | if m in subset: |
|
1234 | if m in subset: | |
1235 | return baseset([m]) |
|
1235 | return baseset([m]) | |
1236 | return baseset() |
|
1236 | return baseset() | |
1237 |
|
1237 | |||
1238 | def modifies(repo, subset, x): |
|
1238 | def modifies(repo, subset, x): | |
1239 | """``modifies(pattern)`` |
|
1239 | """``modifies(pattern)`` | |
1240 | Changesets modifying files matched by pattern. |
|
1240 | Changesets modifying files matched by pattern. | |
1241 |
|
1241 | |||
1242 | The pattern without explicit kind like ``glob:`` is expected to be |
|
1242 | The pattern without explicit kind like ``glob:`` is expected to be | |
1243 | relative to the current directory and match against a file or a |
|
1243 | relative to the current directory and match against a file or a | |
1244 | directory. |
|
1244 | directory. | |
1245 | """ |
|
1245 | """ | |
1246 | # i18n: "modifies" is a keyword |
|
1246 | # i18n: "modifies" is a keyword | |
1247 | pat = getstring(x, _("modifies requires a pattern")) |
|
1247 | pat = getstring(x, _("modifies requires a pattern")) | |
1248 | return checkstatus(repo, subset, pat, 0) |
|
1248 | return checkstatus(repo, subset, pat, 0) | |
1249 |
|
1249 | |||
1250 | def named(repo, subset, x): |
|
1250 | def named(repo, subset, x): | |
1251 | """``named(namespace)`` |
|
1251 | """``named(namespace)`` | |
1252 | The changesets in a given namespace. |
|
1252 | The changesets in a given namespace. | |
1253 |
|
1253 | |||
1254 | If `namespace` starts with `re:`, the remainder of the string is treated as |
|
1254 | 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:`, |
|
1255 | a regular expression. To match a namespace that actually starts with `re:`, | |
1256 | use the prefix `literal:`. |
|
1256 | use the prefix `literal:`. | |
1257 | """ |
|
1257 | """ | |
1258 | # i18n: "named" is a keyword |
|
1258 | # i18n: "named" is a keyword | |
1259 | args = getargs(x, 1, 1, _('named requires a namespace argument')) |
|
1259 | args = getargs(x, 1, 1, _('named requires a namespace argument')) | |
1260 |
|
1260 | |||
1261 | ns = getstring(args[0], |
|
1261 | ns = getstring(args[0], | |
1262 | # i18n: "named" is a keyword |
|
1262 | # i18n: "named" is a keyword | |
1263 | _('the argument to named must be a string')) |
|
1263 | _('the argument to named must be a string')) | |
1264 | kind, pattern, matcher = _stringmatcher(ns) |
|
1264 | kind, pattern, matcher = _stringmatcher(ns) | |
1265 | namespaces = set() |
|
1265 | namespaces = set() | |
1266 | if kind == 'literal': |
|
1266 | if kind == 'literal': | |
1267 | if pattern not in repo.names: |
|
1267 | if pattern not in repo.names: | |
1268 | raise error.RepoLookupError(_("namespace '%s' does not exist") |
|
1268 | raise error.RepoLookupError(_("namespace '%s' does not exist") | |
1269 | % ns) |
|
1269 | % ns) | |
1270 | namespaces.add(repo.names[pattern]) |
|
1270 | namespaces.add(repo.names[pattern]) | |
1271 | else: |
|
1271 | else: | |
1272 | for name, ns in repo.names.iteritems(): |
|
1272 | for name, ns in repo.names.iteritems(): | |
1273 | if matcher(name): |
|
1273 | if matcher(name): | |
1274 | namespaces.add(ns) |
|
1274 | namespaces.add(ns) | |
1275 | if not namespaces: |
|
1275 | if not namespaces: | |
1276 | raise error.RepoLookupError(_("no namespace exists" |
|
1276 | raise error.RepoLookupError(_("no namespace exists" | |
1277 | " that match '%s'") % pattern) |
|
1277 | " that match '%s'") % pattern) | |
1278 |
|
1278 | |||
1279 | names = set() |
|
1279 | names = set() | |
1280 | for ns in namespaces: |
|
1280 | for ns in namespaces: | |
1281 | for name in ns.listnames(repo): |
|
1281 | for name in ns.listnames(repo): | |
1282 | if name not in ns.deprecated: |
|
1282 | if name not in ns.deprecated: | |
1283 | names.update(repo[n].rev() for n in ns.nodes(repo, name)) |
|
1283 | names.update(repo[n].rev() for n in ns.nodes(repo, name)) | |
1284 |
|
1284 | |||
1285 | names -= set([node.nullrev]) |
|
1285 | names -= set([node.nullrev]) | |
1286 | return subset & names |
|
1286 | return subset & names | |
1287 |
|
1287 | |||
1288 | def node_(repo, subset, x): |
|
1288 | def node_(repo, subset, x): | |
1289 | """``id(string)`` |
|
1289 | """``id(string)`` | |
1290 | Revision non-ambiguously specified by the given hex string prefix. |
|
1290 | Revision non-ambiguously specified by the given hex string prefix. | |
1291 | """ |
|
1291 | """ | |
1292 | # i18n: "id" is a keyword |
|
1292 | # i18n: "id" is a keyword | |
1293 | l = getargs(x, 1, 1, _("id requires one argument")) |
|
1293 | l = getargs(x, 1, 1, _("id requires one argument")) | |
1294 | # i18n: "id" is a keyword |
|
1294 | # i18n: "id" is a keyword | |
1295 | n = getstring(l[0], _("id requires a string")) |
|
1295 | n = getstring(l[0], _("id requires a string")) | |
1296 | if len(n) == 40: |
|
1296 | if len(n) == 40: | |
1297 | rn = repo[n].rev() |
|
1297 | try: | |
|
1298 | rn = repo.changelog.rev(node.bin(n)) | |||
|
1299 | except (LookupError, TypeError): | |||
|
1300 | rn = None | |||
1298 | else: |
|
1301 | else: | |
1299 | rn = None |
|
1302 | rn = None | |
1300 | pm = repo.changelog._partialmatch(n) |
|
1303 | pm = repo.changelog._partialmatch(n) | |
1301 | if pm is not None: |
|
1304 | if pm is not None: | |
1302 | rn = repo.changelog.rev(pm) |
|
1305 | rn = repo.changelog.rev(pm) | |
1303 |
|
1306 | |||
1304 | if rn is None: |
|
1307 | if rn is None: | |
1305 | return baseset() |
|
1308 | return baseset() | |
1306 | result = baseset([rn]) |
|
1309 | result = baseset([rn]) | |
1307 | return result & subset |
|
1310 | return result & subset | |
1308 |
|
1311 | |||
1309 | def obsolete(repo, subset, x): |
|
1312 | def obsolete(repo, subset, x): | |
1310 | """``obsolete()`` |
|
1313 | """``obsolete()`` | |
1311 | Mutable changeset with a newer version.""" |
|
1314 | Mutable changeset with a newer version.""" | |
1312 | # i18n: "obsolete" is a keyword |
|
1315 | # i18n: "obsolete" is a keyword | |
1313 | getargs(x, 0, 0, _("obsolete takes no arguments")) |
|
1316 | getargs(x, 0, 0, _("obsolete takes no arguments")) | |
1314 | obsoletes = obsmod.getrevs(repo, 'obsolete') |
|
1317 | obsoletes = obsmod.getrevs(repo, 'obsolete') | |
1315 | return subset & obsoletes |
|
1318 | return subset & obsoletes | |
1316 |
|
1319 | |||
1317 | def only(repo, subset, x): |
|
1320 | def only(repo, subset, x): | |
1318 | """``only(set, [set])`` |
|
1321 | """``only(set, [set])`` | |
1319 | Changesets that are ancestors of the first set that are not ancestors |
|
1322 | Changesets that are ancestors of the first set that are not ancestors | |
1320 | of any other head in the repo. If a second set is specified, the result |
|
1323 | of any other head in the repo. If a second set is specified, the result | |
1321 | is ancestors of the first set that are not ancestors of the second set |
|
1324 | is ancestors of the first set that are not ancestors of the second set | |
1322 | (i.e. ::<set1> - ::<set2>). |
|
1325 | (i.e. ::<set1> - ::<set2>). | |
1323 | """ |
|
1326 | """ | |
1324 | cl = repo.changelog |
|
1327 | cl = repo.changelog | |
1325 | # i18n: "only" is a keyword |
|
1328 | # i18n: "only" is a keyword | |
1326 | args = getargs(x, 1, 2, _('only takes one or two arguments')) |
|
1329 | args = getargs(x, 1, 2, _('only takes one or two arguments')) | |
1327 | include = getset(repo, fullreposet(repo), args[0]) |
|
1330 | include = getset(repo, fullreposet(repo), args[0]) | |
1328 | if len(args) == 1: |
|
1331 | if len(args) == 1: | |
1329 | if not include: |
|
1332 | if not include: | |
1330 | return baseset() |
|
1333 | return baseset() | |
1331 |
|
1334 | |||
1332 | descendants = set(_revdescendants(repo, include, False)) |
|
1335 | descendants = set(_revdescendants(repo, include, False)) | |
1333 | exclude = [rev for rev in cl.headrevs() |
|
1336 | exclude = [rev for rev in cl.headrevs() | |
1334 | if not rev in descendants and not rev in include] |
|
1337 | if not rev in descendants and not rev in include] | |
1335 | else: |
|
1338 | else: | |
1336 | exclude = getset(repo, fullreposet(repo), args[1]) |
|
1339 | exclude = getset(repo, fullreposet(repo), args[1]) | |
1337 |
|
1340 | |||
1338 | results = set(cl.findmissingrevs(common=exclude, heads=include)) |
|
1341 | results = set(cl.findmissingrevs(common=exclude, heads=include)) | |
1339 | return subset & results |
|
1342 | return subset & results | |
1340 |
|
1343 | |||
1341 | def origin(repo, subset, x): |
|
1344 | def origin(repo, subset, x): | |
1342 | """``origin([set])`` |
|
1345 | """``origin([set])`` | |
1343 | Changesets that were specified as a source for the grafts, transplants or |
|
1346 | Changesets that were specified as a source for the grafts, transplants or | |
1344 | rebases that created the given revisions. Omitting the optional set is the |
|
1347 | rebases that created the given revisions. Omitting the optional set is the | |
1345 | same as passing all(). If a changeset created by these operations is itself |
|
1348 | same as passing all(). If a changeset created by these operations is itself | |
1346 | specified as a source for one of these operations, only the source changeset |
|
1349 | specified as a source for one of these operations, only the source changeset | |
1347 | for the first operation is selected. |
|
1350 | for the first operation is selected. | |
1348 | """ |
|
1351 | """ | |
1349 | if x is not None: |
|
1352 | if x is not None: | |
1350 | dests = getset(repo, fullreposet(repo), x) |
|
1353 | dests = getset(repo, fullreposet(repo), x) | |
1351 | else: |
|
1354 | else: | |
1352 | dests = fullreposet(repo) |
|
1355 | dests = fullreposet(repo) | |
1353 |
|
1356 | |||
1354 | def _firstsrc(rev): |
|
1357 | def _firstsrc(rev): | |
1355 | src = _getrevsource(repo, rev) |
|
1358 | src = _getrevsource(repo, rev) | |
1356 | if src is None: |
|
1359 | if src is None: | |
1357 | return None |
|
1360 | return None | |
1358 |
|
1361 | |||
1359 | while True: |
|
1362 | while True: | |
1360 | prev = _getrevsource(repo, src) |
|
1363 | prev = _getrevsource(repo, src) | |
1361 |
|
1364 | |||
1362 | if prev is None: |
|
1365 | if prev is None: | |
1363 | return src |
|
1366 | return src | |
1364 | src = prev |
|
1367 | src = prev | |
1365 |
|
1368 | |||
1366 | o = set([_firstsrc(r) for r in dests]) |
|
1369 | o = set([_firstsrc(r) for r in dests]) | |
1367 | o -= set([None]) |
|
1370 | o -= set([None]) | |
1368 | return subset & o |
|
1371 | return subset & o | |
1369 |
|
1372 | |||
1370 | def outgoing(repo, subset, x): |
|
1373 | def outgoing(repo, subset, x): | |
1371 | """``outgoing([path])`` |
|
1374 | """``outgoing([path])`` | |
1372 | Changesets not found in the specified destination repository, or the |
|
1375 | Changesets not found in the specified destination repository, or the | |
1373 | default push location. |
|
1376 | default push location. | |
1374 | """ |
|
1377 | """ | |
1375 | # Avoid cycles. |
|
1378 | # Avoid cycles. | |
1376 | import discovery |
|
1379 | import discovery | |
1377 | import hg |
|
1380 | import hg | |
1378 | # i18n: "outgoing" is a keyword |
|
1381 | # i18n: "outgoing" is a keyword | |
1379 | l = getargs(x, 0, 1, _("outgoing takes one or no arguments")) |
|
1382 | l = getargs(x, 0, 1, _("outgoing takes one or no arguments")) | |
1380 | # i18n: "outgoing" is a keyword |
|
1383 | # i18n: "outgoing" is a keyword | |
1381 | dest = l and getstring(l[0], _("outgoing requires a repository path")) or '' |
|
1384 | dest = l and getstring(l[0], _("outgoing requires a repository path")) or '' | |
1382 | dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') |
|
1385 | dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') | |
1383 | dest, branches = hg.parseurl(dest) |
|
1386 | dest, branches = hg.parseurl(dest) | |
1384 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) |
|
1387 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) | |
1385 | if revs: |
|
1388 | if revs: | |
1386 | revs = [repo.lookup(rev) for rev in revs] |
|
1389 | revs = [repo.lookup(rev) for rev in revs] | |
1387 | other = hg.peer(repo, {}, dest) |
|
1390 | other = hg.peer(repo, {}, dest) | |
1388 | repo.ui.pushbuffer() |
|
1391 | repo.ui.pushbuffer() | |
1389 | outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) |
|
1392 | outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) | |
1390 | repo.ui.popbuffer() |
|
1393 | repo.ui.popbuffer() | |
1391 | cl = repo.changelog |
|
1394 | cl = repo.changelog | |
1392 | o = set([cl.rev(r) for r in outgoing.missing]) |
|
1395 | o = set([cl.rev(r) for r in outgoing.missing]) | |
1393 | return subset & o |
|
1396 | return subset & o | |
1394 |
|
1397 | |||
1395 | def p1(repo, subset, x): |
|
1398 | def p1(repo, subset, x): | |
1396 | """``p1([set])`` |
|
1399 | """``p1([set])`` | |
1397 | First parent of changesets in set, or the working directory. |
|
1400 | First parent of changesets in set, or the working directory. | |
1398 | """ |
|
1401 | """ | |
1399 | if x is None: |
|
1402 | if x is None: | |
1400 | p = repo[x].p1().rev() |
|
1403 | p = repo[x].p1().rev() | |
1401 | if p >= 0: |
|
1404 | if p >= 0: | |
1402 | return subset & baseset([p]) |
|
1405 | return subset & baseset([p]) | |
1403 | return baseset() |
|
1406 | return baseset() | |
1404 |
|
1407 | |||
1405 | ps = set() |
|
1408 | ps = set() | |
1406 | cl = repo.changelog |
|
1409 | cl = repo.changelog | |
1407 | for r in getset(repo, fullreposet(repo), x): |
|
1410 | for r in getset(repo, fullreposet(repo), x): | |
1408 | ps.add(cl.parentrevs(r)[0]) |
|
1411 | ps.add(cl.parentrevs(r)[0]) | |
1409 | ps -= set([node.nullrev]) |
|
1412 | ps -= set([node.nullrev]) | |
1410 | return subset & ps |
|
1413 | return subset & ps | |
1411 |
|
1414 | |||
1412 | def p2(repo, subset, x): |
|
1415 | def p2(repo, subset, x): | |
1413 | """``p2([set])`` |
|
1416 | """``p2([set])`` | |
1414 | Second parent of changesets in set, or the working directory. |
|
1417 | Second parent of changesets in set, or the working directory. | |
1415 | """ |
|
1418 | """ | |
1416 | if x is None: |
|
1419 | if x is None: | |
1417 | ps = repo[x].parents() |
|
1420 | ps = repo[x].parents() | |
1418 | try: |
|
1421 | try: | |
1419 | p = ps[1].rev() |
|
1422 | p = ps[1].rev() | |
1420 | if p >= 0: |
|
1423 | if p >= 0: | |
1421 | return subset & baseset([p]) |
|
1424 | return subset & baseset([p]) | |
1422 | return baseset() |
|
1425 | return baseset() | |
1423 | except IndexError: |
|
1426 | except IndexError: | |
1424 | return baseset() |
|
1427 | return baseset() | |
1425 |
|
1428 | |||
1426 | ps = set() |
|
1429 | ps = set() | |
1427 | cl = repo.changelog |
|
1430 | cl = repo.changelog | |
1428 | for r in getset(repo, fullreposet(repo), x): |
|
1431 | for r in getset(repo, fullreposet(repo), x): | |
1429 | ps.add(cl.parentrevs(r)[1]) |
|
1432 | ps.add(cl.parentrevs(r)[1]) | |
1430 | ps -= set([node.nullrev]) |
|
1433 | ps -= set([node.nullrev]) | |
1431 | return subset & ps |
|
1434 | return subset & ps | |
1432 |
|
1435 | |||
1433 | def parents(repo, subset, x): |
|
1436 | def parents(repo, subset, x): | |
1434 | """``parents([set])`` |
|
1437 | """``parents([set])`` | |
1435 | The set of all parents for all changesets in set, or the working directory. |
|
1438 | The set of all parents for all changesets in set, or the working directory. | |
1436 | """ |
|
1439 | """ | |
1437 | if x is None: |
|
1440 | if x is None: | |
1438 | ps = set(p.rev() for p in repo[x].parents()) |
|
1441 | ps = set(p.rev() for p in repo[x].parents()) | |
1439 | else: |
|
1442 | else: | |
1440 | ps = set() |
|
1443 | ps = set() | |
1441 | cl = repo.changelog |
|
1444 | cl = repo.changelog | |
1442 | for r in getset(repo, fullreposet(repo), x): |
|
1445 | for r in getset(repo, fullreposet(repo), x): | |
1443 | ps.update(cl.parentrevs(r)) |
|
1446 | ps.update(cl.parentrevs(r)) | |
1444 | ps -= set([node.nullrev]) |
|
1447 | ps -= set([node.nullrev]) | |
1445 | return subset & ps |
|
1448 | return subset & ps | |
1446 |
|
1449 | |||
1447 | def parentspec(repo, subset, x, n): |
|
1450 | def parentspec(repo, subset, x, n): | |
1448 | """``set^0`` |
|
1451 | """``set^0`` | |
1449 | The set. |
|
1452 | The set. | |
1450 | ``set^1`` (or ``set^``), ``set^2`` |
|
1453 | ``set^1`` (or ``set^``), ``set^2`` | |
1451 | First or second parent, respectively, of all changesets in set. |
|
1454 | First or second parent, respectively, of all changesets in set. | |
1452 | """ |
|
1455 | """ | |
1453 | try: |
|
1456 | try: | |
1454 | n = int(n[1]) |
|
1457 | n = int(n[1]) | |
1455 | if n not in (0, 1, 2): |
|
1458 | if n not in (0, 1, 2): | |
1456 | raise ValueError |
|
1459 | raise ValueError | |
1457 | except (TypeError, ValueError): |
|
1460 | except (TypeError, ValueError): | |
1458 | raise error.ParseError(_("^ expects a number 0, 1, or 2")) |
|
1461 | raise error.ParseError(_("^ expects a number 0, 1, or 2")) | |
1459 | ps = set() |
|
1462 | ps = set() | |
1460 | cl = repo.changelog |
|
1463 | cl = repo.changelog | |
1461 | for r in getset(repo, fullreposet(repo), x): |
|
1464 | for r in getset(repo, fullreposet(repo), x): | |
1462 | if n == 0: |
|
1465 | if n == 0: | |
1463 | ps.add(r) |
|
1466 | ps.add(r) | |
1464 | elif n == 1: |
|
1467 | elif n == 1: | |
1465 | ps.add(cl.parentrevs(r)[0]) |
|
1468 | ps.add(cl.parentrevs(r)[0]) | |
1466 | elif n == 2: |
|
1469 | elif n == 2: | |
1467 | parents = cl.parentrevs(r) |
|
1470 | parents = cl.parentrevs(r) | |
1468 | if len(parents) > 1: |
|
1471 | if len(parents) > 1: | |
1469 | ps.add(parents[1]) |
|
1472 | ps.add(parents[1]) | |
1470 | return subset & ps |
|
1473 | return subset & ps | |
1471 |
|
1474 | |||
1472 | def present(repo, subset, x): |
|
1475 | def present(repo, subset, x): | |
1473 | """``present(set)`` |
|
1476 | """``present(set)`` | |
1474 | An empty set, if any revision in set isn't found; otherwise, |
|
1477 | An empty set, if any revision in set isn't found; otherwise, | |
1475 | all revisions in set. |
|
1478 | all revisions in set. | |
1476 |
|
1479 | |||
1477 | If any of specified revisions is not present in the local repository, |
|
1480 | If any of specified revisions is not present in the local repository, | |
1478 | the query is normally aborted. But this predicate allows the query |
|
1481 | the query is normally aborted. But this predicate allows the query | |
1479 | to continue even in such cases. |
|
1482 | to continue even in such cases. | |
1480 | """ |
|
1483 | """ | |
1481 | try: |
|
1484 | try: | |
1482 | return getset(repo, subset, x) |
|
1485 | return getset(repo, subset, x) | |
1483 | except error.RepoLookupError: |
|
1486 | except error.RepoLookupError: | |
1484 | return baseset() |
|
1487 | return baseset() | |
1485 |
|
1488 | |||
1486 | def public(repo, subset, x): |
|
1489 | def public(repo, subset, x): | |
1487 | """``public()`` |
|
1490 | """``public()`` | |
1488 | Changeset in public phase.""" |
|
1491 | Changeset in public phase.""" | |
1489 | # i18n: "public" is a keyword |
|
1492 | # i18n: "public" is a keyword | |
1490 | getargs(x, 0, 0, _("public takes no arguments")) |
|
1493 | getargs(x, 0, 0, _("public takes no arguments")) | |
1491 | phase = repo._phasecache.phase |
|
1494 | phase = repo._phasecache.phase | |
1492 | target = phases.public |
|
1495 | target = phases.public | |
1493 | condition = lambda r: phase(repo, r) == target |
|
1496 | condition = lambda r: phase(repo, r) == target | |
1494 | return subset.filter(condition, cache=False) |
|
1497 | return subset.filter(condition, cache=False) | |
1495 |
|
1498 | |||
1496 | def remote(repo, subset, x): |
|
1499 | def remote(repo, subset, x): | |
1497 | """``remote([id [,path]])`` |
|
1500 | """``remote([id [,path]])`` | |
1498 | Local revision that corresponds to the given identifier in a |
|
1501 | Local revision that corresponds to the given identifier in a | |
1499 | remote repository, if present. Here, the '.' identifier is a |
|
1502 | remote repository, if present. Here, the '.' identifier is a | |
1500 | synonym for the current local branch. |
|
1503 | synonym for the current local branch. | |
1501 | """ |
|
1504 | """ | |
1502 |
|
1505 | |||
1503 | import hg # avoid start-up nasties |
|
1506 | import hg # avoid start-up nasties | |
1504 | # i18n: "remote" is a keyword |
|
1507 | # i18n: "remote" is a keyword | |
1505 | l = getargs(x, 0, 2, _("remote takes one, two or no arguments")) |
|
1508 | l = getargs(x, 0, 2, _("remote takes one, two or no arguments")) | |
1506 |
|
1509 | |||
1507 | q = '.' |
|
1510 | q = '.' | |
1508 | if len(l) > 0: |
|
1511 | if len(l) > 0: | |
1509 | # i18n: "remote" is a keyword |
|
1512 | # i18n: "remote" is a keyword | |
1510 | q = getstring(l[0], _("remote requires a string id")) |
|
1513 | q = getstring(l[0], _("remote requires a string id")) | |
1511 | if q == '.': |
|
1514 | if q == '.': | |
1512 | q = repo['.'].branch() |
|
1515 | q = repo['.'].branch() | |
1513 |
|
1516 | |||
1514 | dest = '' |
|
1517 | dest = '' | |
1515 | if len(l) > 1: |
|
1518 | if len(l) > 1: | |
1516 | # i18n: "remote" is a keyword |
|
1519 | # i18n: "remote" is a keyword | |
1517 | dest = getstring(l[1], _("remote requires a repository path")) |
|
1520 | dest = getstring(l[1], _("remote requires a repository path")) | |
1518 | dest = repo.ui.expandpath(dest or 'default') |
|
1521 | dest = repo.ui.expandpath(dest or 'default') | |
1519 | dest, branches = hg.parseurl(dest) |
|
1522 | dest, branches = hg.parseurl(dest) | |
1520 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) |
|
1523 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) | |
1521 | if revs: |
|
1524 | if revs: | |
1522 | revs = [repo.lookup(rev) for rev in revs] |
|
1525 | revs = [repo.lookup(rev) for rev in revs] | |
1523 | other = hg.peer(repo, {}, dest) |
|
1526 | other = hg.peer(repo, {}, dest) | |
1524 | n = other.lookup(q) |
|
1527 | n = other.lookup(q) | |
1525 | if n in repo: |
|
1528 | if n in repo: | |
1526 | r = repo[n].rev() |
|
1529 | r = repo[n].rev() | |
1527 | if r in subset: |
|
1530 | if r in subset: | |
1528 | return baseset([r]) |
|
1531 | return baseset([r]) | |
1529 | return baseset() |
|
1532 | return baseset() | |
1530 |
|
1533 | |||
1531 | def removes(repo, subset, x): |
|
1534 | def removes(repo, subset, x): | |
1532 | """``removes(pattern)`` |
|
1535 | """``removes(pattern)`` | |
1533 | Changesets which remove files matching pattern. |
|
1536 | Changesets which remove files matching pattern. | |
1534 |
|
1537 | |||
1535 | The pattern without explicit kind like ``glob:`` is expected to be |
|
1538 | The pattern without explicit kind like ``glob:`` is expected to be | |
1536 | relative to the current directory and match against a file or a |
|
1539 | relative to the current directory and match against a file or a | |
1537 | directory. |
|
1540 | directory. | |
1538 | """ |
|
1541 | """ | |
1539 | # i18n: "removes" is a keyword |
|
1542 | # i18n: "removes" is a keyword | |
1540 | pat = getstring(x, _("removes requires a pattern")) |
|
1543 | pat = getstring(x, _("removes requires a pattern")) | |
1541 | return checkstatus(repo, subset, pat, 2) |
|
1544 | return checkstatus(repo, subset, pat, 2) | |
1542 |
|
1545 | |||
1543 | def rev(repo, subset, x): |
|
1546 | def rev(repo, subset, x): | |
1544 | """``rev(number)`` |
|
1547 | """``rev(number)`` | |
1545 | Revision with the given numeric identifier. |
|
1548 | Revision with the given numeric identifier. | |
1546 | """ |
|
1549 | """ | |
1547 | # i18n: "rev" is a keyword |
|
1550 | # i18n: "rev" is a keyword | |
1548 | l = getargs(x, 1, 1, _("rev requires one argument")) |
|
1551 | l = getargs(x, 1, 1, _("rev requires one argument")) | |
1549 | try: |
|
1552 | try: | |
1550 | # i18n: "rev" is a keyword |
|
1553 | # i18n: "rev" is a keyword | |
1551 | l = int(getstring(l[0], _("rev requires a number"))) |
|
1554 | l = int(getstring(l[0], _("rev requires a number"))) | |
1552 | except (TypeError, ValueError): |
|
1555 | except (TypeError, ValueError): | |
1553 | # i18n: "rev" is a keyword |
|
1556 | # i18n: "rev" is a keyword | |
1554 | raise error.ParseError(_("rev expects a number")) |
|
1557 | raise error.ParseError(_("rev expects a number")) | |
1555 | if l not in repo.changelog and l != node.nullrev: |
|
1558 | if l not in repo.changelog and l != node.nullrev: | |
1556 | return baseset() |
|
1559 | return baseset() | |
1557 | return subset & baseset([l]) |
|
1560 | return subset & baseset([l]) | |
1558 |
|
1561 | |||
1559 | def matching(repo, subset, x): |
|
1562 | def matching(repo, subset, x): | |
1560 | """``matching(revision [, field])`` |
|
1563 | """``matching(revision [, field])`` | |
1561 | Changesets in which a given set of fields match the set of fields in the |
|
1564 | Changesets in which a given set of fields match the set of fields in the | |
1562 | selected revision or set. |
|
1565 | selected revision or set. | |
1563 |
|
1566 | |||
1564 | To match more than one field pass the list of fields to match separated |
|
1567 | To match more than one field pass the list of fields to match separated | |
1565 | by spaces (e.g. ``author description``). |
|
1568 | by spaces (e.g. ``author description``). | |
1566 |
|
1569 | |||
1567 | Valid fields are most regular revision fields and some special fields. |
|
1570 | Valid fields are most regular revision fields and some special fields. | |
1568 |
|
1571 | |||
1569 | Regular revision fields are ``description``, ``author``, ``branch``, |
|
1572 | Regular revision fields are ``description``, ``author``, ``branch``, | |
1570 | ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` |
|
1573 | ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` | |
1571 | and ``diff``. |
|
1574 | and ``diff``. | |
1572 | Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the |
|
1575 | Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the | |
1573 | contents of the revision. Two revisions matching their ``diff`` will |
|
1576 | contents of the revision. Two revisions matching their ``diff`` will | |
1574 | also match their ``files``. |
|
1577 | also match their ``files``. | |
1575 |
|
1578 | |||
1576 | Special fields are ``summary`` and ``metadata``: |
|
1579 | Special fields are ``summary`` and ``metadata``: | |
1577 | ``summary`` matches the first line of the description. |
|
1580 | ``summary`` matches the first line of the description. | |
1578 | ``metadata`` is equivalent to matching ``description user date`` |
|
1581 | ``metadata`` is equivalent to matching ``description user date`` | |
1579 | (i.e. it matches the main metadata fields). |
|
1582 | (i.e. it matches the main metadata fields). | |
1580 |
|
1583 | |||
1581 | ``metadata`` is the default field which is used when no fields are |
|
1584 | ``metadata`` is the default field which is used when no fields are | |
1582 | specified. You can match more than one field at a time. |
|
1585 | specified. You can match more than one field at a time. | |
1583 | """ |
|
1586 | """ | |
1584 | # i18n: "matching" is a keyword |
|
1587 | # i18n: "matching" is a keyword | |
1585 | l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments")) |
|
1588 | l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments")) | |
1586 |
|
1589 | |||
1587 | revs = getset(repo, fullreposet(repo), l[0]) |
|
1590 | revs = getset(repo, fullreposet(repo), l[0]) | |
1588 |
|
1591 | |||
1589 | fieldlist = ['metadata'] |
|
1592 | fieldlist = ['metadata'] | |
1590 | if len(l) > 1: |
|
1593 | if len(l) > 1: | |
1591 | fieldlist = getstring(l[1], |
|
1594 | fieldlist = getstring(l[1], | |
1592 | # i18n: "matching" is a keyword |
|
1595 | # i18n: "matching" is a keyword | |
1593 | _("matching requires a string " |
|
1596 | _("matching requires a string " | |
1594 | "as its second argument")).split() |
|
1597 | "as its second argument")).split() | |
1595 |
|
1598 | |||
1596 | # Make sure that there are no repeated fields, |
|
1599 | # Make sure that there are no repeated fields, | |
1597 | # expand the 'special' 'metadata' field type |
|
1600 | # expand the 'special' 'metadata' field type | |
1598 | # and check the 'files' whenever we check the 'diff' |
|
1601 | # and check the 'files' whenever we check the 'diff' | |
1599 | fields = [] |
|
1602 | fields = [] | |
1600 | for field in fieldlist: |
|
1603 | for field in fieldlist: | |
1601 | if field == 'metadata': |
|
1604 | if field == 'metadata': | |
1602 | fields += ['user', 'description', 'date'] |
|
1605 | fields += ['user', 'description', 'date'] | |
1603 | elif field == 'diff': |
|
1606 | elif field == 'diff': | |
1604 | # a revision matching the diff must also match the files |
|
1607 | # a revision matching the diff must also match the files | |
1605 | # since matching the diff is very costly, make sure to |
|
1608 | # since matching the diff is very costly, make sure to | |
1606 | # also match the files first |
|
1609 | # also match the files first | |
1607 | fields += ['files', 'diff'] |
|
1610 | fields += ['files', 'diff'] | |
1608 | else: |
|
1611 | else: | |
1609 | if field == 'author': |
|
1612 | if field == 'author': | |
1610 | field = 'user' |
|
1613 | field = 'user' | |
1611 | fields.append(field) |
|
1614 | fields.append(field) | |
1612 | fields = set(fields) |
|
1615 | fields = set(fields) | |
1613 | if 'summary' in fields and 'description' in fields: |
|
1616 | if 'summary' in fields and 'description' in fields: | |
1614 | # If a revision matches its description it also matches its summary |
|
1617 | # If a revision matches its description it also matches its summary | |
1615 | fields.discard('summary') |
|
1618 | fields.discard('summary') | |
1616 |
|
1619 | |||
1617 | # We may want to match more than one field |
|
1620 | # We may want to match more than one field | |
1618 | # Not all fields take the same amount of time to be matched |
|
1621 | # Not all fields take the same amount of time to be matched | |
1619 | # Sort the selected fields in order of increasing matching cost |
|
1622 | # Sort the selected fields in order of increasing matching cost | |
1620 | fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary', |
|
1623 | fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary', | |
1621 | 'files', 'description', 'substate', 'diff'] |
|
1624 | 'files', 'description', 'substate', 'diff'] | |
1622 | def fieldkeyfunc(f): |
|
1625 | def fieldkeyfunc(f): | |
1623 | try: |
|
1626 | try: | |
1624 | return fieldorder.index(f) |
|
1627 | return fieldorder.index(f) | |
1625 | except ValueError: |
|
1628 | except ValueError: | |
1626 | # assume an unknown field is very costly |
|
1629 | # assume an unknown field is very costly | |
1627 | return len(fieldorder) |
|
1630 | return len(fieldorder) | |
1628 | fields = list(fields) |
|
1631 | fields = list(fields) | |
1629 | fields.sort(key=fieldkeyfunc) |
|
1632 | fields.sort(key=fieldkeyfunc) | |
1630 |
|
1633 | |||
1631 | # Each field will be matched with its own "getfield" function |
|
1634 | # Each field will be matched with its own "getfield" function | |
1632 | # which will be added to the getfieldfuncs array of functions |
|
1635 | # which will be added to the getfieldfuncs array of functions | |
1633 | getfieldfuncs = [] |
|
1636 | getfieldfuncs = [] | |
1634 | _funcs = { |
|
1637 | _funcs = { | |
1635 | 'user': lambda r: repo[r].user(), |
|
1638 | 'user': lambda r: repo[r].user(), | |
1636 | 'branch': lambda r: repo[r].branch(), |
|
1639 | 'branch': lambda r: repo[r].branch(), | |
1637 | 'date': lambda r: repo[r].date(), |
|
1640 | 'date': lambda r: repo[r].date(), | |
1638 | 'description': lambda r: repo[r].description(), |
|
1641 | 'description': lambda r: repo[r].description(), | |
1639 | 'files': lambda r: repo[r].files(), |
|
1642 | 'files': lambda r: repo[r].files(), | |
1640 | 'parents': lambda r: repo[r].parents(), |
|
1643 | 'parents': lambda r: repo[r].parents(), | |
1641 | 'phase': lambda r: repo[r].phase(), |
|
1644 | 'phase': lambda r: repo[r].phase(), | |
1642 | 'substate': lambda r: repo[r].substate, |
|
1645 | 'substate': lambda r: repo[r].substate, | |
1643 | 'summary': lambda r: repo[r].description().splitlines()[0], |
|
1646 | 'summary': lambda r: repo[r].description().splitlines()[0], | |
1644 | 'diff': lambda r: list(repo[r].diff(git=True),) |
|
1647 | 'diff': lambda r: list(repo[r].diff(git=True),) | |
1645 | } |
|
1648 | } | |
1646 | for info in fields: |
|
1649 | for info in fields: | |
1647 | getfield = _funcs.get(info, None) |
|
1650 | getfield = _funcs.get(info, None) | |
1648 | if getfield is None: |
|
1651 | if getfield is None: | |
1649 | raise error.ParseError( |
|
1652 | raise error.ParseError( | |
1650 | # i18n: "matching" is a keyword |
|
1653 | # i18n: "matching" is a keyword | |
1651 | _("unexpected field name passed to matching: %s") % info) |
|
1654 | _("unexpected field name passed to matching: %s") % info) | |
1652 | getfieldfuncs.append(getfield) |
|
1655 | getfieldfuncs.append(getfield) | |
1653 | # convert the getfield array of functions into a "getinfo" function |
|
1656 | # convert the getfield array of functions into a "getinfo" function | |
1654 | # which returns an array of field values (or a single value if there |
|
1657 | # which returns an array of field values (or a single value if there | |
1655 | # is only one field to match) |
|
1658 | # is only one field to match) | |
1656 | getinfo = lambda r: [f(r) for f in getfieldfuncs] |
|
1659 | getinfo = lambda r: [f(r) for f in getfieldfuncs] | |
1657 |
|
1660 | |||
1658 | def matches(x): |
|
1661 | def matches(x): | |
1659 | for rev in revs: |
|
1662 | for rev in revs: | |
1660 | target = getinfo(rev) |
|
1663 | target = getinfo(rev) | |
1661 | match = True |
|
1664 | match = True | |
1662 | for n, f in enumerate(getfieldfuncs): |
|
1665 | for n, f in enumerate(getfieldfuncs): | |
1663 | if target[n] != f(x): |
|
1666 | if target[n] != f(x): | |
1664 | match = False |
|
1667 | match = False | |
1665 | if match: |
|
1668 | if match: | |
1666 | return True |
|
1669 | return True | |
1667 | return False |
|
1670 | return False | |
1668 |
|
1671 | |||
1669 | return subset.filter(matches) |
|
1672 | return subset.filter(matches) | |
1670 |
|
1673 | |||
1671 | def reverse(repo, subset, x): |
|
1674 | def reverse(repo, subset, x): | |
1672 | """``reverse(set)`` |
|
1675 | """``reverse(set)`` | |
1673 | Reverse order of set. |
|
1676 | Reverse order of set. | |
1674 | """ |
|
1677 | """ | |
1675 | l = getset(repo, subset, x) |
|
1678 | l = getset(repo, subset, x) | |
1676 | l.reverse() |
|
1679 | l.reverse() | |
1677 | return l |
|
1680 | return l | |
1678 |
|
1681 | |||
1679 | def roots(repo, subset, x): |
|
1682 | def roots(repo, subset, x): | |
1680 | """``roots(set)`` |
|
1683 | """``roots(set)`` | |
1681 | Changesets in set with no parent changeset in set. |
|
1684 | Changesets in set with no parent changeset in set. | |
1682 | """ |
|
1685 | """ | |
1683 | s = getset(repo, fullreposet(repo), x) |
|
1686 | s = getset(repo, fullreposet(repo), x) | |
1684 | subset = baseset([r for r in s if r in subset]) |
|
1687 | subset = baseset([r for r in s if r in subset]) | |
1685 | cs = _children(repo, subset, s) |
|
1688 | cs = _children(repo, subset, s) | |
1686 | return subset - cs |
|
1689 | return subset - cs | |
1687 |
|
1690 | |||
1688 | def secret(repo, subset, x): |
|
1691 | def secret(repo, subset, x): | |
1689 | """``secret()`` |
|
1692 | """``secret()`` | |
1690 | Changeset in secret phase.""" |
|
1693 | Changeset in secret phase.""" | |
1691 | # i18n: "secret" is a keyword |
|
1694 | # i18n: "secret" is a keyword | |
1692 | getargs(x, 0, 0, _("secret takes no arguments")) |
|
1695 | getargs(x, 0, 0, _("secret takes no arguments")) | |
1693 | phase = repo._phasecache.phase |
|
1696 | phase = repo._phasecache.phase | |
1694 | target = phases.secret |
|
1697 | target = phases.secret | |
1695 | condition = lambda r: phase(repo, r) == target |
|
1698 | condition = lambda r: phase(repo, r) == target | |
1696 | return subset.filter(condition, cache=False) |
|
1699 | return subset.filter(condition, cache=False) | |
1697 |
|
1700 | |||
1698 | def sort(repo, subset, x): |
|
1701 | def sort(repo, subset, x): | |
1699 | """``sort(set[, [-]key...])`` |
|
1702 | """``sort(set[, [-]key...])`` | |
1700 | Sort set by keys. The default sort order is ascending, specify a key |
|
1703 | Sort set by keys. The default sort order is ascending, specify a key | |
1701 | as ``-key`` to sort in descending order. |
|
1704 | as ``-key`` to sort in descending order. | |
1702 |
|
1705 | |||
1703 | The keys can be: |
|
1706 | The keys can be: | |
1704 |
|
1707 | |||
1705 | - ``rev`` for the revision number, |
|
1708 | - ``rev`` for the revision number, | |
1706 | - ``branch`` for the branch name, |
|
1709 | - ``branch`` for the branch name, | |
1707 | - ``desc`` for the commit message (description), |
|
1710 | - ``desc`` for the commit message (description), | |
1708 | - ``user`` for user name (``author`` can be used as an alias), |
|
1711 | - ``user`` for user name (``author`` can be used as an alias), | |
1709 | - ``date`` for the commit date |
|
1712 | - ``date`` for the commit date | |
1710 | """ |
|
1713 | """ | |
1711 | # i18n: "sort" is a keyword |
|
1714 | # i18n: "sort" is a keyword | |
1712 | l = getargs(x, 1, 2, _("sort requires one or two arguments")) |
|
1715 | l = getargs(x, 1, 2, _("sort requires one or two arguments")) | |
1713 | keys = "rev" |
|
1716 | keys = "rev" | |
1714 | if len(l) == 2: |
|
1717 | if len(l) == 2: | |
1715 | # i18n: "sort" is a keyword |
|
1718 | # i18n: "sort" is a keyword | |
1716 | keys = getstring(l[1], _("sort spec must be a string")) |
|
1719 | keys = getstring(l[1], _("sort spec must be a string")) | |
1717 |
|
1720 | |||
1718 | s = l[0] |
|
1721 | s = l[0] | |
1719 | keys = keys.split() |
|
1722 | keys = keys.split() | |
1720 | l = [] |
|
1723 | l = [] | |
1721 | def invert(s): |
|
1724 | def invert(s): | |
1722 | return "".join(chr(255 - ord(c)) for c in s) |
|
1725 | return "".join(chr(255 - ord(c)) for c in s) | |
1723 | revs = getset(repo, subset, s) |
|
1726 | revs = getset(repo, subset, s) | |
1724 | if keys == ["rev"]: |
|
1727 | if keys == ["rev"]: | |
1725 | revs.sort() |
|
1728 | revs.sort() | |
1726 | return revs |
|
1729 | return revs | |
1727 | elif keys == ["-rev"]: |
|
1730 | elif keys == ["-rev"]: | |
1728 | revs.sort(reverse=True) |
|
1731 | revs.sort(reverse=True) | |
1729 | return revs |
|
1732 | return revs | |
1730 | for r in revs: |
|
1733 | for r in revs: | |
1731 | c = repo[r] |
|
1734 | c = repo[r] | |
1732 | e = [] |
|
1735 | e = [] | |
1733 | for k in keys: |
|
1736 | for k in keys: | |
1734 | if k == 'rev': |
|
1737 | if k == 'rev': | |
1735 | e.append(r) |
|
1738 | e.append(r) | |
1736 | elif k == '-rev': |
|
1739 | elif k == '-rev': | |
1737 | e.append(-r) |
|
1740 | e.append(-r) | |
1738 | elif k == 'branch': |
|
1741 | elif k == 'branch': | |
1739 | e.append(c.branch()) |
|
1742 | e.append(c.branch()) | |
1740 | elif k == '-branch': |
|
1743 | elif k == '-branch': | |
1741 | e.append(invert(c.branch())) |
|
1744 | e.append(invert(c.branch())) | |
1742 | elif k == 'desc': |
|
1745 | elif k == 'desc': | |
1743 | e.append(c.description()) |
|
1746 | e.append(c.description()) | |
1744 | elif k == '-desc': |
|
1747 | elif k == '-desc': | |
1745 | e.append(invert(c.description())) |
|
1748 | e.append(invert(c.description())) | |
1746 | elif k in 'user author': |
|
1749 | elif k in 'user author': | |
1747 | e.append(c.user()) |
|
1750 | e.append(c.user()) | |
1748 | elif k in '-user -author': |
|
1751 | elif k in '-user -author': | |
1749 | e.append(invert(c.user())) |
|
1752 | e.append(invert(c.user())) | |
1750 | elif k == 'date': |
|
1753 | elif k == 'date': | |
1751 | e.append(c.date()[0]) |
|
1754 | e.append(c.date()[0]) | |
1752 | elif k == '-date': |
|
1755 | elif k == '-date': | |
1753 | e.append(-c.date()[0]) |
|
1756 | e.append(-c.date()[0]) | |
1754 | else: |
|
1757 | else: | |
1755 | raise error.ParseError(_("unknown sort key %r") % k) |
|
1758 | raise error.ParseError(_("unknown sort key %r") % k) | |
1756 | e.append(r) |
|
1759 | e.append(r) | |
1757 | l.append(e) |
|
1760 | l.append(e) | |
1758 | l.sort() |
|
1761 | l.sort() | |
1759 | return baseset([e[-1] for e in l]) |
|
1762 | return baseset([e[-1] for e in l]) | |
1760 |
|
1763 | |||
1761 | def subrepo(repo, subset, x): |
|
1764 | def subrepo(repo, subset, x): | |
1762 | """``subrepo([pattern])`` |
|
1765 | """``subrepo([pattern])`` | |
1763 | Changesets that add, modify or remove the given subrepo. If no subrepo |
|
1766 | Changesets that add, modify or remove the given subrepo. If no subrepo | |
1764 | pattern is named, any subrepo changes are returned. |
|
1767 | pattern is named, any subrepo changes are returned. | |
1765 | """ |
|
1768 | """ | |
1766 | # i18n: "subrepo" is a keyword |
|
1769 | # i18n: "subrepo" is a keyword | |
1767 | args = getargs(x, 0, 1, _('subrepo takes at most one argument')) |
|
1770 | args = getargs(x, 0, 1, _('subrepo takes at most one argument')) | |
1768 | if len(args) != 0: |
|
1771 | if len(args) != 0: | |
1769 | pat = getstring(args[0], _("subrepo requires a pattern")) |
|
1772 | pat = getstring(args[0], _("subrepo requires a pattern")) | |
1770 |
|
1773 | |||
1771 | m = matchmod.exact(repo.root, repo.root, ['.hgsubstate']) |
|
1774 | m = matchmod.exact(repo.root, repo.root, ['.hgsubstate']) | |
1772 |
|
1775 | |||
1773 | def submatches(names): |
|
1776 | def submatches(names): | |
1774 | k, p, m = _stringmatcher(pat) |
|
1777 | k, p, m = _stringmatcher(pat) | |
1775 | for name in names: |
|
1778 | for name in names: | |
1776 | if m(name): |
|
1779 | if m(name): | |
1777 | yield name |
|
1780 | yield name | |
1778 |
|
1781 | |||
1779 | def matches(x): |
|
1782 | def matches(x): | |
1780 | c = repo[x] |
|
1783 | c = repo[x] | |
1781 | s = repo.status(c.p1().node(), c.node(), match=m) |
|
1784 | s = repo.status(c.p1().node(), c.node(), match=m) | |
1782 |
|
1785 | |||
1783 | if len(args) == 0: |
|
1786 | if len(args) == 0: | |
1784 | return s.added or s.modified or s.removed |
|
1787 | return s.added or s.modified or s.removed | |
1785 |
|
1788 | |||
1786 | if s.added: |
|
1789 | if s.added: | |
1787 | return util.any(submatches(c.substate.keys())) |
|
1790 | return util.any(submatches(c.substate.keys())) | |
1788 |
|
1791 | |||
1789 | if s.modified: |
|
1792 | if s.modified: | |
1790 | subs = set(c.p1().substate.keys()) |
|
1793 | subs = set(c.p1().substate.keys()) | |
1791 | subs.update(c.substate.keys()) |
|
1794 | subs.update(c.substate.keys()) | |
1792 |
|
1795 | |||
1793 | for path in submatches(subs): |
|
1796 | for path in submatches(subs): | |
1794 | if c.p1().substate.get(path) != c.substate.get(path): |
|
1797 | if c.p1().substate.get(path) != c.substate.get(path): | |
1795 | return True |
|
1798 | return True | |
1796 |
|
1799 | |||
1797 | if s.removed: |
|
1800 | if s.removed: | |
1798 | return util.any(submatches(c.p1().substate.keys())) |
|
1801 | return util.any(submatches(c.p1().substate.keys())) | |
1799 |
|
1802 | |||
1800 | return False |
|
1803 | return False | |
1801 |
|
1804 | |||
1802 | return subset.filter(matches) |
|
1805 | return subset.filter(matches) | |
1803 |
|
1806 | |||
1804 | def _stringmatcher(pattern): |
|
1807 | def _stringmatcher(pattern): | |
1805 | """ |
|
1808 | """ | |
1806 | accepts a string, possibly starting with 're:' or 'literal:' prefix. |
|
1809 | accepts a string, possibly starting with 're:' or 'literal:' prefix. | |
1807 | returns the matcher name, pattern, and matcher function. |
|
1810 | returns the matcher name, pattern, and matcher function. | |
1808 | missing or unknown prefixes are treated as literal matches. |
|
1811 | missing or unknown prefixes are treated as literal matches. | |
1809 |
|
1812 | |||
1810 | helper for tests: |
|
1813 | helper for tests: | |
1811 | >>> def test(pattern, *tests): |
|
1814 | >>> def test(pattern, *tests): | |
1812 | ... kind, pattern, matcher = _stringmatcher(pattern) |
|
1815 | ... kind, pattern, matcher = _stringmatcher(pattern) | |
1813 | ... return (kind, pattern, [bool(matcher(t)) for t in tests]) |
|
1816 | ... return (kind, pattern, [bool(matcher(t)) for t in tests]) | |
1814 |
|
1817 | |||
1815 | exact matching (no prefix): |
|
1818 | exact matching (no prefix): | |
1816 | >>> test('abcdefg', 'abc', 'def', 'abcdefg') |
|
1819 | >>> test('abcdefg', 'abc', 'def', 'abcdefg') | |
1817 | ('literal', 'abcdefg', [False, False, True]) |
|
1820 | ('literal', 'abcdefg', [False, False, True]) | |
1818 |
|
1821 | |||
1819 | regex matching ('re:' prefix) |
|
1822 | regex matching ('re:' prefix) | |
1820 | >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar') |
|
1823 | >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar') | |
1821 | ('re', 'a.+b', [False, False, True]) |
|
1824 | ('re', 'a.+b', [False, False, True]) | |
1822 |
|
1825 | |||
1823 | force exact matches ('literal:' prefix) |
|
1826 | force exact matches ('literal:' prefix) | |
1824 | >>> test('literal:re:foobar', 'foobar', 're:foobar') |
|
1827 | >>> test('literal:re:foobar', 'foobar', 're:foobar') | |
1825 | ('literal', 're:foobar', [False, True]) |
|
1828 | ('literal', 're:foobar', [False, True]) | |
1826 |
|
1829 | |||
1827 | unknown prefixes are ignored and treated as literals |
|
1830 | unknown prefixes are ignored and treated as literals | |
1828 | >>> test('foo:bar', 'foo', 'bar', 'foo:bar') |
|
1831 | >>> test('foo:bar', 'foo', 'bar', 'foo:bar') | |
1829 | ('literal', 'foo:bar', [False, False, True]) |
|
1832 | ('literal', 'foo:bar', [False, False, True]) | |
1830 | """ |
|
1833 | """ | |
1831 | if pattern.startswith('re:'): |
|
1834 | if pattern.startswith('re:'): | |
1832 | pattern = pattern[3:] |
|
1835 | pattern = pattern[3:] | |
1833 | try: |
|
1836 | try: | |
1834 | regex = re.compile(pattern) |
|
1837 | regex = re.compile(pattern) | |
1835 | except re.error, e: |
|
1838 | except re.error, e: | |
1836 | raise error.ParseError(_('invalid regular expression: %s') |
|
1839 | raise error.ParseError(_('invalid regular expression: %s') | |
1837 | % e) |
|
1840 | % e) | |
1838 | return 're', pattern, regex.search |
|
1841 | return 're', pattern, regex.search | |
1839 | elif pattern.startswith('literal:'): |
|
1842 | elif pattern.startswith('literal:'): | |
1840 | pattern = pattern[8:] |
|
1843 | pattern = pattern[8:] | |
1841 | return 'literal', pattern, pattern.__eq__ |
|
1844 | return 'literal', pattern, pattern.__eq__ | |
1842 |
|
1845 | |||
1843 | def _substringmatcher(pattern): |
|
1846 | def _substringmatcher(pattern): | |
1844 | kind, pattern, matcher = _stringmatcher(pattern) |
|
1847 | kind, pattern, matcher = _stringmatcher(pattern) | |
1845 | if kind == 'literal': |
|
1848 | if kind == 'literal': | |
1846 | matcher = lambda s: pattern in s |
|
1849 | matcher = lambda s: pattern in s | |
1847 | return kind, pattern, matcher |
|
1850 | return kind, pattern, matcher | |
1848 |
|
1851 | |||
1849 | def tag(repo, subset, x): |
|
1852 | def tag(repo, subset, x): | |
1850 | """``tag([name])`` |
|
1853 | """``tag([name])`` | |
1851 | The specified tag by name, or all tagged revisions if no name is given. |
|
1854 | The specified tag by name, or all tagged revisions if no name is given. | |
1852 |
|
1855 | |||
1853 | If `name` starts with `re:`, the remainder of the name is treated as |
|
1856 | If `name` starts with `re:`, the remainder of the name is treated as | |
1854 | a regular expression. To match a tag that actually starts with `re:`, |
|
1857 | a regular expression. To match a tag that actually starts with `re:`, | |
1855 | use the prefix `literal:`. |
|
1858 | use the prefix `literal:`. | |
1856 | """ |
|
1859 | """ | |
1857 | # i18n: "tag" is a keyword |
|
1860 | # i18n: "tag" is a keyword | |
1858 | args = getargs(x, 0, 1, _("tag takes one or no arguments")) |
|
1861 | args = getargs(x, 0, 1, _("tag takes one or no arguments")) | |
1859 | cl = repo.changelog |
|
1862 | cl = repo.changelog | |
1860 | if args: |
|
1863 | if args: | |
1861 | pattern = getstring(args[0], |
|
1864 | pattern = getstring(args[0], | |
1862 | # i18n: "tag" is a keyword |
|
1865 | # i18n: "tag" is a keyword | |
1863 | _('the argument to tag must be a string')) |
|
1866 | _('the argument to tag must be a string')) | |
1864 | kind, pattern, matcher = _stringmatcher(pattern) |
|
1867 | kind, pattern, matcher = _stringmatcher(pattern) | |
1865 | if kind == 'literal': |
|
1868 | if kind == 'literal': | |
1866 | # avoid resolving all tags |
|
1869 | # avoid resolving all tags | |
1867 | tn = repo._tagscache.tags.get(pattern, None) |
|
1870 | tn = repo._tagscache.tags.get(pattern, None) | |
1868 | if tn is None: |
|
1871 | if tn is None: | |
1869 | raise error.RepoLookupError(_("tag '%s' does not exist") |
|
1872 | raise error.RepoLookupError(_("tag '%s' does not exist") | |
1870 | % pattern) |
|
1873 | % pattern) | |
1871 | s = set([repo[tn].rev()]) |
|
1874 | s = set([repo[tn].rev()]) | |
1872 | else: |
|
1875 | else: | |
1873 | s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)]) |
|
1876 | s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)]) | |
1874 | else: |
|
1877 | else: | |
1875 | s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) |
|
1878 | s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) | |
1876 | return subset & s |
|
1879 | return subset & s | |
1877 |
|
1880 | |||
1878 | def tagged(repo, subset, x): |
|
1881 | def tagged(repo, subset, x): | |
1879 | return tag(repo, subset, x) |
|
1882 | return tag(repo, subset, x) | |
1880 |
|
1883 | |||
1881 | def unstable(repo, subset, x): |
|
1884 | def unstable(repo, subset, x): | |
1882 | """``unstable()`` |
|
1885 | """``unstable()`` | |
1883 | Non-obsolete changesets with obsolete ancestors. |
|
1886 | Non-obsolete changesets with obsolete ancestors. | |
1884 | """ |
|
1887 | """ | |
1885 | # i18n: "unstable" is a keyword |
|
1888 | # i18n: "unstable" is a keyword | |
1886 | getargs(x, 0, 0, _("unstable takes no arguments")) |
|
1889 | getargs(x, 0, 0, _("unstable takes no arguments")) | |
1887 | unstables = obsmod.getrevs(repo, 'unstable') |
|
1890 | unstables = obsmod.getrevs(repo, 'unstable') | |
1888 | return subset & unstables |
|
1891 | return subset & unstables | |
1889 |
|
1892 | |||
1890 |
|
1893 | |||
1891 | def user(repo, subset, x): |
|
1894 | def user(repo, subset, x): | |
1892 | """``user(string)`` |
|
1895 | """``user(string)`` | |
1893 | User name contains string. The match is case-insensitive. |
|
1896 | User name contains string. The match is case-insensitive. | |
1894 |
|
1897 | |||
1895 | If `string` starts with `re:`, the remainder of the string is treated as |
|
1898 | If `string` starts with `re:`, the remainder of the string is treated as | |
1896 | a regular expression. To match a user that actually contains `re:`, use |
|
1899 | a regular expression. To match a user that actually contains `re:`, use | |
1897 | the prefix `literal:`. |
|
1900 | the prefix `literal:`. | |
1898 | """ |
|
1901 | """ | |
1899 | return author(repo, subset, x) |
|
1902 | return author(repo, subset, x) | |
1900 |
|
1903 | |||
1901 | # experimental |
|
1904 | # experimental | |
1902 | def wdir(repo, subset, x): |
|
1905 | def wdir(repo, subset, x): | |
1903 | # i18n: "wdir" is a keyword |
|
1906 | # i18n: "wdir" is a keyword | |
1904 | getargs(x, 0, 0, _("wdir takes no arguments")) |
|
1907 | getargs(x, 0, 0, _("wdir takes no arguments")) | |
1905 | if None in subset: |
|
1908 | if None in subset: | |
1906 | return baseset([None]) |
|
1909 | return baseset([None]) | |
1907 | return baseset() |
|
1910 | return baseset() | |
1908 |
|
1911 | |||
1909 | # for internal use |
|
1912 | # for internal use | |
1910 | def _list(repo, subset, x): |
|
1913 | def _list(repo, subset, x): | |
1911 | s = getstring(x, "internal error") |
|
1914 | s = getstring(x, "internal error") | |
1912 | if not s: |
|
1915 | if not s: | |
1913 | return baseset() |
|
1916 | return baseset() | |
1914 | ls = [repo[r].rev() for r in s.split('\0')] |
|
1917 | ls = [repo[r].rev() for r in s.split('\0')] | |
1915 | s = subset |
|
1918 | s = subset | |
1916 | return baseset([r for r in ls if r in s]) |
|
1919 | return baseset([r for r in ls if r in s]) | |
1917 |
|
1920 | |||
1918 | # for internal use |
|
1921 | # for internal use | |
1919 | def _intlist(repo, subset, x): |
|
1922 | def _intlist(repo, subset, x): | |
1920 | s = getstring(x, "internal error") |
|
1923 | s = getstring(x, "internal error") | |
1921 | if not s: |
|
1924 | if not s: | |
1922 | return baseset() |
|
1925 | return baseset() | |
1923 | ls = [int(r) for r in s.split('\0')] |
|
1926 | ls = [int(r) for r in s.split('\0')] | |
1924 | s = subset |
|
1927 | s = subset | |
1925 | return baseset([r for r in ls if r in s]) |
|
1928 | return baseset([r for r in ls if r in s]) | |
1926 |
|
1929 | |||
1927 | # for internal use |
|
1930 | # for internal use | |
1928 | def _hexlist(repo, subset, x): |
|
1931 | def _hexlist(repo, subset, x): | |
1929 | s = getstring(x, "internal error") |
|
1932 | s = getstring(x, "internal error") | |
1930 | if not s: |
|
1933 | if not s: | |
1931 | return baseset() |
|
1934 | return baseset() | |
1932 | cl = repo.changelog |
|
1935 | cl = repo.changelog | |
1933 | ls = [cl.rev(node.bin(r)) for r in s.split('\0')] |
|
1936 | ls = [cl.rev(node.bin(r)) for r in s.split('\0')] | |
1934 | s = subset |
|
1937 | s = subset | |
1935 | return baseset([r for r in ls if r in s]) |
|
1938 | return baseset([r for r in ls if r in s]) | |
1936 |
|
1939 | |||
1937 | symbols = { |
|
1940 | symbols = { | |
1938 | "adds": adds, |
|
1941 | "adds": adds, | |
1939 | "all": getall, |
|
1942 | "all": getall, | |
1940 | "ancestor": ancestor, |
|
1943 | "ancestor": ancestor, | |
1941 | "ancestors": ancestors, |
|
1944 | "ancestors": ancestors, | |
1942 | "_firstancestors": _firstancestors, |
|
1945 | "_firstancestors": _firstancestors, | |
1943 | "author": author, |
|
1946 | "author": author, | |
1944 | "bisect": bisect, |
|
1947 | "bisect": bisect, | |
1945 | "bisected": bisected, |
|
1948 | "bisected": bisected, | |
1946 | "bookmark": bookmark, |
|
1949 | "bookmark": bookmark, | |
1947 | "branch": branch, |
|
1950 | "branch": branch, | |
1948 | "branchpoint": branchpoint, |
|
1951 | "branchpoint": branchpoint, | |
1949 | "bumped": bumped, |
|
1952 | "bumped": bumped, | |
1950 | "bundle": bundle, |
|
1953 | "bundle": bundle, | |
1951 | "children": children, |
|
1954 | "children": children, | |
1952 | "closed": closed, |
|
1955 | "closed": closed, | |
1953 | "contains": contains, |
|
1956 | "contains": contains, | |
1954 | "converted": converted, |
|
1957 | "converted": converted, | |
1955 | "date": date, |
|
1958 | "date": date, | |
1956 | "desc": desc, |
|
1959 | "desc": desc, | |
1957 | "descendants": descendants, |
|
1960 | "descendants": descendants, | |
1958 | "_firstdescendants": _firstdescendants, |
|
1961 | "_firstdescendants": _firstdescendants, | |
1959 | "destination": destination, |
|
1962 | "destination": destination, | |
1960 | "divergent": divergent, |
|
1963 | "divergent": divergent, | |
1961 | "draft": draft, |
|
1964 | "draft": draft, | |
1962 | "extinct": extinct, |
|
1965 | "extinct": extinct, | |
1963 | "extra": extra, |
|
1966 | "extra": extra, | |
1964 | "file": hasfile, |
|
1967 | "file": hasfile, | |
1965 | "filelog": filelog, |
|
1968 | "filelog": filelog, | |
1966 | "first": first, |
|
1969 | "first": first, | |
1967 | "follow": follow, |
|
1970 | "follow": follow, | |
1968 | "_followfirst": _followfirst, |
|
1971 | "_followfirst": _followfirst, | |
1969 | "grep": grep, |
|
1972 | "grep": grep, | |
1970 | "head": head, |
|
1973 | "head": head, | |
1971 | "heads": heads, |
|
1974 | "heads": heads, | |
1972 | "hidden": hidden, |
|
1975 | "hidden": hidden, | |
1973 | "id": node_, |
|
1976 | "id": node_, | |
1974 | "keyword": keyword, |
|
1977 | "keyword": keyword, | |
1975 | "last": last, |
|
1978 | "last": last, | |
1976 | "limit": limit, |
|
1979 | "limit": limit, | |
1977 | "_matchfiles": _matchfiles, |
|
1980 | "_matchfiles": _matchfiles, | |
1978 | "max": maxrev, |
|
1981 | "max": maxrev, | |
1979 | "merge": merge, |
|
1982 | "merge": merge, | |
1980 | "min": minrev, |
|
1983 | "min": minrev, | |
1981 | "modifies": modifies, |
|
1984 | "modifies": modifies, | |
1982 | "named": named, |
|
1985 | "named": named, | |
1983 | "obsolete": obsolete, |
|
1986 | "obsolete": obsolete, | |
1984 | "only": only, |
|
1987 | "only": only, | |
1985 | "origin": origin, |
|
1988 | "origin": origin, | |
1986 | "outgoing": outgoing, |
|
1989 | "outgoing": outgoing, | |
1987 | "p1": p1, |
|
1990 | "p1": p1, | |
1988 | "p2": p2, |
|
1991 | "p2": p2, | |
1989 | "parents": parents, |
|
1992 | "parents": parents, | |
1990 | "present": present, |
|
1993 | "present": present, | |
1991 | "public": public, |
|
1994 | "public": public, | |
1992 | "remote": remote, |
|
1995 | "remote": remote, | |
1993 | "removes": removes, |
|
1996 | "removes": removes, | |
1994 | "rev": rev, |
|
1997 | "rev": rev, | |
1995 | "reverse": reverse, |
|
1998 | "reverse": reverse, | |
1996 | "roots": roots, |
|
1999 | "roots": roots, | |
1997 | "sort": sort, |
|
2000 | "sort": sort, | |
1998 | "secret": secret, |
|
2001 | "secret": secret, | |
1999 | "subrepo": subrepo, |
|
2002 | "subrepo": subrepo, | |
2000 | "matching": matching, |
|
2003 | "matching": matching, | |
2001 | "tag": tag, |
|
2004 | "tag": tag, | |
2002 | "tagged": tagged, |
|
2005 | "tagged": tagged, | |
2003 | "user": user, |
|
2006 | "user": user, | |
2004 | "unstable": unstable, |
|
2007 | "unstable": unstable, | |
2005 | "wdir": wdir, |
|
2008 | "wdir": wdir, | |
2006 | "_list": _list, |
|
2009 | "_list": _list, | |
2007 | "_intlist": _intlist, |
|
2010 | "_intlist": _intlist, | |
2008 | "_hexlist": _hexlist, |
|
2011 | "_hexlist": _hexlist, | |
2009 | } |
|
2012 | } | |
2010 |
|
2013 | |||
2011 | # symbols which can't be used for a DoS attack for any given input |
|
2014 | # symbols which can't be used for a DoS attack for any given input | |
2012 | # (e.g. those which accept regexes as plain strings shouldn't be included) |
|
2015 | # (e.g. those which accept regexes as plain strings shouldn't be included) | |
2013 | # functions that just return a lot of changesets (like all) don't count here |
|
2016 | # functions that just return a lot of changesets (like all) don't count here | |
2014 | safesymbols = set([ |
|
2017 | safesymbols = set([ | |
2015 | "adds", |
|
2018 | "adds", | |
2016 | "all", |
|
2019 | "all", | |
2017 | "ancestor", |
|
2020 | "ancestor", | |
2018 | "ancestors", |
|
2021 | "ancestors", | |
2019 | "_firstancestors", |
|
2022 | "_firstancestors", | |
2020 | "author", |
|
2023 | "author", | |
2021 | "bisect", |
|
2024 | "bisect", | |
2022 | "bisected", |
|
2025 | "bisected", | |
2023 | "bookmark", |
|
2026 | "bookmark", | |
2024 | "branch", |
|
2027 | "branch", | |
2025 | "branchpoint", |
|
2028 | "branchpoint", | |
2026 | "bumped", |
|
2029 | "bumped", | |
2027 | "bundle", |
|
2030 | "bundle", | |
2028 | "children", |
|
2031 | "children", | |
2029 | "closed", |
|
2032 | "closed", | |
2030 | "converted", |
|
2033 | "converted", | |
2031 | "date", |
|
2034 | "date", | |
2032 | "desc", |
|
2035 | "desc", | |
2033 | "descendants", |
|
2036 | "descendants", | |
2034 | "_firstdescendants", |
|
2037 | "_firstdescendants", | |
2035 | "destination", |
|
2038 | "destination", | |
2036 | "divergent", |
|
2039 | "divergent", | |
2037 | "draft", |
|
2040 | "draft", | |
2038 | "extinct", |
|
2041 | "extinct", | |
2039 | "extra", |
|
2042 | "extra", | |
2040 | "file", |
|
2043 | "file", | |
2041 | "filelog", |
|
2044 | "filelog", | |
2042 | "first", |
|
2045 | "first", | |
2043 | "follow", |
|
2046 | "follow", | |
2044 | "_followfirst", |
|
2047 | "_followfirst", | |
2045 | "head", |
|
2048 | "head", | |
2046 | "heads", |
|
2049 | "heads", | |
2047 | "hidden", |
|
2050 | "hidden", | |
2048 | "id", |
|
2051 | "id", | |
2049 | "keyword", |
|
2052 | "keyword", | |
2050 | "last", |
|
2053 | "last", | |
2051 | "limit", |
|
2054 | "limit", | |
2052 | "_matchfiles", |
|
2055 | "_matchfiles", | |
2053 | "max", |
|
2056 | "max", | |
2054 | "merge", |
|
2057 | "merge", | |
2055 | "min", |
|
2058 | "min", | |
2056 | "modifies", |
|
2059 | "modifies", | |
2057 | "obsolete", |
|
2060 | "obsolete", | |
2058 | "only", |
|
2061 | "only", | |
2059 | "origin", |
|
2062 | "origin", | |
2060 | "outgoing", |
|
2063 | "outgoing", | |
2061 | "p1", |
|
2064 | "p1", | |
2062 | "p2", |
|
2065 | "p2", | |
2063 | "parents", |
|
2066 | "parents", | |
2064 | "present", |
|
2067 | "present", | |
2065 | "public", |
|
2068 | "public", | |
2066 | "remote", |
|
2069 | "remote", | |
2067 | "removes", |
|
2070 | "removes", | |
2068 | "rev", |
|
2071 | "rev", | |
2069 | "reverse", |
|
2072 | "reverse", | |
2070 | "roots", |
|
2073 | "roots", | |
2071 | "sort", |
|
2074 | "sort", | |
2072 | "secret", |
|
2075 | "secret", | |
2073 | "matching", |
|
2076 | "matching", | |
2074 | "tag", |
|
2077 | "tag", | |
2075 | "tagged", |
|
2078 | "tagged", | |
2076 | "user", |
|
2079 | "user", | |
2077 | "unstable", |
|
2080 | "unstable", | |
2078 | "wdir", |
|
2081 | "wdir", | |
2079 | "_list", |
|
2082 | "_list", | |
2080 | "_intlist", |
|
2083 | "_intlist", | |
2081 | "_hexlist", |
|
2084 | "_hexlist", | |
2082 | ]) |
|
2085 | ]) | |
2083 |
|
2086 | |||
2084 | methods = { |
|
2087 | methods = { | |
2085 | "range": rangeset, |
|
2088 | "range": rangeset, | |
2086 | "dagrange": dagrange, |
|
2089 | "dagrange": dagrange, | |
2087 | "string": stringset, |
|
2090 | "string": stringset, | |
2088 | "symbol": symbolset, |
|
2091 | "symbol": symbolset, | |
2089 | "and": andset, |
|
2092 | "and": andset, | |
2090 | "or": orset, |
|
2093 | "or": orset, | |
2091 | "not": notset, |
|
2094 | "not": notset, | |
2092 | "list": listset, |
|
2095 | "list": listset, | |
2093 | "func": func, |
|
2096 | "func": func, | |
2094 | "ancestor": ancestorspec, |
|
2097 | "ancestor": ancestorspec, | |
2095 | "parent": parentspec, |
|
2098 | "parent": parentspec, | |
2096 | "parentpost": p1, |
|
2099 | "parentpost": p1, | |
2097 | "only": only, |
|
2100 | "only": only, | |
2098 | "onlypost": only, |
|
2101 | "onlypost": only, | |
2099 | } |
|
2102 | } | |
2100 |
|
2103 | |||
2101 | def optimize(x, small): |
|
2104 | def optimize(x, small): | |
2102 | if x is None: |
|
2105 | if x is None: | |
2103 | return 0, x |
|
2106 | return 0, x | |
2104 |
|
2107 | |||
2105 | smallbonus = 1 |
|
2108 | smallbonus = 1 | |
2106 | if small: |
|
2109 | if small: | |
2107 | smallbonus = .5 |
|
2110 | smallbonus = .5 | |
2108 |
|
2111 | |||
2109 | op = x[0] |
|
2112 | op = x[0] | |
2110 | if op == 'minus': |
|
2113 | if op == 'minus': | |
2111 | return optimize(('and', x[1], ('not', x[2])), small) |
|
2114 | return optimize(('and', x[1], ('not', x[2])), small) | |
2112 | elif op == 'only': |
|
2115 | elif op == 'only': | |
2113 | return optimize(('func', ('symbol', 'only'), |
|
2116 | return optimize(('func', ('symbol', 'only'), | |
2114 | ('list', x[1], x[2])), small) |
|
2117 | ('list', x[1], x[2])), small) | |
2115 | elif op == 'dagrangepre': |
|
2118 | elif op == 'dagrangepre': | |
2116 | return optimize(('func', ('symbol', 'ancestors'), x[1]), small) |
|
2119 | return optimize(('func', ('symbol', 'ancestors'), x[1]), small) | |
2117 | elif op == 'dagrangepost': |
|
2120 | elif op == 'dagrangepost': | |
2118 | return optimize(('func', ('symbol', 'descendants'), x[1]), small) |
|
2121 | return optimize(('func', ('symbol', 'descendants'), x[1]), small) | |
2119 | elif op == 'rangepre': |
|
2122 | elif op == 'rangepre': | |
2120 | return optimize(('range', ('string', '0'), x[1]), small) |
|
2123 | return optimize(('range', ('string', '0'), x[1]), small) | |
2121 | elif op == 'rangepost': |
|
2124 | elif op == 'rangepost': | |
2122 | return optimize(('range', x[1], ('string', 'tip')), small) |
|
2125 | return optimize(('range', x[1], ('string', 'tip')), small) | |
2123 | elif op == 'negate': |
|
2126 | elif op == 'negate': | |
2124 | return optimize(('string', |
|
2127 | return optimize(('string', | |
2125 | '-' + getstring(x[1], _("can't negate that"))), small) |
|
2128 | '-' + getstring(x[1], _("can't negate that"))), small) | |
2126 | elif op in 'string symbol negate': |
|
2129 | elif op in 'string symbol negate': | |
2127 | return smallbonus, x # single revisions are small |
|
2130 | return smallbonus, x # single revisions are small | |
2128 | elif op == 'and': |
|
2131 | elif op == 'and': | |
2129 | wa, ta = optimize(x[1], True) |
|
2132 | wa, ta = optimize(x[1], True) | |
2130 | wb, tb = optimize(x[2], True) |
|
2133 | wb, tb = optimize(x[2], True) | |
2131 |
|
2134 | |||
2132 | # (::x and not ::y)/(not ::y and ::x) have a fast path |
|
2135 | # (::x and not ::y)/(not ::y and ::x) have a fast path | |
2133 | def isonly(revs, bases): |
|
2136 | def isonly(revs, bases): | |
2134 | return ( |
|
2137 | return ( | |
2135 | revs[0] == 'func' |
|
2138 | revs[0] == 'func' | |
2136 | and getstring(revs[1], _('not a symbol')) == 'ancestors' |
|
2139 | and getstring(revs[1], _('not a symbol')) == 'ancestors' | |
2137 | and bases[0] == 'not' |
|
2140 | and bases[0] == 'not' | |
2138 | and bases[1][0] == 'func' |
|
2141 | and bases[1][0] == 'func' | |
2139 | and getstring(bases[1][1], _('not a symbol')) == 'ancestors') |
|
2142 | and getstring(bases[1][1], _('not a symbol')) == 'ancestors') | |
2140 |
|
2143 | |||
2141 | w = min(wa, wb) |
|
2144 | w = min(wa, wb) | |
2142 | if isonly(ta, tb): |
|
2145 | if isonly(ta, tb): | |
2143 | return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2])) |
|
2146 | return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2])) | |
2144 | if isonly(tb, ta): |
|
2147 | if isonly(tb, ta): | |
2145 | return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2])) |
|
2148 | return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2])) | |
2146 |
|
2149 | |||
2147 | if wa > wb: |
|
2150 | if wa > wb: | |
2148 | return w, (op, tb, ta) |
|
2151 | return w, (op, tb, ta) | |
2149 | return w, (op, ta, tb) |
|
2152 | return w, (op, ta, tb) | |
2150 | elif op == 'or': |
|
2153 | elif op == 'or': | |
2151 | wa, ta = optimize(x[1], False) |
|
2154 | wa, ta = optimize(x[1], False) | |
2152 | wb, tb = optimize(x[2], False) |
|
2155 | wb, tb = optimize(x[2], False) | |
2153 | if wb < wa: |
|
2156 | if wb < wa: | |
2154 | wb, wa = wa, wb |
|
2157 | wb, wa = wa, wb | |
2155 | return max(wa, wb), (op, ta, tb) |
|
2158 | return max(wa, wb), (op, ta, tb) | |
2156 | elif op == 'not': |
|
2159 | elif op == 'not': | |
2157 | o = optimize(x[1], not small) |
|
2160 | o = optimize(x[1], not small) | |
2158 | return o[0], (op, o[1]) |
|
2161 | return o[0], (op, o[1]) | |
2159 | elif op == 'parentpost': |
|
2162 | elif op == 'parentpost': | |
2160 | o = optimize(x[1], small) |
|
2163 | o = optimize(x[1], small) | |
2161 | return o[0], (op, o[1]) |
|
2164 | return o[0], (op, o[1]) | |
2162 | elif op == 'group': |
|
2165 | elif op == 'group': | |
2163 | return optimize(x[1], small) |
|
2166 | return optimize(x[1], small) | |
2164 | elif op in 'dagrange range list parent ancestorspec': |
|
2167 | elif op in 'dagrange range list parent ancestorspec': | |
2165 | if op == 'parent': |
|
2168 | if op == 'parent': | |
2166 | # x^:y means (x^) : y, not x ^ (:y) |
|
2169 | # x^:y means (x^) : y, not x ^ (:y) | |
2167 | post = ('parentpost', x[1]) |
|
2170 | post = ('parentpost', x[1]) | |
2168 | if x[2][0] == 'dagrangepre': |
|
2171 | if x[2][0] == 'dagrangepre': | |
2169 | return optimize(('dagrange', post, x[2][1]), small) |
|
2172 | return optimize(('dagrange', post, x[2][1]), small) | |
2170 | elif x[2][0] == 'rangepre': |
|
2173 | elif x[2][0] == 'rangepre': | |
2171 | return optimize(('range', post, x[2][1]), small) |
|
2174 | return optimize(('range', post, x[2][1]), small) | |
2172 |
|
2175 | |||
2173 | wa, ta = optimize(x[1], small) |
|
2176 | wa, ta = optimize(x[1], small) | |
2174 | wb, tb = optimize(x[2], small) |
|
2177 | wb, tb = optimize(x[2], small) | |
2175 | return wa + wb, (op, ta, tb) |
|
2178 | return wa + wb, (op, ta, tb) | |
2176 | elif op == 'func': |
|
2179 | elif op == 'func': | |
2177 | f = getstring(x[1], _("not a symbol")) |
|
2180 | f = getstring(x[1], _("not a symbol")) | |
2178 | wa, ta = optimize(x[2], small) |
|
2181 | wa, ta = optimize(x[2], small) | |
2179 | if f in ("author branch closed date desc file grep keyword " |
|
2182 | if f in ("author branch closed date desc file grep keyword " | |
2180 | "outgoing user"): |
|
2183 | "outgoing user"): | |
2181 | w = 10 # slow |
|
2184 | w = 10 # slow | |
2182 | elif f in "modifies adds removes": |
|
2185 | elif f in "modifies adds removes": | |
2183 | w = 30 # slower |
|
2186 | w = 30 # slower | |
2184 | elif f == "contains": |
|
2187 | elif f == "contains": | |
2185 | w = 100 # very slow |
|
2188 | w = 100 # very slow | |
2186 | elif f == "ancestor": |
|
2189 | elif f == "ancestor": | |
2187 | w = 1 * smallbonus |
|
2190 | w = 1 * smallbonus | |
2188 | elif f in "reverse limit first _intlist": |
|
2191 | elif f in "reverse limit first _intlist": | |
2189 | w = 0 |
|
2192 | w = 0 | |
2190 | elif f in "sort": |
|
2193 | elif f in "sort": | |
2191 | w = 10 # assume most sorts look at changelog |
|
2194 | w = 10 # assume most sorts look at changelog | |
2192 | else: |
|
2195 | else: | |
2193 | w = 1 |
|
2196 | w = 1 | |
2194 | return w + wa, (op, x[1], ta) |
|
2197 | return w + wa, (op, x[1], ta) | |
2195 | return 1, x |
|
2198 | return 1, x | |
2196 |
|
2199 | |||
2197 | _aliasarg = ('func', ('symbol', '_aliasarg')) |
|
2200 | _aliasarg = ('func', ('symbol', '_aliasarg')) | |
2198 | def _getaliasarg(tree): |
|
2201 | def _getaliasarg(tree): | |
2199 | """If tree matches ('func', ('symbol', '_aliasarg'), ('string', X)) |
|
2202 | """If tree matches ('func', ('symbol', '_aliasarg'), ('string', X)) | |
2200 | return X, None otherwise. |
|
2203 | return X, None otherwise. | |
2201 | """ |
|
2204 | """ | |
2202 | if (len(tree) == 3 and tree[:2] == _aliasarg |
|
2205 | if (len(tree) == 3 and tree[:2] == _aliasarg | |
2203 | and tree[2][0] == 'string'): |
|
2206 | and tree[2][0] == 'string'): | |
2204 | return tree[2][1] |
|
2207 | return tree[2][1] | |
2205 | return None |
|
2208 | return None | |
2206 |
|
2209 | |||
2207 | def _checkaliasarg(tree, known=None): |
|
2210 | def _checkaliasarg(tree, known=None): | |
2208 | """Check tree contains no _aliasarg construct or only ones which |
|
2211 | """Check tree contains no _aliasarg construct or only ones which | |
2209 | value is in known. Used to avoid alias placeholders injection. |
|
2212 | value is in known. Used to avoid alias placeholders injection. | |
2210 | """ |
|
2213 | """ | |
2211 | if isinstance(tree, tuple): |
|
2214 | if isinstance(tree, tuple): | |
2212 | arg = _getaliasarg(tree) |
|
2215 | arg = _getaliasarg(tree) | |
2213 | if arg is not None and (not known or arg not in known): |
|
2216 | if arg is not None and (not known or arg not in known): | |
2214 | raise error.UnknownIdentifier('_aliasarg', []) |
|
2217 | raise error.UnknownIdentifier('_aliasarg', []) | |
2215 | for t in tree: |
|
2218 | for t in tree: | |
2216 | _checkaliasarg(t, known) |
|
2219 | _checkaliasarg(t, known) | |
2217 |
|
2220 | |||
2218 | # the set of valid characters for the initial letter of symbols in |
|
2221 | # the set of valid characters for the initial letter of symbols in | |
2219 | # alias declarations and definitions |
|
2222 | # alias declarations and definitions | |
2220 | _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)] |
|
2223 | _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)] | |
2221 | if c.isalnum() or c in '._@$' or ord(c) > 127) |
|
2224 | if c.isalnum() or c in '._@$' or ord(c) > 127) | |
2222 |
|
2225 | |||
2223 | def _tokenizealias(program, lookup=None): |
|
2226 | def _tokenizealias(program, lookup=None): | |
2224 | """Parse alias declaration/definition into a stream of tokens |
|
2227 | """Parse alias declaration/definition into a stream of tokens | |
2225 |
|
2228 | |||
2226 | This allows symbol names to use also ``$`` as an initial letter |
|
2229 | This allows symbol names to use also ``$`` as an initial letter | |
2227 | (for backward compatibility), and callers of this function should |
|
2230 | (for backward compatibility), and callers of this function should | |
2228 | examine whether ``$`` is used also for unexpected symbols or not. |
|
2231 | examine whether ``$`` is used also for unexpected symbols or not. | |
2229 | """ |
|
2232 | """ | |
2230 | return tokenize(program, lookup=lookup, |
|
2233 | return tokenize(program, lookup=lookup, | |
2231 | syminitletters=_aliassyminitletters) |
|
2234 | syminitletters=_aliassyminitletters) | |
2232 |
|
2235 | |||
2233 | def _parsealiasdecl(decl): |
|
2236 | def _parsealiasdecl(decl): | |
2234 | """Parse alias declaration ``decl`` |
|
2237 | """Parse alias declaration ``decl`` | |
2235 |
|
2238 | |||
2236 | This returns ``(name, tree, args, errorstr)`` tuple: |
|
2239 | This returns ``(name, tree, args, errorstr)`` tuple: | |
2237 |
|
2240 | |||
2238 | - ``name``: of declared alias (may be ``decl`` itself at error) |
|
2241 | - ``name``: of declared alias (may be ``decl`` itself at error) | |
2239 | - ``tree``: parse result (or ``None`` at error) |
|
2242 | - ``tree``: parse result (or ``None`` at error) | |
2240 | - ``args``: list of alias argument names (or None for symbol declaration) |
|
2243 | - ``args``: list of alias argument names (or None for symbol declaration) | |
2241 | - ``errorstr``: detail about detected error (or None) |
|
2244 | - ``errorstr``: detail about detected error (or None) | |
2242 |
|
2245 | |||
2243 | >>> _parsealiasdecl('foo') |
|
2246 | >>> _parsealiasdecl('foo') | |
2244 | ('foo', ('symbol', 'foo'), None, None) |
|
2247 | ('foo', ('symbol', 'foo'), None, None) | |
2245 | >>> _parsealiasdecl('$foo') |
|
2248 | >>> _parsealiasdecl('$foo') | |
2246 | ('$foo', None, None, "'$' not for alias arguments") |
|
2249 | ('$foo', None, None, "'$' not for alias arguments") | |
2247 | >>> _parsealiasdecl('foo::bar') |
|
2250 | >>> _parsealiasdecl('foo::bar') | |
2248 | ('foo::bar', None, None, 'invalid format') |
|
2251 | ('foo::bar', None, None, 'invalid format') | |
2249 | >>> _parsealiasdecl('foo bar') |
|
2252 | >>> _parsealiasdecl('foo bar') | |
2250 | ('foo bar', None, None, 'at 4: invalid token') |
|
2253 | ('foo bar', None, None, 'at 4: invalid token') | |
2251 | >>> _parsealiasdecl('foo()') |
|
2254 | >>> _parsealiasdecl('foo()') | |
2252 | ('foo', ('func', ('symbol', 'foo')), [], None) |
|
2255 | ('foo', ('func', ('symbol', 'foo')), [], None) | |
2253 | >>> _parsealiasdecl('$foo()') |
|
2256 | >>> _parsealiasdecl('$foo()') | |
2254 | ('$foo()', None, None, "'$' not for alias arguments") |
|
2257 | ('$foo()', None, None, "'$' not for alias arguments") | |
2255 | >>> _parsealiasdecl('foo($1, $2)') |
|
2258 | >>> _parsealiasdecl('foo($1, $2)') | |
2256 | ('foo', ('func', ('symbol', 'foo')), ['$1', '$2'], None) |
|
2259 | ('foo', ('func', ('symbol', 'foo')), ['$1', '$2'], None) | |
2257 | >>> _parsealiasdecl('foo(bar_bar, baz.baz)') |
|
2260 | >>> _parsealiasdecl('foo(bar_bar, baz.baz)') | |
2258 | ('foo', ('func', ('symbol', 'foo')), ['bar_bar', 'baz.baz'], None) |
|
2261 | ('foo', ('func', ('symbol', 'foo')), ['bar_bar', 'baz.baz'], None) | |
2259 | >>> _parsealiasdecl('foo($1, $2, nested($1, $2))') |
|
2262 | >>> _parsealiasdecl('foo($1, $2, nested($1, $2))') | |
2260 | ('foo($1, $2, nested($1, $2))', None, None, 'invalid argument list') |
|
2263 | ('foo($1, $2, nested($1, $2))', None, None, 'invalid argument list') | |
2261 | >>> _parsealiasdecl('foo(bar($1, $2))') |
|
2264 | >>> _parsealiasdecl('foo(bar($1, $2))') | |
2262 | ('foo(bar($1, $2))', None, None, 'invalid argument list') |
|
2265 | ('foo(bar($1, $2))', None, None, 'invalid argument list') | |
2263 | >>> _parsealiasdecl('foo("string")') |
|
2266 | >>> _parsealiasdecl('foo("string")') | |
2264 | ('foo("string")', None, None, 'invalid argument list') |
|
2267 | ('foo("string")', None, None, 'invalid argument list') | |
2265 | >>> _parsealiasdecl('foo($1, $2') |
|
2268 | >>> _parsealiasdecl('foo($1, $2') | |
2266 | ('foo($1, $2', None, None, 'at 10: unexpected token: end') |
|
2269 | ('foo($1, $2', None, None, 'at 10: unexpected token: end') | |
2267 | >>> _parsealiasdecl('foo("string') |
|
2270 | >>> _parsealiasdecl('foo("string') | |
2268 | ('foo("string', None, None, 'at 5: unterminated string') |
|
2271 | ('foo("string', None, None, 'at 5: unterminated string') | |
2269 | >>> _parsealiasdecl('foo($1, $2, $1)') |
|
2272 | >>> _parsealiasdecl('foo($1, $2, $1)') | |
2270 | ('foo', None, None, 'argument names collide with each other') |
|
2273 | ('foo', None, None, 'argument names collide with each other') | |
2271 | """ |
|
2274 | """ | |
2272 | p = parser.parser(_tokenizealias, elements) |
|
2275 | p = parser.parser(_tokenizealias, elements) | |
2273 | try: |
|
2276 | try: | |
2274 | tree, pos = p.parse(decl) |
|
2277 | tree, pos = p.parse(decl) | |
2275 | if (pos != len(decl)): |
|
2278 | if (pos != len(decl)): | |
2276 | raise error.ParseError(_('invalid token'), pos) |
|
2279 | raise error.ParseError(_('invalid token'), pos) | |
2277 |
|
2280 | |||
2278 | if isvalidsymbol(tree): |
|
2281 | if isvalidsymbol(tree): | |
2279 | # "name = ...." style |
|
2282 | # "name = ...." style | |
2280 | name = getsymbol(tree) |
|
2283 | name = getsymbol(tree) | |
2281 | if name.startswith('$'): |
|
2284 | if name.startswith('$'): | |
2282 | return (decl, None, None, _("'$' not for alias arguments")) |
|
2285 | return (decl, None, None, _("'$' not for alias arguments")) | |
2283 | return (name, ('symbol', name), None, None) |
|
2286 | return (name, ('symbol', name), None, None) | |
2284 |
|
2287 | |||
2285 | if isvalidfunc(tree): |
|
2288 | if isvalidfunc(tree): | |
2286 | # "name(arg, ....) = ...." style |
|
2289 | # "name(arg, ....) = ...." style | |
2287 | name = getfuncname(tree) |
|
2290 | name = getfuncname(tree) | |
2288 | if name.startswith('$'): |
|
2291 | if name.startswith('$'): | |
2289 | return (decl, None, None, _("'$' not for alias arguments")) |
|
2292 | return (decl, None, None, _("'$' not for alias arguments")) | |
2290 | args = [] |
|
2293 | args = [] | |
2291 | for arg in getfuncargs(tree): |
|
2294 | for arg in getfuncargs(tree): | |
2292 | if not isvalidsymbol(arg): |
|
2295 | if not isvalidsymbol(arg): | |
2293 | return (decl, None, None, _("invalid argument list")) |
|
2296 | return (decl, None, None, _("invalid argument list")) | |
2294 | args.append(getsymbol(arg)) |
|
2297 | args.append(getsymbol(arg)) | |
2295 | if len(args) != len(set(args)): |
|
2298 | if len(args) != len(set(args)): | |
2296 | return (name, None, None, |
|
2299 | return (name, None, None, | |
2297 | _("argument names collide with each other")) |
|
2300 | _("argument names collide with each other")) | |
2298 | return (name, ('func', ('symbol', name)), args, None) |
|
2301 | return (name, ('func', ('symbol', name)), args, None) | |
2299 |
|
2302 | |||
2300 | return (decl, None, None, _("invalid format")) |
|
2303 | return (decl, None, None, _("invalid format")) | |
2301 | except error.ParseError, inst: |
|
2304 | except error.ParseError, inst: | |
2302 | return (decl, None, None, parseerrordetail(inst)) |
|
2305 | return (decl, None, None, parseerrordetail(inst)) | |
2303 |
|
2306 | |||
2304 | def _parsealiasdefn(defn, args): |
|
2307 | def _parsealiasdefn(defn, args): | |
2305 | """Parse alias definition ``defn`` |
|
2308 | """Parse alias definition ``defn`` | |
2306 |
|
2309 | |||
2307 | This function also replaces alias argument references in the |
|
2310 | This function also replaces alias argument references in the | |
2308 | specified definition by ``_aliasarg(ARGNAME)``. |
|
2311 | specified definition by ``_aliasarg(ARGNAME)``. | |
2309 |
|
2312 | |||
2310 | ``args`` is a list of alias argument names, or None if the alias |
|
2313 | ``args`` is a list of alias argument names, or None if the alias | |
2311 | is declared as a symbol. |
|
2314 | is declared as a symbol. | |
2312 |
|
2315 | |||
2313 | This returns "tree" as parsing result. |
|
2316 | This returns "tree" as parsing result. | |
2314 |
|
2317 | |||
2315 | >>> args = ['$1', '$2', 'foo'] |
|
2318 | >>> args = ['$1', '$2', 'foo'] | |
2316 | >>> print prettyformat(_parsealiasdefn('$1 or foo', args)) |
|
2319 | >>> print prettyformat(_parsealiasdefn('$1 or foo', args)) | |
2317 | (or |
|
2320 | (or | |
2318 | (func |
|
2321 | (func | |
2319 | ('symbol', '_aliasarg') |
|
2322 | ('symbol', '_aliasarg') | |
2320 | ('string', '$1')) |
|
2323 | ('string', '$1')) | |
2321 | (func |
|
2324 | (func | |
2322 | ('symbol', '_aliasarg') |
|
2325 | ('symbol', '_aliasarg') | |
2323 | ('string', 'foo'))) |
|
2326 | ('string', 'foo'))) | |
2324 | >>> try: |
|
2327 | >>> try: | |
2325 | ... _parsealiasdefn('$1 or $bar', args) |
|
2328 | ... _parsealiasdefn('$1 or $bar', args) | |
2326 | ... except error.ParseError, inst: |
|
2329 | ... except error.ParseError, inst: | |
2327 | ... print parseerrordetail(inst) |
|
2330 | ... print parseerrordetail(inst) | |
2328 | at 6: '$' not for alias arguments |
|
2331 | at 6: '$' not for alias arguments | |
2329 | >>> args = ['$1', '$10', 'foo'] |
|
2332 | >>> args = ['$1', '$10', 'foo'] | |
2330 | >>> print prettyformat(_parsealiasdefn('$10 or foobar', args)) |
|
2333 | >>> print prettyformat(_parsealiasdefn('$10 or foobar', args)) | |
2331 | (or |
|
2334 | (or | |
2332 | (func |
|
2335 | (func | |
2333 | ('symbol', '_aliasarg') |
|
2336 | ('symbol', '_aliasarg') | |
2334 | ('string', '$10')) |
|
2337 | ('string', '$10')) | |
2335 | ('symbol', 'foobar')) |
|
2338 | ('symbol', 'foobar')) | |
2336 | >>> print prettyformat(_parsealiasdefn('"$1" or "foo"', args)) |
|
2339 | >>> print prettyformat(_parsealiasdefn('"$1" or "foo"', args)) | |
2337 | (or |
|
2340 | (or | |
2338 | ('string', '$1') |
|
2341 | ('string', '$1') | |
2339 | ('string', 'foo')) |
|
2342 | ('string', 'foo')) | |
2340 | """ |
|
2343 | """ | |
2341 | def tokenizedefn(program, lookup=None): |
|
2344 | def tokenizedefn(program, lookup=None): | |
2342 | if args: |
|
2345 | if args: | |
2343 | argset = set(args) |
|
2346 | argset = set(args) | |
2344 | else: |
|
2347 | else: | |
2345 | argset = set() |
|
2348 | argset = set() | |
2346 |
|
2349 | |||
2347 | for t, value, pos in _tokenizealias(program, lookup=lookup): |
|
2350 | for t, value, pos in _tokenizealias(program, lookup=lookup): | |
2348 | if t == 'symbol': |
|
2351 | if t == 'symbol': | |
2349 | if value in argset: |
|
2352 | if value in argset: | |
2350 | # emulate tokenization of "_aliasarg('ARGNAME')": |
|
2353 | # emulate tokenization of "_aliasarg('ARGNAME')": | |
2351 | # "_aliasarg()" is an unknown symbol only used separate |
|
2354 | # "_aliasarg()" is an unknown symbol only used separate | |
2352 | # alias argument placeholders from regular strings. |
|
2355 | # alias argument placeholders from regular strings. | |
2353 | yield ('symbol', '_aliasarg', pos) |
|
2356 | yield ('symbol', '_aliasarg', pos) | |
2354 | yield ('(', None, pos) |
|
2357 | yield ('(', None, pos) | |
2355 | yield ('string', value, pos) |
|
2358 | yield ('string', value, pos) | |
2356 | yield (')', None, pos) |
|
2359 | yield (')', None, pos) | |
2357 | continue |
|
2360 | continue | |
2358 | elif value.startswith('$'): |
|
2361 | elif value.startswith('$'): | |
2359 | raise error.ParseError(_("'$' not for alias arguments"), |
|
2362 | raise error.ParseError(_("'$' not for alias arguments"), | |
2360 | pos) |
|
2363 | pos) | |
2361 | yield (t, value, pos) |
|
2364 | yield (t, value, pos) | |
2362 |
|
2365 | |||
2363 | p = parser.parser(tokenizedefn, elements) |
|
2366 | p = parser.parser(tokenizedefn, elements) | |
2364 | tree, pos = p.parse(defn) |
|
2367 | tree, pos = p.parse(defn) | |
2365 | if pos != len(defn): |
|
2368 | if pos != len(defn): | |
2366 | raise error.ParseError(_('invalid token'), pos) |
|
2369 | raise error.ParseError(_('invalid token'), pos) | |
2367 | return tree |
|
2370 | return tree | |
2368 |
|
2371 | |||
2369 | class revsetalias(object): |
|
2372 | class revsetalias(object): | |
2370 | # whether own `error` information is already shown or not. |
|
2373 | # whether own `error` information is already shown or not. | |
2371 | # this avoids showing same warning multiple times at each `findaliases`. |
|
2374 | # this avoids showing same warning multiple times at each `findaliases`. | |
2372 | warned = False |
|
2375 | warned = False | |
2373 |
|
2376 | |||
2374 | def __init__(self, name, value): |
|
2377 | def __init__(self, name, value): | |
2375 | '''Aliases like: |
|
2378 | '''Aliases like: | |
2376 |
|
2379 | |||
2377 | h = heads(default) |
|
2380 | h = heads(default) | |
2378 | b($1) = ancestors($1) - ancestors(default) |
|
2381 | b($1) = ancestors($1) - ancestors(default) | |
2379 | ''' |
|
2382 | ''' | |
2380 | self.name, self.tree, self.args, self.error = _parsealiasdecl(name) |
|
2383 | self.name, self.tree, self.args, self.error = _parsealiasdecl(name) | |
2381 | if self.error: |
|
2384 | if self.error: | |
2382 | self.error = _('failed to parse the declaration of revset alias' |
|
2385 | self.error = _('failed to parse the declaration of revset alias' | |
2383 | ' "%s": %s') % (self.name, self.error) |
|
2386 | ' "%s": %s') % (self.name, self.error) | |
2384 | return |
|
2387 | return | |
2385 |
|
2388 | |||
2386 | try: |
|
2389 | try: | |
2387 | self.replacement = _parsealiasdefn(value, self.args) |
|
2390 | self.replacement = _parsealiasdefn(value, self.args) | |
2388 | # Check for placeholder injection |
|
2391 | # Check for placeholder injection | |
2389 | _checkaliasarg(self.replacement, self.args) |
|
2392 | _checkaliasarg(self.replacement, self.args) | |
2390 | except error.ParseError, inst: |
|
2393 | except error.ParseError, inst: | |
2391 | self.error = _('failed to parse the definition of revset alias' |
|
2394 | self.error = _('failed to parse the definition of revset alias' | |
2392 | ' "%s": %s') % (self.name, parseerrordetail(inst)) |
|
2395 | ' "%s": %s') % (self.name, parseerrordetail(inst)) | |
2393 |
|
2396 | |||
2394 | def _getalias(aliases, tree): |
|
2397 | def _getalias(aliases, tree): | |
2395 | """If tree looks like an unexpanded alias, return it. Return None |
|
2398 | """If tree looks like an unexpanded alias, return it. Return None | |
2396 | otherwise. |
|
2399 | otherwise. | |
2397 | """ |
|
2400 | """ | |
2398 | if isinstance(tree, tuple) and tree: |
|
2401 | if isinstance(tree, tuple) and tree: | |
2399 | if tree[0] == 'symbol' and len(tree) == 2: |
|
2402 | if tree[0] == 'symbol' and len(tree) == 2: | |
2400 | name = tree[1] |
|
2403 | name = tree[1] | |
2401 | alias = aliases.get(name) |
|
2404 | alias = aliases.get(name) | |
2402 | if alias and alias.args is None and alias.tree == tree: |
|
2405 | if alias and alias.args is None and alias.tree == tree: | |
2403 | return alias |
|
2406 | return alias | |
2404 | if tree[0] == 'func' and len(tree) > 1: |
|
2407 | if tree[0] == 'func' and len(tree) > 1: | |
2405 | if tree[1][0] == 'symbol' and len(tree[1]) == 2: |
|
2408 | if tree[1][0] == 'symbol' and len(tree[1]) == 2: | |
2406 | name = tree[1][1] |
|
2409 | name = tree[1][1] | |
2407 | alias = aliases.get(name) |
|
2410 | alias = aliases.get(name) | |
2408 | if alias and alias.args is not None and alias.tree == tree[:2]: |
|
2411 | if alias and alias.args is not None and alias.tree == tree[:2]: | |
2409 | return alias |
|
2412 | return alias | |
2410 | return None |
|
2413 | return None | |
2411 |
|
2414 | |||
2412 | def _expandargs(tree, args): |
|
2415 | def _expandargs(tree, args): | |
2413 | """Replace _aliasarg instances with the substitution value of the |
|
2416 | """Replace _aliasarg instances with the substitution value of the | |
2414 | same name in args, recursively. |
|
2417 | same name in args, recursively. | |
2415 | """ |
|
2418 | """ | |
2416 | if not tree or not isinstance(tree, tuple): |
|
2419 | if not tree or not isinstance(tree, tuple): | |
2417 | return tree |
|
2420 | return tree | |
2418 | arg = _getaliasarg(tree) |
|
2421 | arg = _getaliasarg(tree) | |
2419 | if arg is not None: |
|
2422 | if arg is not None: | |
2420 | return args[arg] |
|
2423 | return args[arg] | |
2421 | return tuple(_expandargs(t, args) for t in tree) |
|
2424 | return tuple(_expandargs(t, args) for t in tree) | |
2422 |
|
2425 | |||
2423 | def _expandaliases(aliases, tree, expanding, cache): |
|
2426 | def _expandaliases(aliases, tree, expanding, cache): | |
2424 | """Expand aliases in tree, recursively. |
|
2427 | """Expand aliases in tree, recursively. | |
2425 |
|
2428 | |||
2426 | 'aliases' is a dictionary mapping user defined aliases to |
|
2429 | 'aliases' is a dictionary mapping user defined aliases to | |
2427 | revsetalias objects. |
|
2430 | revsetalias objects. | |
2428 | """ |
|
2431 | """ | |
2429 | if not isinstance(tree, tuple): |
|
2432 | if not isinstance(tree, tuple): | |
2430 | # Do not expand raw strings |
|
2433 | # Do not expand raw strings | |
2431 | return tree |
|
2434 | return tree | |
2432 | alias = _getalias(aliases, tree) |
|
2435 | alias = _getalias(aliases, tree) | |
2433 | if alias is not None: |
|
2436 | if alias is not None: | |
2434 | if alias.error: |
|
2437 | if alias.error: | |
2435 | raise util.Abort(alias.error) |
|
2438 | raise util.Abort(alias.error) | |
2436 | if alias in expanding: |
|
2439 | if alias in expanding: | |
2437 | raise error.ParseError(_('infinite expansion of revset alias "%s" ' |
|
2440 | raise error.ParseError(_('infinite expansion of revset alias "%s" ' | |
2438 | 'detected') % alias.name) |
|
2441 | 'detected') % alias.name) | |
2439 | expanding.append(alias) |
|
2442 | expanding.append(alias) | |
2440 | if alias.name not in cache: |
|
2443 | if alias.name not in cache: | |
2441 | cache[alias.name] = _expandaliases(aliases, alias.replacement, |
|
2444 | cache[alias.name] = _expandaliases(aliases, alias.replacement, | |
2442 | expanding, cache) |
|
2445 | expanding, cache) | |
2443 | result = cache[alias.name] |
|
2446 | result = cache[alias.name] | |
2444 | expanding.pop() |
|
2447 | expanding.pop() | |
2445 | if alias.args is not None: |
|
2448 | if alias.args is not None: | |
2446 | l = getlist(tree[2]) |
|
2449 | l = getlist(tree[2]) | |
2447 | if len(l) != len(alias.args): |
|
2450 | if len(l) != len(alias.args): | |
2448 | raise error.ParseError( |
|
2451 | raise error.ParseError( | |
2449 | _('invalid number of arguments: %s') % len(l)) |
|
2452 | _('invalid number of arguments: %s') % len(l)) | |
2450 | l = [_expandaliases(aliases, a, [], cache) for a in l] |
|
2453 | l = [_expandaliases(aliases, a, [], cache) for a in l] | |
2451 | result = _expandargs(result, dict(zip(alias.args, l))) |
|
2454 | result = _expandargs(result, dict(zip(alias.args, l))) | |
2452 | else: |
|
2455 | else: | |
2453 | result = tuple(_expandaliases(aliases, t, expanding, cache) |
|
2456 | result = tuple(_expandaliases(aliases, t, expanding, cache) | |
2454 | for t in tree) |
|
2457 | for t in tree) | |
2455 | return result |
|
2458 | return result | |
2456 |
|
2459 | |||
2457 | def findaliases(ui, tree, showwarning=None): |
|
2460 | def findaliases(ui, tree, showwarning=None): | |
2458 | _checkaliasarg(tree) |
|
2461 | _checkaliasarg(tree) | |
2459 | aliases = {} |
|
2462 | aliases = {} | |
2460 | for k, v in ui.configitems('revsetalias'): |
|
2463 | for k, v in ui.configitems('revsetalias'): | |
2461 | alias = revsetalias(k, v) |
|
2464 | alias = revsetalias(k, v) | |
2462 | aliases[alias.name] = alias |
|
2465 | aliases[alias.name] = alias | |
2463 | tree = _expandaliases(aliases, tree, [], {}) |
|
2466 | tree = _expandaliases(aliases, tree, [], {}) | |
2464 | if showwarning: |
|
2467 | if showwarning: | |
2465 | # warn about problematic (but not referred) aliases |
|
2468 | # warn about problematic (but not referred) aliases | |
2466 | for name, alias in sorted(aliases.iteritems()): |
|
2469 | for name, alias in sorted(aliases.iteritems()): | |
2467 | if alias.error and not alias.warned: |
|
2470 | if alias.error and not alias.warned: | |
2468 | showwarning(_('warning: %s\n') % (alias.error)) |
|
2471 | showwarning(_('warning: %s\n') % (alias.error)) | |
2469 | alias.warned = True |
|
2472 | alias.warned = True | |
2470 | return tree |
|
2473 | return tree | |
2471 |
|
2474 | |||
2472 | def foldconcat(tree): |
|
2475 | def foldconcat(tree): | |
2473 | """Fold elements to be concatenated by `##` |
|
2476 | """Fold elements to be concatenated by `##` | |
2474 | """ |
|
2477 | """ | |
2475 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): |
|
2478 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): | |
2476 | return tree |
|
2479 | return tree | |
2477 | if tree[0] == '_concat': |
|
2480 | if tree[0] == '_concat': | |
2478 | pending = [tree] |
|
2481 | pending = [tree] | |
2479 | l = [] |
|
2482 | l = [] | |
2480 | while pending: |
|
2483 | while pending: | |
2481 | e = pending.pop() |
|
2484 | e = pending.pop() | |
2482 | if e[0] == '_concat': |
|
2485 | if e[0] == '_concat': | |
2483 | pending.extend(reversed(e[1:])) |
|
2486 | pending.extend(reversed(e[1:])) | |
2484 | elif e[0] in ('string', 'symbol'): |
|
2487 | elif e[0] in ('string', 'symbol'): | |
2485 | l.append(e[1]) |
|
2488 | l.append(e[1]) | |
2486 | else: |
|
2489 | else: | |
2487 | msg = _("\"##\" can't concatenate \"%s\" element") % (e[0]) |
|
2490 | msg = _("\"##\" can't concatenate \"%s\" element") % (e[0]) | |
2488 | raise error.ParseError(msg) |
|
2491 | raise error.ParseError(msg) | |
2489 | return ('string', ''.join(l)) |
|
2492 | return ('string', ''.join(l)) | |
2490 | else: |
|
2493 | else: | |
2491 | return tuple(foldconcat(t) for t in tree) |
|
2494 | return tuple(foldconcat(t) for t in tree) | |
2492 |
|
2495 | |||
2493 | def parse(spec, lookup=None): |
|
2496 | def parse(spec, lookup=None): | |
2494 | p = parser.parser(tokenize, elements) |
|
2497 | p = parser.parser(tokenize, elements) | |
2495 | return p.parse(spec, lookup=lookup) |
|
2498 | return p.parse(spec, lookup=lookup) | |
2496 |
|
2499 | |||
2497 | def posttreebuilthook(tree, repo): |
|
2500 | def posttreebuilthook(tree, repo): | |
2498 | # hook for extensions to execute code on the optimized tree |
|
2501 | # hook for extensions to execute code on the optimized tree | |
2499 | pass |
|
2502 | pass | |
2500 |
|
2503 | |||
2501 | def match(ui, spec, repo=None): |
|
2504 | def match(ui, spec, repo=None): | |
2502 | if not spec: |
|
2505 | if not spec: | |
2503 | raise error.ParseError(_("empty query")) |
|
2506 | raise error.ParseError(_("empty query")) | |
2504 | lookup = None |
|
2507 | lookup = None | |
2505 | if repo: |
|
2508 | if repo: | |
2506 | lookup = repo.__contains__ |
|
2509 | lookup = repo.__contains__ | |
2507 | tree, pos = parse(spec, lookup) |
|
2510 | tree, pos = parse(spec, lookup) | |
2508 | if (pos != len(spec)): |
|
2511 | if (pos != len(spec)): | |
2509 | raise error.ParseError(_("invalid token"), pos) |
|
2512 | raise error.ParseError(_("invalid token"), pos) | |
2510 | if ui: |
|
2513 | if ui: | |
2511 | tree = findaliases(ui, tree, showwarning=ui.warn) |
|
2514 | tree = findaliases(ui, tree, showwarning=ui.warn) | |
2512 | tree = foldconcat(tree) |
|
2515 | tree = foldconcat(tree) | |
2513 | weight, tree = optimize(tree, True) |
|
2516 | weight, tree = optimize(tree, True) | |
2514 | posttreebuilthook(tree, repo) |
|
2517 | posttreebuilthook(tree, repo) | |
2515 | def mfunc(repo, subset=None): |
|
2518 | def mfunc(repo, subset=None): | |
2516 | if subset is None: |
|
2519 | if subset is None: | |
2517 | subset = fullreposet(repo) |
|
2520 | subset = fullreposet(repo) | |
2518 | if util.safehasattr(subset, 'isascending'): |
|
2521 | if util.safehasattr(subset, 'isascending'): | |
2519 | result = getset(repo, subset, tree) |
|
2522 | result = getset(repo, subset, tree) | |
2520 | else: |
|
2523 | else: | |
2521 | result = getset(repo, baseset(subset), tree) |
|
2524 | result = getset(repo, baseset(subset), tree) | |
2522 | return result |
|
2525 | return result | |
2523 | return mfunc |
|
2526 | return mfunc | |
2524 |
|
2527 | |||
2525 | def formatspec(expr, *args): |
|
2528 | def formatspec(expr, *args): | |
2526 | ''' |
|
2529 | ''' | |
2527 | This is a convenience function for using revsets internally, and |
|
2530 | This is a convenience function for using revsets internally, and | |
2528 | escapes arguments appropriately. Aliases are intentionally ignored |
|
2531 | escapes arguments appropriately. Aliases are intentionally ignored | |
2529 | so that intended expression behavior isn't accidentally subverted. |
|
2532 | so that intended expression behavior isn't accidentally subverted. | |
2530 |
|
2533 | |||
2531 | Supported arguments: |
|
2534 | Supported arguments: | |
2532 |
|
2535 | |||
2533 | %r = revset expression, parenthesized |
|
2536 | %r = revset expression, parenthesized | |
2534 | %d = int(arg), no quoting |
|
2537 | %d = int(arg), no quoting | |
2535 | %s = string(arg), escaped and single-quoted |
|
2538 | %s = string(arg), escaped and single-quoted | |
2536 | %b = arg.branch(), escaped and single-quoted |
|
2539 | %b = arg.branch(), escaped and single-quoted | |
2537 | %n = hex(arg), single-quoted |
|
2540 | %n = hex(arg), single-quoted | |
2538 | %% = a literal '%' |
|
2541 | %% = a literal '%' | |
2539 |
|
2542 | |||
2540 | Prefixing the type with 'l' specifies a parenthesized list of that type. |
|
2543 | Prefixing the type with 'l' specifies a parenthesized list of that type. | |
2541 |
|
2544 | |||
2542 | >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()")) |
|
2545 | >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()")) | |
2543 | '(10 or 11):: and ((this()) or (that()))' |
|
2546 | '(10 or 11):: and ((this()) or (that()))' | |
2544 | >>> formatspec('%d:: and not %d::', 10, 20) |
|
2547 | >>> formatspec('%d:: and not %d::', 10, 20) | |
2545 | '10:: and not 20::' |
|
2548 | '10:: and not 20::' | |
2546 | >>> formatspec('%ld or %ld', [], [1]) |
|
2549 | >>> formatspec('%ld or %ld', [], [1]) | |
2547 | "_list('') or 1" |
|
2550 | "_list('') or 1" | |
2548 | >>> formatspec('keyword(%s)', 'foo\\xe9') |
|
2551 | >>> formatspec('keyword(%s)', 'foo\\xe9') | |
2549 | "keyword('foo\\\\xe9')" |
|
2552 | "keyword('foo\\\\xe9')" | |
2550 | >>> b = lambda: 'default' |
|
2553 | >>> b = lambda: 'default' | |
2551 | >>> b.branch = b |
|
2554 | >>> b.branch = b | |
2552 | >>> formatspec('branch(%b)', b) |
|
2555 | >>> formatspec('branch(%b)', b) | |
2553 | "branch('default')" |
|
2556 | "branch('default')" | |
2554 | >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) |
|
2557 | >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) | |
2555 | "root(_list('a\\x00b\\x00c\\x00d'))" |
|
2558 | "root(_list('a\\x00b\\x00c\\x00d'))" | |
2556 | ''' |
|
2559 | ''' | |
2557 |
|
2560 | |||
2558 | def quote(s): |
|
2561 | def quote(s): | |
2559 | return repr(str(s)) |
|
2562 | return repr(str(s)) | |
2560 |
|
2563 | |||
2561 | def argtype(c, arg): |
|
2564 | def argtype(c, arg): | |
2562 | if c == 'd': |
|
2565 | if c == 'd': | |
2563 | return str(int(arg)) |
|
2566 | return str(int(arg)) | |
2564 | elif c == 's': |
|
2567 | elif c == 's': | |
2565 | return quote(arg) |
|
2568 | return quote(arg) | |
2566 | elif c == 'r': |
|
2569 | elif c == 'r': | |
2567 | parse(arg) # make sure syntax errors are confined |
|
2570 | parse(arg) # make sure syntax errors are confined | |
2568 | return '(%s)' % arg |
|
2571 | return '(%s)' % arg | |
2569 | elif c == 'n': |
|
2572 | elif c == 'n': | |
2570 | return quote(node.hex(arg)) |
|
2573 | return quote(node.hex(arg)) | |
2571 | elif c == 'b': |
|
2574 | elif c == 'b': | |
2572 | return quote(arg.branch()) |
|
2575 | return quote(arg.branch()) | |
2573 |
|
2576 | |||
2574 | def listexp(s, t): |
|
2577 | def listexp(s, t): | |
2575 | l = len(s) |
|
2578 | l = len(s) | |
2576 | if l == 0: |
|
2579 | if l == 0: | |
2577 | return "_list('')" |
|
2580 | return "_list('')" | |
2578 | elif l == 1: |
|
2581 | elif l == 1: | |
2579 | return argtype(t, s[0]) |
|
2582 | return argtype(t, s[0]) | |
2580 | elif t == 'd': |
|
2583 | elif t == 'd': | |
2581 | return "_intlist('%s')" % "\0".join(str(int(a)) for a in s) |
|
2584 | return "_intlist('%s')" % "\0".join(str(int(a)) for a in s) | |
2582 | elif t == 's': |
|
2585 | elif t == 's': | |
2583 | return "_list('%s')" % "\0".join(s) |
|
2586 | return "_list('%s')" % "\0".join(s) | |
2584 | elif t == 'n': |
|
2587 | elif t == 'n': | |
2585 | return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s) |
|
2588 | return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s) | |
2586 | elif t == 'b': |
|
2589 | elif t == 'b': | |
2587 | return "_list('%s')" % "\0".join(a.branch() for a in s) |
|
2590 | return "_list('%s')" % "\0".join(a.branch() for a in s) | |
2588 |
|
2591 | |||
2589 | m = l // 2 |
|
2592 | m = l // 2 | |
2590 | return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) |
|
2593 | return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) | |
2591 |
|
2594 | |||
2592 | ret = '' |
|
2595 | ret = '' | |
2593 | pos = 0 |
|
2596 | pos = 0 | |
2594 | arg = 0 |
|
2597 | arg = 0 | |
2595 | while pos < len(expr): |
|
2598 | while pos < len(expr): | |
2596 | c = expr[pos] |
|
2599 | c = expr[pos] | |
2597 | if c == '%': |
|
2600 | if c == '%': | |
2598 | pos += 1 |
|
2601 | pos += 1 | |
2599 | d = expr[pos] |
|
2602 | d = expr[pos] | |
2600 | if d == '%': |
|
2603 | if d == '%': | |
2601 | ret += d |
|
2604 | ret += d | |
2602 | elif d in 'dsnbr': |
|
2605 | elif d in 'dsnbr': | |
2603 | ret += argtype(d, args[arg]) |
|
2606 | ret += argtype(d, args[arg]) | |
2604 | arg += 1 |
|
2607 | arg += 1 | |
2605 | elif d == 'l': |
|
2608 | elif d == 'l': | |
2606 | # a list of some type |
|
2609 | # a list of some type | |
2607 | pos += 1 |
|
2610 | pos += 1 | |
2608 | d = expr[pos] |
|
2611 | d = expr[pos] | |
2609 | ret += listexp(list(args[arg]), d) |
|
2612 | ret += listexp(list(args[arg]), d) | |
2610 | arg += 1 |
|
2613 | arg += 1 | |
2611 | else: |
|
2614 | else: | |
2612 | raise util.Abort('unexpected revspec format character %s' % d) |
|
2615 | raise util.Abort('unexpected revspec format character %s' % d) | |
2613 | else: |
|
2616 | else: | |
2614 | ret += c |
|
2617 | ret += c | |
2615 | pos += 1 |
|
2618 | pos += 1 | |
2616 |
|
2619 | |||
2617 | return ret |
|
2620 | return ret | |
2618 |
|
2621 | |||
2619 | def prettyformat(tree): |
|
2622 | def prettyformat(tree): | |
2620 | def _prettyformat(tree, level, lines): |
|
2623 | def _prettyformat(tree, level, lines): | |
2621 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): |
|
2624 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): | |
2622 | lines.append((level, str(tree))) |
|
2625 | lines.append((level, str(tree))) | |
2623 | else: |
|
2626 | else: | |
2624 | lines.append((level, '(%s' % tree[0])) |
|
2627 | lines.append((level, '(%s' % tree[0])) | |
2625 | for s in tree[1:]: |
|
2628 | for s in tree[1:]: | |
2626 | _prettyformat(s, level + 1, lines) |
|
2629 | _prettyformat(s, level + 1, lines) | |
2627 | lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] |
|
2630 | lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] | |
2628 |
|
2631 | |||
2629 | lines = [] |
|
2632 | lines = [] | |
2630 | _prettyformat(tree, 0, lines) |
|
2633 | _prettyformat(tree, 0, lines) | |
2631 | output = '\n'.join((' '*l + s) for l, s in lines) |
|
2634 | output = '\n'.join((' '*l + s) for l, s in lines) | |
2632 | return output |
|
2635 | return output | |
2633 |
|
2636 | |||
2634 | def depth(tree): |
|
2637 | def depth(tree): | |
2635 | if isinstance(tree, tuple): |
|
2638 | if isinstance(tree, tuple): | |
2636 | return max(map(depth, tree)) + 1 |
|
2639 | return max(map(depth, tree)) + 1 | |
2637 | else: |
|
2640 | else: | |
2638 | return 0 |
|
2641 | return 0 | |
2639 |
|
2642 | |||
2640 | def funcsused(tree): |
|
2643 | def funcsused(tree): | |
2641 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): |
|
2644 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): | |
2642 | return set() |
|
2645 | return set() | |
2643 | else: |
|
2646 | else: | |
2644 | funcs = set() |
|
2647 | funcs = set() | |
2645 | for s in tree[1:]: |
|
2648 | for s in tree[1:]: | |
2646 | funcs |= funcsused(s) |
|
2649 | funcs |= funcsused(s) | |
2647 | if tree[0] == 'func': |
|
2650 | if tree[0] == 'func': | |
2648 | funcs.add(tree[1][1]) |
|
2651 | funcs.add(tree[1][1]) | |
2649 | return funcs |
|
2652 | return funcs | |
2650 |
|
2653 | |||
2651 | class abstractsmartset(object): |
|
2654 | class abstractsmartset(object): | |
2652 |
|
2655 | |||
2653 | def __nonzero__(self): |
|
2656 | def __nonzero__(self): | |
2654 | """True if the smartset is not empty""" |
|
2657 | """True if the smartset is not empty""" | |
2655 | raise NotImplementedError() |
|
2658 | raise NotImplementedError() | |
2656 |
|
2659 | |||
2657 | def __contains__(self, rev): |
|
2660 | def __contains__(self, rev): | |
2658 | """provide fast membership testing""" |
|
2661 | """provide fast membership testing""" | |
2659 | raise NotImplementedError() |
|
2662 | raise NotImplementedError() | |
2660 |
|
2663 | |||
2661 | def __iter__(self): |
|
2664 | def __iter__(self): | |
2662 | """iterate the set in the order it is supposed to be iterated""" |
|
2665 | """iterate the set in the order it is supposed to be iterated""" | |
2663 | raise NotImplementedError() |
|
2666 | raise NotImplementedError() | |
2664 |
|
2667 | |||
2665 | # Attributes containing a function to perform a fast iteration in a given |
|
2668 | # Attributes containing a function to perform a fast iteration in a given | |
2666 | # direction. A smartset can have none, one, or both defined. |
|
2669 | # direction. A smartset can have none, one, or both defined. | |
2667 | # |
|
2670 | # | |
2668 | # Default value is None instead of a function returning None to avoid |
|
2671 | # Default value is None instead of a function returning None to avoid | |
2669 | # initializing an iterator just for testing if a fast method exists. |
|
2672 | # initializing an iterator just for testing if a fast method exists. | |
2670 | fastasc = None |
|
2673 | fastasc = None | |
2671 | fastdesc = None |
|
2674 | fastdesc = None | |
2672 |
|
2675 | |||
2673 | def isascending(self): |
|
2676 | def isascending(self): | |
2674 | """True if the set will iterate in ascending order""" |
|
2677 | """True if the set will iterate in ascending order""" | |
2675 | raise NotImplementedError() |
|
2678 | raise NotImplementedError() | |
2676 |
|
2679 | |||
2677 | def isdescending(self): |
|
2680 | def isdescending(self): | |
2678 | """True if the set will iterate in descending order""" |
|
2681 | """True if the set will iterate in descending order""" | |
2679 | raise NotImplementedError() |
|
2682 | raise NotImplementedError() | |
2680 |
|
2683 | |||
2681 | def min(self): |
|
2684 | def min(self): | |
2682 | """return the minimum element in the set""" |
|
2685 | """return the minimum element in the set""" | |
2683 | if self.fastasc is not None: |
|
2686 | if self.fastasc is not None: | |
2684 | for r in self.fastasc(): |
|
2687 | for r in self.fastasc(): | |
2685 | return r |
|
2688 | return r | |
2686 | raise ValueError('arg is an empty sequence') |
|
2689 | raise ValueError('arg is an empty sequence') | |
2687 | return min(self) |
|
2690 | return min(self) | |
2688 |
|
2691 | |||
2689 | def max(self): |
|
2692 | def max(self): | |
2690 | """return the maximum element in the set""" |
|
2693 | """return the maximum element in the set""" | |
2691 | if self.fastdesc is not None: |
|
2694 | if self.fastdesc is not None: | |
2692 | for r in self.fastdesc(): |
|
2695 | for r in self.fastdesc(): | |
2693 | return r |
|
2696 | return r | |
2694 | raise ValueError('arg is an empty sequence') |
|
2697 | raise ValueError('arg is an empty sequence') | |
2695 | return max(self) |
|
2698 | return max(self) | |
2696 |
|
2699 | |||
2697 | def first(self): |
|
2700 | def first(self): | |
2698 | """return the first element in the set (user iteration perspective) |
|
2701 | """return the first element in the set (user iteration perspective) | |
2699 |
|
2702 | |||
2700 | Return None if the set is empty""" |
|
2703 | Return None if the set is empty""" | |
2701 | raise NotImplementedError() |
|
2704 | raise NotImplementedError() | |
2702 |
|
2705 | |||
2703 | def last(self): |
|
2706 | def last(self): | |
2704 | """return the last element in the set (user iteration perspective) |
|
2707 | """return the last element in the set (user iteration perspective) | |
2705 |
|
2708 | |||
2706 | Return None if the set is empty""" |
|
2709 | Return None if the set is empty""" | |
2707 | raise NotImplementedError() |
|
2710 | raise NotImplementedError() | |
2708 |
|
2711 | |||
2709 | def __len__(self): |
|
2712 | def __len__(self): | |
2710 | """return the length of the smartsets |
|
2713 | """return the length of the smartsets | |
2711 |
|
2714 | |||
2712 | This can be expensive on smartset that could be lazy otherwise.""" |
|
2715 | This can be expensive on smartset that could be lazy otherwise.""" | |
2713 | raise NotImplementedError() |
|
2716 | raise NotImplementedError() | |
2714 |
|
2717 | |||
2715 | def reverse(self): |
|
2718 | def reverse(self): | |
2716 | """reverse the expected iteration order""" |
|
2719 | """reverse the expected iteration order""" | |
2717 | raise NotImplementedError() |
|
2720 | raise NotImplementedError() | |
2718 |
|
2721 | |||
2719 | def sort(self, reverse=True): |
|
2722 | def sort(self, reverse=True): | |
2720 | """get the set to iterate in an ascending or descending order""" |
|
2723 | """get the set to iterate in an ascending or descending order""" | |
2721 | raise NotImplementedError() |
|
2724 | raise NotImplementedError() | |
2722 |
|
2725 | |||
2723 | def __and__(self, other): |
|
2726 | def __and__(self, other): | |
2724 | """Returns a new object with the intersection of the two collections. |
|
2727 | """Returns a new object with the intersection of the two collections. | |
2725 |
|
2728 | |||
2726 | This is part of the mandatory API for smartset.""" |
|
2729 | This is part of the mandatory API for smartset.""" | |
2727 | if isinstance(other, fullreposet): |
|
2730 | if isinstance(other, fullreposet): | |
2728 | return self |
|
2731 | return self | |
2729 | return self.filter(other.__contains__, cache=False) |
|
2732 | return self.filter(other.__contains__, cache=False) | |
2730 |
|
2733 | |||
2731 | def __add__(self, other): |
|
2734 | def __add__(self, other): | |
2732 | """Returns a new object with the union of the two collections. |
|
2735 | """Returns a new object with the union of the two collections. | |
2733 |
|
2736 | |||
2734 | This is part of the mandatory API for smartset.""" |
|
2737 | This is part of the mandatory API for smartset.""" | |
2735 | return addset(self, other) |
|
2738 | return addset(self, other) | |
2736 |
|
2739 | |||
2737 | def __sub__(self, other): |
|
2740 | def __sub__(self, other): | |
2738 | """Returns a new object with the substraction of the two collections. |
|
2741 | """Returns a new object with the substraction of the two collections. | |
2739 |
|
2742 | |||
2740 | This is part of the mandatory API for smartset.""" |
|
2743 | This is part of the mandatory API for smartset.""" | |
2741 | c = other.__contains__ |
|
2744 | c = other.__contains__ | |
2742 | return self.filter(lambda r: not c(r), cache=False) |
|
2745 | return self.filter(lambda r: not c(r), cache=False) | |
2743 |
|
2746 | |||
2744 | def filter(self, condition, cache=True): |
|
2747 | def filter(self, condition, cache=True): | |
2745 | """Returns this smartset filtered by condition as a new smartset. |
|
2748 | """Returns this smartset filtered by condition as a new smartset. | |
2746 |
|
2749 | |||
2747 | `condition` is a callable which takes a revision number and returns a |
|
2750 | `condition` is a callable which takes a revision number and returns a | |
2748 | boolean. |
|
2751 | boolean. | |
2749 |
|
2752 | |||
2750 | This is part of the mandatory API for smartset.""" |
|
2753 | This is part of the mandatory API for smartset.""" | |
2751 | # builtin cannot be cached. but do not needs to |
|
2754 | # builtin cannot be cached. but do not needs to | |
2752 | if cache and util.safehasattr(condition, 'func_code'): |
|
2755 | if cache and util.safehasattr(condition, 'func_code'): | |
2753 | condition = util.cachefunc(condition) |
|
2756 | condition = util.cachefunc(condition) | |
2754 | return filteredset(self, condition) |
|
2757 | return filteredset(self, condition) | |
2755 |
|
2758 | |||
2756 | class baseset(abstractsmartset): |
|
2759 | class baseset(abstractsmartset): | |
2757 | """Basic data structure that represents a revset and contains the basic |
|
2760 | """Basic data structure that represents a revset and contains the basic | |
2758 | operation that it should be able to perform. |
|
2761 | operation that it should be able to perform. | |
2759 |
|
2762 | |||
2760 | Every method in this class should be implemented by any smartset class. |
|
2763 | Every method in this class should be implemented by any smartset class. | |
2761 | """ |
|
2764 | """ | |
2762 | def __init__(self, data=()): |
|
2765 | def __init__(self, data=()): | |
2763 | if not isinstance(data, list): |
|
2766 | if not isinstance(data, list): | |
2764 | data = list(data) |
|
2767 | data = list(data) | |
2765 | self._list = data |
|
2768 | self._list = data | |
2766 | self._ascending = None |
|
2769 | self._ascending = None | |
2767 |
|
2770 | |||
2768 | @util.propertycache |
|
2771 | @util.propertycache | |
2769 | def _set(self): |
|
2772 | def _set(self): | |
2770 | return set(self._list) |
|
2773 | return set(self._list) | |
2771 |
|
2774 | |||
2772 | @util.propertycache |
|
2775 | @util.propertycache | |
2773 | def _asclist(self): |
|
2776 | def _asclist(self): | |
2774 | asclist = self._list[:] |
|
2777 | asclist = self._list[:] | |
2775 | asclist.sort() |
|
2778 | asclist.sort() | |
2776 | return asclist |
|
2779 | return asclist | |
2777 |
|
2780 | |||
2778 | def __iter__(self): |
|
2781 | def __iter__(self): | |
2779 | if self._ascending is None: |
|
2782 | if self._ascending is None: | |
2780 | return iter(self._list) |
|
2783 | return iter(self._list) | |
2781 | elif self._ascending: |
|
2784 | elif self._ascending: | |
2782 | return iter(self._asclist) |
|
2785 | return iter(self._asclist) | |
2783 | else: |
|
2786 | else: | |
2784 | return reversed(self._asclist) |
|
2787 | return reversed(self._asclist) | |
2785 |
|
2788 | |||
2786 | def fastasc(self): |
|
2789 | def fastasc(self): | |
2787 | return iter(self._asclist) |
|
2790 | return iter(self._asclist) | |
2788 |
|
2791 | |||
2789 | def fastdesc(self): |
|
2792 | def fastdesc(self): | |
2790 | return reversed(self._asclist) |
|
2793 | return reversed(self._asclist) | |
2791 |
|
2794 | |||
2792 | @util.propertycache |
|
2795 | @util.propertycache | |
2793 | def __contains__(self): |
|
2796 | def __contains__(self): | |
2794 | return self._set.__contains__ |
|
2797 | return self._set.__contains__ | |
2795 |
|
2798 | |||
2796 | def __nonzero__(self): |
|
2799 | def __nonzero__(self): | |
2797 | return bool(self._list) |
|
2800 | return bool(self._list) | |
2798 |
|
2801 | |||
2799 | def sort(self, reverse=False): |
|
2802 | def sort(self, reverse=False): | |
2800 | self._ascending = not bool(reverse) |
|
2803 | self._ascending = not bool(reverse) | |
2801 |
|
2804 | |||
2802 | def reverse(self): |
|
2805 | def reverse(self): | |
2803 | if self._ascending is None: |
|
2806 | if self._ascending is None: | |
2804 | self._list.reverse() |
|
2807 | self._list.reverse() | |
2805 | else: |
|
2808 | else: | |
2806 | self._ascending = not self._ascending |
|
2809 | self._ascending = not self._ascending | |
2807 |
|
2810 | |||
2808 | def __len__(self): |
|
2811 | def __len__(self): | |
2809 | return len(self._list) |
|
2812 | return len(self._list) | |
2810 |
|
2813 | |||
2811 | def isascending(self): |
|
2814 | def isascending(self): | |
2812 | """Returns True if the collection is ascending order, False if not. |
|
2815 | """Returns True if the collection is ascending order, False if not. | |
2813 |
|
2816 | |||
2814 | This is part of the mandatory API for smartset.""" |
|
2817 | This is part of the mandatory API for smartset.""" | |
2815 | if len(self) <= 1: |
|
2818 | if len(self) <= 1: | |
2816 | return True |
|
2819 | return True | |
2817 | return self._ascending is not None and self._ascending |
|
2820 | return self._ascending is not None and self._ascending | |
2818 |
|
2821 | |||
2819 | def isdescending(self): |
|
2822 | def isdescending(self): | |
2820 | """Returns True if the collection is descending order, False if not. |
|
2823 | """Returns True if the collection is descending order, False if not. | |
2821 |
|
2824 | |||
2822 | This is part of the mandatory API for smartset.""" |
|
2825 | This is part of the mandatory API for smartset.""" | |
2823 | if len(self) <= 1: |
|
2826 | if len(self) <= 1: | |
2824 | return True |
|
2827 | return True | |
2825 | return self._ascending is not None and not self._ascending |
|
2828 | return self._ascending is not None and not self._ascending | |
2826 |
|
2829 | |||
2827 | def first(self): |
|
2830 | def first(self): | |
2828 | if self: |
|
2831 | if self: | |
2829 | if self._ascending is None: |
|
2832 | if self._ascending is None: | |
2830 | return self._list[0] |
|
2833 | return self._list[0] | |
2831 | elif self._ascending: |
|
2834 | elif self._ascending: | |
2832 | return self._asclist[0] |
|
2835 | return self._asclist[0] | |
2833 | else: |
|
2836 | else: | |
2834 | return self._asclist[-1] |
|
2837 | return self._asclist[-1] | |
2835 | return None |
|
2838 | return None | |
2836 |
|
2839 | |||
2837 | def last(self): |
|
2840 | def last(self): | |
2838 | if self: |
|
2841 | if self: | |
2839 | if self._ascending is None: |
|
2842 | if self._ascending is None: | |
2840 | return self._list[-1] |
|
2843 | return self._list[-1] | |
2841 | elif self._ascending: |
|
2844 | elif self._ascending: | |
2842 | return self._asclist[-1] |
|
2845 | return self._asclist[-1] | |
2843 | else: |
|
2846 | else: | |
2844 | return self._asclist[0] |
|
2847 | return self._asclist[0] | |
2845 | return None |
|
2848 | return None | |
2846 |
|
2849 | |||
2847 | def __repr__(self): |
|
2850 | def __repr__(self): | |
2848 | d = {None: '', False: '-', True: '+'}[self._ascending] |
|
2851 | d = {None: '', False: '-', True: '+'}[self._ascending] | |
2849 | return '<%s%s %r>' % (type(self).__name__, d, self._list) |
|
2852 | return '<%s%s %r>' % (type(self).__name__, d, self._list) | |
2850 |
|
2853 | |||
2851 | class filteredset(abstractsmartset): |
|
2854 | class filteredset(abstractsmartset): | |
2852 | """Duck type for baseset class which iterates lazily over the revisions in |
|
2855 | """Duck type for baseset class which iterates lazily over the revisions in | |
2853 | the subset and contains a function which tests for membership in the |
|
2856 | the subset and contains a function which tests for membership in the | |
2854 | revset |
|
2857 | revset | |
2855 | """ |
|
2858 | """ | |
2856 | def __init__(self, subset, condition=lambda x: True): |
|
2859 | def __init__(self, subset, condition=lambda x: True): | |
2857 | """ |
|
2860 | """ | |
2858 | condition: a function that decide whether a revision in the subset |
|
2861 | condition: a function that decide whether a revision in the subset | |
2859 | belongs to the revset or not. |
|
2862 | belongs to the revset or not. | |
2860 | """ |
|
2863 | """ | |
2861 | self._subset = subset |
|
2864 | self._subset = subset | |
2862 | self._condition = condition |
|
2865 | self._condition = condition | |
2863 | self._cache = {} |
|
2866 | self._cache = {} | |
2864 |
|
2867 | |||
2865 | def __contains__(self, x): |
|
2868 | def __contains__(self, x): | |
2866 | c = self._cache |
|
2869 | c = self._cache | |
2867 | if x not in c: |
|
2870 | if x not in c: | |
2868 | v = c[x] = x in self._subset and self._condition(x) |
|
2871 | v = c[x] = x in self._subset and self._condition(x) | |
2869 | return v |
|
2872 | return v | |
2870 | return c[x] |
|
2873 | return c[x] | |
2871 |
|
2874 | |||
2872 | def __iter__(self): |
|
2875 | def __iter__(self): | |
2873 | return self._iterfilter(self._subset) |
|
2876 | return self._iterfilter(self._subset) | |
2874 |
|
2877 | |||
2875 | def _iterfilter(self, it): |
|
2878 | def _iterfilter(self, it): | |
2876 | cond = self._condition |
|
2879 | cond = self._condition | |
2877 | for x in it: |
|
2880 | for x in it: | |
2878 | if cond(x): |
|
2881 | if cond(x): | |
2879 | yield x |
|
2882 | yield x | |
2880 |
|
2883 | |||
2881 | @property |
|
2884 | @property | |
2882 | def fastasc(self): |
|
2885 | def fastasc(self): | |
2883 | it = self._subset.fastasc |
|
2886 | it = self._subset.fastasc | |
2884 | if it is None: |
|
2887 | if it is None: | |
2885 | return None |
|
2888 | return None | |
2886 | return lambda: self._iterfilter(it()) |
|
2889 | return lambda: self._iterfilter(it()) | |
2887 |
|
2890 | |||
2888 | @property |
|
2891 | @property | |
2889 | def fastdesc(self): |
|
2892 | def fastdesc(self): | |
2890 | it = self._subset.fastdesc |
|
2893 | it = self._subset.fastdesc | |
2891 | if it is None: |
|
2894 | if it is None: | |
2892 | return None |
|
2895 | return None | |
2893 | return lambda: self._iterfilter(it()) |
|
2896 | return lambda: self._iterfilter(it()) | |
2894 |
|
2897 | |||
2895 | def __nonzero__(self): |
|
2898 | def __nonzero__(self): | |
2896 | for r in self: |
|
2899 | for r in self: | |
2897 | return True |
|
2900 | return True | |
2898 | return False |
|
2901 | return False | |
2899 |
|
2902 | |||
2900 | def __len__(self): |
|
2903 | def __len__(self): | |
2901 | # Basic implementation to be changed in future patches. |
|
2904 | # Basic implementation to be changed in future patches. | |
2902 | l = baseset([r for r in self]) |
|
2905 | l = baseset([r for r in self]) | |
2903 | return len(l) |
|
2906 | return len(l) | |
2904 |
|
2907 | |||
2905 | def sort(self, reverse=False): |
|
2908 | def sort(self, reverse=False): | |
2906 | self._subset.sort(reverse=reverse) |
|
2909 | self._subset.sort(reverse=reverse) | |
2907 |
|
2910 | |||
2908 | def reverse(self): |
|
2911 | def reverse(self): | |
2909 | self._subset.reverse() |
|
2912 | self._subset.reverse() | |
2910 |
|
2913 | |||
2911 | def isascending(self): |
|
2914 | def isascending(self): | |
2912 | return self._subset.isascending() |
|
2915 | return self._subset.isascending() | |
2913 |
|
2916 | |||
2914 | def isdescending(self): |
|
2917 | def isdescending(self): | |
2915 | return self._subset.isdescending() |
|
2918 | return self._subset.isdescending() | |
2916 |
|
2919 | |||
2917 | def first(self): |
|
2920 | def first(self): | |
2918 | for x in self: |
|
2921 | for x in self: | |
2919 | return x |
|
2922 | return x | |
2920 | return None |
|
2923 | return None | |
2921 |
|
2924 | |||
2922 | def last(self): |
|
2925 | def last(self): | |
2923 | it = None |
|
2926 | it = None | |
2924 | if self._subset.isascending: |
|
2927 | if self._subset.isascending: | |
2925 | it = self.fastdesc |
|
2928 | it = self.fastdesc | |
2926 | elif self._subset.isdescending: |
|
2929 | elif self._subset.isdescending: | |
2927 | it = self.fastdesc |
|
2930 | it = self.fastdesc | |
2928 | if it is None: |
|
2931 | if it is None: | |
2929 | # slowly consume everything. This needs improvement |
|
2932 | # slowly consume everything. This needs improvement | |
2930 | it = lambda: reversed(list(self)) |
|
2933 | it = lambda: reversed(list(self)) | |
2931 | for x in it(): |
|
2934 | for x in it(): | |
2932 | return x |
|
2935 | return x | |
2933 | return None |
|
2936 | return None | |
2934 |
|
2937 | |||
2935 | def __repr__(self): |
|
2938 | def __repr__(self): | |
2936 | return '<%s %r>' % (type(self).__name__, self._subset) |
|
2939 | return '<%s %r>' % (type(self).__name__, self._subset) | |
2937 |
|
2940 | |||
2938 | class addset(abstractsmartset): |
|
2941 | class addset(abstractsmartset): | |
2939 | """Represent the addition of two sets |
|
2942 | """Represent the addition of two sets | |
2940 |
|
2943 | |||
2941 | Wrapper structure for lazily adding two structures without losing much |
|
2944 | Wrapper structure for lazily adding two structures without losing much | |
2942 | performance on the __contains__ method |
|
2945 | performance on the __contains__ method | |
2943 |
|
2946 | |||
2944 | If the ascending attribute is set, that means the two structures are |
|
2947 | If the ascending attribute is set, that means the two structures are | |
2945 | ordered in either an ascending or descending way. Therefore, we can add |
|
2948 | ordered in either an ascending or descending way. Therefore, we can add | |
2946 | them maintaining the order by iterating over both at the same time |
|
2949 | them maintaining the order by iterating over both at the same time | |
2947 | """ |
|
2950 | """ | |
2948 | def __init__(self, revs1, revs2, ascending=None): |
|
2951 | def __init__(self, revs1, revs2, ascending=None): | |
2949 | self._r1 = revs1 |
|
2952 | self._r1 = revs1 | |
2950 | self._r2 = revs2 |
|
2953 | self._r2 = revs2 | |
2951 | self._iter = None |
|
2954 | self._iter = None | |
2952 | self._ascending = ascending |
|
2955 | self._ascending = ascending | |
2953 | self._genlist = None |
|
2956 | self._genlist = None | |
2954 | self._asclist = None |
|
2957 | self._asclist = None | |
2955 |
|
2958 | |||
2956 | def __len__(self): |
|
2959 | def __len__(self): | |
2957 | return len(self._list) |
|
2960 | return len(self._list) | |
2958 |
|
2961 | |||
2959 | def __nonzero__(self): |
|
2962 | def __nonzero__(self): | |
2960 | return bool(self._r1) or bool(self._r2) |
|
2963 | return bool(self._r1) or bool(self._r2) | |
2961 |
|
2964 | |||
2962 | @util.propertycache |
|
2965 | @util.propertycache | |
2963 | def _list(self): |
|
2966 | def _list(self): | |
2964 | if not self._genlist: |
|
2967 | if not self._genlist: | |
2965 | self._genlist = baseset(self._iterator()) |
|
2968 | self._genlist = baseset(self._iterator()) | |
2966 | return self._genlist |
|
2969 | return self._genlist | |
2967 |
|
2970 | |||
2968 | def _iterator(self): |
|
2971 | def _iterator(self): | |
2969 | """Iterate over both collections without repeating elements |
|
2972 | """Iterate over both collections without repeating elements | |
2970 |
|
2973 | |||
2971 | If the ascending attribute is not set, iterate over the first one and |
|
2974 | If the ascending attribute is not set, iterate over the first one and | |
2972 | then over the second one checking for membership on the first one so we |
|
2975 | then over the second one checking for membership on the first one so we | |
2973 | dont yield any duplicates. |
|
2976 | dont yield any duplicates. | |
2974 |
|
2977 | |||
2975 | If the ascending attribute is set, iterate over both collections at the |
|
2978 | If the ascending attribute is set, iterate over both collections at the | |
2976 | same time, yielding only one value at a time in the given order. |
|
2979 | same time, yielding only one value at a time in the given order. | |
2977 | """ |
|
2980 | """ | |
2978 | if self._ascending is None: |
|
2981 | if self._ascending is None: | |
2979 | def gen(): |
|
2982 | def gen(): | |
2980 | for r in self._r1: |
|
2983 | for r in self._r1: | |
2981 | yield r |
|
2984 | yield r | |
2982 | inr1 = self._r1.__contains__ |
|
2985 | inr1 = self._r1.__contains__ | |
2983 | for r in self._r2: |
|
2986 | for r in self._r2: | |
2984 | if not inr1(r): |
|
2987 | if not inr1(r): | |
2985 | yield r |
|
2988 | yield r | |
2986 | gen = gen() |
|
2989 | gen = gen() | |
2987 | else: |
|
2990 | else: | |
2988 | iter1 = iter(self._r1) |
|
2991 | iter1 = iter(self._r1) | |
2989 | iter2 = iter(self._r2) |
|
2992 | iter2 = iter(self._r2) | |
2990 | gen = self._iterordered(self._ascending, iter1, iter2) |
|
2993 | gen = self._iterordered(self._ascending, iter1, iter2) | |
2991 | return gen |
|
2994 | return gen | |
2992 |
|
2995 | |||
2993 | def __iter__(self): |
|
2996 | def __iter__(self): | |
2994 | if self._ascending is None: |
|
2997 | if self._ascending is None: | |
2995 | if self._genlist: |
|
2998 | if self._genlist: | |
2996 | return iter(self._genlist) |
|
2999 | return iter(self._genlist) | |
2997 | return iter(self._iterator()) |
|
3000 | return iter(self._iterator()) | |
2998 | self._trysetasclist() |
|
3001 | self._trysetasclist() | |
2999 | if self._ascending: |
|
3002 | if self._ascending: | |
3000 | it = self.fastasc |
|
3003 | it = self.fastasc | |
3001 | else: |
|
3004 | else: | |
3002 | it = self.fastdesc |
|
3005 | it = self.fastdesc | |
3003 | if it is None: |
|
3006 | if it is None: | |
3004 | # consume the gen and try again |
|
3007 | # consume the gen and try again | |
3005 | self._list |
|
3008 | self._list | |
3006 | return iter(self) |
|
3009 | return iter(self) | |
3007 | return it() |
|
3010 | return it() | |
3008 |
|
3011 | |||
3009 | def _trysetasclist(self): |
|
3012 | def _trysetasclist(self): | |
3010 | """populate the _asclist attribute if possible and necessary""" |
|
3013 | """populate the _asclist attribute if possible and necessary""" | |
3011 | if self._genlist is not None and self._asclist is None: |
|
3014 | if self._genlist is not None and self._asclist is None: | |
3012 | self._asclist = sorted(self._genlist) |
|
3015 | self._asclist = sorted(self._genlist) | |
3013 |
|
3016 | |||
3014 | @property |
|
3017 | @property | |
3015 | def fastasc(self): |
|
3018 | def fastasc(self): | |
3016 | self._trysetasclist() |
|
3019 | self._trysetasclist() | |
3017 | if self._asclist is not None: |
|
3020 | if self._asclist is not None: | |
3018 | return self._asclist.__iter__ |
|
3021 | return self._asclist.__iter__ | |
3019 | iter1 = self._r1.fastasc |
|
3022 | iter1 = self._r1.fastasc | |
3020 | iter2 = self._r2.fastasc |
|
3023 | iter2 = self._r2.fastasc | |
3021 | if None in (iter1, iter2): |
|
3024 | if None in (iter1, iter2): | |
3022 | return None |
|
3025 | return None | |
3023 | return lambda: self._iterordered(True, iter1(), iter2()) |
|
3026 | return lambda: self._iterordered(True, iter1(), iter2()) | |
3024 |
|
3027 | |||
3025 | @property |
|
3028 | @property | |
3026 | def fastdesc(self): |
|
3029 | def fastdesc(self): | |
3027 | self._trysetasclist() |
|
3030 | self._trysetasclist() | |
3028 | if self._asclist is not None: |
|
3031 | if self._asclist is not None: | |
3029 | return self._asclist.__reversed__ |
|
3032 | return self._asclist.__reversed__ | |
3030 | iter1 = self._r1.fastdesc |
|
3033 | iter1 = self._r1.fastdesc | |
3031 | iter2 = self._r2.fastdesc |
|
3034 | iter2 = self._r2.fastdesc | |
3032 | if None in (iter1, iter2): |
|
3035 | if None in (iter1, iter2): | |
3033 | return None |
|
3036 | return None | |
3034 | return lambda: self._iterordered(False, iter1(), iter2()) |
|
3037 | return lambda: self._iterordered(False, iter1(), iter2()) | |
3035 |
|
3038 | |||
3036 | def _iterordered(self, ascending, iter1, iter2): |
|
3039 | def _iterordered(self, ascending, iter1, iter2): | |
3037 | """produce an ordered iteration from two iterators with the same order |
|
3040 | """produce an ordered iteration from two iterators with the same order | |
3038 |
|
3041 | |||
3039 | The ascending is used to indicated the iteration direction. |
|
3042 | The ascending is used to indicated the iteration direction. | |
3040 | """ |
|
3043 | """ | |
3041 | choice = max |
|
3044 | choice = max | |
3042 | if ascending: |
|
3045 | if ascending: | |
3043 | choice = min |
|
3046 | choice = min | |
3044 |
|
3047 | |||
3045 | val1 = None |
|
3048 | val1 = None | |
3046 | val2 = None |
|
3049 | val2 = None | |
3047 |
|
3050 | |||
3048 | choice = max |
|
3051 | choice = max | |
3049 | if ascending: |
|
3052 | if ascending: | |
3050 | choice = min |
|
3053 | choice = min | |
3051 | try: |
|
3054 | try: | |
3052 | # Consume both iterators in an ordered way until one is |
|
3055 | # Consume both iterators in an ordered way until one is | |
3053 | # empty |
|
3056 | # empty | |
3054 | while True: |
|
3057 | while True: | |
3055 | if val1 is None: |
|
3058 | if val1 is None: | |
3056 | val1 = iter1.next() |
|
3059 | val1 = iter1.next() | |
3057 | if val2 is None: |
|
3060 | if val2 is None: | |
3058 | val2 = iter2.next() |
|
3061 | val2 = iter2.next() | |
3059 | next = choice(val1, val2) |
|
3062 | next = choice(val1, val2) | |
3060 | yield next |
|
3063 | yield next | |
3061 | if val1 == next: |
|
3064 | if val1 == next: | |
3062 | val1 = None |
|
3065 | val1 = None | |
3063 | if val2 == next: |
|
3066 | if val2 == next: | |
3064 | val2 = None |
|
3067 | val2 = None | |
3065 | except StopIteration: |
|
3068 | except StopIteration: | |
3066 | # Flush any remaining values and consume the other one |
|
3069 | # Flush any remaining values and consume the other one | |
3067 | it = iter2 |
|
3070 | it = iter2 | |
3068 | if val1 is not None: |
|
3071 | if val1 is not None: | |
3069 | yield val1 |
|
3072 | yield val1 | |
3070 | it = iter1 |
|
3073 | it = iter1 | |
3071 | elif val2 is not None: |
|
3074 | elif val2 is not None: | |
3072 | # might have been equality and both are empty |
|
3075 | # might have been equality and both are empty | |
3073 | yield val2 |
|
3076 | yield val2 | |
3074 | for val in it: |
|
3077 | for val in it: | |
3075 | yield val |
|
3078 | yield val | |
3076 |
|
3079 | |||
3077 | def __contains__(self, x): |
|
3080 | def __contains__(self, x): | |
3078 | return x in self._r1 or x in self._r2 |
|
3081 | return x in self._r1 or x in self._r2 | |
3079 |
|
3082 | |||
3080 | def sort(self, reverse=False): |
|
3083 | def sort(self, reverse=False): | |
3081 | """Sort the added set |
|
3084 | """Sort the added set | |
3082 |
|
3085 | |||
3083 | For this we use the cached list with all the generated values and if we |
|
3086 | For this we use the cached list with all the generated values and if we | |
3084 | know they are ascending or descending we can sort them in a smart way. |
|
3087 | know they are ascending or descending we can sort them in a smart way. | |
3085 | """ |
|
3088 | """ | |
3086 | self._ascending = not reverse |
|
3089 | self._ascending = not reverse | |
3087 |
|
3090 | |||
3088 | def isascending(self): |
|
3091 | def isascending(self): | |
3089 | return self._ascending is not None and self._ascending |
|
3092 | return self._ascending is not None and self._ascending | |
3090 |
|
3093 | |||
3091 | def isdescending(self): |
|
3094 | def isdescending(self): | |
3092 | return self._ascending is not None and not self._ascending |
|
3095 | return self._ascending is not None and not self._ascending | |
3093 |
|
3096 | |||
3094 | def reverse(self): |
|
3097 | def reverse(self): | |
3095 | if self._ascending is None: |
|
3098 | if self._ascending is None: | |
3096 | self._list.reverse() |
|
3099 | self._list.reverse() | |
3097 | else: |
|
3100 | else: | |
3098 | self._ascending = not self._ascending |
|
3101 | self._ascending = not self._ascending | |
3099 |
|
3102 | |||
3100 | def first(self): |
|
3103 | def first(self): | |
3101 | for x in self: |
|
3104 | for x in self: | |
3102 | return x |
|
3105 | return x | |
3103 | return None |
|
3106 | return None | |
3104 |
|
3107 | |||
3105 | def last(self): |
|
3108 | def last(self): | |
3106 | self.reverse() |
|
3109 | self.reverse() | |
3107 | val = self.first() |
|
3110 | val = self.first() | |
3108 | self.reverse() |
|
3111 | self.reverse() | |
3109 | return val |
|
3112 | return val | |
3110 |
|
3113 | |||
3111 | def __repr__(self): |
|
3114 | def __repr__(self): | |
3112 | d = {None: '', False: '-', True: '+'}[self._ascending] |
|
3115 | d = {None: '', False: '-', True: '+'}[self._ascending] | |
3113 | return '<%s%s %r, %r>' % (type(self).__name__, d, self._r1, self._r2) |
|
3116 | return '<%s%s %r, %r>' % (type(self).__name__, d, self._r1, self._r2) | |
3114 |
|
3117 | |||
3115 | class generatorset(abstractsmartset): |
|
3118 | class generatorset(abstractsmartset): | |
3116 | """Wrap a generator for lazy iteration |
|
3119 | """Wrap a generator for lazy iteration | |
3117 |
|
3120 | |||
3118 | Wrapper structure for generators that provides lazy membership and can |
|
3121 | Wrapper structure for generators that provides lazy membership and can | |
3119 | be iterated more than once. |
|
3122 | be iterated more than once. | |
3120 | When asked for membership it generates values until either it finds the |
|
3123 | When asked for membership it generates values until either it finds the | |
3121 | requested one or has gone through all the elements in the generator |
|
3124 | requested one or has gone through all the elements in the generator | |
3122 | """ |
|
3125 | """ | |
3123 | def __init__(self, gen, iterasc=None): |
|
3126 | def __init__(self, gen, iterasc=None): | |
3124 | """ |
|
3127 | """ | |
3125 | gen: a generator producing the values for the generatorset. |
|
3128 | gen: a generator producing the values for the generatorset. | |
3126 | """ |
|
3129 | """ | |
3127 | self._gen = gen |
|
3130 | self._gen = gen | |
3128 | self._asclist = None |
|
3131 | self._asclist = None | |
3129 | self._cache = {} |
|
3132 | self._cache = {} | |
3130 | self._genlist = [] |
|
3133 | self._genlist = [] | |
3131 | self._finished = False |
|
3134 | self._finished = False | |
3132 | self._ascending = True |
|
3135 | self._ascending = True | |
3133 | if iterasc is not None: |
|
3136 | if iterasc is not None: | |
3134 | if iterasc: |
|
3137 | if iterasc: | |
3135 | self.fastasc = self._iterator |
|
3138 | self.fastasc = self._iterator | |
3136 | self.__contains__ = self._asccontains |
|
3139 | self.__contains__ = self._asccontains | |
3137 | else: |
|
3140 | else: | |
3138 | self.fastdesc = self._iterator |
|
3141 | self.fastdesc = self._iterator | |
3139 | self.__contains__ = self._desccontains |
|
3142 | self.__contains__ = self._desccontains | |
3140 |
|
3143 | |||
3141 | def __nonzero__(self): |
|
3144 | def __nonzero__(self): | |
3142 | for r in self: |
|
3145 | for r in self: | |
3143 | return True |
|
3146 | return True | |
3144 | return False |
|
3147 | return False | |
3145 |
|
3148 | |||
3146 | def __contains__(self, x): |
|
3149 | def __contains__(self, x): | |
3147 | if x in self._cache: |
|
3150 | if x in self._cache: | |
3148 | return self._cache[x] |
|
3151 | return self._cache[x] | |
3149 |
|
3152 | |||
3150 | # Use new values only, as existing values would be cached. |
|
3153 | # Use new values only, as existing values would be cached. | |
3151 | for l in self._consumegen(): |
|
3154 | for l in self._consumegen(): | |
3152 | if l == x: |
|
3155 | if l == x: | |
3153 | return True |
|
3156 | return True | |
3154 |
|
3157 | |||
3155 | self._cache[x] = False |
|
3158 | self._cache[x] = False | |
3156 | return False |
|
3159 | return False | |
3157 |
|
3160 | |||
3158 | def _asccontains(self, x): |
|
3161 | def _asccontains(self, x): | |
3159 | """version of contains optimised for ascending generator""" |
|
3162 | """version of contains optimised for ascending generator""" | |
3160 | if x in self._cache: |
|
3163 | if x in self._cache: | |
3161 | return self._cache[x] |
|
3164 | return self._cache[x] | |
3162 |
|
3165 | |||
3163 | # Use new values only, as existing values would be cached. |
|
3166 | # Use new values only, as existing values would be cached. | |
3164 | for l in self._consumegen(): |
|
3167 | for l in self._consumegen(): | |
3165 | if l == x: |
|
3168 | if l == x: | |
3166 | return True |
|
3169 | return True | |
3167 | if l > x: |
|
3170 | if l > x: | |
3168 | break |
|
3171 | break | |
3169 |
|
3172 | |||
3170 | self._cache[x] = False |
|
3173 | self._cache[x] = False | |
3171 | return False |
|
3174 | return False | |
3172 |
|
3175 | |||
3173 | def _desccontains(self, x): |
|
3176 | def _desccontains(self, x): | |
3174 | """version of contains optimised for descending generator""" |
|
3177 | """version of contains optimised for descending generator""" | |
3175 | if x in self._cache: |
|
3178 | if x in self._cache: | |
3176 | return self._cache[x] |
|
3179 | return self._cache[x] | |
3177 |
|
3180 | |||
3178 | # Use new values only, as existing values would be cached. |
|
3181 | # Use new values only, as existing values would be cached. | |
3179 | for l in self._consumegen(): |
|
3182 | for l in self._consumegen(): | |
3180 | if l == x: |
|
3183 | if l == x: | |
3181 | return True |
|
3184 | return True | |
3182 | if l < x: |
|
3185 | if l < x: | |
3183 | break |
|
3186 | break | |
3184 |
|
3187 | |||
3185 | self._cache[x] = False |
|
3188 | self._cache[x] = False | |
3186 | return False |
|
3189 | return False | |
3187 |
|
3190 | |||
3188 | def __iter__(self): |
|
3191 | def __iter__(self): | |
3189 | if self._ascending: |
|
3192 | if self._ascending: | |
3190 | it = self.fastasc |
|
3193 | it = self.fastasc | |
3191 | else: |
|
3194 | else: | |
3192 | it = self.fastdesc |
|
3195 | it = self.fastdesc | |
3193 | if it is not None: |
|
3196 | if it is not None: | |
3194 | return it() |
|
3197 | return it() | |
3195 | # we need to consume the iterator |
|
3198 | # we need to consume the iterator | |
3196 | for x in self._consumegen(): |
|
3199 | for x in self._consumegen(): | |
3197 | pass |
|
3200 | pass | |
3198 | # recall the same code |
|
3201 | # recall the same code | |
3199 | return iter(self) |
|
3202 | return iter(self) | |
3200 |
|
3203 | |||
3201 | def _iterator(self): |
|
3204 | def _iterator(self): | |
3202 | if self._finished: |
|
3205 | if self._finished: | |
3203 | return iter(self._genlist) |
|
3206 | return iter(self._genlist) | |
3204 |
|
3207 | |||
3205 | # We have to use this complex iteration strategy to allow multiple |
|
3208 | # We have to use this complex iteration strategy to allow multiple | |
3206 | # iterations at the same time. We need to be able to catch revision |
|
3209 | # iterations at the same time. We need to be able to catch revision | |
3207 | # removed from _consumegen and added to genlist in another instance. |
|
3210 | # removed from _consumegen and added to genlist in another instance. | |
3208 | # |
|
3211 | # | |
3209 | # Getting rid of it would provide an about 15% speed up on this |
|
3212 | # Getting rid of it would provide an about 15% speed up on this | |
3210 | # iteration. |
|
3213 | # iteration. | |
3211 | genlist = self._genlist |
|
3214 | genlist = self._genlist | |
3212 | nextrev = self._consumegen().next |
|
3215 | nextrev = self._consumegen().next | |
3213 | _len = len # cache global lookup |
|
3216 | _len = len # cache global lookup | |
3214 | def gen(): |
|
3217 | def gen(): | |
3215 | i = 0 |
|
3218 | i = 0 | |
3216 | while True: |
|
3219 | while True: | |
3217 | if i < _len(genlist): |
|
3220 | if i < _len(genlist): | |
3218 | yield genlist[i] |
|
3221 | yield genlist[i] | |
3219 | else: |
|
3222 | else: | |
3220 | yield nextrev() |
|
3223 | yield nextrev() | |
3221 | i += 1 |
|
3224 | i += 1 | |
3222 | return gen() |
|
3225 | return gen() | |
3223 |
|
3226 | |||
3224 | def _consumegen(self): |
|
3227 | def _consumegen(self): | |
3225 | cache = self._cache |
|
3228 | cache = self._cache | |
3226 | genlist = self._genlist.append |
|
3229 | genlist = self._genlist.append | |
3227 | for item in self._gen: |
|
3230 | for item in self._gen: | |
3228 | cache[item] = True |
|
3231 | cache[item] = True | |
3229 | genlist(item) |
|
3232 | genlist(item) | |
3230 | yield item |
|
3233 | yield item | |
3231 | if not self._finished: |
|
3234 | if not self._finished: | |
3232 | self._finished = True |
|
3235 | self._finished = True | |
3233 | asc = self._genlist[:] |
|
3236 | asc = self._genlist[:] | |
3234 | asc.sort() |
|
3237 | asc.sort() | |
3235 | self._asclist = asc |
|
3238 | self._asclist = asc | |
3236 | self.fastasc = asc.__iter__ |
|
3239 | self.fastasc = asc.__iter__ | |
3237 | self.fastdesc = asc.__reversed__ |
|
3240 | self.fastdesc = asc.__reversed__ | |
3238 |
|
3241 | |||
3239 | def __len__(self): |
|
3242 | def __len__(self): | |
3240 | for x in self._consumegen(): |
|
3243 | for x in self._consumegen(): | |
3241 | pass |
|
3244 | pass | |
3242 | return len(self._genlist) |
|
3245 | return len(self._genlist) | |
3243 |
|
3246 | |||
3244 | def sort(self, reverse=False): |
|
3247 | def sort(self, reverse=False): | |
3245 | self._ascending = not reverse |
|
3248 | self._ascending = not reverse | |
3246 |
|
3249 | |||
3247 | def reverse(self): |
|
3250 | def reverse(self): | |
3248 | self._ascending = not self._ascending |
|
3251 | self._ascending = not self._ascending | |
3249 |
|
3252 | |||
3250 | def isascending(self): |
|
3253 | def isascending(self): | |
3251 | return self._ascending |
|
3254 | return self._ascending | |
3252 |
|
3255 | |||
3253 | def isdescending(self): |
|
3256 | def isdescending(self): | |
3254 | return not self._ascending |
|
3257 | return not self._ascending | |
3255 |
|
3258 | |||
3256 | def first(self): |
|
3259 | def first(self): | |
3257 | if self._ascending: |
|
3260 | if self._ascending: | |
3258 | it = self.fastasc |
|
3261 | it = self.fastasc | |
3259 | else: |
|
3262 | else: | |
3260 | it = self.fastdesc |
|
3263 | it = self.fastdesc | |
3261 | if it is None: |
|
3264 | if it is None: | |
3262 | # we need to consume all and try again |
|
3265 | # we need to consume all and try again | |
3263 | for x in self._consumegen(): |
|
3266 | for x in self._consumegen(): | |
3264 | pass |
|
3267 | pass | |
3265 | return self.first() |
|
3268 | return self.first() | |
3266 | if self: |
|
3269 | if self: | |
3267 | return it().next() |
|
3270 | return it().next() | |
3268 | return None |
|
3271 | return None | |
3269 |
|
3272 | |||
3270 | def last(self): |
|
3273 | def last(self): | |
3271 | if self._ascending: |
|
3274 | if self._ascending: | |
3272 | it = self.fastdesc |
|
3275 | it = self.fastdesc | |
3273 | else: |
|
3276 | else: | |
3274 | it = self.fastasc |
|
3277 | it = self.fastasc | |
3275 | if it is None: |
|
3278 | if it is None: | |
3276 | # we need to consume all and try again |
|
3279 | # we need to consume all and try again | |
3277 | for x in self._consumegen(): |
|
3280 | for x in self._consumegen(): | |
3278 | pass |
|
3281 | pass | |
3279 | return self.first() |
|
3282 | return self.first() | |
3280 | if self: |
|
3283 | if self: | |
3281 | return it().next() |
|
3284 | return it().next() | |
3282 | return None |
|
3285 | return None | |
3283 |
|
3286 | |||
3284 | def __repr__(self): |
|
3287 | def __repr__(self): | |
3285 | d = {False: '-', True: '+'}[self._ascending] |
|
3288 | d = {False: '-', True: '+'}[self._ascending] | |
3286 | return '<%s%s>' % (type(self).__name__, d) |
|
3289 | return '<%s%s>' % (type(self).__name__, d) | |
3287 |
|
3290 | |||
3288 | class spanset(abstractsmartset): |
|
3291 | class spanset(abstractsmartset): | |
3289 | """Duck type for baseset class which represents a range of revisions and |
|
3292 | """Duck type for baseset class which represents a range of revisions and | |
3290 | can work lazily and without having all the range in memory |
|
3293 | can work lazily and without having all the range in memory | |
3291 |
|
3294 | |||
3292 | Note that spanset(x, y) behave almost like xrange(x, y) except for two |
|
3295 | Note that spanset(x, y) behave almost like xrange(x, y) except for two | |
3293 | notable points: |
|
3296 | notable points: | |
3294 | - when x < y it will be automatically descending, |
|
3297 | - when x < y it will be automatically descending, | |
3295 | - revision filtered with this repoview will be skipped. |
|
3298 | - revision filtered with this repoview will be skipped. | |
3296 |
|
3299 | |||
3297 | """ |
|
3300 | """ | |
3298 | def __init__(self, repo, start=0, end=None): |
|
3301 | def __init__(self, repo, start=0, end=None): | |
3299 | """ |
|
3302 | """ | |
3300 | start: first revision included the set |
|
3303 | start: first revision included the set | |
3301 | (default to 0) |
|
3304 | (default to 0) | |
3302 | end: first revision excluded (last+1) |
|
3305 | end: first revision excluded (last+1) | |
3303 | (default to len(repo) |
|
3306 | (default to len(repo) | |
3304 |
|
3307 | |||
3305 | Spanset will be descending if `end` < `start`. |
|
3308 | Spanset will be descending if `end` < `start`. | |
3306 | """ |
|
3309 | """ | |
3307 | if end is None: |
|
3310 | if end is None: | |
3308 | end = len(repo) |
|
3311 | end = len(repo) | |
3309 | self._ascending = start <= end |
|
3312 | self._ascending = start <= end | |
3310 | if not self._ascending: |
|
3313 | if not self._ascending: | |
3311 | start, end = end + 1, start +1 |
|
3314 | start, end = end + 1, start +1 | |
3312 | self._start = start |
|
3315 | self._start = start | |
3313 | self._end = end |
|
3316 | self._end = end | |
3314 | self._hiddenrevs = repo.changelog.filteredrevs |
|
3317 | self._hiddenrevs = repo.changelog.filteredrevs | |
3315 |
|
3318 | |||
3316 | def sort(self, reverse=False): |
|
3319 | def sort(self, reverse=False): | |
3317 | self._ascending = not reverse |
|
3320 | self._ascending = not reverse | |
3318 |
|
3321 | |||
3319 | def reverse(self): |
|
3322 | def reverse(self): | |
3320 | self._ascending = not self._ascending |
|
3323 | self._ascending = not self._ascending | |
3321 |
|
3324 | |||
3322 | def _iterfilter(self, iterrange): |
|
3325 | def _iterfilter(self, iterrange): | |
3323 | s = self._hiddenrevs |
|
3326 | s = self._hiddenrevs | |
3324 | for r in iterrange: |
|
3327 | for r in iterrange: | |
3325 | if r not in s: |
|
3328 | if r not in s: | |
3326 | yield r |
|
3329 | yield r | |
3327 |
|
3330 | |||
3328 | def __iter__(self): |
|
3331 | def __iter__(self): | |
3329 | if self._ascending: |
|
3332 | if self._ascending: | |
3330 | return self.fastasc() |
|
3333 | return self.fastasc() | |
3331 | else: |
|
3334 | else: | |
3332 | return self.fastdesc() |
|
3335 | return self.fastdesc() | |
3333 |
|
3336 | |||
3334 | def fastasc(self): |
|
3337 | def fastasc(self): | |
3335 | iterrange = xrange(self._start, self._end) |
|
3338 | iterrange = xrange(self._start, self._end) | |
3336 | if self._hiddenrevs: |
|
3339 | if self._hiddenrevs: | |
3337 | return self._iterfilter(iterrange) |
|
3340 | return self._iterfilter(iterrange) | |
3338 | return iter(iterrange) |
|
3341 | return iter(iterrange) | |
3339 |
|
3342 | |||
3340 | def fastdesc(self): |
|
3343 | def fastdesc(self): | |
3341 | iterrange = xrange(self._end - 1, self._start - 1, -1) |
|
3344 | iterrange = xrange(self._end - 1, self._start - 1, -1) | |
3342 | if self._hiddenrevs: |
|
3345 | if self._hiddenrevs: | |
3343 | return self._iterfilter(iterrange) |
|
3346 | return self._iterfilter(iterrange) | |
3344 | return iter(iterrange) |
|
3347 | return iter(iterrange) | |
3345 |
|
3348 | |||
3346 | def __contains__(self, rev): |
|
3349 | def __contains__(self, rev): | |
3347 | hidden = self._hiddenrevs |
|
3350 | hidden = self._hiddenrevs | |
3348 | return ((self._start <= rev < self._end) |
|
3351 | return ((self._start <= rev < self._end) | |
3349 | and not (hidden and rev in hidden)) |
|
3352 | and not (hidden and rev in hidden)) | |
3350 |
|
3353 | |||
3351 | def __nonzero__(self): |
|
3354 | def __nonzero__(self): | |
3352 | for r in self: |
|
3355 | for r in self: | |
3353 | return True |
|
3356 | return True | |
3354 | return False |
|
3357 | return False | |
3355 |
|
3358 | |||
3356 | def __len__(self): |
|
3359 | def __len__(self): | |
3357 | if not self._hiddenrevs: |
|
3360 | if not self._hiddenrevs: | |
3358 | return abs(self._end - self._start) |
|
3361 | return abs(self._end - self._start) | |
3359 | else: |
|
3362 | else: | |
3360 | count = 0 |
|
3363 | count = 0 | |
3361 | start = self._start |
|
3364 | start = self._start | |
3362 | end = self._end |
|
3365 | end = self._end | |
3363 | for rev in self._hiddenrevs: |
|
3366 | for rev in self._hiddenrevs: | |
3364 | if (end < rev <= start) or (start <= rev < end): |
|
3367 | if (end < rev <= start) or (start <= rev < end): | |
3365 | count += 1 |
|
3368 | count += 1 | |
3366 | return abs(self._end - self._start) - count |
|
3369 | return abs(self._end - self._start) - count | |
3367 |
|
3370 | |||
3368 | def isascending(self): |
|
3371 | def isascending(self): | |
3369 | return self._ascending |
|
3372 | return self._ascending | |
3370 |
|
3373 | |||
3371 | def isdescending(self): |
|
3374 | def isdescending(self): | |
3372 | return not self._ascending |
|
3375 | return not self._ascending | |
3373 |
|
3376 | |||
3374 | def first(self): |
|
3377 | def first(self): | |
3375 | if self._ascending: |
|
3378 | if self._ascending: | |
3376 | it = self.fastasc |
|
3379 | it = self.fastasc | |
3377 | else: |
|
3380 | else: | |
3378 | it = self.fastdesc |
|
3381 | it = self.fastdesc | |
3379 | for x in it(): |
|
3382 | for x in it(): | |
3380 | return x |
|
3383 | return x | |
3381 | return None |
|
3384 | return None | |
3382 |
|
3385 | |||
3383 | def last(self): |
|
3386 | def last(self): | |
3384 | if self._ascending: |
|
3387 | if self._ascending: | |
3385 | it = self.fastdesc |
|
3388 | it = self.fastdesc | |
3386 | else: |
|
3389 | else: | |
3387 | it = self.fastasc |
|
3390 | it = self.fastasc | |
3388 | for x in it(): |
|
3391 | for x in it(): | |
3389 | return x |
|
3392 | return x | |
3390 | return None |
|
3393 | return None | |
3391 |
|
3394 | |||
3392 | def __repr__(self): |
|
3395 | def __repr__(self): | |
3393 | d = {False: '-', True: '+'}[self._ascending] |
|
3396 | d = {False: '-', True: '+'}[self._ascending] | |
3394 | return '<%s%s %d:%d>' % (type(self).__name__, d, |
|
3397 | return '<%s%s %d:%d>' % (type(self).__name__, d, | |
3395 | self._start, self._end - 1) |
|
3398 | self._start, self._end - 1) | |
3396 |
|
3399 | |||
3397 | class fullreposet(spanset): |
|
3400 | class fullreposet(spanset): | |
3398 | """a set containing all revisions in the repo |
|
3401 | """a set containing all revisions in the repo | |
3399 |
|
3402 | |||
3400 | This class exists to host special optimization and magic to handle virtual |
|
3403 | This class exists to host special optimization and magic to handle virtual | |
3401 | revisions such as "null". |
|
3404 | revisions such as "null". | |
3402 | """ |
|
3405 | """ | |
3403 |
|
3406 | |||
3404 | def __init__(self, repo): |
|
3407 | def __init__(self, repo): | |
3405 | super(fullreposet, self).__init__(repo) |
|
3408 | super(fullreposet, self).__init__(repo) | |
3406 |
|
3409 | |||
3407 | def __contains__(self, rev): |
|
3410 | def __contains__(self, rev): | |
3408 | # assumes the given rev is valid |
|
3411 | # assumes the given rev is valid | |
3409 | hidden = self._hiddenrevs |
|
3412 | hidden = self._hiddenrevs | |
3410 | return not (hidden and rev in hidden) |
|
3413 | return not (hidden and rev in hidden) | |
3411 |
|
3414 | |||
3412 | def __and__(self, other): |
|
3415 | def __and__(self, other): | |
3413 | """As self contains the whole repo, all of the other set should also be |
|
3416 | """As self contains the whole repo, all of the other set should also be | |
3414 | in self. Therefore `self & other = other`. |
|
3417 | in self. Therefore `self & other = other`. | |
3415 |
|
3418 | |||
3416 | This boldly assumes the other contains valid revs only. |
|
3419 | This boldly assumes the other contains valid revs only. | |
3417 | """ |
|
3420 | """ | |
3418 | # other not a smartset, make is so |
|
3421 | # other not a smartset, make is so | |
3419 | if not util.safehasattr(other, 'isascending'): |
|
3422 | if not util.safehasattr(other, 'isascending'): | |
3420 | # filter out hidden revision |
|
3423 | # filter out hidden revision | |
3421 | # (this boldly assumes all smartset are pure) |
|
3424 | # (this boldly assumes all smartset are pure) | |
3422 | # |
|
3425 | # | |
3423 | # `other` was used with "&", let's assume this is a set like |
|
3426 | # `other` was used with "&", let's assume this is a set like | |
3424 | # object. |
|
3427 | # object. | |
3425 | other = baseset(other - self._hiddenrevs) |
|
3428 | other = baseset(other - self._hiddenrevs) | |
3426 |
|
3429 | |||
3427 | other.sort(reverse=self.isdescending()) |
|
3430 | other.sort(reverse=self.isdescending()) | |
3428 | return other |
|
3431 | return other | |
3429 |
|
3432 | |||
3430 | def prettyformatset(revs): |
|
3433 | def prettyformatset(revs): | |
3431 | lines = [] |
|
3434 | lines = [] | |
3432 | rs = repr(revs) |
|
3435 | rs = repr(revs) | |
3433 | p = 0 |
|
3436 | p = 0 | |
3434 | while p < len(rs): |
|
3437 | while p < len(rs): | |
3435 | q = rs.find('<', p + 1) |
|
3438 | q = rs.find('<', p + 1) | |
3436 | if q < 0: |
|
3439 | if q < 0: | |
3437 | q = len(rs) |
|
3440 | q = len(rs) | |
3438 | l = rs.count('<', 0, p) - rs.count('>', 0, p) |
|
3441 | l = rs.count('<', 0, p) - rs.count('>', 0, p) | |
3439 | assert l >= 0 |
|
3442 | assert l >= 0 | |
3440 | lines.append((l, rs[p:q].rstrip())) |
|
3443 | lines.append((l, rs[p:q].rstrip())) | |
3441 | p = q |
|
3444 | p = q | |
3442 | return '\n'.join(' ' * l + s for l, s in lines) |
|
3445 | return '\n'.join(' ' * l + s for l, s in lines) | |
3443 |
|
3446 | |||
3444 | # tell hggettext to extract docstrings from these functions: |
|
3447 | # tell hggettext to extract docstrings from these functions: | |
3445 | i18nfunctions = symbols.values() |
|
3448 | i18nfunctions = symbols.values() |
@@ -1,1601 +1,1619 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 |
|
91 | |||
91 | $ hg clone --quiet -U -r 7 . ../remote1 |
|
92 | $ hg clone --quiet -U -r 7 . ../remote1 | |
92 | $ hg clone --quiet -U -r 8 . ../remote2 |
|
93 | $ hg clone --quiet -U -r 8 . ../remote2 | |
93 | $ echo "[paths]" >> .hg/hgrc |
|
94 | $ echo "[paths]" >> .hg/hgrc | |
94 | $ echo "default = ../remote1" >> .hg/hgrc |
|
95 | $ echo "default = ../remote1" >> .hg/hgrc | |
95 |
|
96 | |||
96 | trivial |
|
97 | trivial | |
97 |
|
98 | |||
98 | $ try 0:1 |
|
99 | $ try 0:1 | |
99 | (range |
|
100 | (range | |
100 | ('symbol', '0') |
|
101 | ('symbol', '0') | |
101 | ('symbol', '1')) |
|
102 | ('symbol', '1')) | |
102 | * set: |
|
103 | * set: | |
103 | <spanset+ 0:1> |
|
104 | <spanset+ 0:1> | |
104 | 0 |
|
105 | 0 | |
105 | 1 |
|
106 | 1 | |
106 | $ try 3::6 |
|
107 | $ try 3::6 | |
107 | (dagrange |
|
108 | (dagrange | |
108 | ('symbol', '3') |
|
109 | ('symbol', '3') | |
109 | ('symbol', '6')) |
|
110 | ('symbol', '6')) | |
110 | * set: |
|
111 | * set: | |
111 | <baseset [3, 5, 6]> |
|
112 | <baseset [3, 5, 6]> | |
112 | 3 |
|
113 | 3 | |
113 | 5 |
|
114 | 5 | |
114 | 6 |
|
115 | 6 | |
115 | $ try '0|1|2' |
|
116 | $ try '0|1|2' | |
116 | (or |
|
117 | (or | |
117 | (or |
|
118 | (or | |
118 | ('symbol', '0') |
|
119 | ('symbol', '0') | |
119 | ('symbol', '1')) |
|
120 | ('symbol', '1')) | |
120 | ('symbol', '2')) |
|
121 | ('symbol', '2')) | |
121 | * set: |
|
122 | * set: | |
122 | <addset |
|
123 | <addset | |
123 | <addset |
|
124 | <addset | |
124 | <baseset [0]>, |
|
125 | <baseset [0]>, | |
125 | <baseset [1]>>, |
|
126 | <baseset [1]>>, | |
126 | <baseset [2]>> |
|
127 | <baseset [2]>> | |
127 | 0 |
|
128 | 0 | |
128 | 1 |
|
129 | 1 | |
129 | 2 |
|
130 | 2 | |
130 |
|
131 | |||
131 | names that should work without quoting |
|
132 | names that should work without quoting | |
132 |
|
133 | |||
133 | $ try a |
|
134 | $ try a | |
134 | ('symbol', 'a') |
|
135 | ('symbol', 'a') | |
135 | * set: |
|
136 | * set: | |
136 | <baseset [0]> |
|
137 | <baseset [0]> | |
137 | 0 |
|
138 | 0 | |
138 | $ try b-a |
|
139 | $ try b-a | |
139 | (minus |
|
140 | (minus | |
140 | ('symbol', 'b') |
|
141 | ('symbol', 'b') | |
141 | ('symbol', 'a')) |
|
142 | ('symbol', 'a')) | |
142 | * set: |
|
143 | * set: | |
143 | <filteredset |
|
144 | <filteredset | |
144 | <baseset [1]>> |
|
145 | <baseset [1]>> | |
145 | 1 |
|
146 | 1 | |
146 | $ try _a_b_c_ |
|
147 | $ try _a_b_c_ | |
147 | ('symbol', '_a_b_c_') |
|
148 | ('symbol', '_a_b_c_') | |
148 | * set: |
|
149 | * set: | |
149 | <baseset [6]> |
|
150 | <baseset [6]> | |
150 | 6 |
|
151 | 6 | |
151 | $ try _a_b_c_-a |
|
152 | $ try _a_b_c_-a | |
152 | (minus |
|
153 | (minus | |
153 | ('symbol', '_a_b_c_') |
|
154 | ('symbol', '_a_b_c_') | |
154 | ('symbol', 'a')) |
|
155 | ('symbol', 'a')) | |
155 | * set: |
|
156 | * set: | |
156 | <filteredset |
|
157 | <filteredset | |
157 | <baseset [6]>> |
|
158 | <baseset [6]>> | |
158 | 6 |
|
159 | 6 | |
159 | $ try .a.b.c. |
|
160 | $ try .a.b.c. | |
160 | ('symbol', '.a.b.c.') |
|
161 | ('symbol', '.a.b.c.') | |
161 | * set: |
|
162 | * set: | |
162 | <baseset [7]> |
|
163 | <baseset [7]> | |
163 | 7 |
|
164 | 7 | |
164 | $ try .a.b.c.-a |
|
165 | $ try .a.b.c.-a | |
165 | (minus |
|
166 | (minus | |
166 | ('symbol', '.a.b.c.') |
|
167 | ('symbol', '.a.b.c.') | |
167 | ('symbol', 'a')) |
|
168 | ('symbol', 'a')) | |
168 | * set: |
|
169 | * set: | |
169 | <filteredset |
|
170 | <filteredset | |
170 | <baseset [7]>> |
|
171 | <baseset [7]>> | |
171 | 7 |
|
172 | 7 | |
172 | $ try -- '-a-b-c-' # complains |
|
173 | $ try -- '-a-b-c-' # complains | |
173 | hg: parse error at 7: not a prefix: end |
|
174 | hg: parse error at 7: not a prefix: end | |
174 | [255] |
|
175 | [255] | |
175 | $ log -a-b-c- # succeeds with fallback |
|
176 | $ log -a-b-c- # succeeds with fallback | |
176 | 4 |
|
177 | 4 | |
177 |
|
178 | |||
178 | $ try -- -a-b-c--a # complains |
|
179 | $ try -- -a-b-c--a # complains | |
179 | (minus |
|
180 | (minus | |
180 | (minus |
|
181 | (minus | |
181 | (minus |
|
182 | (minus | |
182 | (negate |
|
183 | (negate | |
183 | ('symbol', 'a')) |
|
184 | ('symbol', 'a')) | |
184 | ('symbol', 'b')) |
|
185 | ('symbol', 'b')) | |
185 | ('symbol', 'c')) |
|
186 | ('symbol', 'c')) | |
186 | (negate |
|
187 | (negate | |
187 | ('symbol', 'a'))) |
|
188 | ('symbol', 'a'))) | |
188 | abort: unknown revision '-a'! |
|
189 | abort: unknown revision '-a'! | |
189 | [255] |
|
190 | [255] | |
190 | $ try Γ© |
|
191 | $ try Γ© | |
191 | ('symbol', '\xc3\xa9') |
|
192 | ('symbol', '\xc3\xa9') | |
192 | * set: |
|
193 | * set: | |
193 | <baseset [9]> |
|
194 | <baseset [9]> | |
194 | 9 |
|
195 | 9 | |
195 |
|
196 | |||
196 | no quoting needed |
|
197 | no quoting needed | |
197 |
|
198 | |||
198 | $ log ::a-b-c- |
|
199 | $ log ::a-b-c- | |
199 | 0 |
|
200 | 0 | |
200 | 1 |
|
201 | 1 | |
201 | 2 |
|
202 | 2 | |
202 |
|
203 | |||
203 | quoting needed |
|
204 | quoting needed | |
204 |
|
205 | |||
205 | $ try '"-a-b-c-"-a' |
|
206 | $ try '"-a-b-c-"-a' | |
206 | (minus |
|
207 | (minus | |
207 | ('string', '-a-b-c-') |
|
208 | ('string', '-a-b-c-') | |
208 | ('symbol', 'a')) |
|
209 | ('symbol', 'a')) | |
209 | * set: |
|
210 | * set: | |
210 | <filteredset |
|
211 | <filteredset | |
211 | <baseset [4]>> |
|
212 | <baseset [4]>> | |
212 | 4 |
|
213 | 4 | |
213 |
|
214 | |||
214 | $ log '1 or 2' |
|
215 | $ log '1 or 2' | |
215 | 1 |
|
216 | 1 | |
216 | 2 |
|
217 | 2 | |
217 | $ log '1|2' |
|
218 | $ log '1|2' | |
218 | 1 |
|
219 | 1 | |
219 | 2 |
|
220 | 2 | |
220 | $ log '1 and 2' |
|
221 | $ log '1 and 2' | |
221 | $ log '1&2' |
|
222 | $ log '1&2' | |
222 | $ try '1&2|3' # precedence - and is higher |
|
223 | $ try '1&2|3' # precedence - and is higher | |
223 | (or |
|
224 | (or | |
224 | (and |
|
225 | (and | |
225 | ('symbol', '1') |
|
226 | ('symbol', '1') | |
226 | ('symbol', '2')) |
|
227 | ('symbol', '2')) | |
227 | ('symbol', '3')) |
|
228 | ('symbol', '3')) | |
228 | * set: |
|
229 | * set: | |
229 | <addset |
|
230 | <addset | |
230 | <baseset []>, |
|
231 | <baseset []>, | |
231 | <baseset [3]>> |
|
232 | <baseset [3]>> | |
232 | 3 |
|
233 | 3 | |
233 | $ try '1|2&3' |
|
234 | $ try '1|2&3' | |
234 | (or |
|
235 | (or | |
235 | ('symbol', '1') |
|
236 | ('symbol', '1') | |
236 | (and |
|
237 | (and | |
237 | ('symbol', '2') |
|
238 | ('symbol', '2') | |
238 | ('symbol', '3'))) |
|
239 | ('symbol', '3'))) | |
239 | * set: |
|
240 | * set: | |
240 | <addset |
|
241 | <addset | |
241 | <baseset [1]>, |
|
242 | <baseset [1]>, | |
242 | <baseset []>> |
|
243 | <baseset []>> | |
243 | 1 |
|
244 | 1 | |
244 | $ try '1&2&3' # associativity |
|
245 | $ try '1&2&3' # associativity | |
245 | (and |
|
246 | (and | |
246 | (and |
|
247 | (and | |
247 | ('symbol', '1') |
|
248 | ('symbol', '1') | |
248 | ('symbol', '2')) |
|
249 | ('symbol', '2')) | |
249 | ('symbol', '3')) |
|
250 | ('symbol', '3')) | |
250 | * set: |
|
251 | * set: | |
251 | <baseset []> |
|
252 | <baseset []> | |
252 | $ try '1|(2|3)' |
|
253 | $ try '1|(2|3)' | |
253 | (or |
|
254 | (or | |
254 | ('symbol', '1') |
|
255 | ('symbol', '1') | |
255 | (group |
|
256 | (group | |
256 | (or |
|
257 | (or | |
257 | ('symbol', '2') |
|
258 | ('symbol', '2') | |
258 | ('symbol', '3')))) |
|
259 | ('symbol', '3')))) | |
259 | * set: |
|
260 | * set: | |
260 | <addset |
|
261 | <addset | |
261 | <baseset [1]>, |
|
262 | <baseset [1]>, | |
262 | <addset |
|
263 | <addset | |
263 | <baseset [2]>, |
|
264 | <baseset [2]>, | |
264 | <baseset [3]>>> |
|
265 | <baseset [3]>>> | |
265 | 1 |
|
266 | 1 | |
266 | 2 |
|
267 | 2 | |
267 | 3 |
|
268 | 3 | |
268 | $ log '1.0' # tag |
|
269 | $ log '1.0' # tag | |
269 | 6 |
|
270 | 6 | |
270 | $ log 'a' # branch |
|
271 | $ log 'a' # branch | |
271 | 0 |
|
272 | 0 | |
272 | $ log '2785f51ee' |
|
273 | $ log '2785f51ee' | |
273 | 0 |
|
274 | 0 | |
274 | $ log 'date(2005)' |
|
275 | $ log 'date(2005)' | |
275 | 4 |
|
276 | 4 | |
276 | $ log 'date(this is a test)' |
|
277 | $ log 'date(this is a test)' | |
277 | hg: parse error at 10: unexpected token: symbol |
|
278 | hg: parse error at 10: unexpected token: symbol | |
278 | [255] |
|
279 | [255] | |
279 | $ log 'date()' |
|
280 | $ log 'date()' | |
280 | hg: parse error: date requires a string |
|
281 | hg: parse error: date requires a string | |
281 | [255] |
|
282 | [255] | |
282 | $ log 'date' |
|
283 | $ log 'date' | |
283 | hg: parse error: can't use date here |
|
284 | hg: parse error: can't use date here | |
284 | [255] |
|
285 | [255] | |
285 | $ log 'date(' |
|
286 | $ log 'date(' | |
286 | hg: parse error at 5: not a prefix: end |
|
287 | hg: parse error at 5: not a prefix: end | |
287 | [255] |
|
288 | [255] | |
288 | $ log 'date(tip)' |
|
289 | $ log 'date(tip)' | |
289 | abort: invalid date: 'tip' |
|
290 | abort: invalid date: 'tip' | |
290 | [255] |
|
291 | [255] | |
291 | $ log '"date"' |
|
292 | $ log '"date"' | |
292 | abort: unknown revision 'date'! |
|
293 | abort: unknown revision 'date'! | |
293 | [255] |
|
294 | [255] | |
294 | $ log 'date(2005) and 1::' |
|
295 | $ log 'date(2005) and 1::' | |
295 | 4 |
|
296 | 4 | |
296 |
|
297 | |||
297 | ancestor can accept 0 or more arguments |
|
298 | ancestor can accept 0 or more arguments | |
298 |
|
299 | |||
299 | $ log 'ancestor()' |
|
300 | $ log 'ancestor()' | |
300 | $ log 'ancestor(1)' |
|
301 | $ log 'ancestor(1)' | |
301 | 1 |
|
302 | 1 | |
302 | $ log 'ancestor(4,5)' |
|
303 | $ log 'ancestor(4,5)' | |
303 | 1 |
|
304 | 1 | |
304 | $ log 'ancestor(4,5) and 4' |
|
305 | $ log 'ancestor(4,5) and 4' | |
305 | $ log 'ancestor(0,0,1,3)' |
|
306 | $ log 'ancestor(0,0,1,3)' | |
306 | 0 |
|
307 | 0 | |
307 | $ log 'ancestor(3,1,5,3,5,1)' |
|
308 | $ log 'ancestor(3,1,5,3,5,1)' | |
308 | 1 |
|
309 | 1 | |
309 | $ log 'ancestor(0,1,3,5)' |
|
310 | $ log 'ancestor(0,1,3,5)' | |
310 | 0 |
|
311 | 0 | |
311 | $ log 'ancestor(1,2,3,4,5)' |
|
312 | $ log 'ancestor(1,2,3,4,5)' | |
312 | 1 |
|
313 | 1 | |
313 | $ log 'ancestors(5)' |
|
314 | $ log 'ancestors(5)' | |
314 | 0 |
|
315 | 0 | |
315 | 1 |
|
316 | 1 | |
316 | 3 |
|
317 | 3 | |
317 | 5 |
|
318 | 5 | |
318 | $ log 'ancestor(ancestors(5))' |
|
319 | $ log 'ancestor(ancestors(5))' | |
319 | 0 |
|
320 | 0 | |
320 | $ log 'author(bob)' |
|
321 | $ log 'author(bob)' | |
321 | 2 |
|
322 | 2 | |
322 | $ log 'author("re:bob|test")' |
|
323 | $ log 'author("re:bob|test")' | |
323 | 0 |
|
324 | 0 | |
324 | 1 |
|
325 | 1 | |
325 | 2 |
|
326 | 2 | |
326 | 3 |
|
327 | 3 | |
327 | 4 |
|
328 | 4 | |
328 | 5 |
|
329 | 5 | |
329 | 6 |
|
330 | 6 | |
330 | 7 |
|
331 | 7 | |
331 | 8 |
|
332 | 8 | |
332 | 9 |
|
333 | 9 | |
333 | $ log 'branch(Γ©)' |
|
334 | $ log 'branch(Γ©)' | |
334 | 8 |
|
335 | 8 | |
335 | 9 |
|
336 | 9 | |
336 | $ log 'branch(a)' |
|
337 | $ log 'branch(a)' | |
337 | 0 |
|
338 | 0 | |
338 | $ hg log -r 'branch("re:a")' --template '{rev} {branch}\n' |
|
339 | $ hg log -r 'branch("re:a")' --template '{rev} {branch}\n' | |
339 | 0 a |
|
340 | 0 a | |
340 | 2 a-b-c- |
|
341 | 2 a-b-c- | |
341 | 3 +a+b+c+ |
|
342 | 3 +a+b+c+ | |
342 | 4 -a-b-c- |
|
343 | 4 -a-b-c- | |
343 | 5 !a/b/c/ |
|
344 | 5 !a/b/c/ | |
344 | 6 _a_b_c_ |
|
345 | 6 _a_b_c_ | |
345 | 7 .a.b.c. |
|
346 | 7 .a.b.c. | |
346 | $ log 'children(ancestor(4,5))' |
|
347 | $ log 'children(ancestor(4,5))' | |
347 | 2 |
|
348 | 2 | |
348 | 3 |
|
349 | 3 | |
349 | $ log 'closed()' |
|
350 | $ log 'closed()' | |
350 | $ log 'contains(a)' |
|
351 | $ log 'contains(a)' | |
351 | 0 |
|
352 | 0 | |
352 | 1 |
|
353 | 1 | |
353 | 3 |
|
354 | 3 | |
354 | 5 |
|
355 | 5 | |
355 | $ log 'contains("../repo/a")' |
|
356 | $ log 'contains("../repo/a")' | |
356 | 0 |
|
357 | 0 | |
357 | 1 |
|
358 | 1 | |
358 | 3 |
|
359 | 3 | |
359 | 5 |
|
360 | 5 | |
360 | $ log 'desc(B)' |
|
361 | $ log 'desc(B)' | |
361 | 5 |
|
362 | 5 | |
362 | $ log 'descendants(2 or 3)' |
|
363 | $ log 'descendants(2 or 3)' | |
363 | 2 |
|
364 | 2 | |
364 | 3 |
|
365 | 3 | |
365 | 4 |
|
366 | 4 | |
366 | 5 |
|
367 | 5 | |
367 | 6 |
|
368 | 6 | |
368 | 7 |
|
369 | 7 | |
369 | 8 |
|
370 | 8 | |
370 | 9 |
|
371 | 9 | |
371 | $ log 'file("b*")' |
|
372 | $ log 'file("b*")' | |
372 | 1 |
|
373 | 1 | |
373 | 4 |
|
374 | 4 | |
374 | $ log 'filelog("b")' |
|
375 | $ log 'filelog("b")' | |
375 | 1 |
|
376 | 1 | |
376 | 4 |
|
377 | 4 | |
377 | $ log 'filelog("../repo/b")' |
|
378 | $ log 'filelog("../repo/b")' | |
378 | 1 |
|
379 | 1 | |
379 | 4 |
|
380 | 4 | |
380 | $ log 'follow()' |
|
381 | $ log 'follow()' | |
381 | 0 |
|
382 | 0 | |
382 | 1 |
|
383 | 1 | |
383 | 2 |
|
384 | 2 | |
384 | 4 |
|
385 | 4 | |
385 | 8 |
|
386 | 8 | |
386 | 9 |
|
387 | 9 | |
387 | $ log 'grep("issue\d+")' |
|
388 | $ log 'grep("issue\d+")' | |
388 | 6 |
|
389 | 6 | |
389 | $ try 'grep("(")' # invalid regular expression |
|
390 | $ try 'grep("(")' # invalid regular expression | |
390 | (func |
|
391 | (func | |
391 | ('symbol', 'grep') |
|
392 | ('symbol', 'grep') | |
392 | ('string', '(')) |
|
393 | ('string', '(')) | |
393 | hg: parse error: invalid match pattern: unbalanced parenthesis |
|
394 | hg: parse error: invalid match pattern: unbalanced parenthesis | |
394 | [255] |
|
395 | [255] | |
395 | $ try 'grep("\bissue\d+")' |
|
396 | $ try 'grep("\bissue\d+")' | |
396 | (func |
|
397 | (func | |
397 | ('symbol', 'grep') |
|
398 | ('symbol', 'grep') | |
398 | ('string', '\x08issue\\d+')) |
|
399 | ('string', '\x08issue\\d+')) | |
399 | * set: |
|
400 | * set: | |
400 | <filteredset |
|
401 | <filteredset | |
401 | <fullreposet+ 0:9>> |
|
402 | <fullreposet+ 0:9>> | |
402 | $ try 'grep(r"\bissue\d+")' |
|
403 | $ try 'grep(r"\bissue\d+")' | |
403 | (func |
|
404 | (func | |
404 | ('symbol', 'grep') |
|
405 | ('symbol', 'grep') | |
405 | ('string', '\\bissue\\d+')) |
|
406 | ('string', '\\bissue\\d+')) | |
406 | * set: |
|
407 | * set: | |
407 | <filteredset |
|
408 | <filteredset | |
408 | <fullreposet+ 0:9>> |
|
409 | <fullreposet+ 0:9>> | |
409 | 6 |
|
410 | 6 | |
410 | $ try 'grep(r"\")' |
|
411 | $ try 'grep(r"\")' | |
411 | hg: parse error at 7: unterminated string |
|
412 | hg: parse error at 7: unterminated string | |
412 | [255] |
|
413 | [255] | |
413 | $ log 'head()' |
|
414 | $ log 'head()' | |
414 | 0 |
|
415 | 0 | |
415 | 1 |
|
416 | 1 | |
416 | 2 |
|
417 | 2 | |
417 | 3 |
|
418 | 3 | |
418 | 4 |
|
419 | 4 | |
419 | 5 |
|
420 | 5 | |
420 | 6 |
|
421 | 6 | |
421 | 7 |
|
422 | 7 | |
422 | 9 |
|
423 | 9 | |
423 | $ log 'heads(6::)' |
|
424 | $ log 'heads(6::)' | |
424 | 7 |
|
425 | 7 | |
425 | $ log 'keyword(issue)' |
|
426 | $ log 'keyword(issue)' | |
426 | 6 |
|
427 | 6 | |
427 | $ log 'keyword("test a")' |
|
428 | $ log 'keyword("test a")' | |
428 | $ log 'limit(head(), 1)' |
|
429 | $ log 'limit(head(), 1)' | |
429 | 0 |
|
430 | 0 | |
430 | $ log 'matching(6)' |
|
431 | $ log 'matching(6)' | |
431 | 6 |
|
432 | 6 | |
432 | $ log 'matching(6:7, "phase parents user date branch summary files description substate")' |
|
433 | $ log 'matching(6:7, "phase parents user date branch summary files description substate")' | |
433 | 6 |
|
434 | 6 | |
434 | 7 |
|
435 | 7 | |
435 |
|
436 | |||
436 | Testing min and max |
|
437 | Testing min and max | |
437 |
|
438 | |||
438 | max: simple |
|
439 | max: simple | |
439 |
|
440 | |||
440 | $ log 'max(contains(a))' |
|
441 | $ log 'max(contains(a))' | |
441 | 5 |
|
442 | 5 | |
442 |
|
443 | |||
443 | max: simple on unordered set) |
|
444 | max: simple on unordered set) | |
444 |
|
445 | |||
445 | $ log 'max((4+0+2+5+7) and contains(a))' |
|
446 | $ log 'max((4+0+2+5+7) and contains(a))' | |
446 | 5 |
|
447 | 5 | |
447 |
|
448 | |||
448 | max: no result |
|
449 | max: no result | |
449 |
|
450 | |||
450 | $ log 'max(contains(stringthatdoesnotappearanywhere))' |
|
451 | $ log 'max(contains(stringthatdoesnotappearanywhere))' | |
451 |
|
452 | |||
452 | max: no result on unordered set |
|
453 | max: no result on unordered set | |
453 |
|
454 | |||
454 | $ log 'max((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))' |
|
455 | $ log 'max((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))' | |
455 |
|
456 | |||
456 | min: simple |
|
457 | min: simple | |
457 |
|
458 | |||
458 | $ log 'min(contains(a))' |
|
459 | $ log 'min(contains(a))' | |
459 | 0 |
|
460 | 0 | |
460 |
|
461 | |||
461 | min: simple on unordered set |
|
462 | min: simple on unordered set | |
462 |
|
463 | |||
463 | $ log 'min((4+0+2+5+7) and contains(a))' |
|
464 | $ log 'min((4+0+2+5+7) and contains(a))' | |
464 | 0 |
|
465 | 0 | |
465 |
|
466 | |||
466 | min: empty |
|
467 | min: empty | |
467 |
|
468 | |||
468 | $ log 'min(contains(stringthatdoesnotappearanywhere))' |
|
469 | $ log 'min(contains(stringthatdoesnotappearanywhere))' | |
469 |
|
470 | |||
470 | min: empty on unordered set |
|
471 | min: empty on unordered set | |
471 |
|
472 | |||
472 | $ log 'min((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))' |
|
473 | $ log 'min((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))' | |
473 |
|
474 | |||
474 |
|
475 | |||
475 | $ log 'merge()' |
|
476 | $ log 'merge()' | |
476 | 6 |
|
477 | 6 | |
477 | $ log 'branchpoint()' |
|
478 | $ log 'branchpoint()' | |
478 | 1 |
|
479 | 1 | |
479 | 4 |
|
480 | 4 | |
480 | $ log 'modifies(b)' |
|
481 | $ log 'modifies(b)' | |
481 | 4 |
|
482 | 4 | |
482 | $ log 'modifies("path:b")' |
|
483 | $ log 'modifies("path:b")' | |
483 | 4 |
|
484 | 4 | |
484 | $ log 'modifies("*")' |
|
485 | $ log 'modifies("*")' | |
485 | 4 |
|
486 | 4 | |
486 | 6 |
|
487 | 6 | |
487 | $ log 'modifies("set:modified()")' |
|
488 | $ log 'modifies("set:modified()")' | |
488 | 4 |
|
489 | 4 | |
489 | $ log 'id(5)' |
|
490 | $ log 'id(5)' | |
490 | 2 |
|
491 | 2 | |
491 | $ log 'only(9)' |
|
492 | $ log 'only(9)' | |
492 | 8 |
|
493 | 8 | |
493 | 9 |
|
494 | 9 | |
494 | $ log 'only(8)' |
|
495 | $ log 'only(8)' | |
495 | 8 |
|
496 | 8 | |
496 | $ log 'only(9, 5)' |
|
497 | $ log 'only(9, 5)' | |
497 | 2 |
|
498 | 2 | |
498 | 4 |
|
499 | 4 | |
499 | 8 |
|
500 | 8 | |
500 | 9 |
|
501 | 9 | |
501 | $ log 'only(7 + 9, 5 + 2)' |
|
502 | $ log 'only(7 + 9, 5 + 2)' | |
502 | 4 |
|
503 | 4 | |
503 | 6 |
|
504 | 6 | |
504 | 7 |
|
505 | 7 | |
505 | 8 |
|
506 | 8 | |
506 | 9 |
|
507 | 9 | |
507 |
|
508 | |||
508 | Test empty set input |
|
509 | Test empty set input | |
509 | $ log 'only(p2())' |
|
510 | $ log 'only(p2())' | |
510 | $ log 'only(p1(), p2())' |
|
511 | $ log 'only(p1(), p2())' | |
511 | 0 |
|
512 | 0 | |
512 | 1 |
|
513 | 1 | |
513 | 2 |
|
514 | 2 | |
514 | 4 |
|
515 | 4 | |
515 | 8 |
|
516 | 8 | |
516 | 9 |
|
517 | 9 | |
517 |
|
518 | |||
518 | Test '%' operator |
|
519 | Test '%' operator | |
519 |
|
520 | |||
520 | $ log '9%' |
|
521 | $ log '9%' | |
521 | 8 |
|
522 | 8 | |
522 | 9 |
|
523 | 9 | |
523 | $ log '9%5' |
|
524 | $ log '9%5' | |
524 | 2 |
|
525 | 2 | |
525 | 4 |
|
526 | 4 | |
526 | 8 |
|
527 | 8 | |
527 | 9 |
|
528 | 9 | |
528 | $ log '(7 + 9)%(5 + 2)' |
|
529 | $ log '(7 + 9)%(5 + 2)' | |
529 | 4 |
|
530 | 4 | |
530 | 6 |
|
531 | 6 | |
531 | 7 |
|
532 | 7 | |
532 | 8 |
|
533 | 8 | |
533 | 9 |
|
534 | 9 | |
534 |
|
535 | |||
535 | Test the order of operations |
|
536 | Test the order of operations | |
536 |
|
537 | |||
537 | $ log '7 + 9%5 + 2' |
|
538 | $ log '7 + 9%5 + 2' | |
538 | 7 |
|
539 | 7 | |
539 | 2 |
|
540 | 2 | |
540 | 4 |
|
541 | 4 | |
541 | 8 |
|
542 | 8 | |
542 | 9 |
|
543 | 9 | |
543 |
|
544 | |||
544 | Test explicit numeric revision |
|
545 | Test explicit numeric revision | |
545 | $ log 'rev(-2)' |
|
546 | $ log 'rev(-2)' | |
546 | $ log 'rev(-1)' |
|
547 | $ log 'rev(-1)' | |
547 | -1 |
|
548 | -1 | |
548 | $ log 'rev(0)' |
|
549 | $ log 'rev(0)' | |
549 | 0 |
|
550 | 0 | |
550 | $ log 'rev(9)' |
|
551 | $ log 'rev(9)' | |
551 | 9 |
|
552 | 9 | |
552 | $ log 'rev(10)' |
|
553 | $ log 'rev(10)' | |
553 | $ log 'rev(tip)' |
|
554 | $ log 'rev(tip)' | |
554 | hg: parse error: rev expects a number |
|
555 | hg: parse error: rev expects a number | |
555 | [255] |
|
556 | [255] | |
556 |
|
557 | |||
|
558 | Test hexadecimal revision | |||
|
559 | $ log 'id(2)' | |||
|
560 | abort: 00changelog.i@2: ambiguous identifier! | |||
|
561 | [255] | |||
|
562 | $ log 'id(23268)' | |||
|
563 | 4 | |||
|
564 | $ log 'id(2785f51eece)' | |||
|
565 | 0 | |||
|
566 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532c)' | |||
|
567 | 8 | |||
|
568 | $ log 'id(d5d0dcbdc4a)' | |||
|
569 | $ log 'id(d5d0dcbdc4w)' | |||
|
570 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532d)' | |||
|
571 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532q)' | |||
|
572 | $ log 'id(1.0)' | |||
|
573 | $ log 'id(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)' | |||
|
574 | ||||
557 | Test null revision |
|
575 | Test null revision | |
558 | $ log '(null)' |
|
576 | $ log '(null)' | |
559 | -1 |
|
577 | -1 | |
560 | $ log '(null:0)' |
|
578 | $ log '(null:0)' | |
561 | -1 |
|
579 | -1 | |
562 | 0 |
|
580 | 0 | |
563 | $ log '(0:null)' |
|
581 | $ log '(0:null)' | |
564 | 0 |
|
582 | 0 | |
565 | -1 |
|
583 | -1 | |
566 | $ log 'null::0' |
|
584 | $ log 'null::0' | |
567 | -1 |
|
585 | -1 | |
568 | 0 |
|
586 | 0 | |
569 | $ log 'null:tip - 0:' |
|
587 | $ log 'null:tip - 0:' | |
570 | -1 |
|
588 | -1 | |
571 | $ log 'null: and null::' | head -1 |
|
589 | $ log 'null: and null::' | head -1 | |
572 | -1 |
|
590 | -1 | |
573 | $ log 'null: or 0:' | head -2 |
|
591 | $ log 'null: or 0:' | head -2 | |
574 | -1 |
|
592 | -1 | |
575 | 0 |
|
593 | 0 | |
576 | $ log 'ancestors(null)' |
|
594 | $ log 'ancestors(null)' | |
577 | -1 |
|
595 | -1 | |
578 | $ log 'reverse(null:)' | tail -2 |
|
596 | $ log 'reverse(null:)' | tail -2 | |
579 | 0 |
|
597 | 0 | |
580 | -1 |
|
598 | -1 | |
581 | $ log 'first(null:)' |
|
599 | $ log 'first(null:)' | |
582 | -1 |
|
600 | -1 | |
583 | $ log 'min(null:)' |
|
601 | $ log 'min(null:)' | |
584 | -1 |
|
602 | -1 | |
585 | $ log 'tip:null and all()' | tail -2 |
|
603 | $ log 'tip:null and all()' | tail -2 | |
586 | 1 |
|
604 | 1 | |
587 | 0 |
|
605 | 0 | |
588 |
|
606 | |||
589 | Test working-directory revision |
|
607 | Test working-directory revision | |
590 | $ hg debugrevspec 'wdir()' |
|
608 | $ hg debugrevspec 'wdir()' | |
591 | None |
|
609 | None | |
592 | $ hg debugrevspec 'tip or wdir()' |
|
610 | $ hg debugrevspec 'tip or wdir()' | |
593 | 9 |
|
611 | 9 | |
594 | None |
|
612 | None | |
595 | $ hg debugrevspec '0:tip and wdir()' |
|
613 | $ hg debugrevspec '0:tip and wdir()' | |
596 |
|
614 | |||
597 | $ log 'outgoing()' |
|
615 | $ log 'outgoing()' | |
598 | 8 |
|
616 | 8 | |
599 | 9 |
|
617 | 9 | |
600 | $ log 'outgoing("../remote1")' |
|
618 | $ log 'outgoing("../remote1")' | |
601 | 8 |
|
619 | 8 | |
602 | 9 |
|
620 | 9 | |
603 | $ log 'outgoing("../remote2")' |
|
621 | $ log 'outgoing("../remote2")' | |
604 | 3 |
|
622 | 3 | |
605 | 5 |
|
623 | 5 | |
606 | 6 |
|
624 | 6 | |
607 | 7 |
|
625 | 7 | |
608 | 9 |
|
626 | 9 | |
609 | $ log 'p1(merge())' |
|
627 | $ log 'p1(merge())' | |
610 | 5 |
|
628 | 5 | |
611 | $ log 'p2(merge())' |
|
629 | $ log 'p2(merge())' | |
612 | 4 |
|
630 | 4 | |
613 | $ log 'parents(merge())' |
|
631 | $ log 'parents(merge())' | |
614 | 4 |
|
632 | 4 | |
615 | 5 |
|
633 | 5 | |
616 | $ log 'p1(branchpoint())' |
|
634 | $ log 'p1(branchpoint())' | |
617 | 0 |
|
635 | 0 | |
618 | 2 |
|
636 | 2 | |
619 | $ log 'p2(branchpoint())' |
|
637 | $ log 'p2(branchpoint())' | |
620 | $ log 'parents(branchpoint())' |
|
638 | $ log 'parents(branchpoint())' | |
621 | 0 |
|
639 | 0 | |
622 | 2 |
|
640 | 2 | |
623 | $ log 'removes(a)' |
|
641 | $ log 'removes(a)' | |
624 | 2 |
|
642 | 2 | |
625 | 6 |
|
643 | 6 | |
626 | $ log 'roots(all())' |
|
644 | $ log 'roots(all())' | |
627 | 0 |
|
645 | 0 | |
628 | $ log 'reverse(2 or 3 or 4 or 5)' |
|
646 | $ log 'reverse(2 or 3 or 4 or 5)' | |
629 | 5 |
|
647 | 5 | |
630 | 4 |
|
648 | 4 | |
631 | 3 |
|
649 | 3 | |
632 | 2 |
|
650 | 2 | |
633 | $ log 'reverse(all())' |
|
651 | $ log 'reverse(all())' | |
634 | 9 |
|
652 | 9 | |
635 | 8 |
|
653 | 8 | |
636 | 7 |
|
654 | 7 | |
637 | 6 |
|
655 | 6 | |
638 | 5 |
|
656 | 5 | |
639 | 4 |
|
657 | 4 | |
640 | 3 |
|
658 | 3 | |
641 | 2 |
|
659 | 2 | |
642 | 1 |
|
660 | 1 | |
643 | 0 |
|
661 | 0 | |
644 | $ log 'reverse(all()) & filelog(b)' |
|
662 | $ log 'reverse(all()) & filelog(b)' | |
645 | 4 |
|
663 | 4 | |
646 | 1 |
|
664 | 1 | |
647 | $ log 'rev(5)' |
|
665 | $ log 'rev(5)' | |
648 | 5 |
|
666 | 5 | |
649 | $ log 'sort(limit(reverse(all()), 3))' |
|
667 | $ log 'sort(limit(reverse(all()), 3))' | |
650 | 7 |
|
668 | 7 | |
651 | 8 |
|
669 | 8 | |
652 | 9 |
|
670 | 9 | |
653 | $ log 'sort(2 or 3 or 4 or 5, date)' |
|
671 | $ log 'sort(2 or 3 or 4 or 5, date)' | |
654 | 2 |
|
672 | 2 | |
655 | 3 |
|
673 | 3 | |
656 | 5 |
|
674 | 5 | |
657 | 4 |
|
675 | 4 | |
658 | $ log 'tagged()' |
|
676 | $ log 'tagged()' | |
659 | 6 |
|
677 | 6 | |
660 | $ log 'tag()' |
|
678 | $ log 'tag()' | |
661 | 6 |
|
679 | 6 | |
662 | $ log 'tag(1.0)' |
|
680 | $ log 'tag(1.0)' | |
663 | 6 |
|
681 | 6 | |
664 | $ log 'tag(tip)' |
|
682 | $ log 'tag(tip)' | |
665 | 9 |
|
683 | 9 | |
666 |
|
684 | |||
667 | test sort revset |
|
685 | test sort revset | |
668 | -------------------------------------------- |
|
686 | -------------------------------------------- | |
669 |
|
687 | |||
670 | test when adding two unordered revsets |
|
688 | test when adding two unordered revsets | |
671 |
|
689 | |||
672 | $ log 'sort(keyword(issue) or modifies(b))' |
|
690 | $ log 'sort(keyword(issue) or modifies(b))' | |
673 | 4 |
|
691 | 4 | |
674 | 6 |
|
692 | 6 | |
675 |
|
693 | |||
676 | test when sorting a reversed collection in the same way it is |
|
694 | test when sorting a reversed collection in the same way it is | |
677 |
|
695 | |||
678 | $ log 'sort(reverse(all()), -rev)' |
|
696 | $ log 'sort(reverse(all()), -rev)' | |
679 | 9 |
|
697 | 9 | |
680 | 8 |
|
698 | 8 | |
681 | 7 |
|
699 | 7 | |
682 | 6 |
|
700 | 6 | |
683 | 5 |
|
701 | 5 | |
684 | 4 |
|
702 | 4 | |
685 | 3 |
|
703 | 3 | |
686 | 2 |
|
704 | 2 | |
687 | 1 |
|
705 | 1 | |
688 | 0 |
|
706 | 0 | |
689 |
|
707 | |||
690 | test when sorting a reversed collection |
|
708 | test when sorting a reversed collection | |
691 |
|
709 | |||
692 | $ log 'sort(reverse(all()), rev)' |
|
710 | $ log 'sort(reverse(all()), rev)' | |
693 | 0 |
|
711 | 0 | |
694 | 1 |
|
712 | 1 | |
695 | 2 |
|
713 | 2 | |
696 | 3 |
|
714 | 3 | |
697 | 4 |
|
715 | 4 | |
698 | 5 |
|
716 | 5 | |
699 | 6 |
|
717 | 6 | |
700 | 7 |
|
718 | 7 | |
701 | 8 |
|
719 | 8 | |
702 | 9 |
|
720 | 9 | |
703 |
|
721 | |||
704 |
|
722 | |||
705 | test sorting two sorted collections in different orders |
|
723 | test sorting two sorted collections in different orders | |
706 |
|
724 | |||
707 | $ log 'sort(outgoing() or reverse(removes(a)), rev)' |
|
725 | $ log 'sort(outgoing() or reverse(removes(a)), rev)' | |
708 | 2 |
|
726 | 2 | |
709 | 6 |
|
727 | 6 | |
710 | 8 |
|
728 | 8 | |
711 | 9 |
|
729 | 9 | |
712 |
|
730 | |||
713 | test sorting two sorted collections in different orders backwards |
|
731 | test sorting two sorted collections in different orders backwards | |
714 |
|
732 | |||
715 | $ log 'sort(outgoing() or reverse(removes(a)), -rev)' |
|
733 | $ log 'sort(outgoing() or reverse(removes(a)), -rev)' | |
716 | 9 |
|
734 | 9 | |
717 | 8 |
|
735 | 8 | |
718 | 6 |
|
736 | 6 | |
719 | 2 |
|
737 | 2 | |
720 |
|
738 | |||
721 | test subtracting something from an addset |
|
739 | test subtracting something from an addset | |
722 |
|
740 | |||
723 | $ log '(outgoing() or removes(a)) - removes(a)' |
|
741 | $ log '(outgoing() or removes(a)) - removes(a)' | |
724 | 8 |
|
742 | 8 | |
725 | 9 |
|
743 | 9 | |
726 |
|
744 | |||
727 | test intersecting something with an addset |
|
745 | test intersecting something with an addset | |
728 |
|
746 | |||
729 | $ log 'parents(outgoing() or removes(a))' |
|
747 | $ log 'parents(outgoing() or removes(a))' | |
730 | 1 |
|
748 | 1 | |
731 | 4 |
|
749 | 4 | |
732 | 5 |
|
750 | 5 | |
733 | 8 |
|
751 | 8 | |
734 |
|
752 | |||
735 | test that `or` operation combines elements in the right order: |
|
753 | test that `or` operation combines elements in the right order: | |
736 |
|
754 | |||
737 | $ log '3:4 or 2:5' |
|
755 | $ log '3:4 or 2:5' | |
738 | 3 |
|
756 | 3 | |
739 | 4 |
|
757 | 4 | |
740 | 2 |
|
758 | 2 | |
741 | 5 |
|
759 | 5 | |
742 | $ log '3:4 or 5:2' |
|
760 | $ log '3:4 or 5:2' | |
743 | 3 |
|
761 | 3 | |
744 | 4 |
|
762 | 4 | |
745 | 5 |
|
763 | 5 | |
746 | 2 |
|
764 | 2 | |
747 | $ log 'sort(3:4 or 2:5)' |
|
765 | $ log 'sort(3:4 or 2:5)' | |
748 | 2 |
|
766 | 2 | |
749 | 3 |
|
767 | 3 | |
750 | 4 |
|
768 | 4 | |
751 | 5 |
|
769 | 5 | |
752 | $ log 'sort(3:4 or 5:2)' |
|
770 | $ log 'sort(3:4 or 5:2)' | |
753 | 2 |
|
771 | 2 | |
754 | 3 |
|
772 | 3 | |
755 | 4 |
|
773 | 4 | |
756 | 5 |
|
774 | 5 | |
757 |
|
775 | |||
758 | check that conversion to only works |
|
776 | check that conversion to only works | |
759 | $ try --optimize '::3 - ::1' |
|
777 | $ try --optimize '::3 - ::1' | |
760 | (minus |
|
778 | (minus | |
761 | (dagrangepre |
|
779 | (dagrangepre | |
762 | ('symbol', '3')) |
|
780 | ('symbol', '3')) | |
763 | (dagrangepre |
|
781 | (dagrangepre | |
764 | ('symbol', '1'))) |
|
782 | ('symbol', '1'))) | |
765 | * optimized: |
|
783 | * optimized: | |
766 | (func |
|
784 | (func | |
767 | ('symbol', 'only') |
|
785 | ('symbol', 'only') | |
768 | (list |
|
786 | (list | |
769 | ('symbol', '3') |
|
787 | ('symbol', '3') | |
770 | ('symbol', '1'))) |
|
788 | ('symbol', '1'))) | |
771 | * set: |
|
789 | * set: | |
772 | <baseset+ [3]> |
|
790 | <baseset+ [3]> | |
773 | 3 |
|
791 | 3 | |
774 | $ try --optimize 'ancestors(1) - ancestors(3)' |
|
792 | $ try --optimize 'ancestors(1) - ancestors(3)' | |
775 | (minus |
|
793 | (minus | |
776 | (func |
|
794 | (func | |
777 | ('symbol', 'ancestors') |
|
795 | ('symbol', 'ancestors') | |
778 | ('symbol', '1')) |
|
796 | ('symbol', '1')) | |
779 | (func |
|
797 | (func | |
780 | ('symbol', 'ancestors') |
|
798 | ('symbol', 'ancestors') | |
781 | ('symbol', '3'))) |
|
799 | ('symbol', '3'))) | |
782 | * optimized: |
|
800 | * optimized: | |
783 | (func |
|
801 | (func | |
784 | ('symbol', 'only') |
|
802 | ('symbol', 'only') | |
785 | (list |
|
803 | (list | |
786 | ('symbol', '1') |
|
804 | ('symbol', '1') | |
787 | ('symbol', '3'))) |
|
805 | ('symbol', '3'))) | |
788 | * set: |
|
806 | * set: | |
789 | <baseset+ []> |
|
807 | <baseset+ []> | |
790 | $ try --optimize 'not ::2 and ::6' |
|
808 | $ try --optimize 'not ::2 and ::6' | |
791 | (and |
|
809 | (and | |
792 | (not |
|
810 | (not | |
793 | (dagrangepre |
|
811 | (dagrangepre | |
794 | ('symbol', '2'))) |
|
812 | ('symbol', '2'))) | |
795 | (dagrangepre |
|
813 | (dagrangepre | |
796 | ('symbol', '6'))) |
|
814 | ('symbol', '6'))) | |
797 | * optimized: |
|
815 | * optimized: | |
798 | (func |
|
816 | (func | |
799 | ('symbol', 'only') |
|
817 | ('symbol', 'only') | |
800 | (list |
|
818 | (list | |
801 | ('symbol', '6') |
|
819 | ('symbol', '6') | |
802 | ('symbol', '2'))) |
|
820 | ('symbol', '2'))) | |
803 | * set: |
|
821 | * set: | |
804 | <baseset+ [3, 4, 5, 6]> |
|
822 | <baseset+ [3, 4, 5, 6]> | |
805 | 3 |
|
823 | 3 | |
806 | 4 |
|
824 | 4 | |
807 | 5 |
|
825 | 5 | |
808 | 6 |
|
826 | 6 | |
809 | $ try --optimize 'ancestors(6) and not ancestors(4)' |
|
827 | $ try --optimize 'ancestors(6) and not ancestors(4)' | |
810 | (and |
|
828 | (and | |
811 | (func |
|
829 | (func | |
812 | ('symbol', 'ancestors') |
|
830 | ('symbol', 'ancestors') | |
813 | ('symbol', '6')) |
|
831 | ('symbol', '6')) | |
814 | (not |
|
832 | (not | |
815 | (func |
|
833 | (func | |
816 | ('symbol', 'ancestors') |
|
834 | ('symbol', 'ancestors') | |
817 | ('symbol', '4')))) |
|
835 | ('symbol', '4')))) | |
818 | * optimized: |
|
836 | * optimized: | |
819 | (func |
|
837 | (func | |
820 | ('symbol', 'only') |
|
838 | ('symbol', 'only') | |
821 | (list |
|
839 | (list | |
822 | ('symbol', '6') |
|
840 | ('symbol', '6') | |
823 | ('symbol', '4'))) |
|
841 | ('symbol', '4'))) | |
824 | * set: |
|
842 | * set: | |
825 | <baseset+ [3, 5, 6]> |
|
843 | <baseset+ [3, 5, 6]> | |
826 | 3 |
|
844 | 3 | |
827 | 5 |
|
845 | 5 | |
828 | 6 |
|
846 | 6 | |
829 |
|
847 | |||
830 | we can use patterns when searching for tags |
|
848 | we can use patterns when searching for tags | |
831 |
|
849 | |||
832 | $ log 'tag("1..*")' |
|
850 | $ log 'tag("1..*")' | |
833 | abort: tag '1..*' does not exist! |
|
851 | abort: tag '1..*' does not exist! | |
834 | [255] |
|
852 | [255] | |
835 | $ log 'tag("re:1..*")' |
|
853 | $ log 'tag("re:1..*")' | |
836 | 6 |
|
854 | 6 | |
837 | $ log 'tag("re:[0-9].[0-9]")' |
|
855 | $ log 'tag("re:[0-9].[0-9]")' | |
838 | 6 |
|
856 | 6 | |
839 | $ log 'tag("literal:1.0")' |
|
857 | $ log 'tag("literal:1.0")' | |
840 | 6 |
|
858 | 6 | |
841 | $ log 'tag("re:0..*")' |
|
859 | $ log 'tag("re:0..*")' | |
842 |
|
860 | |||
843 | $ log 'tag(unknown)' |
|
861 | $ log 'tag(unknown)' | |
844 | abort: tag 'unknown' does not exist! |
|
862 | abort: tag 'unknown' does not exist! | |
845 | [255] |
|
863 | [255] | |
846 | $ log 'tag("re:unknown")' |
|
864 | $ log 'tag("re:unknown")' | |
847 | $ log 'present(tag("unknown"))' |
|
865 | $ log 'present(tag("unknown"))' | |
848 | $ log 'present(tag("re:unknown"))' |
|
866 | $ log 'present(tag("re:unknown"))' | |
849 | $ log 'branch(unknown)' |
|
867 | $ log 'branch(unknown)' | |
850 | abort: unknown revision 'unknown'! |
|
868 | abort: unknown revision 'unknown'! | |
851 | [255] |
|
869 | [255] | |
852 | $ log 'branch("re:unknown")' |
|
870 | $ log 'branch("re:unknown")' | |
853 | $ log 'present(branch("unknown"))' |
|
871 | $ log 'present(branch("unknown"))' | |
854 | $ log 'present(branch("re:unknown"))' |
|
872 | $ log 'present(branch("re:unknown"))' | |
855 | $ log 'user(bob)' |
|
873 | $ log 'user(bob)' | |
856 | 2 |
|
874 | 2 | |
857 |
|
875 | |||
858 | $ log '4::8' |
|
876 | $ log '4::8' | |
859 | 4 |
|
877 | 4 | |
860 | 8 |
|
878 | 8 | |
861 | $ log '4:8' |
|
879 | $ log '4:8' | |
862 | 4 |
|
880 | 4 | |
863 | 5 |
|
881 | 5 | |
864 | 6 |
|
882 | 6 | |
865 | 7 |
|
883 | 7 | |
866 | 8 |
|
884 | 8 | |
867 |
|
885 | |||
868 | $ log 'sort(!merge() & (modifies(b) | user(bob) | keyword(bug) | keyword(issue) & 1::9), "-date")' |
|
886 | $ log 'sort(!merge() & (modifies(b) | user(bob) | keyword(bug) | keyword(issue) & 1::9), "-date")' | |
869 | 4 |
|
887 | 4 | |
870 | 2 |
|
888 | 2 | |
871 | 5 |
|
889 | 5 | |
872 |
|
890 | |||
873 | $ log 'not 0 and 0:2' |
|
891 | $ log 'not 0 and 0:2' | |
874 | 1 |
|
892 | 1 | |
875 | 2 |
|
893 | 2 | |
876 | $ log 'not 1 and 0:2' |
|
894 | $ log 'not 1 and 0:2' | |
877 | 0 |
|
895 | 0 | |
878 | 2 |
|
896 | 2 | |
879 | $ log 'not 2 and 0:2' |
|
897 | $ log 'not 2 and 0:2' | |
880 | 0 |
|
898 | 0 | |
881 | 1 |
|
899 | 1 | |
882 | $ log '(1 and 2)::' |
|
900 | $ log '(1 and 2)::' | |
883 | $ log '(1 and 2):' |
|
901 | $ log '(1 and 2):' | |
884 | $ log '(1 and 2):3' |
|
902 | $ log '(1 and 2):3' | |
885 | $ log 'sort(head(), -rev)' |
|
903 | $ log 'sort(head(), -rev)' | |
886 | 9 |
|
904 | 9 | |
887 | 7 |
|
905 | 7 | |
888 | 6 |
|
906 | 6 | |
889 | 5 |
|
907 | 5 | |
890 | 4 |
|
908 | 4 | |
891 | 3 |
|
909 | 3 | |
892 | 2 |
|
910 | 2 | |
893 | 1 |
|
911 | 1 | |
894 | 0 |
|
912 | 0 | |
895 | $ log '4::8 - 8' |
|
913 | $ log '4::8 - 8' | |
896 | 4 |
|
914 | 4 | |
897 | $ log 'matching(1 or 2 or 3) and (2 or 3 or 1)' |
|
915 | $ log 'matching(1 or 2 or 3) and (2 or 3 or 1)' | |
898 | 2 |
|
916 | 2 | |
899 | 3 |
|
917 | 3 | |
900 | 1 |
|
918 | 1 | |
901 |
|
919 | |||
902 | $ log 'named("unknown")' |
|
920 | $ log 'named("unknown")' | |
903 | abort: namespace 'unknown' does not exist! |
|
921 | abort: namespace 'unknown' does not exist! | |
904 | [255] |
|
922 | [255] | |
905 | $ log 'named("re:unknown")' |
|
923 | $ log 'named("re:unknown")' | |
906 | abort: no namespace exists that match 'unknown'! |
|
924 | abort: no namespace exists that match 'unknown'! | |
907 | [255] |
|
925 | [255] | |
908 | $ log 'present(named("unknown"))' |
|
926 | $ log 'present(named("unknown"))' | |
909 | $ log 'present(named("re:unknown"))' |
|
927 | $ log 'present(named("re:unknown"))' | |
910 |
|
928 | |||
911 | $ log 'tag()' |
|
929 | $ log 'tag()' | |
912 | 6 |
|
930 | 6 | |
913 | $ log 'named("tags")' |
|
931 | $ log 'named("tags")' | |
914 | 6 |
|
932 | 6 | |
915 |
|
933 | |||
916 | issue2437 |
|
934 | issue2437 | |
917 |
|
935 | |||
918 | $ log '3 and p1(5)' |
|
936 | $ log '3 and p1(5)' | |
919 | 3 |
|
937 | 3 | |
920 | $ log '4 and p2(6)' |
|
938 | $ log '4 and p2(6)' | |
921 | 4 |
|
939 | 4 | |
922 | $ log '1 and parents(:2)' |
|
940 | $ log '1 and parents(:2)' | |
923 | 1 |
|
941 | 1 | |
924 | $ log '2 and children(1:)' |
|
942 | $ log '2 and children(1:)' | |
925 | 2 |
|
943 | 2 | |
926 | $ log 'roots(all()) or roots(all())' |
|
944 | $ log 'roots(all()) or roots(all())' | |
927 | 0 |
|
945 | 0 | |
928 | $ hg debugrevspec 'roots(all()) or roots(all())' |
|
946 | $ hg debugrevspec 'roots(all()) or roots(all())' | |
929 | 0 |
|
947 | 0 | |
930 | $ log 'heads(branch(Γ©)) or heads(branch(Γ©))' |
|
948 | $ log 'heads(branch(Γ©)) or heads(branch(Γ©))' | |
931 | 9 |
|
949 | 9 | |
932 | $ log 'ancestors(8) and (heads(branch("-a-b-c-")) or heads(branch(Γ©)))' |
|
950 | $ log 'ancestors(8) and (heads(branch("-a-b-c-")) or heads(branch(Γ©)))' | |
933 | 4 |
|
951 | 4 | |
934 |
|
952 | |||
935 | issue2654: report a parse error if the revset was not completely parsed |
|
953 | issue2654: report a parse error if the revset was not completely parsed | |
936 |
|
954 | |||
937 | $ log '1 OR 2' |
|
955 | $ log '1 OR 2' | |
938 | hg: parse error at 2: invalid token |
|
956 | hg: parse error at 2: invalid token | |
939 | [255] |
|
957 | [255] | |
940 |
|
958 | |||
941 | or operator should preserve ordering: |
|
959 | or operator should preserve ordering: | |
942 | $ log 'reverse(2::4) or tip' |
|
960 | $ log 'reverse(2::4) or tip' | |
943 | 4 |
|
961 | 4 | |
944 | 2 |
|
962 | 2 | |
945 | 9 |
|
963 | 9 | |
946 |
|
964 | |||
947 | parentrevspec |
|
965 | parentrevspec | |
948 |
|
966 | |||
949 | $ log 'merge()^0' |
|
967 | $ log 'merge()^0' | |
950 | 6 |
|
968 | 6 | |
951 | $ log 'merge()^' |
|
969 | $ log 'merge()^' | |
952 | 5 |
|
970 | 5 | |
953 | $ log 'merge()^1' |
|
971 | $ log 'merge()^1' | |
954 | 5 |
|
972 | 5 | |
955 | $ log 'merge()^2' |
|
973 | $ log 'merge()^2' | |
956 | 4 |
|
974 | 4 | |
957 | $ log 'merge()^^' |
|
975 | $ log 'merge()^^' | |
958 | 3 |
|
976 | 3 | |
959 | $ log 'merge()^1^' |
|
977 | $ log 'merge()^1^' | |
960 | 3 |
|
978 | 3 | |
961 | $ log 'merge()^^^' |
|
979 | $ log 'merge()^^^' | |
962 | 1 |
|
980 | 1 | |
963 |
|
981 | |||
964 | $ log 'merge()~0' |
|
982 | $ log 'merge()~0' | |
965 | 6 |
|
983 | 6 | |
966 | $ log 'merge()~1' |
|
984 | $ log 'merge()~1' | |
967 | 5 |
|
985 | 5 | |
968 | $ log 'merge()~2' |
|
986 | $ log 'merge()~2' | |
969 | 3 |
|
987 | 3 | |
970 | $ log 'merge()~2^1' |
|
988 | $ log 'merge()~2^1' | |
971 | 1 |
|
989 | 1 | |
972 | $ log 'merge()~3' |
|
990 | $ log 'merge()~3' | |
973 | 1 |
|
991 | 1 | |
974 |
|
992 | |||
975 | $ log '(-3:tip)^' |
|
993 | $ log '(-3:tip)^' | |
976 | 4 |
|
994 | 4 | |
977 | 6 |
|
995 | 6 | |
978 | 8 |
|
996 | 8 | |
979 |
|
997 | |||
980 | $ log 'tip^foo' |
|
998 | $ log 'tip^foo' | |
981 | hg: parse error: ^ expects a number 0, 1, or 2 |
|
999 | hg: parse error: ^ expects a number 0, 1, or 2 | |
982 | [255] |
|
1000 | [255] | |
983 |
|
1001 | |||
984 | Bogus function gets suggestions |
|
1002 | Bogus function gets suggestions | |
985 | $ log 'add()' |
|
1003 | $ log 'add()' | |
986 | hg: parse error: unknown identifier: add |
|
1004 | hg: parse error: unknown identifier: add | |
987 | (did you mean 'adds'?) |
|
1005 | (did you mean 'adds'?) | |
988 | [255] |
|
1006 | [255] | |
989 | $ log 'added()' |
|
1007 | $ log 'added()' | |
990 | hg: parse error: unknown identifier: added |
|
1008 | hg: parse error: unknown identifier: added | |
991 | (did you mean 'adds'?) |
|
1009 | (did you mean 'adds'?) | |
992 | [255] |
|
1010 | [255] | |
993 | $ log 'remo()' |
|
1011 | $ log 'remo()' | |
994 | hg: parse error: unknown identifier: remo |
|
1012 | hg: parse error: unknown identifier: remo | |
995 | (did you mean one of remote, removes?) |
|
1013 | (did you mean one of remote, removes?) | |
996 | [255] |
|
1014 | [255] | |
997 | $ log 'babar()' |
|
1015 | $ log 'babar()' | |
998 | hg: parse error: unknown identifier: babar |
|
1016 | hg: parse error: unknown identifier: babar | |
999 | [255] |
|
1017 | [255] | |
1000 |
|
1018 | |||
1001 | multiple revspecs |
|
1019 | multiple revspecs | |
1002 |
|
1020 | |||
1003 | $ hg log -r 'tip~1:tip' -r 'tip~2:tip~1' --template '{rev}\n' |
|
1021 | $ hg log -r 'tip~1:tip' -r 'tip~2:tip~1' --template '{rev}\n' | |
1004 | 8 |
|
1022 | 8 | |
1005 | 9 |
|
1023 | 9 | |
1006 | 4 |
|
1024 | 4 | |
1007 | 5 |
|
1025 | 5 | |
1008 | 6 |
|
1026 | 6 | |
1009 | 7 |
|
1027 | 7 | |
1010 |
|
1028 | |||
1011 | test usage in revpair (with "+") |
|
1029 | test usage in revpair (with "+") | |
1012 |
|
1030 | |||
1013 | (real pair) |
|
1031 | (real pair) | |
1014 |
|
1032 | |||
1015 | $ hg diff -r 'tip^^' -r 'tip' |
|
1033 | $ hg diff -r 'tip^^' -r 'tip' | |
1016 | diff -r 2326846efdab -r 24286f4ae135 .hgtags |
|
1034 | diff -r 2326846efdab -r 24286f4ae135 .hgtags | |
1017 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
1035 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
1018 | +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000 |
|
1036 | +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000 | |
1019 | @@ -0,0 +1,1 @@ |
|
1037 | @@ -0,0 +1,1 @@ | |
1020 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 |
|
1038 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 | |
1021 | $ hg diff -r 'tip^^::tip' |
|
1039 | $ hg diff -r 'tip^^::tip' | |
1022 | diff -r 2326846efdab -r 24286f4ae135 .hgtags |
|
1040 | diff -r 2326846efdab -r 24286f4ae135 .hgtags | |
1023 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
1041 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
1024 | +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000 |
|
1042 | +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000 | |
1025 | @@ -0,0 +1,1 @@ |
|
1043 | @@ -0,0 +1,1 @@ | |
1026 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 |
|
1044 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 | |
1027 |
|
1045 | |||
1028 | (single rev) |
|
1046 | (single rev) | |
1029 |
|
1047 | |||
1030 | $ hg diff -r 'tip^' -r 'tip^' |
|
1048 | $ hg diff -r 'tip^' -r 'tip^' | |
1031 | $ hg diff -r 'tip^::tip^ or tip^' |
|
1049 | $ hg diff -r 'tip^::tip^ or tip^' | |
1032 |
|
1050 | |||
1033 | (single rev that does not looks like a range) |
|
1051 | (single rev that does not looks like a range) | |
1034 |
|
1052 | |||
1035 | $ hg diff -r 'tip^ or tip^' |
|
1053 | $ hg diff -r 'tip^ or tip^' | |
1036 | diff -r d5d0dcbdc4d9 .hgtags |
|
1054 | diff -r d5d0dcbdc4d9 .hgtags | |
1037 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
1055 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
1038 | +++ b/.hgtags * (glob) |
|
1056 | +++ b/.hgtags * (glob) | |
1039 | @@ -0,0 +1,1 @@ |
|
1057 | @@ -0,0 +1,1 @@ | |
1040 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 |
|
1058 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 | |
1041 |
|
1059 | |||
1042 | (no rev) |
|
1060 | (no rev) | |
1043 |
|
1061 | |||
1044 | $ hg diff -r 'author("babar") or author("celeste")' |
|
1062 | $ hg diff -r 'author("babar") or author("celeste")' | |
1045 | abort: empty revision range |
|
1063 | abort: empty revision range | |
1046 | [255] |
|
1064 | [255] | |
1047 |
|
1065 | |||
1048 | aliases: |
|
1066 | aliases: | |
1049 |
|
1067 | |||
1050 | $ echo '[revsetalias]' >> .hg/hgrc |
|
1068 | $ echo '[revsetalias]' >> .hg/hgrc | |
1051 | $ echo 'm = merge()' >> .hg/hgrc |
|
1069 | $ echo 'm = merge()' >> .hg/hgrc | |
1052 | (revset aliases can override builtin revsets) |
|
1070 | (revset aliases can override builtin revsets) | |
1053 | $ echo 'p2($1) = p1($1)' >> .hg/hgrc |
|
1071 | $ echo 'p2($1) = p1($1)' >> .hg/hgrc | |
1054 | $ echo 'sincem = descendants(m)' >> .hg/hgrc |
|
1072 | $ echo 'sincem = descendants(m)' >> .hg/hgrc | |
1055 | $ echo 'd($1) = reverse(sort($1, date))' >> .hg/hgrc |
|
1073 | $ echo 'd($1) = reverse(sort($1, date))' >> .hg/hgrc | |
1056 | $ echo 'rs(ARG1, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc |
|
1074 | $ echo 'rs(ARG1, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc | |
1057 | $ echo 'rs4(ARG1, ARGA, ARGB, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc |
|
1075 | $ echo 'rs4(ARG1, ARGA, ARGB, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc | |
1058 |
|
1076 | |||
1059 | $ try m |
|
1077 | $ try m | |
1060 | ('symbol', 'm') |
|
1078 | ('symbol', 'm') | |
1061 | (func |
|
1079 | (func | |
1062 | ('symbol', 'merge') |
|
1080 | ('symbol', 'merge') | |
1063 | None) |
|
1081 | None) | |
1064 | * set: |
|
1082 | * set: | |
1065 | <filteredset |
|
1083 | <filteredset | |
1066 | <fullreposet+ 0:9>> |
|
1084 | <fullreposet+ 0:9>> | |
1067 | 6 |
|
1085 | 6 | |
1068 |
|
1086 | |||
1069 | $ HGPLAIN=1 |
|
1087 | $ HGPLAIN=1 | |
1070 | $ export HGPLAIN |
|
1088 | $ export HGPLAIN | |
1071 | $ try m |
|
1089 | $ try m | |
1072 | ('symbol', 'm') |
|
1090 | ('symbol', 'm') | |
1073 | abort: unknown revision 'm'! |
|
1091 | abort: unknown revision 'm'! | |
1074 | [255] |
|
1092 | [255] | |
1075 |
|
1093 | |||
1076 | $ HGPLAINEXCEPT=revsetalias |
|
1094 | $ HGPLAINEXCEPT=revsetalias | |
1077 | $ export HGPLAINEXCEPT |
|
1095 | $ export HGPLAINEXCEPT | |
1078 | $ try m |
|
1096 | $ try m | |
1079 | ('symbol', 'm') |
|
1097 | ('symbol', 'm') | |
1080 | (func |
|
1098 | (func | |
1081 | ('symbol', 'merge') |
|
1099 | ('symbol', 'merge') | |
1082 | None) |
|
1100 | None) | |
1083 | * set: |
|
1101 | * set: | |
1084 | <filteredset |
|
1102 | <filteredset | |
1085 | <fullreposet+ 0:9>> |
|
1103 | <fullreposet+ 0:9>> | |
1086 | 6 |
|
1104 | 6 | |
1087 |
|
1105 | |||
1088 | $ unset HGPLAIN |
|
1106 | $ unset HGPLAIN | |
1089 | $ unset HGPLAINEXCEPT |
|
1107 | $ unset HGPLAINEXCEPT | |
1090 |
|
1108 | |||
1091 | $ try 'p2(.)' |
|
1109 | $ try 'p2(.)' | |
1092 | (func |
|
1110 | (func | |
1093 | ('symbol', 'p2') |
|
1111 | ('symbol', 'p2') | |
1094 | ('symbol', '.')) |
|
1112 | ('symbol', '.')) | |
1095 | (func |
|
1113 | (func | |
1096 | ('symbol', 'p1') |
|
1114 | ('symbol', 'p1') | |
1097 | ('symbol', '.')) |
|
1115 | ('symbol', '.')) | |
1098 | * set: |
|
1116 | * set: | |
1099 | <baseset+ [8]> |
|
1117 | <baseset+ [8]> | |
1100 | 8 |
|
1118 | 8 | |
1101 |
|
1119 | |||
1102 | $ HGPLAIN=1 |
|
1120 | $ HGPLAIN=1 | |
1103 | $ export HGPLAIN |
|
1121 | $ export HGPLAIN | |
1104 | $ try 'p2(.)' |
|
1122 | $ try 'p2(.)' | |
1105 | (func |
|
1123 | (func | |
1106 | ('symbol', 'p2') |
|
1124 | ('symbol', 'p2') | |
1107 | ('symbol', '.')) |
|
1125 | ('symbol', '.')) | |
1108 | * set: |
|
1126 | * set: | |
1109 | <baseset+ []> |
|
1127 | <baseset+ []> | |
1110 |
|
1128 | |||
1111 | $ HGPLAINEXCEPT=revsetalias |
|
1129 | $ HGPLAINEXCEPT=revsetalias | |
1112 | $ export HGPLAINEXCEPT |
|
1130 | $ export HGPLAINEXCEPT | |
1113 | $ try 'p2(.)' |
|
1131 | $ try 'p2(.)' | |
1114 | (func |
|
1132 | (func | |
1115 | ('symbol', 'p2') |
|
1133 | ('symbol', 'p2') | |
1116 | ('symbol', '.')) |
|
1134 | ('symbol', '.')) | |
1117 | (func |
|
1135 | (func | |
1118 | ('symbol', 'p1') |
|
1136 | ('symbol', 'p1') | |
1119 | ('symbol', '.')) |
|
1137 | ('symbol', '.')) | |
1120 | * set: |
|
1138 | * set: | |
1121 | <baseset+ [8]> |
|
1139 | <baseset+ [8]> | |
1122 | 8 |
|
1140 | 8 | |
1123 |
|
1141 | |||
1124 | $ unset HGPLAIN |
|
1142 | $ unset HGPLAIN | |
1125 | $ unset HGPLAINEXCEPT |
|
1143 | $ unset HGPLAINEXCEPT | |
1126 |
|
1144 | |||
1127 | test alias recursion |
|
1145 | test alias recursion | |
1128 |
|
1146 | |||
1129 | $ try sincem |
|
1147 | $ try sincem | |
1130 | ('symbol', 'sincem') |
|
1148 | ('symbol', 'sincem') | |
1131 | (func |
|
1149 | (func | |
1132 | ('symbol', 'descendants') |
|
1150 | ('symbol', 'descendants') | |
1133 | (func |
|
1151 | (func | |
1134 | ('symbol', 'merge') |
|
1152 | ('symbol', 'merge') | |
1135 | None)) |
|
1153 | None)) | |
1136 | * set: |
|
1154 | * set: | |
1137 | <addset+ |
|
1155 | <addset+ | |
1138 | <filteredset |
|
1156 | <filteredset | |
1139 | <fullreposet+ 0:9>>, |
|
1157 | <fullreposet+ 0:9>>, | |
1140 | <generatorset+>> |
|
1158 | <generatorset+>> | |
1141 | 6 |
|
1159 | 6 | |
1142 | 7 |
|
1160 | 7 | |
1143 |
|
1161 | |||
1144 | test infinite recursion |
|
1162 | test infinite recursion | |
1145 |
|
1163 | |||
1146 | $ echo 'recurse1 = recurse2' >> .hg/hgrc |
|
1164 | $ echo 'recurse1 = recurse2' >> .hg/hgrc | |
1147 | $ echo 'recurse2 = recurse1' >> .hg/hgrc |
|
1165 | $ echo 'recurse2 = recurse1' >> .hg/hgrc | |
1148 | $ try recurse1 |
|
1166 | $ try recurse1 | |
1149 | ('symbol', 'recurse1') |
|
1167 | ('symbol', 'recurse1') | |
1150 | hg: parse error: infinite expansion of revset alias "recurse1" detected |
|
1168 | hg: parse error: infinite expansion of revset alias "recurse1" detected | |
1151 | [255] |
|
1169 | [255] | |
1152 |
|
1170 | |||
1153 | $ echo 'level1($1, $2) = $1 or $2' >> .hg/hgrc |
|
1171 | $ echo 'level1($1, $2) = $1 or $2' >> .hg/hgrc | |
1154 | $ echo 'level2($1, $2) = level1($2, $1)' >> .hg/hgrc |
|
1172 | $ echo 'level2($1, $2) = level1($2, $1)' >> .hg/hgrc | |
1155 | $ try "level2(level1(1, 2), 3)" |
|
1173 | $ try "level2(level1(1, 2), 3)" | |
1156 | (func |
|
1174 | (func | |
1157 | ('symbol', 'level2') |
|
1175 | ('symbol', 'level2') | |
1158 | (list |
|
1176 | (list | |
1159 | (func |
|
1177 | (func | |
1160 | ('symbol', 'level1') |
|
1178 | ('symbol', 'level1') | |
1161 | (list |
|
1179 | (list | |
1162 | ('symbol', '1') |
|
1180 | ('symbol', '1') | |
1163 | ('symbol', '2'))) |
|
1181 | ('symbol', '2'))) | |
1164 | ('symbol', '3'))) |
|
1182 | ('symbol', '3'))) | |
1165 | (or |
|
1183 | (or | |
1166 | ('symbol', '3') |
|
1184 | ('symbol', '3') | |
1167 | (or |
|
1185 | (or | |
1168 | ('symbol', '1') |
|
1186 | ('symbol', '1') | |
1169 | ('symbol', '2'))) |
|
1187 | ('symbol', '2'))) | |
1170 | * set: |
|
1188 | * set: | |
1171 | <addset |
|
1189 | <addset | |
1172 | <baseset [3]>, |
|
1190 | <baseset [3]>, | |
1173 | <addset |
|
1191 | <addset | |
1174 | <baseset [1]>, |
|
1192 | <baseset [1]>, | |
1175 | <baseset [2]>>> |
|
1193 | <baseset [2]>>> | |
1176 | 3 |
|
1194 | 3 | |
1177 | 1 |
|
1195 | 1 | |
1178 | 2 |
|
1196 | 2 | |
1179 |
|
1197 | |||
1180 | test nesting and variable passing |
|
1198 | test nesting and variable passing | |
1181 |
|
1199 | |||
1182 | $ echo 'nested($1) = nested2($1)' >> .hg/hgrc |
|
1200 | $ echo 'nested($1) = nested2($1)' >> .hg/hgrc | |
1183 | $ echo 'nested2($1) = nested3($1)' >> .hg/hgrc |
|
1201 | $ echo 'nested2($1) = nested3($1)' >> .hg/hgrc | |
1184 | $ echo 'nested3($1) = max($1)' >> .hg/hgrc |
|
1202 | $ echo 'nested3($1) = max($1)' >> .hg/hgrc | |
1185 | $ try 'nested(2:5)' |
|
1203 | $ try 'nested(2:5)' | |
1186 | (func |
|
1204 | (func | |
1187 | ('symbol', 'nested') |
|
1205 | ('symbol', 'nested') | |
1188 | (range |
|
1206 | (range | |
1189 | ('symbol', '2') |
|
1207 | ('symbol', '2') | |
1190 | ('symbol', '5'))) |
|
1208 | ('symbol', '5'))) | |
1191 | (func |
|
1209 | (func | |
1192 | ('symbol', 'max') |
|
1210 | ('symbol', 'max') | |
1193 | (range |
|
1211 | (range | |
1194 | ('symbol', '2') |
|
1212 | ('symbol', '2') | |
1195 | ('symbol', '5'))) |
|
1213 | ('symbol', '5'))) | |
1196 | * set: |
|
1214 | * set: | |
1197 | <baseset [5]> |
|
1215 | <baseset [5]> | |
1198 | 5 |
|
1216 | 5 | |
1199 |
|
1217 | |||
1200 | test variable isolation, variable placeholders are rewritten as string |
|
1218 | test variable isolation, variable placeholders are rewritten as string | |
1201 | then parsed and matched again as string. Check they do not leak too |
|
1219 | then parsed and matched again as string. Check they do not leak too | |
1202 | far away. |
|
1220 | far away. | |
1203 |
|
1221 | |||
1204 | $ echo 'injectparamasstring = max("$1")' >> .hg/hgrc |
|
1222 | $ echo 'injectparamasstring = max("$1")' >> .hg/hgrc | |
1205 | $ echo 'callinjection($1) = descendants(injectparamasstring)' >> .hg/hgrc |
|
1223 | $ echo 'callinjection($1) = descendants(injectparamasstring)' >> .hg/hgrc | |
1206 | $ try 'callinjection(2:5)' |
|
1224 | $ try 'callinjection(2:5)' | |
1207 | (func |
|
1225 | (func | |
1208 | ('symbol', 'callinjection') |
|
1226 | ('symbol', 'callinjection') | |
1209 | (range |
|
1227 | (range | |
1210 | ('symbol', '2') |
|
1228 | ('symbol', '2') | |
1211 | ('symbol', '5'))) |
|
1229 | ('symbol', '5'))) | |
1212 | (func |
|
1230 | (func | |
1213 | ('symbol', 'descendants') |
|
1231 | ('symbol', 'descendants') | |
1214 | (func |
|
1232 | (func | |
1215 | ('symbol', 'max') |
|
1233 | ('symbol', 'max') | |
1216 | ('string', '$1'))) |
|
1234 | ('string', '$1'))) | |
1217 | abort: unknown revision '$1'! |
|
1235 | abort: unknown revision '$1'! | |
1218 | [255] |
|
1236 | [255] | |
1219 |
|
1237 | |||
1220 | $ echo 'injectparamasstring2 = max(_aliasarg("$1"))' >> .hg/hgrc |
|
1238 | $ echo 'injectparamasstring2 = max(_aliasarg("$1"))' >> .hg/hgrc | |
1221 | $ echo 'callinjection2($1) = descendants(injectparamasstring2)' >> .hg/hgrc |
|
1239 | $ echo 'callinjection2($1) = descendants(injectparamasstring2)' >> .hg/hgrc | |
1222 | $ try 'callinjection2(2:5)' |
|
1240 | $ try 'callinjection2(2:5)' | |
1223 | (func |
|
1241 | (func | |
1224 | ('symbol', 'callinjection2') |
|
1242 | ('symbol', 'callinjection2') | |
1225 | (range |
|
1243 | (range | |
1226 | ('symbol', '2') |
|
1244 | ('symbol', '2') | |
1227 | ('symbol', '5'))) |
|
1245 | ('symbol', '5'))) | |
1228 | abort: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg |
|
1246 | abort: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg | |
1229 | [255] |
|
1247 | [255] | |
1230 | $ hg debugrevspec --debug --config revsetalias.anotherbadone='branch(' "tip" |
|
1248 | $ hg debugrevspec --debug --config revsetalias.anotherbadone='branch(' "tip" | |
1231 | ('symbol', 'tip') |
|
1249 | ('symbol', 'tip') | |
1232 | warning: failed to parse the definition of revset alias "anotherbadone": at 7: not a prefix: end |
|
1250 | warning: failed to parse the definition of revset alias "anotherbadone": at 7: not a prefix: end | |
1233 | warning: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg |
|
1251 | warning: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg | |
1234 | * set: |
|
1252 | * set: | |
1235 | <baseset [9]> |
|
1253 | <baseset [9]> | |
1236 | 9 |
|
1254 | 9 | |
1237 | >>> data = file('.hg/hgrc', 'rb').read() |
|
1255 | >>> data = file('.hg/hgrc', 'rb').read() | |
1238 | >>> file('.hg/hgrc', 'wb').write(data.replace('_aliasarg', '')) |
|
1256 | >>> file('.hg/hgrc', 'wb').write(data.replace('_aliasarg', '')) | |
1239 |
|
1257 | |||
1240 | $ try 'tip' |
|
1258 | $ try 'tip' | |
1241 | ('symbol', 'tip') |
|
1259 | ('symbol', 'tip') | |
1242 | * set: |
|
1260 | * set: | |
1243 | <baseset [9]> |
|
1261 | <baseset [9]> | |
1244 | 9 |
|
1262 | 9 | |
1245 |
|
1263 | |||
1246 | $ hg debugrevspec --debug --config revsetalias.'bad name'='tip' "tip" |
|
1264 | $ hg debugrevspec --debug --config revsetalias.'bad name'='tip' "tip" | |
1247 | ('symbol', 'tip') |
|
1265 | ('symbol', 'tip') | |
1248 | warning: failed to parse the declaration of revset alias "bad name": at 4: invalid token |
|
1266 | warning: failed to parse the declaration of revset alias "bad name": at 4: invalid token | |
1249 | * set: |
|
1267 | * set: | |
1250 | <baseset [9]> |
|
1268 | <baseset [9]> | |
1251 | 9 |
|
1269 | 9 | |
1252 | $ echo 'strictreplacing($1, $10) = $10 or desc("$1")' >> .hg/hgrc |
|
1270 | $ echo 'strictreplacing($1, $10) = $10 or desc("$1")' >> .hg/hgrc | |
1253 | $ try 'strictreplacing("foo", tip)' |
|
1271 | $ try 'strictreplacing("foo", tip)' | |
1254 | (func |
|
1272 | (func | |
1255 | ('symbol', 'strictreplacing') |
|
1273 | ('symbol', 'strictreplacing') | |
1256 | (list |
|
1274 | (list | |
1257 | ('string', 'foo') |
|
1275 | ('string', 'foo') | |
1258 | ('symbol', 'tip'))) |
|
1276 | ('symbol', 'tip'))) | |
1259 | (or |
|
1277 | (or | |
1260 | ('symbol', 'tip') |
|
1278 | ('symbol', 'tip') | |
1261 | (func |
|
1279 | (func | |
1262 | ('symbol', 'desc') |
|
1280 | ('symbol', 'desc') | |
1263 | ('string', '$1'))) |
|
1281 | ('string', '$1'))) | |
1264 | * set: |
|
1282 | * set: | |
1265 | <addset |
|
1283 | <addset | |
1266 | <baseset [9]>, |
|
1284 | <baseset [9]>, | |
1267 | <filteredset |
|
1285 | <filteredset | |
1268 | <filteredset |
|
1286 | <filteredset | |
1269 | <fullreposet+ 0:9>>>> |
|
1287 | <fullreposet+ 0:9>>>> | |
1270 | 9 |
|
1288 | 9 | |
1271 |
|
1289 | |||
1272 | $ try 'd(2:5)' |
|
1290 | $ try 'd(2:5)' | |
1273 | (func |
|
1291 | (func | |
1274 | ('symbol', 'd') |
|
1292 | ('symbol', 'd') | |
1275 | (range |
|
1293 | (range | |
1276 | ('symbol', '2') |
|
1294 | ('symbol', '2') | |
1277 | ('symbol', '5'))) |
|
1295 | ('symbol', '5'))) | |
1278 | (func |
|
1296 | (func | |
1279 | ('symbol', 'reverse') |
|
1297 | ('symbol', 'reverse') | |
1280 | (func |
|
1298 | (func | |
1281 | ('symbol', 'sort') |
|
1299 | ('symbol', 'sort') | |
1282 | (list |
|
1300 | (list | |
1283 | (range |
|
1301 | (range | |
1284 | ('symbol', '2') |
|
1302 | ('symbol', '2') | |
1285 | ('symbol', '5')) |
|
1303 | ('symbol', '5')) | |
1286 | ('symbol', 'date')))) |
|
1304 | ('symbol', 'date')))) | |
1287 | * set: |
|
1305 | * set: | |
1288 | <baseset [4, 5, 3, 2]> |
|
1306 | <baseset [4, 5, 3, 2]> | |
1289 | 4 |
|
1307 | 4 | |
1290 | 5 |
|
1308 | 5 | |
1291 | 3 |
|
1309 | 3 | |
1292 | 2 |
|
1310 | 2 | |
1293 | $ try 'rs(2 or 3, date)' |
|
1311 | $ try 'rs(2 or 3, date)' | |
1294 | (func |
|
1312 | (func | |
1295 | ('symbol', 'rs') |
|
1313 | ('symbol', 'rs') | |
1296 | (list |
|
1314 | (list | |
1297 | (or |
|
1315 | (or | |
1298 | ('symbol', '2') |
|
1316 | ('symbol', '2') | |
1299 | ('symbol', '3')) |
|
1317 | ('symbol', '3')) | |
1300 | ('symbol', 'date'))) |
|
1318 | ('symbol', 'date'))) | |
1301 | (func |
|
1319 | (func | |
1302 | ('symbol', 'reverse') |
|
1320 | ('symbol', 'reverse') | |
1303 | (func |
|
1321 | (func | |
1304 | ('symbol', 'sort') |
|
1322 | ('symbol', 'sort') | |
1305 | (list |
|
1323 | (list | |
1306 | (or |
|
1324 | (or | |
1307 | ('symbol', '2') |
|
1325 | ('symbol', '2') | |
1308 | ('symbol', '3')) |
|
1326 | ('symbol', '3')) | |
1309 | ('symbol', 'date')))) |
|
1327 | ('symbol', 'date')))) | |
1310 | * set: |
|
1328 | * set: | |
1311 | <baseset [3, 2]> |
|
1329 | <baseset [3, 2]> | |
1312 | 3 |
|
1330 | 3 | |
1313 | 2 |
|
1331 | 2 | |
1314 | $ try 'rs()' |
|
1332 | $ try 'rs()' | |
1315 | (func |
|
1333 | (func | |
1316 | ('symbol', 'rs') |
|
1334 | ('symbol', 'rs') | |
1317 | None) |
|
1335 | None) | |
1318 | hg: parse error: invalid number of arguments: 0 |
|
1336 | hg: parse error: invalid number of arguments: 0 | |
1319 | [255] |
|
1337 | [255] | |
1320 | $ try 'rs(2)' |
|
1338 | $ try 'rs(2)' | |
1321 | (func |
|
1339 | (func | |
1322 | ('symbol', 'rs') |
|
1340 | ('symbol', 'rs') | |
1323 | ('symbol', '2')) |
|
1341 | ('symbol', '2')) | |
1324 | hg: parse error: invalid number of arguments: 1 |
|
1342 | hg: parse error: invalid number of arguments: 1 | |
1325 | [255] |
|
1343 | [255] | |
1326 | $ try 'rs(2, data, 7)' |
|
1344 | $ try 'rs(2, data, 7)' | |
1327 | (func |
|
1345 | (func | |
1328 | ('symbol', 'rs') |
|
1346 | ('symbol', 'rs') | |
1329 | (list |
|
1347 | (list | |
1330 | (list |
|
1348 | (list | |
1331 | ('symbol', '2') |
|
1349 | ('symbol', '2') | |
1332 | ('symbol', 'data')) |
|
1350 | ('symbol', 'data')) | |
1333 | ('symbol', '7'))) |
|
1351 | ('symbol', '7'))) | |
1334 | hg: parse error: invalid number of arguments: 3 |
|
1352 | hg: parse error: invalid number of arguments: 3 | |
1335 | [255] |
|
1353 | [255] | |
1336 | $ try 'rs4(2 or 3, x, x, date)' |
|
1354 | $ try 'rs4(2 or 3, x, x, date)' | |
1337 | (func |
|
1355 | (func | |
1338 | ('symbol', 'rs4') |
|
1356 | ('symbol', 'rs4') | |
1339 | (list |
|
1357 | (list | |
1340 | (list |
|
1358 | (list | |
1341 | (list |
|
1359 | (list | |
1342 | (or |
|
1360 | (or | |
1343 | ('symbol', '2') |
|
1361 | ('symbol', '2') | |
1344 | ('symbol', '3')) |
|
1362 | ('symbol', '3')) | |
1345 | ('symbol', 'x')) |
|
1363 | ('symbol', 'x')) | |
1346 | ('symbol', 'x')) |
|
1364 | ('symbol', 'x')) | |
1347 | ('symbol', 'date'))) |
|
1365 | ('symbol', 'date'))) | |
1348 | (func |
|
1366 | (func | |
1349 | ('symbol', 'reverse') |
|
1367 | ('symbol', 'reverse') | |
1350 | (func |
|
1368 | (func | |
1351 | ('symbol', 'sort') |
|
1369 | ('symbol', 'sort') | |
1352 | (list |
|
1370 | (list | |
1353 | (or |
|
1371 | (or | |
1354 | ('symbol', '2') |
|
1372 | ('symbol', '2') | |
1355 | ('symbol', '3')) |
|
1373 | ('symbol', '3')) | |
1356 | ('symbol', 'date')))) |
|
1374 | ('symbol', 'date')))) | |
1357 | * set: |
|
1375 | * set: | |
1358 | <baseset [3, 2]> |
|
1376 | <baseset [3, 2]> | |
1359 | 3 |
|
1377 | 3 | |
1360 | 2 |
|
1378 | 2 | |
1361 |
|
1379 | |||
1362 | issue4553: check that revset aliases override existing hash prefix |
|
1380 | issue4553: check that revset aliases override existing hash prefix | |
1363 |
|
1381 | |||
1364 | $ hg log -qr e |
|
1382 | $ hg log -qr e | |
1365 | 6:e0cc66ef77e8 |
|
1383 | 6:e0cc66ef77e8 | |
1366 |
|
1384 | |||
1367 | $ hg log -qr e --config revsetalias.e="all()" |
|
1385 | $ hg log -qr e --config revsetalias.e="all()" | |
1368 | 0:2785f51eece5 |
|
1386 | 0:2785f51eece5 | |
1369 | 1:d75937da8da0 |
|
1387 | 1:d75937da8da0 | |
1370 | 2:5ed5505e9f1c |
|
1388 | 2:5ed5505e9f1c | |
1371 | 3:8528aa5637f2 |
|
1389 | 3:8528aa5637f2 | |
1372 | 4:2326846efdab |
|
1390 | 4:2326846efdab | |
1373 | 5:904fa392b941 |
|
1391 | 5:904fa392b941 | |
1374 | 6:e0cc66ef77e8 |
|
1392 | 6:e0cc66ef77e8 | |
1375 | 7:013af1973af4 |
|
1393 | 7:013af1973af4 | |
1376 | 8:d5d0dcbdc4d9 |
|
1394 | 8:d5d0dcbdc4d9 | |
1377 | 9:24286f4ae135 |
|
1395 | 9:24286f4ae135 | |
1378 |
|
1396 | |||
1379 | $ hg log -qr e: --config revsetalias.e="0" |
|
1397 | $ hg log -qr e: --config revsetalias.e="0" | |
1380 | 0:2785f51eece5 |
|
1398 | 0:2785f51eece5 | |
1381 | 1:d75937da8da0 |
|
1399 | 1:d75937da8da0 | |
1382 | 2:5ed5505e9f1c |
|
1400 | 2:5ed5505e9f1c | |
1383 | 3:8528aa5637f2 |
|
1401 | 3:8528aa5637f2 | |
1384 | 4:2326846efdab |
|
1402 | 4:2326846efdab | |
1385 | 5:904fa392b941 |
|
1403 | 5:904fa392b941 | |
1386 | 6:e0cc66ef77e8 |
|
1404 | 6:e0cc66ef77e8 | |
1387 | 7:013af1973af4 |
|
1405 | 7:013af1973af4 | |
1388 | 8:d5d0dcbdc4d9 |
|
1406 | 8:d5d0dcbdc4d9 | |
1389 | 9:24286f4ae135 |
|
1407 | 9:24286f4ae135 | |
1390 |
|
1408 | |||
1391 | $ hg log -qr :e --config revsetalias.e="9" |
|
1409 | $ hg log -qr :e --config revsetalias.e="9" | |
1392 | 0:2785f51eece5 |
|
1410 | 0:2785f51eece5 | |
1393 | 1:d75937da8da0 |
|
1411 | 1:d75937da8da0 | |
1394 | 2:5ed5505e9f1c |
|
1412 | 2:5ed5505e9f1c | |
1395 | 3:8528aa5637f2 |
|
1413 | 3:8528aa5637f2 | |
1396 | 4:2326846efdab |
|
1414 | 4:2326846efdab | |
1397 | 5:904fa392b941 |
|
1415 | 5:904fa392b941 | |
1398 | 6:e0cc66ef77e8 |
|
1416 | 6:e0cc66ef77e8 | |
1399 | 7:013af1973af4 |
|
1417 | 7:013af1973af4 | |
1400 | 8:d5d0dcbdc4d9 |
|
1418 | 8:d5d0dcbdc4d9 | |
1401 | 9:24286f4ae135 |
|
1419 | 9:24286f4ae135 | |
1402 |
|
1420 | |||
1403 | $ hg log -qr e: |
|
1421 | $ hg log -qr e: | |
1404 | 6:e0cc66ef77e8 |
|
1422 | 6:e0cc66ef77e8 | |
1405 | 7:013af1973af4 |
|
1423 | 7:013af1973af4 | |
1406 | 8:d5d0dcbdc4d9 |
|
1424 | 8:d5d0dcbdc4d9 | |
1407 | 9:24286f4ae135 |
|
1425 | 9:24286f4ae135 | |
1408 |
|
1426 | |||
1409 | $ hg log -qr :e |
|
1427 | $ hg log -qr :e | |
1410 | 0:2785f51eece5 |
|
1428 | 0:2785f51eece5 | |
1411 | 1:d75937da8da0 |
|
1429 | 1:d75937da8da0 | |
1412 | 2:5ed5505e9f1c |
|
1430 | 2:5ed5505e9f1c | |
1413 | 3:8528aa5637f2 |
|
1431 | 3:8528aa5637f2 | |
1414 | 4:2326846efdab |
|
1432 | 4:2326846efdab | |
1415 | 5:904fa392b941 |
|
1433 | 5:904fa392b941 | |
1416 | 6:e0cc66ef77e8 |
|
1434 | 6:e0cc66ef77e8 | |
1417 |
|
1435 | |||
1418 | issue2549 - correct optimizations |
|
1436 | issue2549 - correct optimizations | |
1419 |
|
1437 | |||
1420 | $ log 'limit(1 or 2 or 3, 2) and not 2' |
|
1438 | $ log 'limit(1 or 2 or 3, 2) and not 2' | |
1421 | 1 |
|
1439 | 1 | |
1422 | $ log 'max(1 or 2) and not 2' |
|
1440 | $ log 'max(1 or 2) and not 2' | |
1423 | $ log 'min(1 or 2) and not 1' |
|
1441 | $ log 'min(1 or 2) and not 1' | |
1424 | $ log 'last(1 or 2, 1) and not 2' |
|
1442 | $ log 'last(1 or 2, 1) and not 2' | |
1425 |
|
1443 | |||
1426 | issue4289 - ordering of built-ins |
|
1444 | issue4289 - ordering of built-ins | |
1427 | $ hg log -M -q -r 3:2 |
|
1445 | $ hg log -M -q -r 3:2 | |
1428 | 3:8528aa5637f2 |
|
1446 | 3:8528aa5637f2 | |
1429 | 2:5ed5505e9f1c |
|
1447 | 2:5ed5505e9f1c | |
1430 |
|
1448 | |||
1431 | test revsets started with 40-chars hash (issue3669) |
|
1449 | test revsets started with 40-chars hash (issue3669) | |
1432 |
|
1450 | |||
1433 | $ ISSUE3669_TIP=`hg tip --template '{node}'` |
|
1451 | $ ISSUE3669_TIP=`hg tip --template '{node}'` | |
1434 | $ hg log -r "${ISSUE3669_TIP}" --template '{rev}\n' |
|
1452 | $ hg log -r "${ISSUE3669_TIP}" --template '{rev}\n' | |
1435 | 9 |
|
1453 | 9 | |
1436 | $ hg log -r "${ISSUE3669_TIP}^" --template '{rev}\n' |
|
1454 | $ hg log -r "${ISSUE3669_TIP}^" --template '{rev}\n' | |
1437 | 8 |
|
1455 | 8 | |
1438 |
|
1456 | |||
1439 | test or-ed indirect predicates (issue3775) |
|
1457 | test or-ed indirect predicates (issue3775) | |
1440 |
|
1458 | |||
1441 | $ log '6 or 6^1' | sort |
|
1459 | $ log '6 or 6^1' | sort | |
1442 | 5 |
|
1460 | 5 | |
1443 | 6 |
|
1461 | 6 | |
1444 | $ log '6^1 or 6' | sort |
|
1462 | $ log '6^1 or 6' | sort | |
1445 | 5 |
|
1463 | 5 | |
1446 | 6 |
|
1464 | 6 | |
1447 | $ log '4 or 4~1' | sort |
|
1465 | $ log '4 or 4~1' | sort | |
1448 | 2 |
|
1466 | 2 | |
1449 | 4 |
|
1467 | 4 | |
1450 | $ log '4~1 or 4' | sort |
|
1468 | $ log '4~1 or 4' | sort | |
1451 | 2 |
|
1469 | 2 | |
1452 | 4 |
|
1470 | 4 | |
1453 | $ log '(0 or 2):(4 or 6) or 0 or 6' | sort |
|
1471 | $ log '(0 or 2):(4 or 6) or 0 or 6' | sort | |
1454 | 0 |
|
1472 | 0 | |
1455 | 1 |
|
1473 | 1 | |
1456 | 2 |
|
1474 | 2 | |
1457 | 3 |
|
1475 | 3 | |
1458 | 4 |
|
1476 | 4 | |
1459 | 5 |
|
1477 | 5 | |
1460 | 6 |
|
1478 | 6 | |
1461 | $ log '0 or 6 or (0 or 2):(4 or 6)' | sort |
|
1479 | $ log '0 or 6 or (0 or 2):(4 or 6)' | sort | |
1462 | 0 |
|
1480 | 0 | |
1463 | 1 |
|
1481 | 1 | |
1464 | 2 |
|
1482 | 2 | |
1465 | 3 |
|
1483 | 3 | |
1466 | 4 |
|
1484 | 4 | |
1467 | 5 |
|
1485 | 5 | |
1468 | 6 |
|
1486 | 6 | |
1469 |
|
1487 | |||
1470 | tests for 'remote()' predicate: |
|
1488 | tests for 'remote()' predicate: | |
1471 | #. (csets in remote) (id) (remote) |
|
1489 | #. (csets in remote) (id) (remote) | |
1472 | 1. less than local current branch "default" |
|
1490 | 1. less than local current branch "default" | |
1473 | 2. same with local specified "default" |
|
1491 | 2. same with local specified "default" | |
1474 | 3. more than local specified specified |
|
1492 | 3. more than local specified specified | |
1475 |
|
1493 | |||
1476 | $ hg clone --quiet -U . ../remote3 |
|
1494 | $ hg clone --quiet -U . ../remote3 | |
1477 | $ cd ../remote3 |
|
1495 | $ cd ../remote3 | |
1478 | $ hg update -q 7 |
|
1496 | $ hg update -q 7 | |
1479 | $ echo r > r |
|
1497 | $ echo r > r | |
1480 | $ hg ci -Aqm 10 |
|
1498 | $ hg ci -Aqm 10 | |
1481 | $ log 'remote()' |
|
1499 | $ log 'remote()' | |
1482 | 7 |
|
1500 | 7 | |
1483 | $ log 'remote("a-b-c-")' |
|
1501 | $ log 'remote("a-b-c-")' | |
1484 | 2 |
|
1502 | 2 | |
1485 | $ cd ../repo |
|
1503 | $ cd ../repo | |
1486 | $ log 'remote(".a.b.c.", "../remote3")' |
|
1504 | $ log 'remote(".a.b.c.", "../remote3")' | |
1487 |
|
1505 | |||
1488 | tests for concatenation of strings/symbols by "##" |
|
1506 | tests for concatenation of strings/symbols by "##" | |
1489 |
|
1507 | |||
1490 | $ try "278 ## '5f5' ## 1ee ## 'ce5'" |
|
1508 | $ try "278 ## '5f5' ## 1ee ## 'ce5'" | |
1491 | (_concat |
|
1509 | (_concat | |
1492 | (_concat |
|
1510 | (_concat | |
1493 | (_concat |
|
1511 | (_concat | |
1494 | ('symbol', '278') |
|
1512 | ('symbol', '278') | |
1495 | ('string', '5f5')) |
|
1513 | ('string', '5f5')) | |
1496 | ('symbol', '1ee')) |
|
1514 | ('symbol', '1ee')) | |
1497 | ('string', 'ce5')) |
|
1515 | ('string', 'ce5')) | |
1498 | ('string', '2785f51eece5') |
|
1516 | ('string', '2785f51eece5') | |
1499 | * set: |
|
1517 | * set: | |
1500 | <baseset [0]> |
|
1518 | <baseset [0]> | |
1501 | 0 |
|
1519 | 0 | |
1502 |
|
1520 | |||
1503 | $ echo 'cat4($1, $2, $3, $4) = $1 ## $2 ## $3 ## $4' >> .hg/hgrc |
|
1521 | $ echo 'cat4($1, $2, $3, $4) = $1 ## $2 ## $3 ## $4' >> .hg/hgrc | |
1504 | $ try "cat4(278, '5f5', 1ee, 'ce5')" |
|
1522 | $ try "cat4(278, '5f5', 1ee, 'ce5')" | |
1505 | (func |
|
1523 | (func | |
1506 | ('symbol', 'cat4') |
|
1524 | ('symbol', 'cat4') | |
1507 | (list |
|
1525 | (list | |
1508 | (list |
|
1526 | (list | |
1509 | (list |
|
1527 | (list | |
1510 | ('symbol', '278') |
|
1528 | ('symbol', '278') | |
1511 | ('string', '5f5')) |
|
1529 | ('string', '5f5')) | |
1512 | ('symbol', '1ee')) |
|
1530 | ('symbol', '1ee')) | |
1513 | ('string', 'ce5'))) |
|
1531 | ('string', 'ce5'))) | |
1514 | (_concat |
|
1532 | (_concat | |
1515 | (_concat |
|
1533 | (_concat | |
1516 | (_concat |
|
1534 | (_concat | |
1517 | ('symbol', '278') |
|
1535 | ('symbol', '278') | |
1518 | ('string', '5f5')) |
|
1536 | ('string', '5f5')) | |
1519 | ('symbol', '1ee')) |
|
1537 | ('symbol', '1ee')) | |
1520 | ('string', 'ce5')) |
|
1538 | ('string', 'ce5')) | |
1521 | ('string', '2785f51eece5') |
|
1539 | ('string', '2785f51eece5') | |
1522 | * set: |
|
1540 | * set: | |
1523 | <baseset [0]> |
|
1541 | <baseset [0]> | |
1524 | 0 |
|
1542 | 0 | |
1525 |
|
1543 | |||
1526 | (check concatenation in alias nesting) |
|
1544 | (check concatenation in alias nesting) | |
1527 |
|
1545 | |||
1528 | $ echo 'cat2($1, $2) = $1 ## $2' >> .hg/hgrc |
|
1546 | $ echo 'cat2($1, $2) = $1 ## $2' >> .hg/hgrc | |
1529 | $ echo 'cat2x2($1, $2, $3, $4) = cat2($1 ## $2, $3 ## $4)' >> .hg/hgrc |
|
1547 | $ echo 'cat2x2($1, $2, $3, $4) = cat2($1 ## $2, $3 ## $4)' >> .hg/hgrc | |
1530 | $ log "cat2x2(278, '5f5', 1ee, 'ce5')" |
|
1548 | $ log "cat2x2(278, '5f5', 1ee, 'ce5')" | |
1531 | 0 |
|
1549 | 0 | |
1532 |
|
1550 | |||
1533 | (check operator priority) |
|
1551 | (check operator priority) | |
1534 |
|
1552 | |||
1535 | $ echo 'cat2n2($1, $2, $3, $4) = $1 ## $2 or $3 ## $4~2' >> .hg/hgrc |
|
1553 | $ echo 'cat2n2($1, $2, $3, $4) = $1 ## $2 or $3 ## $4~2' >> .hg/hgrc | |
1536 | $ log "cat2n2(2785f5, 1eece5, 24286f, 4ae135)" |
|
1554 | $ log "cat2n2(2785f5, 1eece5, 24286f, 4ae135)" | |
1537 | 0 |
|
1555 | 0 | |
1538 | 4 |
|
1556 | 4 | |
1539 |
|
1557 | |||
1540 | $ cd .. |
|
1558 | $ cd .. | |
1541 |
|
1559 | |||
1542 | test author/desc/keyword in problematic encoding |
|
1560 | test author/desc/keyword in problematic encoding | |
1543 | # unicode: cp932: |
|
1561 | # unicode: cp932: | |
1544 | # u30A2 0x83 0x41(= 'A') |
|
1562 | # u30A2 0x83 0x41(= 'A') | |
1545 | # u30C2 0x83 0x61(= 'a') |
|
1563 | # u30C2 0x83 0x61(= 'a') | |
1546 |
|
1564 | |||
1547 | $ hg init problematicencoding |
|
1565 | $ hg init problematicencoding | |
1548 | $ cd problematicencoding |
|
1566 | $ cd problematicencoding | |
1549 |
|
1567 | |||
1550 | $ python > setup.sh <<EOF |
|
1568 | $ python > setup.sh <<EOF | |
1551 | > print u''' |
|
1569 | > print u''' | |
1552 | > echo a > text |
|
1570 | > echo a > text | |
1553 | > hg add text |
|
1571 | > hg add text | |
1554 | > hg --encoding utf-8 commit -u '\u30A2' -m none |
|
1572 | > hg --encoding utf-8 commit -u '\u30A2' -m none | |
1555 | > echo b > text |
|
1573 | > echo b > text | |
1556 | > hg --encoding utf-8 commit -u '\u30C2' -m none |
|
1574 | > hg --encoding utf-8 commit -u '\u30C2' -m none | |
1557 | > echo c > text |
|
1575 | > echo c > text | |
1558 | > hg --encoding utf-8 commit -u none -m '\u30A2' |
|
1576 | > hg --encoding utf-8 commit -u none -m '\u30A2' | |
1559 | > echo d > text |
|
1577 | > echo d > text | |
1560 | > hg --encoding utf-8 commit -u none -m '\u30C2' |
|
1578 | > hg --encoding utf-8 commit -u none -m '\u30C2' | |
1561 | > '''.encode('utf-8') |
|
1579 | > '''.encode('utf-8') | |
1562 | > EOF |
|
1580 | > EOF | |
1563 | $ sh < setup.sh |
|
1581 | $ sh < setup.sh | |
1564 |
|
1582 | |||
1565 | test in problematic encoding |
|
1583 | test in problematic encoding | |
1566 | $ python > test.sh <<EOF |
|
1584 | $ python > test.sh <<EOF | |
1567 | > print u''' |
|
1585 | > print u''' | |
1568 | > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30A2)' |
|
1586 | > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30A2)' | |
1569 | > echo ==== |
|
1587 | > echo ==== | |
1570 | > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30C2)' |
|
1588 | > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30C2)' | |
1571 | > echo ==== |
|
1589 | > echo ==== | |
1572 | > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30A2)' |
|
1590 | > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30A2)' | |
1573 | > echo ==== |
|
1591 | > echo ==== | |
1574 | > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30C2)' |
|
1592 | > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30C2)' | |
1575 | > echo ==== |
|
1593 | > echo ==== | |
1576 | > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30A2)' |
|
1594 | > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30A2)' | |
1577 | > echo ==== |
|
1595 | > echo ==== | |
1578 | > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30C2)' |
|
1596 | > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30C2)' | |
1579 | > '''.encode('cp932') |
|
1597 | > '''.encode('cp932') | |
1580 | > EOF |
|
1598 | > EOF | |
1581 | $ sh < test.sh |
|
1599 | $ sh < test.sh | |
1582 | 0 |
|
1600 | 0 | |
1583 | ==== |
|
1601 | ==== | |
1584 | 1 |
|
1602 | 1 | |
1585 | ==== |
|
1603 | ==== | |
1586 | 2 |
|
1604 | 2 | |
1587 | ==== |
|
1605 | ==== | |
1588 | 3 |
|
1606 | 3 | |
1589 | ==== |
|
1607 | ==== | |
1590 | 0 |
|
1608 | 0 | |
1591 | 2 |
|
1609 | 2 | |
1592 | ==== |
|
1610 | ==== | |
1593 | 1 |
|
1611 | 1 | |
1594 | 3 |
|
1612 | 3 | |
1595 |
|
1613 | |||
1596 | test error message of bad revset |
|
1614 | test error message of bad revset | |
1597 | $ hg log -r 'foo\\' |
|
1615 | $ hg log -r 'foo\\' | |
1598 | hg: parse error at 3: syntax error in revset 'foo\\' |
|
1616 | hg: parse error at 3: syntax error in revset 'foo\\' | |
1599 | [255] |
|
1617 | [255] | |
1600 |
|
1618 | |||
1601 | $ cd .. |
|
1619 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now