##// END OF EJS Templates
revset: documentation typo "metatadata"
Jesse Glick -
r16639:00290bd3 stable
parent child Browse files
Show More
@@ -1,1495 +1,1495
1 # revset.py - revision set queries for mercurial
1 # revset.py - revision set queries for mercurial
2 #
2 #
3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 import re
8 import re
9 import parser, util, error, discovery, hbisect, phases
9 import parser, util, error, discovery, hbisect, phases
10 import node
10 import node
11 import bookmarks as bookmarksmod
11 import bookmarks as bookmarksmod
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
15
16 def _revancestors(repo, revs, followfirst):
16 def _revancestors(repo, revs, followfirst):
17 """Like revlog.ancestors(), but supports followfirst."""
17 """Like revlog.ancestors(), but supports followfirst."""
18 cut = followfirst and 1 or None
18 cut = followfirst and 1 or None
19 cl = repo.changelog
19 cl = repo.changelog
20 visit = list(revs)
20 visit = list(revs)
21 seen = set([node.nullrev])
21 seen = set([node.nullrev])
22 while visit:
22 while visit:
23 for parent in cl.parentrevs(visit.pop(0))[:cut]:
23 for parent in cl.parentrevs(visit.pop(0))[:cut]:
24 if parent not in seen:
24 if parent not in seen:
25 visit.append(parent)
25 visit.append(parent)
26 seen.add(parent)
26 seen.add(parent)
27 yield parent
27 yield parent
28
28
29 def _revdescendants(repo, revs, followfirst):
29 def _revdescendants(repo, revs, followfirst):
30 """Like revlog.descendants() but supports followfirst."""
30 """Like revlog.descendants() but supports followfirst."""
31 cut = followfirst and 1 or None
31 cut = followfirst and 1 or None
32 cl = repo.changelog
32 cl = repo.changelog
33 first = min(revs)
33 first = min(revs)
34 nullrev = node.nullrev
34 nullrev = node.nullrev
35 if first == nullrev:
35 if first == nullrev:
36 # Are there nodes with a null first parent and a non-null
36 # Are there nodes with a null first parent and a non-null
37 # second one? Maybe. Do we care? Probably not.
37 # second one? Maybe. Do we care? Probably not.
38 for i in cl:
38 for i in cl:
39 yield i
39 yield i
40 return
40 return
41
41
42 seen = set(revs)
42 seen = set(revs)
43 for i in xrange(first + 1, len(cl)):
43 for i in xrange(first + 1, len(cl)):
44 for x in cl.parentrevs(i)[:cut]:
44 for x in cl.parentrevs(i)[:cut]:
45 if x != nullrev and x in seen:
45 if x != nullrev and x in seen:
46 seen.add(i)
46 seen.add(i)
47 yield i
47 yield i
48 break
48 break
49
49
50 elements = {
50 elements = {
51 "(": (20, ("group", 1, ")"), ("func", 1, ")")),
51 "(": (20, ("group", 1, ")"), ("func", 1, ")")),
52 "~": (18, None, ("ancestor", 18)),
52 "~": (18, None, ("ancestor", 18)),
53 "^": (18, None, ("parent", 18), ("parentpost", 18)),
53 "^": (18, None, ("parent", 18), ("parentpost", 18)),
54 "-": (5, ("negate", 19), ("minus", 5)),
54 "-": (5, ("negate", 19), ("minus", 5)),
55 "::": (17, ("dagrangepre", 17), ("dagrange", 17),
55 "::": (17, ("dagrangepre", 17), ("dagrange", 17),
56 ("dagrangepost", 17)),
56 ("dagrangepost", 17)),
57 "..": (17, ("dagrangepre", 17), ("dagrange", 17),
57 "..": (17, ("dagrangepre", 17), ("dagrange", 17),
58 ("dagrangepost", 17)),
58 ("dagrangepost", 17)),
59 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
59 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
60 "not": (10, ("not", 10)),
60 "not": (10, ("not", 10)),
61 "!": (10, ("not", 10)),
61 "!": (10, ("not", 10)),
62 "and": (5, None, ("and", 5)),
62 "and": (5, None, ("and", 5)),
63 "&": (5, None, ("and", 5)),
63 "&": (5, None, ("and", 5)),
64 "or": (4, None, ("or", 4)),
64 "or": (4, None, ("or", 4)),
65 "|": (4, None, ("or", 4)),
65 "|": (4, None, ("or", 4)),
66 "+": (4, None, ("or", 4)),
66 "+": (4, None, ("or", 4)),
67 ",": (2, None, ("list", 2)),
67 ",": (2, None, ("list", 2)),
68 ")": (0, None, None),
68 ")": (0, None, None),
69 "symbol": (0, ("symbol",), None),
69 "symbol": (0, ("symbol",), None),
70 "string": (0, ("string",), None),
70 "string": (0, ("string",), None),
71 "end": (0, None, None),
71 "end": (0, None, None),
72 }
72 }
73
73
74 keywords = set(['and', 'or', 'not'])
74 keywords = set(['and', 'or', 'not'])
75
75
76 def tokenize(program):
76 def tokenize(program):
77 pos, l = 0, len(program)
77 pos, l = 0, len(program)
78 while pos < l:
78 while pos < l:
79 c = program[pos]
79 c = program[pos]
80 if c.isspace(): # skip inter-token whitespace
80 if c.isspace(): # skip inter-token whitespace
81 pass
81 pass
82 elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
82 elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
83 yield ('::', None, pos)
83 yield ('::', None, pos)
84 pos += 1 # skip ahead
84 pos += 1 # skip ahead
85 elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully
85 elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully
86 yield ('..', None, pos)
86 yield ('..', None, pos)
87 pos += 1 # skip ahead
87 pos += 1 # skip ahead
88 elif c in "():,-|&+!~^": # handle simple operators
88 elif c in "():,-|&+!~^": # handle simple operators
89 yield (c, None, pos)
89 yield (c, None, pos)
90 elif (c in '"\'' or c == 'r' and
90 elif (c in '"\'' or c == 'r' and
91 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
91 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
92 if c == 'r':
92 if c == 'r':
93 pos += 1
93 pos += 1
94 c = program[pos]
94 c = program[pos]
95 decode = lambda x: x
95 decode = lambda x: x
96 else:
96 else:
97 decode = lambda x: x.decode('string-escape')
97 decode = lambda x: x.decode('string-escape')
98 pos += 1
98 pos += 1
99 s = pos
99 s = pos
100 while pos < l: # find closing quote
100 while pos < l: # find closing quote
101 d = program[pos]
101 d = program[pos]
102 if d == '\\': # skip over escaped characters
102 if d == '\\': # skip over escaped characters
103 pos += 2
103 pos += 2
104 continue
104 continue
105 if d == c:
105 if d == c:
106 yield ('string', decode(program[s:pos]), s)
106 yield ('string', decode(program[s:pos]), s)
107 break
107 break
108 pos += 1
108 pos += 1
109 else:
109 else:
110 raise error.ParseError(_("unterminated string"), s)
110 raise error.ParseError(_("unterminated string"), s)
111 elif c.isalnum() or c in '._' or ord(c) > 127: # gather up a symbol/keyword
111 elif c.isalnum() or c in '._' or ord(c) > 127: # gather up a symbol/keyword
112 s = pos
112 s = pos
113 pos += 1
113 pos += 1
114 while pos < l: # find end of symbol
114 while pos < l: # find end of symbol
115 d = program[pos]
115 d = program[pos]
116 if not (d.isalnum() or d in "._/" or ord(d) > 127):
116 if not (d.isalnum() or d in "._/" or ord(d) > 127):
117 break
117 break
118 if d == '.' and program[pos - 1] == '.': # special case for ..
118 if d == '.' and program[pos - 1] == '.': # special case for ..
119 pos -= 1
119 pos -= 1
120 break
120 break
121 pos += 1
121 pos += 1
122 sym = program[s:pos]
122 sym = program[s:pos]
123 if sym in keywords: # operator keywords
123 if sym in keywords: # operator keywords
124 yield (sym, None, s)
124 yield (sym, None, s)
125 else:
125 else:
126 yield ('symbol', sym, s)
126 yield ('symbol', sym, s)
127 pos -= 1
127 pos -= 1
128 else:
128 else:
129 raise error.ParseError(_("syntax error"), pos)
129 raise error.ParseError(_("syntax error"), pos)
130 pos += 1
130 pos += 1
131 yield ('end', None, pos)
131 yield ('end', None, pos)
132
132
133 # helpers
133 # helpers
134
134
135 def getstring(x, err):
135 def getstring(x, err):
136 if x and (x[0] == 'string' or x[0] == 'symbol'):
136 if x and (x[0] == 'string' or x[0] == 'symbol'):
137 return x[1]
137 return x[1]
138 raise error.ParseError(err)
138 raise error.ParseError(err)
139
139
140 def getlist(x):
140 def getlist(x):
141 if not x:
141 if not x:
142 return []
142 return []
143 if x[0] == 'list':
143 if x[0] == 'list':
144 return getlist(x[1]) + [x[2]]
144 return getlist(x[1]) + [x[2]]
145 return [x]
145 return [x]
146
146
147 def getargs(x, min, max, err):
147 def getargs(x, min, max, err):
148 l = getlist(x)
148 l = getlist(x)
149 if len(l) < min or (max >= 0 and len(l) > max):
149 if len(l) < min or (max >= 0 and len(l) > max):
150 raise error.ParseError(err)
150 raise error.ParseError(err)
151 return l
151 return l
152
152
153 def getset(repo, subset, x):
153 def getset(repo, subset, x):
154 if not x:
154 if not x:
155 raise error.ParseError(_("missing argument"))
155 raise error.ParseError(_("missing argument"))
156 return methods[x[0]](repo, subset, *x[1:])
156 return methods[x[0]](repo, subset, *x[1:])
157
157
158 # operator methods
158 # operator methods
159
159
160 def stringset(repo, subset, x):
160 def stringset(repo, subset, x):
161 x = repo[x].rev()
161 x = repo[x].rev()
162 if x == -1 and len(subset) == len(repo):
162 if x == -1 and len(subset) == len(repo):
163 return [-1]
163 return [-1]
164 if len(subset) == len(repo) or x in subset:
164 if len(subset) == len(repo) or x in subset:
165 return [x]
165 return [x]
166 return []
166 return []
167
167
168 def symbolset(repo, subset, x):
168 def symbolset(repo, subset, x):
169 if x in symbols:
169 if x in symbols:
170 raise error.ParseError(_("can't use %s here") % x)
170 raise error.ParseError(_("can't use %s here") % x)
171 return stringset(repo, subset, x)
171 return stringset(repo, subset, x)
172
172
173 def rangeset(repo, subset, x, y):
173 def rangeset(repo, subset, x, y):
174 m = getset(repo, subset, x)
174 m = getset(repo, subset, x)
175 if not m:
175 if not m:
176 m = getset(repo, range(len(repo)), x)
176 m = getset(repo, range(len(repo)), x)
177
177
178 n = getset(repo, subset, y)
178 n = getset(repo, subset, y)
179 if not n:
179 if not n:
180 n = getset(repo, range(len(repo)), y)
180 n = getset(repo, range(len(repo)), y)
181
181
182 if not m or not n:
182 if not m or not n:
183 return []
183 return []
184 m, n = m[0], n[-1]
184 m, n = m[0], n[-1]
185
185
186 if m < n:
186 if m < n:
187 r = range(m, n + 1)
187 r = range(m, n + 1)
188 else:
188 else:
189 r = range(m, n - 1, -1)
189 r = range(m, n - 1, -1)
190 s = set(subset)
190 s = set(subset)
191 return [x for x in r if x in s]
191 return [x for x in r if x in s]
192
192
193 def andset(repo, subset, x, y):
193 def andset(repo, subset, x, y):
194 return getset(repo, getset(repo, subset, x), y)
194 return getset(repo, getset(repo, subset, x), y)
195
195
196 def orset(repo, subset, x, y):
196 def orset(repo, subset, x, y):
197 xl = getset(repo, subset, x)
197 xl = getset(repo, subset, x)
198 s = set(xl)
198 s = set(xl)
199 yl = getset(repo, [r for r in subset if r not in s], y)
199 yl = getset(repo, [r for r in subset if r not in s], y)
200 return xl + yl
200 return xl + yl
201
201
202 def notset(repo, subset, x):
202 def notset(repo, subset, x):
203 s = set(getset(repo, subset, x))
203 s = set(getset(repo, subset, x))
204 return [r for r in subset if r not in s]
204 return [r for r in subset if r not in s]
205
205
206 def listset(repo, subset, a, b):
206 def listset(repo, subset, a, b):
207 raise error.ParseError(_("can't use a list in this context"))
207 raise error.ParseError(_("can't use a list in this context"))
208
208
209 def func(repo, subset, a, b):
209 def func(repo, subset, a, b):
210 if a[0] == 'symbol' and a[1] in symbols:
210 if a[0] == 'symbol' and a[1] in symbols:
211 return symbols[a[1]](repo, subset, b)
211 return symbols[a[1]](repo, subset, b)
212 raise error.ParseError(_("not a function: %s") % a[1])
212 raise error.ParseError(_("not a function: %s") % a[1])
213
213
214 # functions
214 # functions
215
215
216 def adds(repo, subset, x):
216 def adds(repo, subset, x):
217 """``adds(pattern)``
217 """``adds(pattern)``
218 Changesets that add a file matching pattern.
218 Changesets that add a file matching pattern.
219 """
219 """
220 # i18n: "adds" is a keyword
220 # i18n: "adds" is a keyword
221 pat = getstring(x, _("adds requires a pattern"))
221 pat = getstring(x, _("adds requires a pattern"))
222 return checkstatus(repo, subset, pat, 1)
222 return checkstatus(repo, subset, pat, 1)
223
223
224 def ancestor(repo, subset, x):
224 def ancestor(repo, subset, x):
225 """``ancestor(single, single)``
225 """``ancestor(single, single)``
226 Greatest common ancestor of the two changesets.
226 Greatest common ancestor of the two changesets.
227 """
227 """
228 # i18n: "ancestor" is a keyword
228 # i18n: "ancestor" is a keyword
229 l = getargs(x, 2, 2, _("ancestor requires two arguments"))
229 l = getargs(x, 2, 2, _("ancestor requires two arguments"))
230 r = range(len(repo))
230 r = range(len(repo))
231 a = getset(repo, r, l[0])
231 a = getset(repo, r, l[0])
232 b = getset(repo, r, l[1])
232 b = getset(repo, r, l[1])
233 if len(a) != 1 or len(b) != 1:
233 if len(a) != 1 or len(b) != 1:
234 # i18n: "ancestor" is a keyword
234 # i18n: "ancestor" is a keyword
235 raise error.ParseError(_("ancestor arguments must be single revisions"))
235 raise error.ParseError(_("ancestor arguments must be single revisions"))
236 an = [repo[a[0]].ancestor(repo[b[0]]).rev()]
236 an = [repo[a[0]].ancestor(repo[b[0]]).rev()]
237
237
238 return [r for r in an if r in subset]
238 return [r for r in an if r in subset]
239
239
240 def _ancestors(repo, subset, x, followfirst=False):
240 def _ancestors(repo, subset, x, followfirst=False):
241 args = getset(repo, range(len(repo)), x)
241 args = getset(repo, range(len(repo)), x)
242 if not args:
242 if not args:
243 return []
243 return []
244 s = set(_revancestors(repo, args, followfirst)) | set(args)
244 s = set(_revancestors(repo, args, followfirst)) | set(args)
245 return [r for r in subset if r in s]
245 return [r for r in subset if r in s]
246
246
247 def ancestors(repo, subset, x):
247 def ancestors(repo, subset, x):
248 """``ancestors(set)``
248 """``ancestors(set)``
249 Changesets that are ancestors of a changeset in set.
249 Changesets that are ancestors of a changeset in set.
250 """
250 """
251 return _ancestors(repo, subset, x)
251 return _ancestors(repo, subset, x)
252
252
253 def _firstancestors(repo, subset, x):
253 def _firstancestors(repo, subset, x):
254 # ``_firstancestors(set)``
254 # ``_firstancestors(set)``
255 # Like ``ancestors(set)`` but follows only the first parents.
255 # Like ``ancestors(set)`` but follows only the first parents.
256 return _ancestors(repo, subset, x, followfirst=True)
256 return _ancestors(repo, subset, x, followfirst=True)
257
257
258 def ancestorspec(repo, subset, x, n):
258 def ancestorspec(repo, subset, x, n):
259 """``set~n``
259 """``set~n``
260 Changesets that are the Nth ancestor (first parents only) of a changeset in set.
260 Changesets that are the Nth ancestor (first parents only) of a changeset in set.
261 """
261 """
262 try:
262 try:
263 n = int(n[1])
263 n = int(n[1])
264 except (TypeError, ValueError):
264 except (TypeError, ValueError):
265 raise error.ParseError(_("~ expects a number"))
265 raise error.ParseError(_("~ expects a number"))
266 ps = set()
266 ps = set()
267 cl = repo.changelog
267 cl = repo.changelog
268 for r in getset(repo, subset, x):
268 for r in getset(repo, subset, x):
269 for i in range(n):
269 for i in range(n):
270 r = cl.parentrevs(r)[0]
270 r = cl.parentrevs(r)[0]
271 ps.add(r)
271 ps.add(r)
272 return [r for r in subset if r in ps]
272 return [r for r in subset if r in ps]
273
273
274 def author(repo, subset, x):
274 def author(repo, subset, x):
275 """``author(string)``
275 """``author(string)``
276 Alias for ``user(string)``.
276 Alias for ``user(string)``.
277 """
277 """
278 # i18n: "author" is a keyword
278 # i18n: "author" is a keyword
279 n = encoding.lower(getstring(x, _("author requires a string")))
279 n = encoding.lower(getstring(x, _("author requires a string")))
280 return [r for r in subset if n in encoding.lower(repo[r].user())]
280 return [r for r in subset if n in encoding.lower(repo[r].user())]
281
281
282 def bisect(repo, subset, x):
282 def bisect(repo, subset, x):
283 """``bisect(string)``
283 """``bisect(string)``
284 Changesets marked in the specified bisect status:
284 Changesets marked in the specified bisect status:
285
285
286 - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
286 - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
287 - ``goods``, ``bads`` : csets topologicaly good/bad
287 - ``goods``, ``bads`` : csets topologicaly good/bad
288 - ``range`` : csets taking part in the bisection
288 - ``range`` : csets taking part in the bisection
289 - ``pruned`` : csets that are goods, bads or skipped
289 - ``pruned`` : csets that are goods, bads or skipped
290 - ``untested`` : csets whose fate is yet unknown
290 - ``untested`` : csets whose fate is yet unknown
291 - ``ignored`` : csets ignored due to DAG topology
291 - ``ignored`` : csets ignored due to DAG topology
292 """
292 """
293 status = getstring(x, _("bisect requires a string")).lower()
293 status = getstring(x, _("bisect requires a string")).lower()
294 state = set(hbisect.get(repo, status))
294 state = set(hbisect.get(repo, status))
295 return [r for r in subset if r in state]
295 return [r for r in subset if r in state]
296
296
297 # Backward-compatibility
297 # Backward-compatibility
298 # - no help entry so that we do not advertise it any more
298 # - no help entry so that we do not advertise it any more
299 def bisected(repo, subset, x):
299 def bisected(repo, subset, x):
300 return bisect(repo, subset, x)
300 return bisect(repo, subset, x)
301
301
302 def bookmark(repo, subset, x):
302 def bookmark(repo, subset, x):
303 """``bookmark([name])``
303 """``bookmark([name])``
304 The named bookmark or all bookmarks.
304 The named bookmark or all bookmarks.
305 """
305 """
306 # i18n: "bookmark" is a keyword
306 # i18n: "bookmark" is a keyword
307 args = getargs(x, 0, 1, _('bookmark takes one or no arguments'))
307 args = getargs(x, 0, 1, _('bookmark takes one or no arguments'))
308 if args:
308 if args:
309 bm = getstring(args[0],
309 bm = getstring(args[0],
310 # i18n: "bookmark" is a keyword
310 # i18n: "bookmark" is a keyword
311 _('the argument to bookmark must be a string'))
311 _('the argument to bookmark must be a string'))
312 bmrev = bookmarksmod.listbookmarks(repo).get(bm, None)
312 bmrev = bookmarksmod.listbookmarks(repo).get(bm, None)
313 if not bmrev:
313 if not bmrev:
314 raise util.Abort(_("bookmark '%s' does not exist") % bm)
314 raise util.Abort(_("bookmark '%s' does not exist") % bm)
315 bmrev = repo[bmrev].rev()
315 bmrev = repo[bmrev].rev()
316 return [r for r in subset if r == bmrev]
316 return [r for r in subset if r == bmrev]
317 bms = set([repo[r].rev()
317 bms = set([repo[r].rev()
318 for r in bookmarksmod.listbookmarks(repo).values()])
318 for r in bookmarksmod.listbookmarks(repo).values()])
319 return [r for r in subset if r in bms]
319 return [r for r in subset if r in bms]
320
320
321 def branch(repo, subset, x):
321 def branch(repo, subset, x):
322 """``branch(string or set)``
322 """``branch(string or set)``
323 All changesets belonging to the given branch or the branches of the given
323 All changesets belonging to the given branch or the branches of the given
324 changesets.
324 changesets.
325 """
325 """
326 try:
326 try:
327 b = getstring(x, '')
327 b = getstring(x, '')
328 if b in repo.branchmap():
328 if b in repo.branchmap():
329 return [r for r in subset if repo[r].branch() == b]
329 return [r for r in subset if repo[r].branch() == b]
330 except error.ParseError:
330 except error.ParseError:
331 # not a string, but another revspec, e.g. tip()
331 # not a string, but another revspec, e.g. tip()
332 pass
332 pass
333
333
334 s = getset(repo, range(len(repo)), x)
334 s = getset(repo, range(len(repo)), x)
335 b = set()
335 b = set()
336 for r in s:
336 for r in s:
337 b.add(repo[r].branch())
337 b.add(repo[r].branch())
338 s = set(s)
338 s = set(s)
339 return [r for r in subset if r in s or repo[r].branch() in b]
339 return [r for r in subset if r in s or repo[r].branch() in b]
340
340
341 def checkstatus(repo, subset, pat, field):
341 def checkstatus(repo, subset, pat, field):
342 m = None
342 m = None
343 s = []
343 s = []
344 hasset = matchmod.patkind(pat) == 'set'
344 hasset = matchmod.patkind(pat) == 'set'
345 fname = None
345 fname = None
346 for r in subset:
346 for r in subset:
347 c = repo[r]
347 c = repo[r]
348 if not m or hasset:
348 if not m or hasset:
349 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
349 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
350 if not m.anypats() and len(m.files()) == 1:
350 if not m.anypats() and len(m.files()) == 1:
351 fname = m.files()[0]
351 fname = m.files()[0]
352 if fname is not None:
352 if fname is not None:
353 if fname not in c.files():
353 if fname not in c.files():
354 continue
354 continue
355 else:
355 else:
356 for f in c.files():
356 for f in c.files():
357 if m(f):
357 if m(f):
358 break
358 break
359 else:
359 else:
360 continue
360 continue
361 files = repo.status(c.p1().node(), c.node())[field]
361 files = repo.status(c.p1().node(), c.node())[field]
362 if fname is not None:
362 if fname is not None:
363 if fname in files:
363 if fname in files:
364 s.append(r)
364 s.append(r)
365 else:
365 else:
366 for f in files:
366 for f in files:
367 if m(f):
367 if m(f):
368 s.append(r)
368 s.append(r)
369 break
369 break
370 return s
370 return s
371
371
372 def _children(repo, narrow, parentset):
372 def _children(repo, narrow, parentset):
373 cs = set()
373 cs = set()
374 pr = repo.changelog.parentrevs
374 pr = repo.changelog.parentrevs
375 for r in narrow:
375 for r in narrow:
376 for p in pr(r):
376 for p in pr(r):
377 if p in parentset:
377 if p in parentset:
378 cs.add(r)
378 cs.add(r)
379 return cs
379 return cs
380
380
381 def children(repo, subset, x):
381 def children(repo, subset, x):
382 """``children(set)``
382 """``children(set)``
383 Child changesets of changesets in set.
383 Child changesets of changesets in set.
384 """
384 """
385 s = set(getset(repo, range(len(repo)), x))
385 s = set(getset(repo, range(len(repo)), x))
386 cs = _children(repo, subset, s)
386 cs = _children(repo, subset, s)
387 return [r for r in subset if r in cs]
387 return [r for r in subset if r in cs]
388
388
389 def closed(repo, subset, x):
389 def closed(repo, subset, x):
390 """``closed()``
390 """``closed()``
391 Changeset is closed.
391 Changeset is closed.
392 """
392 """
393 # i18n: "closed" is a keyword
393 # i18n: "closed" is a keyword
394 getargs(x, 0, 0, _("closed takes no arguments"))
394 getargs(x, 0, 0, _("closed takes no arguments"))
395 return [r for r in subset if repo[r].extra().get('close')]
395 return [r for r in subset if repo[r].extra().get('close')]
396
396
397 def contains(repo, subset, x):
397 def contains(repo, subset, x):
398 """``contains(pattern)``
398 """``contains(pattern)``
399 Revision contains a file matching pattern. See :hg:`help patterns`
399 Revision contains a file matching pattern. See :hg:`help patterns`
400 for information about file patterns.
400 for information about file patterns.
401 """
401 """
402 # i18n: "contains" is a keyword
402 # i18n: "contains" is a keyword
403 pat = getstring(x, _("contains requires a pattern"))
403 pat = getstring(x, _("contains requires a pattern"))
404 m = None
404 m = None
405 s = []
405 s = []
406 if not matchmod.patkind(pat):
406 if not matchmod.patkind(pat):
407 for r in subset:
407 for r in subset:
408 if pat in repo[r]:
408 if pat in repo[r]:
409 s.append(r)
409 s.append(r)
410 else:
410 else:
411 for r in subset:
411 for r in subset:
412 c = repo[r]
412 c = repo[r]
413 if not m or matchmod.patkind(pat) == 'set':
413 if not m or matchmod.patkind(pat) == 'set':
414 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
414 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
415 for f in c.manifest():
415 for f in c.manifest():
416 if m(f):
416 if m(f):
417 s.append(r)
417 s.append(r)
418 break
418 break
419 return s
419 return s
420
420
421 def date(repo, subset, x):
421 def date(repo, subset, x):
422 """``date(interval)``
422 """``date(interval)``
423 Changesets within the interval, see :hg:`help dates`.
423 Changesets within the interval, see :hg:`help dates`.
424 """
424 """
425 # i18n: "date" is a keyword
425 # i18n: "date" is a keyword
426 ds = getstring(x, _("date requires a string"))
426 ds = getstring(x, _("date requires a string"))
427 dm = util.matchdate(ds)
427 dm = util.matchdate(ds)
428 return [r for r in subset if dm(repo[r].date()[0])]
428 return [r for r in subset if dm(repo[r].date()[0])]
429
429
430 def desc(repo, subset, x):
430 def desc(repo, subset, x):
431 """``desc(string)``
431 """``desc(string)``
432 Search commit message for string. The match is case-insensitive.
432 Search commit message for string. The match is case-insensitive.
433 """
433 """
434 # i18n: "desc" is a keyword
434 # i18n: "desc" is a keyword
435 ds = encoding.lower(getstring(x, _("desc requires a string")))
435 ds = encoding.lower(getstring(x, _("desc requires a string")))
436 l = []
436 l = []
437 for r in subset:
437 for r in subset:
438 c = repo[r]
438 c = repo[r]
439 if ds in encoding.lower(c.description()):
439 if ds in encoding.lower(c.description()):
440 l.append(r)
440 l.append(r)
441 return l
441 return l
442
442
443 def _descendants(repo, subset, x, followfirst=False):
443 def _descendants(repo, subset, x, followfirst=False):
444 args = getset(repo, range(len(repo)), x)
444 args = getset(repo, range(len(repo)), x)
445 if not args:
445 if not args:
446 return []
446 return []
447 s = set(_revdescendants(repo, args, followfirst)) | set(args)
447 s = set(_revdescendants(repo, args, followfirst)) | set(args)
448 return [r for r in subset if r in s]
448 return [r for r in subset if r in s]
449
449
450 def descendants(repo, subset, x):
450 def descendants(repo, subset, x):
451 """``descendants(set)``
451 """``descendants(set)``
452 Changesets which are descendants of changesets in set.
452 Changesets which are descendants of changesets in set.
453 """
453 """
454 return _descendants(repo, subset, x)
454 return _descendants(repo, subset, x)
455
455
456 def _firstdescendants(repo, subset, x):
456 def _firstdescendants(repo, subset, x):
457 # ``_firstdescendants(set)``
457 # ``_firstdescendants(set)``
458 # Like ``descendants(set)`` but follows only the first parents.
458 # Like ``descendants(set)`` but follows only the first parents.
459 return _descendants(repo, subset, x, followfirst=True)
459 return _descendants(repo, subset, x, followfirst=True)
460
460
461 def draft(repo, subset, x):
461 def draft(repo, subset, x):
462 """``draft()``
462 """``draft()``
463 Changeset in draft phase."""
463 Changeset in draft phase."""
464 getargs(x, 0, 0, _("draft takes no arguments"))
464 getargs(x, 0, 0, _("draft takes no arguments"))
465 return [r for r in subset if repo._phaserev[r] == phases.draft]
465 return [r for r in subset if repo._phaserev[r] == phases.draft]
466
466
467 def filelog(repo, subset, x):
467 def filelog(repo, subset, x):
468 """``filelog(pattern)``
468 """``filelog(pattern)``
469 Changesets connected to the specified filelog.
469 Changesets connected to the specified filelog.
470 """
470 """
471
471
472 pat = getstring(x, _("filelog requires a pattern"))
472 pat = getstring(x, _("filelog requires a pattern"))
473 m = matchmod.match(repo.root, repo.getcwd(), [pat], default='relpath',
473 m = matchmod.match(repo.root, repo.getcwd(), [pat], default='relpath',
474 ctx=repo[None])
474 ctx=repo[None])
475 s = set()
475 s = set()
476
476
477 if not matchmod.patkind(pat):
477 if not matchmod.patkind(pat):
478 for f in m.files():
478 for f in m.files():
479 fl = repo.file(f)
479 fl = repo.file(f)
480 for fr in fl:
480 for fr in fl:
481 s.add(fl.linkrev(fr))
481 s.add(fl.linkrev(fr))
482 else:
482 else:
483 for f in repo[None]:
483 for f in repo[None]:
484 if m(f):
484 if m(f):
485 fl = repo.file(f)
485 fl = repo.file(f)
486 for fr in fl:
486 for fr in fl:
487 s.add(fl.linkrev(fr))
487 s.add(fl.linkrev(fr))
488
488
489 return [r for r in subset if r in s]
489 return [r for r in subset if r in s]
490
490
491 def first(repo, subset, x):
491 def first(repo, subset, x):
492 """``first(set, [n])``
492 """``first(set, [n])``
493 An alias for limit().
493 An alias for limit().
494 """
494 """
495 return limit(repo, subset, x)
495 return limit(repo, subset, x)
496
496
497 def _follow(repo, subset, x, name, followfirst=False):
497 def _follow(repo, subset, x, name, followfirst=False):
498 l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name)
498 l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name)
499 c = repo['.']
499 c = repo['.']
500 if l:
500 if l:
501 x = getstring(l[0], _("%s expected a filename") % name)
501 x = getstring(l[0], _("%s expected a filename") % name)
502 if x in c:
502 if x in c:
503 cx = c[x]
503 cx = c[x]
504 s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst))
504 s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst))
505 # include the revision responsible for the most recent version
505 # include the revision responsible for the most recent version
506 s.add(cx.linkrev())
506 s.add(cx.linkrev())
507 else:
507 else:
508 return []
508 return []
509 else:
509 else:
510 s = set(_revancestors(repo, [c.rev()], followfirst)) | set([c.rev()])
510 s = set(_revancestors(repo, [c.rev()], followfirst)) | set([c.rev()])
511
511
512 return [r for r in subset if r in s]
512 return [r for r in subset if r in s]
513
513
514 def follow(repo, subset, x):
514 def follow(repo, subset, x):
515 """``follow([file])``
515 """``follow([file])``
516 An alias for ``::.`` (ancestors of the working copy's first parent).
516 An alias for ``::.`` (ancestors of the working copy's first parent).
517 If a filename is specified, the history of the given file is followed,
517 If a filename is specified, the history of the given file is followed,
518 including copies.
518 including copies.
519 """
519 """
520 return _follow(repo, subset, x, 'follow')
520 return _follow(repo, subset, x, 'follow')
521
521
522 def _followfirst(repo, subset, x):
522 def _followfirst(repo, subset, x):
523 # ``followfirst([file])``
523 # ``followfirst([file])``
524 # Like ``follow([file])`` but follows only the first parent of
524 # Like ``follow([file])`` but follows only the first parent of
525 # every revision or file revision.
525 # every revision or file revision.
526 return _follow(repo, subset, x, '_followfirst', followfirst=True)
526 return _follow(repo, subset, x, '_followfirst', followfirst=True)
527
527
528 def getall(repo, subset, x):
528 def getall(repo, subset, x):
529 """``all()``
529 """``all()``
530 All changesets, the same as ``0:tip``.
530 All changesets, the same as ``0:tip``.
531 """
531 """
532 # i18n: "all" is a keyword
532 # i18n: "all" is a keyword
533 getargs(x, 0, 0, _("all takes no arguments"))
533 getargs(x, 0, 0, _("all takes no arguments"))
534 return subset
534 return subset
535
535
536 def grep(repo, subset, x):
536 def grep(repo, subset, x):
537 """``grep(regex)``
537 """``grep(regex)``
538 Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
538 Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
539 to ensure special escape characters are handled correctly. Unlike
539 to ensure special escape characters are handled correctly. Unlike
540 ``keyword(string)``, the match is case-sensitive.
540 ``keyword(string)``, the match is case-sensitive.
541 """
541 """
542 try:
542 try:
543 # i18n: "grep" is a keyword
543 # i18n: "grep" is a keyword
544 gr = re.compile(getstring(x, _("grep requires a string")))
544 gr = re.compile(getstring(x, _("grep requires a string")))
545 except re.error, e:
545 except re.error, e:
546 raise error.ParseError(_('invalid match pattern: %s') % e)
546 raise error.ParseError(_('invalid match pattern: %s') % e)
547 l = []
547 l = []
548 for r in subset:
548 for r in subset:
549 c = repo[r]
549 c = repo[r]
550 for e in c.files() + [c.user(), c.description()]:
550 for e in c.files() + [c.user(), c.description()]:
551 if gr.search(e):
551 if gr.search(e):
552 l.append(r)
552 l.append(r)
553 break
553 break
554 return l
554 return l
555
555
556 def _matchfiles(repo, subset, x):
556 def _matchfiles(repo, subset, x):
557 # _matchfiles takes a revset list of prefixed arguments:
557 # _matchfiles takes a revset list of prefixed arguments:
558 #
558 #
559 # [p:foo, i:bar, x:baz]
559 # [p:foo, i:bar, x:baz]
560 #
560 #
561 # builds a match object from them and filters subset. Allowed
561 # builds a match object from them and filters subset. Allowed
562 # prefixes are 'p:' for regular patterns, 'i:' for include
562 # prefixes are 'p:' for regular patterns, 'i:' for include
563 # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass
563 # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass
564 # a revision identifier, or the empty string to reference the
564 # a revision identifier, or the empty string to reference the
565 # working directory, from which the match object is
565 # working directory, from which the match object is
566 # initialized. Use 'd:' to set the default matching mode, default
566 # initialized. Use 'd:' to set the default matching mode, default
567 # to 'glob'. At most one 'r:' and 'd:' argument can be passed.
567 # to 'glob'. At most one 'r:' and 'd:' argument can be passed.
568
568
569 # i18n: "_matchfiles" is a keyword
569 # i18n: "_matchfiles" is a keyword
570 l = getargs(x, 1, -1, _("_matchfiles requires at least one argument"))
570 l = getargs(x, 1, -1, _("_matchfiles requires at least one argument"))
571 pats, inc, exc = [], [], []
571 pats, inc, exc = [], [], []
572 hasset = False
572 hasset = False
573 rev, default = None, None
573 rev, default = None, None
574 for arg in l:
574 for arg in l:
575 s = getstring(arg, _("_matchfiles requires string arguments"))
575 s = getstring(arg, _("_matchfiles requires string arguments"))
576 prefix, value = s[:2], s[2:]
576 prefix, value = s[:2], s[2:]
577 if prefix == 'p:':
577 if prefix == 'p:':
578 pats.append(value)
578 pats.append(value)
579 elif prefix == 'i:':
579 elif prefix == 'i:':
580 inc.append(value)
580 inc.append(value)
581 elif prefix == 'x:':
581 elif prefix == 'x:':
582 exc.append(value)
582 exc.append(value)
583 elif prefix == 'r:':
583 elif prefix == 'r:':
584 if rev is not None:
584 if rev is not None:
585 raise error.ParseError(_('_matchfiles expected at most one '
585 raise error.ParseError(_('_matchfiles expected at most one '
586 'revision'))
586 'revision'))
587 rev = value
587 rev = value
588 elif prefix == 'd:':
588 elif prefix == 'd:':
589 if default is not None:
589 if default is not None:
590 raise error.ParseError(_('_matchfiles expected at most one '
590 raise error.ParseError(_('_matchfiles expected at most one '
591 'default mode'))
591 'default mode'))
592 default = value
592 default = value
593 else:
593 else:
594 raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix)
594 raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix)
595 if not hasset and matchmod.patkind(value) == 'set':
595 if not hasset and matchmod.patkind(value) == 'set':
596 hasset = True
596 hasset = True
597 if not default:
597 if not default:
598 default = 'glob'
598 default = 'glob'
599 m = None
599 m = None
600 s = []
600 s = []
601 for r in subset:
601 for r in subset:
602 c = repo[r]
602 c = repo[r]
603 if not m or (hasset and rev is None):
603 if not m or (hasset and rev is None):
604 ctx = c
604 ctx = c
605 if rev is not None:
605 if rev is not None:
606 ctx = repo[rev or None]
606 ctx = repo[rev or None]
607 m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc,
607 m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc,
608 exclude=exc, ctx=ctx, default=default)
608 exclude=exc, ctx=ctx, default=default)
609 for f in c.files():
609 for f in c.files():
610 if m(f):
610 if m(f):
611 s.append(r)
611 s.append(r)
612 break
612 break
613 return s
613 return s
614
614
615 def hasfile(repo, subset, x):
615 def hasfile(repo, subset, x):
616 """``file(pattern)``
616 """``file(pattern)``
617 Changesets affecting files matched by pattern.
617 Changesets affecting files matched by pattern.
618 """
618 """
619 # i18n: "file" is a keyword
619 # i18n: "file" is a keyword
620 pat = getstring(x, _("file requires a pattern"))
620 pat = getstring(x, _("file requires a pattern"))
621 return _matchfiles(repo, subset, ('string', 'p:' + pat))
621 return _matchfiles(repo, subset, ('string', 'p:' + pat))
622
622
623 def head(repo, subset, x):
623 def head(repo, subset, x):
624 """``head()``
624 """``head()``
625 Changeset is a named branch head.
625 Changeset is a named branch head.
626 """
626 """
627 # i18n: "head" is a keyword
627 # i18n: "head" is a keyword
628 getargs(x, 0, 0, _("head takes no arguments"))
628 getargs(x, 0, 0, _("head takes no arguments"))
629 hs = set()
629 hs = set()
630 for b, ls in repo.branchmap().iteritems():
630 for b, ls in repo.branchmap().iteritems():
631 hs.update(repo[h].rev() for h in ls)
631 hs.update(repo[h].rev() for h in ls)
632 return [r for r in subset if r in hs]
632 return [r for r in subset if r in hs]
633
633
634 def heads(repo, subset, x):
634 def heads(repo, subset, x):
635 """``heads(set)``
635 """``heads(set)``
636 Members of set with no children in set.
636 Members of set with no children in set.
637 """
637 """
638 s = getset(repo, subset, x)
638 s = getset(repo, subset, x)
639 ps = set(parents(repo, subset, x))
639 ps = set(parents(repo, subset, x))
640 return [r for r in s if r not in ps]
640 return [r for r in s if r not in ps]
641
641
642 def keyword(repo, subset, x):
642 def keyword(repo, subset, x):
643 """``keyword(string)``
643 """``keyword(string)``
644 Search commit message, user name, and names of changed files for
644 Search commit message, user name, and names of changed files for
645 string. The match is case-insensitive.
645 string. The match is case-insensitive.
646 """
646 """
647 # i18n: "keyword" is a keyword
647 # i18n: "keyword" is a keyword
648 kw = encoding.lower(getstring(x, _("keyword requires a string")))
648 kw = encoding.lower(getstring(x, _("keyword requires a string")))
649 l = []
649 l = []
650 for r in subset:
650 for r in subset:
651 c = repo[r]
651 c = repo[r]
652 t = " ".join(c.files() + [c.user(), c.description()])
652 t = " ".join(c.files() + [c.user(), c.description()])
653 if kw in encoding.lower(t):
653 if kw in encoding.lower(t):
654 l.append(r)
654 l.append(r)
655 return l
655 return l
656
656
657 def limit(repo, subset, x):
657 def limit(repo, subset, x):
658 """``limit(set, [n])``
658 """``limit(set, [n])``
659 First n members of set, defaulting to 1.
659 First n members of set, defaulting to 1.
660 """
660 """
661 # i18n: "limit" is a keyword
661 # i18n: "limit" is a keyword
662 l = getargs(x, 1, 2, _("limit requires one or two arguments"))
662 l = getargs(x, 1, 2, _("limit requires one or two arguments"))
663 try:
663 try:
664 lim = 1
664 lim = 1
665 if len(l) == 2:
665 if len(l) == 2:
666 # i18n: "limit" is a keyword
666 # i18n: "limit" is a keyword
667 lim = int(getstring(l[1], _("limit requires a number")))
667 lim = int(getstring(l[1], _("limit requires a number")))
668 except (TypeError, ValueError):
668 except (TypeError, ValueError):
669 # i18n: "limit" is a keyword
669 # i18n: "limit" is a keyword
670 raise error.ParseError(_("limit expects a number"))
670 raise error.ParseError(_("limit expects a number"))
671 ss = set(subset)
671 ss = set(subset)
672 os = getset(repo, range(len(repo)), l[0])[:lim]
672 os = getset(repo, range(len(repo)), l[0])[:lim]
673 return [r for r in os if r in ss]
673 return [r for r in os if r in ss]
674
674
675 def last(repo, subset, x):
675 def last(repo, subset, x):
676 """``last(set, [n])``
676 """``last(set, [n])``
677 Last n members of set, defaulting to 1.
677 Last n members of set, defaulting to 1.
678 """
678 """
679 # i18n: "last" is a keyword
679 # i18n: "last" is a keyword
680 l = getargs(x, 1, 2, _("last requires one or two arguments"))
680 l = getargs(x, 1, 2, _("last requires one or two arguments"))
681 try:
681 try:
682 lim = 1
682 lim = 1
683 if len(l) == 2:
683 if len(l) == 2:
684 # i18n: "last" is a keyword
684 # i18n: "last" is a keyword
685 lim = int(getstring(l[1], _("last requires a number")))
685 lim = int(getstring(l[1], _("last requires a number")))
686 except (TypeError, ValueError):
686 except (TypeError, ValueError):
687 # i18n: "last" is a keyword
687 # i18n: "last" is a keyword
688 raise error.ParseError(_("last expects a number"))
688 raise error.ParseError(_("last expects a number"))
689 ss = set(subset)
689 ss = set(subset)
690 os = getset(repo, range(len(repo)), l[0])[-lim:]
690 os = getset(repo, range(len(repo)), l[0])[-lim:]
691 return [r for r in os if r in ss]
691 return [r for r in os if r in ss]
692
692
693 def maxrev(repo, subset, x):
693 def maxrev(repo, subset, x):
694 """``max(set)``
694 """``max(set)``
695 Changeset with highest revision number in set.
695 Changeset with highest revision number in set.
696 """
696 """
697 os = getset(repo, range(len(repo)), x)
697 os = getset(repo, range(len(repo)), x)
698 if os:
698 if os:
699 m = max(os)
699 m = max(os)
700 if m in subset:
700 if m in subset:
701 return [m]
701 return [m]
702 return []
702 return []
703
703
704 def merge(repo, subset, x):
704 def merge(repo, subset, x):
705 """``merge()``
705 """``merge()``
706 Changeset is a merge changeset.
706 Changeset is a merge changeset.
707 """
707 """
708 # i18n: "merge" is a keyword
708 # i18n: "merge" is a keyword
709 getargs(x, 0, 0, _("merge takes no arguments"))
709 getargs(x, 0, 0, _("merge takes no arguments"))
710 cl = repo.changelog
710 cl = repo.changelog
711 return [r for r in subset if cl.parentrevs(r)[1] != -1]
711 return [r for r in subset if cl.parentrevs(r)[1] != -1]
712
712
713 def minrev(repo, subset, x):
713 def minrev(repo, subset, x):
714 """``min(set)``
714 """``min(set)``
715 Changeset with lowest revision number in set.
715 Changeset with lowest revision number in set.
716 """
716 """
717 os = getset(repo, range(len(repo)), x)
717 os = getset(repo, range(len(repo)), x)
718 if os:
718 if os:
719 m = min(os)
719 m = min(os)
720 if m in subset:
720 if m in subset:
721 return [m]
721 return [m]
722 return []
722 return []
723
723
724 def modifies(repo, subset, x):
724 def modifies(repo, subset, x):
725 """``modifies(pattern)``
725 """``modifies(pattern)``
726 Changesets modifying files matched by pattern.
726 Changesets modifying files matched by pattern.
727 """
727 """
728 # i18n: "modifies" is a keyword
728 # i18n: "modifies" is a keyword
729 pat = getstring(x, _("modifies requires a pattern"))
729 pat = getstring(x, _("modifies requires a pattern"))
730 return checkstatus(repo, subset, pat, 0)
730 return checkstatus(repo, subset, pat, 0)
731
731
732 def node_(repo, subset, x):
732 def node_(repo, subset, x):
733 """``id(string)``
733 """``id(string)``
734 Revision non-ambiguously specified by the given hex string prefix.
734 Revision non-ambiguously specified by the given hex string prefix.
735 """
735 """
736 # i18n: "id" is a keyword
736 # i18n: "id" is a keyword
737 l = getargs(x, 1, 1, _("id requires one argument"))
737 l = getargs(x, 1, 1, _("id requires one argument"))
738 # i18n: "id" is a keyword
738 # i18n: "id" is a keyword
739 n = getstring(l[0], _("id requires a string"))
739 n = getstring(l[0], _("id requires a string"))
740 if len(n) == 40:
740 if len(n) == 40:
741 rn = repo[n].rev()
741 rn = repo[n].rev()
742 else:
742 else:
743 rn = repo.changelog.rev(repo.changelog._partialmatch(n))
743 rn = repo.changelog.rev(repo.changelog._partialmatch(n))
744 return [r for r in subset if r == rn]
744 return [r for r in subset if r == rn]
745
745
746 def outgoing(repo, subset, x):
746 def outgoing(repo, subset, x):
747 """``outgoing([path])``
747 """``outgoing([path])``
748 Changesets not found in the specified destination repository, or the
748 Changesets not found in the specified destination repository, or the
749 default push location.
749 default push location.
750 """
750 """
751 import hg # avoid start-up nasties
751 import hg # avoid start-up nasties
752 # i18n: "outgoing" is a keyword
752 # i18n: "outgoing" is a keyword
753 l = getargs(x, 0, 1, _("outgoing takes one or no arguments"))
753 l = getargs(x, 0, 1, _("outgoing takes one or no arguments"))
754 # i18n: "outgoing" is a keyword
754 # i18n: "outgoing" is a keyword
755 dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
755 dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
756 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
756 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
757 dest, branches = hg.parseurl(dest)
757 dest, branches = hg.parseurl(dest)
758 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
758 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
759 if revs:
759 if revs:
760 revs = [repo.lookup(rev) for rev in revs]
760 revs = [repo.lookup(rev) for rev in revs]
761 other = hg.peer(repo, {}, dest)
761 other = hg.peer(repo, {}, dest)
762 repo.ui.pushbuffer()
762 repo.ui.pushbuffer()
763 outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
763 outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
764 repo.ui.popbuffer()
764 repo.ui.popbuffer()
765 cl = repo.changelog
765 cl = repo.changelog
766 o = set([cl.rev(r) for r in outgoing.missing])
766 o = set([cl.rev(r) for r in outgoing.missing])
767 return [r for r in subset if r in o]
767 return [r for r in subset if r in o]
768
768
769 def p1(repo, subset, x):
769 def p1(repo, subset, x):
770 """``p1([set])``
770 """``p1([set])``
771 First parent of changesets in set, or the working directory.
771 First parent of changesets in set, or the working directory.
772 """
772 """
773 if x is None:
773 if x is None:
774 p = repo[x].p1().rev()
774 p = repo[x].p1().rev()
775 return [r for r in subset if r == p]
775 return [r for r in subset if r == p]
776
776
777 ps = set()
777 ps = set()
778 cl = repo.changelog
778 cl = repo.changelog
779 for r in getset(repo, range(len(repo)), x):
779 for r in getset(repo, range(len(repo)), x):
780 ps.add(cl.parentrevs(r)[0])
780 ps.add(cl.parentrevs(r)[0])
781 return [r for r in subset if r in ps]
781 return [r for r in subset if r in ps]
782
782
783 def p2(repo, subset, x):
783 def p2(repo, subset, x):
784 """``p2([set])``
784 """``p2([set])``
785 Second parent of changesets in set, or the working directory.
785 Second parent of changesets in set, or the working directory.
786 """
786 """
787 if x is None:
787 if x is None:
788 ps = repo[x].parents()
788 ps = repo[x].parents()
789 try:
789 try:
790 p = ps[1].rev()
790 p = ps[1].rev()
791 return [r for r in subset if r == p]
791 return [r for r in subset if r == p]
792 except IndexError:
792 except IndexError:
793 return []
793 return []
794
794
795 ps = set()
795 ps = set()
796 cl = repo.changelog
796 cl = repo.changelog
797 for r in getset(repo, range(len(repo)), x):
797 for r in getset(repo, range(len(repo)), x):
798 ps.add(cl.parentrevs(r)[1])
798 ps.add(cl.parentrevs(r)[1])
799 return [r for r in subset if r in ps]
799 return [r for r in subset if r in ps]
800
800
801 def parents(repo, subset, x):
801 def parents(repo, subset, x):
802 """``parents([set])``
802 """``parents([set])``
803 The set of all parents for all changesets in set, or the working directory.
803 The set of all parents for all changesets in set, or the working directory.
804 """
804 """
805 if x is None:
805 if x is None:
806 ps = tuple(p.rev() for p in repo[x].parents())
806 ps = tuple(p.rev() for p in repo[x].parents())
807 return [r for r in subset if r in ps]
807 return [r for r in subset if r in ps]
808
808
809 ps = set()
809 ps = set()
810 cl = repo.changelog
810 cl = repo.changelog
811 for r in getset(repo, range(len(repo)), x):
811 for r in getset(repo, range(len(repo)), x):
812 ps.update(cl.parentrevs(r))
812 ps.update(cl.parentrevs(r))
813 return [r for r in subset if r in ps]
813 return [r for r in subset if r in ps]
814
814
815 def parentspec(repo, subset, x, n):
815 def parentspec(repo, subset, x, n):
816 """``set^0``
816 """``set^0``
817 The set.
817 The set.
818 ``set^1`` (or ``set^``), ``set^2``
818 ``set^1`` (or ``set^``), ``set^2``
819 First or second parent, respectively, of all changesets in set.
819 First or second parent, respectively, of all changesets in set.
820 """
820 """
821 try:
821 try:
822 n = int(n[1])
822 n = int(n[1])
823 if n not in (0, 1, 2):
823 if n not in (0, 1, 2):
824 raise ValueError
824 raise ValueError
825 except (TypeError, ValueError):
825 except (TypeError, ValueError):
826 raise error.ParseError(_("^ expects a number 0, 1, or 2"))
826 raise error.ParseError(_("^ expects a number 0, 1, or 2"))
827 ps = set()
827 ps = set()
828 cl = repo.changelog
828 cl = repo.changelog
829 for r in getset(repo, subset, x):
829 for r in getset(repo, subset, x):
830 if n == 0:
830 if n == 0:
831 ps.add(r)
831 ps.add(r)
832 elif n == 1:
832 elif n == 1:
833 ps.add(cl.parentrevs(r)[0])
833 ps.add(cl.parentrevs(r)[0])
834 elif n == 2:
834 elif n == 2:
835 parents = cl.parentrevs(r)
835 parents = cl.parentrevs(r)
836 if len(parents) > 1:
836 if len(parents) > 1:
837 ps.add(parents[1])
837 ps.add(parents[1])
838 return [r for r in subset if r in ps]
838 return [r for r in subset if r in ps]
839
839
840 def present(repo, subset, x):
840 def present(repo, subset, x):
841 """``present(set)``
841 """``present(set)``
842 An empty set, if any revision in set isn't found; otherwise,
842 An empty set, if any revision in set isn't found; otherwise,
843 all revisions in set.
843 all revisions in set.
844 """
844 """
845 try:
845 try:
846 return getset(repo, subset, x)
846 return getset(repo, subset, x)
847 except error.RepoLookupError:
847 except error.RepoLookupError:
848 return []
848 return []
849
849
850 def public(repo, subset, x):
850 def public(repo, subset, x):
851 """``public()``
851 """``public()``
852 Changeset in public phase."""
852 Changeset in public phase."""
853 getargs(x, 0, 0, _("public takes no arguments"))
853 getargs(x, 0, 0, _("public takes no arguments"))
854 return [r for r in subset if repo._phaserev[r] == phases.public]
854 return [r for r in subset if repo._phaserev[r] == phases.public]
855
855
856 def remote(repo, subset, x):
856 def remote(repo, subset, x):
857 """``remote([id [,path]])``
857 """``remote([id [,path]])``
858 Local revision that corresponds to the given identifier in a
858 Local revision that corresponds to the given identifier in a
859 remote repository, if present. Here, the '.' identifier is a
859 remote repository, if present. Here, the '.' identifier is a
860 synonym for the current local branch.
860 synonym for the current local branch.
861 """
861 """
862
862
863 import hg # avoid start-up nasties
863 import hg # avoid start-up nasties
864 # i18n: "remote" is a keyword
864 # i18n: "remote" is a keyword
865 l = getargs(x, 0, 2, _("remote takes one, two or no arguments"))
865 l = getargs(x, 0, 2, _("remote takes one, two or no arguments"))
866
866
867 q = '.'
867 q = '.'
868 if len(l) > 0:
868 if len(l) > 0:
869 # i18n: "remote" is a keyword
869 # i18n: "remote" is a keyword
870 q = getstring(l[0], _("remote requires a string id"))
870 q = getstring(l[0], _("remote requires a string id"))
871 if q == '.':
871 if q == '.':
872 q = repo['.'].branch()
872 q = repo['.'].branch()
873
873
874 dest = ''
874 dest = ''
875 if len(l) > 1:
875 if len(l) > 1:
876 # i18n: "remote" is a keyword
876 # i18n: "remote" is a keyword
877 dest = getstring(l[1], _("remote requires a repository path"))
877 dest = getstring(l[1], _("remote requires a repository path"))
878 dest = repo.ui.expandpath(dest or 'default')
878 dest = repo.ui.expandpath(dest or 'default')
879 dest, branches = hg.parseurl(dest)
879 dest, branches = hg.parseurl(dest)
880 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
880 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
881 if revs:
881 if revs:
882 revs = [repo.lookup(rev) for rev in revs]
882 revs = [repo.lookup(rev) for rev in revs]
883 other = hg.peer(repo, {}, dest)
883 other = hg.peer(repo, {}, dest)
884 n = other.lookup(q)
884 n = other.lookup(q)
885 if n in repo:
885 if n in repo:
886 r = repo[n].rev()
886 r = repo[n].rev()
887 if r in subset:
887 if r in subset:
888 return [r]
888 return [r]
889 return []
889 return []
890
890
891 def removes(repo, subset, x):
891 def removes(repo, subset, x):
892 """``removes(pattern)``
892 """``removes(pattern)``
893 Changesets which remove files matching pattern.
893 Changesets which remove files matching pattern.
894 """
894 """
895 # i18n: "removes" is a keyword
895 # i18n: "removes" is a keyword
896 pat = getstring(x, _("removes requires a pattern"))
896 pat = getstring(x, _("removes requires a pattern"))
897 return checkstatus(repo, subset, pat, 2)
897 return checkstatus(repo, subset, pat, 2)
898
898
899 def rev(repo, subset, x):
899 def rev(repo, subset, x):
900 """``rev(number)``
900 """``rev(number)``
901 Revision with the given numeric identifier.
901 Revision with the given numeric identifier.
902 """
902 """
903 # i18n: "rev" is a keyword
903 # i18n: "rev" is a keyword
904 l = getargs(x, 1, 1, _("rev requires one argument"))
904 l = getargs(x, 1, 1, _("rev requires one argument"))
905 try:
905 try:
906 # i18n: "rev" is a keyword
906 # i18n: "rev" is a keyword
907 l = int(getstring(l[0], _("rev requires a number")))
907 l = int(getstring(l[0], _("rev requires a number")))
908 except (TypeError, ValueError):
908 except (TypeError, ValueError):
909 # i18n: "rev" is a keyword
909 # i18n: "rev" is a keyword
910 raise error.ParseError(_("rev expects a number"))
910 raise error.ParseError(_("rev expects a number"))
911 return [r for r in subset if r == l]
911 return [r for r in subset if r == l]
912
912
913 def matching(repo, subset, x):
913 def matching(repo, subset, x):
914 """``matching(revision [, field])``
914 """``matching(revision [, field])``
915 Changesets in which a given set of fields match the set of fields in the
915 Changesets in which a given set of fields match the set of fields in the
916 selected revision or set.
916 selected revision or set.
917
917
918 To match more than one field pass the list of fields to match separated
918 To match more than one field pass the list of fields to match separated
919 by spaces (e.g. ``author description``).
919 by spaces (e.g. ``author description``).
920
920
921 Valid fields are most regular revision fields and some special fields.
921 Valid fields are most regular revision fields and some special fields.
922
922
923 Regular revision fields are ``description``, ``author``, ``branch``,
923 Regular revision fields are ``description``, ``author``, ``branch``,
924 ``date``, ``files``, ``phase``, ``parents``, ``substate`` and ``user``.
924 ``date``, ``files``, ``phase``, ``parents``, ``substate`` and ``user``.
925 Note that ``author`` and ``user`` are synonyms.
925 Note that ``author`` and ``user`` are synonyms.
926
926
927 Special fields are ``summary`` and ``metadata``:
927 Special fields are ``summary`` and ``metadata``:
928 ``summary`` matches the first line of the description.
928 ``summary`` matches the first line of the description.
929 ``metatadata`` is equivalent to matching ``description user date``
929 ``metadata`` is equivalent to matching ``description user date``
930 (i.e. it matches the main metadata fields).
930 (i.e. it matches the main metadata fields).
931
931
932 ``metadata`` is the default field which is used when no fields are
932 ``metadata`` is the default field which is used when no fields are
933 specified. You can match more than one field at a time.
933 specified. You can match more than one field at a time.
934 """
934 """
935 l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments"))
935 l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments"))
936
936
937 revs = getset(repo, xrange(len(repo)), l[0])
937 revs = getset(repo, xrange(len(repo)), l[0])
938
938
939 fieldlist = ['metadata']
939 fieldlist = ['metadata']
940 if len(l) > 1:
940 if len(l) > 1:
941 fieldlist = getstring(l[1],
941 fieldlist = getstring(l[1],
942 _("matching requires a string "
942 _("matching requires a string "
943 "as its second argument")).split()
943 "as its second argument")).split()
944
944
945 # Make sure that there are no repeated fields, and expand the
945 # Make sure that there are no repeated fields, and expand the
946 # 'special' 'metadata' field type
946 # 'special' 'metadata' field type
947 fields = []
947 fields = []
948 for field in fieldlist:
948 for field in fieldlist:
949 if field == 'metadata':
949 if field == 'metadata':
950 fields += ['user', 'description', 'date']
950 fields += ['user', 'description', 'date']
951 else:
951 else:
952 if field == 'author':
952 if field == 'author':
953 field = 'user'
953 field = 'user'
954 fields.append(field)
954 fields.append(field)
955 fields = set(fields)
955 fields = set(fields)
956 if 'summary' in fields and 'description' in fields:
956 if 'summary' in fields and 'description' in fields:
957 # If a revision matches its description it also matches its summary
957 # If a revision matches its description it also matches its summary
958 fields.discard('summary')
958 fields.discard('summary')
959
959
960 # We may want to match more than one field
960 # We may want to match more than one field
961 # Not all fields take the same amount of time to be matched
961 # Not all fields take the same amount of time to be matched
962 # Sort the selected fields in order of increasing matching cost
962 # Sort the selected fields in order of increasing matching cost
963 fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary',
963 fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary',
964 'files', 'description', 'substate']
964 'files', 'description', 'substate']
965 def fieldkeyfunc(f):
965 def fieldkeyfunc(f):
966 try:
966 try:
967 return fieldorder.index(f)
967 return fieldorder.index(f)
968 except ValueError:
968 except ValueError:
969 # assume an unknown field is very costly
969 # assume an unknown field is very costly
970 return len(fieldorder)
970 return len(fieldorder)
971 fields = list(fields)
971 fields = list(fields)
972 fields.sort(key=fieldkeyfunc)
972 fields.sort(key=fieldkeyfunc)
973
973
974 # Each field will be matched with its own "getfield" function
974 # Each field will be matched with its own "getfield" function
975 # which will be added to the getfieldfuncs array of functions
975 # which will be added to the getfieldfuncs array of functions
976 getfieldfuncs = []
976 getfieldfuncs = []
977 _funcs = {
977 _funcs = {
978 'user': lambda r: repo[r].user(),
978 'user': lambda r: repo[r].user(),
979 'branch': lambda r: repo[r].branch(),
979 'branch': lambda r: repo[r].branch(),
980 'date': lambda r: repo[r].date(),
980 'date': lambda r: repo[r].date(),
981 'description': lambda r: repo[r].description(),
981 'description': lambda r: repo[r].description(),
982 'files': lambda r: repo[r].files(),
982 'files': lambda r: repo[r].files(),
983 'parents': lambda r: repo[r].parents(),
983 'parents': lambda r: repo[r].parents(),
984 'phase': lambda r: repo[r].phase(),
984 'phase': lambda r: repo[r].phase(),
985 'substate': lambda r: repo[r].substate,
985 'substate': lambda r: repo[r].substate,
986 'summary': lambda r: repo[r].description().splitlines()[0],
986 'summary': lambda r: repo[r].description().splitlines()[0],
987 }
987 }
988 for info in fields:
988 for info in fields:
989 getfield = _funcs.get(info, None)
989 getfield = _funcs.get(info, None)
990 if getfield is None:
990 if getfield is None:
991 raise error.ParseError(
991 raise error.ParseError(
992 _("unexpected field name passed to matching: %s") % info)
992 _("unexpected field name passed to matching: %s") % info)
993 getfieldfuncs.append(getfield)
993 getfieldfuncs.append(getfield)
994 # convert the getfield array of functions into a "getinfo" function
994 # convert the getfield array of functions into a "getinfo" function
995 # which returns an array of field values (or a single value if there
995 # which returns an array of field values (or a single value if there
996 # is only one field to match)
996 # is only one field to match)
997 getinfo = lambda r: [f(r) for f in getfieldfuncs]
997 getinfo = lambda r: [f(r) for f in getfieldfuncs]
998
998
999 matches = []
999 matches = []
1000 for rev in revs:
1000 for rev in revs:
1001 target = getinfo(rev)
1001 target = getinfo(rev)
1002 for r in subset:
1002 for r in subset:
1003 match = True
1003 match = True
1004 for n, f in enumerate(getfieldfuncs):
1004 for n, f in enumerate(getfieldfuncs):
1005 if target[n] != f(r):
1005 if target[n] != f(r):
1006 match = False
1006 match = False
1007 break
1007 break
1008 if match:
1008 if match:
1009 matches.append(r)
1009 matches.append(r)
1010 if len(revs) > 1:
1010 if len(revs) > 1:
1011 matches = sorted(set(matches))
1011 matches = sorted(set(matches))
1012 return matches
1012 return matches
1013
1013
1014 def reverse(repo, subset, x):
1014 def reverse(repo, subset, x):
1015 """``reverse(set)``
1015 """``reverse(set)``
1016 Reverse order of set.
1016 Reverse order of set.
1017 """
1017 """
1018 l = getset(repo, subset, x)
1018 l = getset(repo, subset, x)
1019 l.reverse()
1019 l.reverse()
1020 return l
1020 return l
1021
1021
1022 def roots(repo, subset, x):
1022 def roots(repo, subset, x):
1023 """``roots(set)``
1023 """``roots(set)``
1024 Changesets in set with no parent changeset in set.
1024 Changesets in set with no parent changeset in set.
1025 """
1025 """
1026 s = set(getset(repo, xrange(len(repo)), x))
1026 s = set(getset(repo, xrange(len(repo)), x))
1027 subset = [r for r in subset if r in s]
1027 subset = [r for r in subset if r in s]
1028 cs = _children(repo, subset, s)
1028 cs = _children(repo, subset, s)
1029 return [r for r in subset if r not in cs]
1029 return [r for r in subset if r not in cs]
1030
1030
1031 def secret(repo, subset, x):
1031 def secret(repo, subset, x):
1032 """``secret()``
1032 """``secret()``
1033 Changeset in secret phase."""
1033 Changeset in secret phase."""
1034 getargs(x, 0, 0, _("secret takes no arguments"))
1034 getargs(x, 0, 0, _("secret takes no arguments"))
1035 return [r for r in subset if repo._phaserev[r] == phases.secret]
1035 return [r for r in subset if repo._phaserev[r] == phases.secret]
1036
1036
1037 def sort(repo, subset, x):
1037 def sort(repo, subset, x):
1038 """``sort(set[, [-]key...])``
1038 """``sort(set[, [-]key...])``
1039 Sort set by keys. The default sort order is ascending, specify a key
1039 Sort set by keys. The default sort order is ascending, specify a key
1040 as ``-key`` to sort in descending order.
1040 as ``-key`` to sort in descending order.
1041
1041
1042 The keys can be:
1042 The keys can be:
1043
1043
1044 - ``rev`` for the revision number,
1044 - ``rev`` for the revision number,
1045 - ``branch`` for the branch name,
1045 - ``branch`` for the branch name,
1046 - ``desc`` for the commit message (description),
1046 - ``desc`` for the commit message (description),
1047 - ``user`` for user name (``author`` can be used as an alias),
1047 - ``user`` for user name (``author`` can be used as an alias),
1048 - ``date`` for the commit date
1048 - ``date`` for the commit date
1049 """
1049 """
1050 # i18n: "sort" is a keyword
1050 # i18n: "sort" is a keyword
1051 l = getargs(x, 1, 2, _("sort requires one or two arguments"))
1051 l = getargs(x, 1, 2, _("sort requires one or two arguments"))
1052 keys = "rev"
1052 keys = "rev"
1053 if len(l) == 2:
1053 if len(l) == 2:
1054 keys = getstring(l[1], _("sort spec must be a string"))
1054 keys = getstring(l[1], _("sort spec must be a string"))
1055
1055
1056 s = l[0]
1056 s = l[0]
1057 keys = keys.split()
1057 keys = keys.split()
1058 l = []
1058 l = []
1059 def invert(s):
1059 def invert(s):
1060 return "".join(chr(255 - ord(c)) for c in s)
1060 return "".join(chr(255 - ord(c)) for c in s)
1061 for r in getset(repo, subset, s):
1061 for r in getset(repo, subset, s):
1062 c = repo[r]
1062 c = repo[r]
1063 e = []
1063 e = []
1064 for k in keys:
1064 for k in keys:
1065 if k == 'rev':
1065 if k == 'rev':
1066 e.append(r)
1066 e.append(r)
1067 elif k == '-rev':
1067 elif k == '-rev':
1068 e.append(-r)
1068 e.append(-r)
1069 elif k == 'branch':
1069 elif k == 'branch':
1070 e.append(c.branch())
1070 e.append(c.branch())
1071 elif k == '-branch':
1071 elif k == '-branch':
1072 e.append(invert(c.branch()))
1072 e.append(invert(c.branch()))
1073 elif k == 'desc':
1073 elif k == 'desc':
1074 e.append(c.description())
1074 e.append(c.description())
1075 elif k == '-desc':
1075 elif k == '-desc':
1076 e.append(invert(c.description()))
1076 e.append(invert(c.description()))
1077 elif k in 'user author':
1077 elif k in 'user author':
1078 e.append(c.user())
1078 e.append(c.user())
1079 elif k in '-user -author':
1079 elif k in '-user -author':
1080 e.append(invert(c.user()))
1080 e.append(invert(c.user()))
1081 elif k == 'date':
1081 elif k == 'date':
1082 e.append(c.date()[0])
1082 e.append(c.date()[0])
1083 elif k == '-date':
1083 elif k == '-date':
1084 e.append(-c.date()[0])
1084 e.append(-c.date()[0])
1085 else:
1085 else:
1086 raise error.ParseError(_("unknown sort key %r") % k)
1086 raise error.ParseError(_("unknown sort key %r") % k)
1087 e.append(r)
1087 e.append(r)
1088 l.append(e)
1088 l.append(e)
1089 l.sort()
1089 l.sort()
1090 return [e[-1] for e in l]
1090 return [e[-1] for e in l]
1091
1091
1092 def tag(repo, subset, x):
1092 def tag(repo, subset, x):
1093 """``tag([name])``
1093 """``tag([name])``
1094 The specified tag by name, or all tagged revisions if no name is given.
1094 The specified tag by name, or all tagged revisions if no name is given.
1095 """
1095 """
1096 # i18n: "tag" is a keyword
1096 # i18n: "tag" is a keyword
1097 args = getargs(x, 0, 1, _("tag takes one or no arguments"))
1097 args = getargs(x, 0, 1, _("tag takes one or no arguments"))
1098 cl = repo.changelog
1098 cl = repo.changelog
1099 if args:
1099 if args:
1100 tn = getstring(args[0],
1100 tn = getstring(args[0],
1101 # i18n: "tag" is a keyword
1101 # i18n: "tag" is a keyword
1102 _('the argument to tag must be a string'))
1102 _('the argument to tag must be a string'))
1103 if not repo.tags().get(tn, None):
1103 if not repo.tags().get(tn, None):
1104 raise util.Abort(_("tag '%s' does not exist") % tn)
1104 raise util.Abort(_("tag '%s' does not exist") % tn)
1105 s = set([cl.rev(n) for t, n in repo.tagslist() if t == tn])
1105 s = set([cl.rev(n) for t, n in repo.tagslist() if t == tn])
1106 else:
1106 else:
1107 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
1107 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
1108 return [r for r in subset if r in s]
1108 return [r for r in subset if r in s]
1109
1109
1110 def tagged(repo, subset, x):
1110 def tagged(repo, subset, x):
1111 return tag(repo, subset, x)
1111 return tag(repo, subset, x)
1112
1112
1113 def user(repo, subset, x):
1113 def user(repo, subset, x):
1114 """``user(string)``
1114 """``user(string)``
1115 User name contains string. The match is case-insensitive.
1115 User name contains string. The match is case-insensitive.
1116 """
1116 """
1117 return author(repo, subset, x)
1117 return author(repo, subset, x)
1118
1118
1119 # for internal use
1119 # for internal use
1120 def _list(repo, subset, x):
1120 def _list(repo, subset, x):
1121 s = getstring(x, "internal error")
1121 s = getstring(x, "internal error")
1122 if not s:
1122 if not s:
1123 return []
1123 return []
1124 if not isinstance(subset, set):
1124 if not isinstance(subset, set):
1125 subset = set(subset)
1125 subset = set(subset)
1126 ls = [repo[r].rev() for r in s.split('\0')]
1126 ls = [repo[r].rev() for r in s.split('\0')]
1127 return [r for r in ls if r in subset]
1127 return [r for r in ls if r in subset]
1128
1128
1129 symbols = {
1129 symbols = {
1130 "adds": adds,
1130 "adds": adds,
1131 "all": getall,
1131 "all": getall,
1132 "ancestor": ancestor,
1132 "ancestor": ancestor,
1133 "ancestors": ancestors,
1133 "ancestors": ancestors,
1134 "_firstancestors": _firstancestors,
1134 "_firstancestors": _firstancestors,
1135 "author": author,
1135 "author": author,
1136 "bisect": bisect,
1136 "bisect": bisect,
1137 "bisected": bisected,
1137 "bisected": bisected,
1138 "bookmark": bookmark,
1138 "bookmark": bookmark,
1139 "branch": branch,
1139 "branch": branch,
1140 "children": children,
1140 "children": children,
1141 "closed": closed,
1141 "closed": closed,
1142 "contains": contains,
1142 "contains": contains,
1143 "date": date,
1143 "date": date,
1144 "desc": desc,
1144 "desc": desc,
1145 "descendants": descendants,
1145 "descendants": descendants,
1146 "_firstdescendants": _firstdescendants,
1146 "_firstdescendants": _firstdescendants,
1147 "draft": draft,
1147 "draft": draft,
1148 "file": hasfile,
1148 "file": hasfile,
1149 "filelog": filelog,
1149 "filelog": filelog,
1150 "first": first,
1150 "first": first,
1151 "follow": follow,
1151 "follow": follow,
1152 "_followfirst": _followfirst,
1152 "_followfirst": _followfirst,
1153 "grep": grep,
1153 "grep": grep,
1154 "head": head,
1154 "head": head,
1155 "heads": heads,
1155 "heads": heads,
1156 "id": node_,
1156 "id": node_,
1157 "keyword": keyword,
1157 "keyword": keyword,
1158 "last": last,
1158 "last": last,
1159 "limit": limit,
1159 "limit": limit,
1160 "_matchfiles": _matchfiles,
1160 "_matchfiles": _matchfiles,
1161 "max": maxrev,
1161 "max": maxrev,
1162 "merge": merge,
1162 "merge": merge,
1163 "min": minrev,
1163 "min": minrev,
1164 "modifies": modifies,
1164 "modifies": modifies,
1165 "outgoing": outgoing,
1165 "outgoing": outgoing,
1166 "p1": p1,
1166 "p1": p1,
1167 "p2": p2,
1167 "p2": p2,
1168 "parents": parents,
1168 "parents": parents,
1169 "present": present,
1169 "present": present,
1170 "public": public,
1170 "public": public,
1171 "remote": remote,
1171 "remote": remote,
1172 "removes": removes,
1172 "removes": removes,
1173 "rev": rev,
1173 "rev": rev,
1174 "reverse": reverse,
1174 "reverse": reverse,
1175 "roots": roots,
1175 "roots": roots,
1176 "sort": sort,
1176 "sort": sort,
1177 "secret": secret,
1177 "secret": secret,
1178 "matching": matching,
1178 "matching": matching,
1179 "tag": tag,
1179 "tag": tag,
1180 "tagged": tagged,
1180 "tagged": tagged,
1181 "user": user,
1181 "user": user,
1182 "_list": _list,
1182 "_list": _list,
1183 }
1183 }
1184
1184
1185 methods = {
1185 methods = {
1186 "range": rangeset,
1186 "range": rangeset,
1187 "string": stringset,
1187 "string": stringset,
1188 "symbol": symbolset,
1188 "symbol": symbolset,
1189 "and": andset,
1189 "and": andset,
1190 "or": orset,
1190 "or": orset,
1191 "not": notset,
1191 "not": notset,
1192 "list": listset,
1192 "list": listset,
1193 "func": func,
1193 "func": func,
1194 "ancestor": ancestorspec,
1194 "ancestor": ancestorspec,
1195 "parent": parentspec,
1195 "parent": parentspec,
1196 "parentpost": p1,
1196 "parentpost": p1,
1197 }
1197 }
1198
1198
1199 def optimize(x, small):
1199 def optimize(x, small):
1200 if x is None:
1200 if x is None:
1201 return 0, x
1201 return 0, x
1202
1202
1203 smallbonus = 1
1203 smallbonus = 1
1204 if small:
1204 if small:
1205 smallbonus = .5
1205 smallbonus = .5
1206
1206
1207 op = x[0]
1207 op = x[0]
1208 if op == 'minus':
1208 if op == 'minus':
1209 return optimize(('and', x[1], ('not', x[2])), small)
1209 return optimize(('and', x[1], ('not', x[2])), small)
1210 elif op == 'dagrange':
1210 elif op == 'dagrange':
1211 return optimize(('and', ('func', ('symbol', 'descendants'), x[1]),
1211 return optimize(('and', ('func', ('symbol', 'descendants'), x[1]),
1212 ('func', ('symbol', 'ancestors'), x[2])), small)
1212 ('func', ('symbol', 'ancestors'), x[2])), small)
1213 elif op == 'dagrangepre':
1213 elif op == 'dagrangepre':
1214 return optimize(('func', ('symbol', 'ancestors'), x[1]), small)
1214 return optimize(('func', ('symbol', 'ancestors'), x[1]), small)
1215 elif op == 'dagrangepost':
1215 elif op == 'dagrangepost':
1216 return optimize(('func', ('symbol', 'descendants'), x[1]), small)
1216 return optimize(('func', ('symbol', 'descendants'), x[1]), small)
1217 elif op == 'rangepre':
1217 elif op == 'rangepre':
1218 return optimize(('range', ('string', '0'), x[1]), small)
1218 return optimize(('range', ('string', '0'), x[1]), small)
1219 elif op == 'rangepost':
1219 elif op == 'rangepost':
1220 return optimize(('range', x[1], ('string', 'tip')), small)
1220 return optimize(('range', x[1], ('string', 'tip')), small)
1221 elif op == 'negate':
1221 elif op == 'negate':
1222 return optimize(('string',
1222 return optimize(('string',
1223 '-' + getstring(x[1], _("can't negate that"))), small)
1223 '-' + getstring(x[1], _("can't negate that"))), small)
1224 elif op in 'string symbol negate':
1224 elif op in 'string symbol negate':
1225 return smallbonus, x # single revisions are small
1225 return smallbonus, x # single revisions are small
1226 elif op == 'and' or op == 'dagrange':
1226 elif op == 'and' or op == 'dagrange':
1227 wa, ta = optimize(x[1], True)
1227 wa, ta = optimize(x[1], True)
1228 wb, tb = optimize(x[2], True)
1228 wb, tb = optimize(x[2], True)
1229 w = min(wa, wb)
1229 w = min(wa, wb)
1230 if wa > wb:
1230 if wa > wb:
1231 return w, (op, tb, ta)
1231 return w, (op, tb, ta)
1232 return w, (op, ta, tb)
1232 return w, (op, ta, tb)
1233 elif op == 'or':
1233 elif op == 'or':
1234 wa, ta = optimize(x[1], False)
1234 wa, ta = optimize(x[1], False)
1235 wb, tb = optimize(x[2], False)
1235 wb, tb = optimize(x[2], False)
1236 if wb < wa:
1236 if wb < wa:
1237 wb, wa = wa, wb
1237 wb, wa = wa, wb
1238 return max(wa, wb), (op, ta, tb)
1238 return max(wa, wb), (op, ta, tb)
1239 elif op == 'not':
1239 elif op == 'not':
1240 o = optimize(x[1], not small)
1240 o = optimize(x[1], not small)
1241 return o[0], (op, o[1])
1241 return o[0], (op, o[1])
1242 elif op == 'parentpost':
1242 elif op == 'parentpost':
1243 o = optimize(x[1], small)
1243 o = optimize(x[1], small)
1244 return o[0], (op, o[1])
1244 return o[0], (op, o[1])
1245 elif op == 'group':
1245 elif op == 'group':
1246 return optimize(x[1], small)
1246 return optimize(x[1], small)
1247 elif op in 'range list parent ancestorspec':
1247 elif op in 'range list parent ancestorspec':
1248 if op == 'parent':
1248 if op == 'parent':
1249 # x^:y means (x^) : y, not x ^ (:y)
1249 # x^:y means (x^) : y, not x ^ (:y)
1250 post = ('parentpost', x[1])
1250 post = ('parentpost', x[1])
1251 if x[2][0] == 'dagrangepre':
1251 if x[2][0] == 'dagrangepre':
1252 return optimize(('dagrange', post, x[2][1]), small)
1252 return optimize(('dagrange', post, x[2][1]), small)
1253 elif x[2][0] == 'rangepre':
1253 elif x[2][0] == 'rangepre':
1254 return optimize(('range', post, x[2][1]), small)
1254 return optimize(('range', post, x[2][1]), small)
1255
1255
1256 wa, ta = optimize(x[1], small)
1256 wa, ta = optimize(x[1], small)
1257 wb, tb = optimize(x[2], small)
1257 wb, tb = optimize(x[2], small)
1258 return wa + wb, (op, ta, tb)
1258 return wa + wb, (op, ta, tb)
1259 elif op == 'func':
1259 elif op == 'func':
1260 f = getstring(x[1], _("not a symbol"))
1260 f = getstring(x[1], _("not a symbol"))
1261 wa, ta = optimize(x[2], small)
1261 wa, ta = optimize(x[2], small)
1262 if f in ("author branch closed date desc file grep keyword "
1262 if f in ("author branch closed date desc file grep keyword "
1263 "outgoing user"):
1263 "outgoing user"):
1264 w = 10 # slow
1264 w = 10 # slow
1265 elif f in "modifies adds removes":
1265 elif f in "modifies adds removes":
1266 w = 30 # slower
1266 w = 30 # slower
1267 elif f == "contains":
1267 elif f == "contains":
1268 w = 100 # very slow
1268 w = 100 # very slow
1269 elif f == "ancestor":
1269 elif f == "ancestor":
1270 w = 1 * smallbonus
1270 w = 1 * smallbonus
1271 elif f in "reverse limit first":
1271 elif f in "reverse limit first":
1272 w = 0
1272 w = 0
1273 elif f in "sort":
1273 elif f in "sort":
1274 w = 10 # assume most sorts look at changelog
1274 w = 10 # assume most sorts look at changelog
1275 else:
1275 else:
1276 w = 1
1276 w = 1
1277 return w + wa, (op, x[1], ta)
1277 return w + wa, (op, x[1], ta)
1278 return 1, x
1278 return 1, x
1279
1279
1280 class revsetalias(object):
1280 class revsetalias(object):
1281 funcre = re.compile('^([^(]+)\(([^)]+)\)$')
1281 funcre = re.compile('^([^(]+)\(([^)]+)\)$')
1282 args = None
1282 args = None
1283
1283
1284 def __init__(self, name, value):
1284 def __init__(self, name, value):
1285 '''Aliases like:
1285 '''Aliases like:
1286
1286
1287 h = heads(default)
1287 h = heads(default)
1288 b($1) = ancestors($1) - ancestors(default)
1288 b($1) = ancestors($1) - ancestors(default)
1289 '''
1289 '''
1290 m = self.funcre.search(name)
1290 m = self.funcre.search(name)
1291 if m:
1291 if m:
1292 self.name = m.group(1)
1292 self.name = m.group(1)
1293 self.tree = ('func', ('symbol', m.group(1)))
1293 self.tree = ('func', ('symbol', m.group(1)))
1294 self.args = [x.strip() for x in m.group(2).split(',')]
1294 self.args = [x.strip() for x in m.group(2).split(',')]
1295 for arg in self.args:
1295 for arg in self.args:
1296 value = value.replace(arg, repr(arg))
1296 value = value.replace(arg, repr(arg))
1297 else:
1297 else:
1298 self.name = name
1298 self.name = name
1299 self.tree = ('symbol', name)
1299 self.tree = ('symbol', name)
1300
1300
1301 self.replacement, pos = parse(value)
1301 self.replacement, pos = parse(value)
1302 if pos != len(value):
1302 if pos != len(value):
1303 raise error.ParseError(_('invalid token'), pos)
1303 raise error.ParseError(_('invalid token'), pos)
1304
1304
1305 def _getalias(aliases, tree):
1305 def _getalias(aliases, tree):
1306 """If tree looks like an unexpanded alias, return it. Return None
1306 """If tree looks like an unexpanded alias, return it. Return None
1307 otherwise.
1307 otherwise.
1308 """
1308 """
1309 if isinstance(tree, tuple) and tree:
1309 if isinstance(tree, tuple) and tree:
1310 if tree[0] == 'symbol' and len(tree) == 2:
1310 if tree[0] == 'symbol' and len(tree) == 2:
1311 name = tree[1]
1311 name = tree[1]
1312 alias = aliases.get(name)
1312 alias = aliases.get(name)
1313 if alias and alias.args is None and alias.tree == tree:
1313 if alias and alias.args is None and alias.tree == tree:
1314 return alias
1314 return alias
1315 if tree[0] == 'func' and len(tree) > 1:
1315 if tree[0] == 'func' and len(tree) > 1:
1316 if tree[1][0] == 'symbol' and len(tree[1]) == 2:
1316 if tree[1][0] == 'symbol' and len(tree[1]) == 2:
1317 name = tree[1][1]
1317 name = tree[1][1]
1318 alias = aliases.get(name)
1318 alias = aliases.get(name)
1319 if alias and alias.args is not None and alias.tree == tree[:2]:
1319 if alias and alias.args is not None and alias.tree == tree[:2]:
1320 return alias
1320 return alias
1321 return None
1321 return None
1322
1322
1323 def _expandargs(tree, args):
1323 def _expandargs(tree, args):
1324 """Replace all occurences of ('string', name) with the
1324 """Replace all occurences of ('string', name) with the
1325 substitution value of the same name in args, recursively.
1325 substitution value of the same name in args, recursively.
1326 """
1326 """
1327 if not isinstance(tree, tuple):
1327 if not isinstance(tree, tuple):
1328 return tree
1328 return tree
1329 if len(tree) == 2 and tree[0] == 'string':
1329 if len(tree) == 2 and tree[0] == 'string':
1330 return args.get(tree[1], tree)
1330 return args.get(tree[1], tree)
1331 return tuple(_expandargs(t, args) for t in tree)
1331 return tuple(_expandargs(t, args) for t in tree)
1332
1332
1333 def _expandaliases(aliases, tree, expanding):
1333 def _expandaliases(aliases, tree, expanding):
1334 """Expand aliases in tree, recursively.
1334 """Expand aliases in tree, recursively.
1335
1335
1336 'aliases' is a dictionary mapping user defined aliases to
1336 'aliases' is a dictionary mapping user defined aliases to
1337 revsetalias objects.
1337 revsetalias objects.
1338 """
1338 """
1339 if not isinstance(tree, tuple):
1339 if not isinstance(tree, tuple):
1340 # Do not expand raw strings
1340 # Do not expand raw strings
1341 return tree
1341 return tree
1342 alias = _getalias(aliases, tree)
1342 alias = _getalias(aliases, tree)
1343 if alias is not None:
1343 if alias is not None:
1344 if alias in expanding:
1344 if alias in expanding:
1345 raise error.ParseError(_('infinite expansion of revset alias "%s" '
1345 raise error.ParseError(_('infinite expansion of revset alias "%s" '
1346 'detected') % alias.name)
1346 'detected') % alias.name)
1347 expanding.append(alias)
1347 expanding.append(alias)
1348 result = alias.replacement
1348 result = alias.replacement
1349 if alias.args is not None:
1349 if alias.args is not None:
1350 l = getlist(tree[2])
1350 l = getlist(tree[2])
1351 if len(l) != len(alias.args):
1351 if len(l) != len(alias.args):
1352 raise error.ParseError(
1352 raise error.ParseError(
1353 _('invalid number of arguments: %s') % len(l))
1353 _('invalid number of arguments: %s') % len(l))
1354 result = _expandargs(result, dict(zip(alias.args, l)))
1354 result = _expandargs(result, dict(zip(alias.args, l)))
1355 # Recurse in place, the base expression may have been rewritten
1355 # Recurse in place, the base expression may have been rewritten
1356 result = _expandaliases(aliases, result, expanding)
1356 result = _expandaliases(aliases, result, expanding)
1357 expanding.pop()
1357 expanding.pop()
1358 else:
1358 else:
1359 result = tuple(_expandaliases(aliases, t, expanding)
1359 result = tuple(_expandaliases(aliases, t, expanding)
1360 for t in tree)
1360 for t in tree)
1361 return result
1361 return result
1362
1362
1363 def findaliases(ui, tree):
1363 def findaliases(ui, tree):
1364 aliases = {}
1364 aliases = {}
1365 for k, v in ui.configitems('revsetalias'):
1365 for k, v in ui.configitems('revsetalias'):
1366 alias = revsetalias(k, v)
1366 alias = revsetalias(k, v)
1367 aliases[alias.name] = alias
1367 aliases[alias.name] = alias
1368 return _expandaliases(aliases, tree, [])
1368 return _expandaliases(aliases, tree, [])
1369
1369
1370 parse = parser.parser(tokenize, elements).parse
1370 parse = parser.parser(tokenize, elements).parse
1371
1371
1372 def match(ui, spec):
1372 def match(ui, spec):
1373 if not spec:
1373 if not spec:
1374 raise error.ParseError(_("empty query"))
1374 raise error.ParseError(_("empty query"))
1375 tree, pos = parse(spec)
1375 tree, pos = parse(spec)
1376 if (pos != len(spec)):
1376 if (pos != len(spec)):
1377 raise error.ParseError(_("invalid token"), pos)
1377 raise error.ParseError(_("invalid token"), pos)
1378 if ui:
1378 if ui:
1379 tree = findaliases(ui, tree)
1379 tree = findaliases(ui, tree)
1380 weight, tree = optimize(tree, True)
1380 weight, tree = optimize(tree, True)
1381 def mfunc(repo, subset):
1381 def mfunc(repo, subset):
1382 return getset(repo, subset, tree)
1382 return getset(repo, subset, tree)
1383 return mfunc
1383 return mfunc
1384
1384
1385 def formatspec(expr, *args):
1385 def formatspec(expr, *args):
1386 '''
1386 '''
1387 This is a convenience function for using revsets internally, and
1387 This is a convenience function for using revsets internally, and
1388 escapes arguments appropriately. Aliases are intentionally ignored
1388 escapes arguments appropriately. Aliases are intentionally ignored
1389 so that intended expression behavior isn't accidentally subverted.
1389 so that intended expression behavior isn't accidentally subverted.
1390
1390
1391 Supported arguments:
1391 Supported arguments:
1392
1392
1393 %r = revset expression, parenthesized
1393 %r = revset expression, parenthesized
1394 %d = int(arg), no quoting
1394 %d = int(arg), no quoting
1395 %s = string(arg), escaped and single-quoted
1395 %s = string(arg), escaped and single-quoted
1396 %b = arg.branch(), escaped and single-quoted
1396 %b = arg.branch(), escaped and single-quoted
1397 %n = hex(arg), single-quoted
1397 %n = hex(arg), single-quoted
1398 %% = a literal '%'
1398 %% = a literal '%'
1399
1399
1400 Prefixing the type with 'l' specifies a parenthesized list of that type.
1400 Prefixing the type with 'l' specifies a parenthesized list of that type.
1401
1401
1402 >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()"))
1402 >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()"))
1403 '(10 or 11):: and ((this()) or (that()))'
1403 '(10 or 11):: and ((this()) or (that()))'
1404 >>> formatspec('%d:: and not %d::', 10, 20)
1404 >>> formatspec('%d:: and not %d::', 10, 20)
1405 '10:: and not 20::'
1405 '10:: and not 20::'
1406 >>> formatspec('%ld or %ld', [], [1])
1406 >>> formatspec('%ld or %ld', [], [1])
1407 "_list('') or 1"
1407 "_list('') or 1"
1408 >>> formatspec('keyword(%s)', 'foo\\xe9')
1408 >>> formatspec('keyword(%s)', 'foo\\xe9')
1409 "keyword('foo\\\\xe9')"
1409 "keyword('foo\\\\xe9')"
1410 >>> b = lambda: 'default'
1410 >>> b = lambda: 'default'
1411 >>> b.branch = b
1411 >>> b.branch = b
1412 >>> formatspec('branch(%b)', b)
1412 >>> formatspec('branch(%b)', b)
1413 "branch('default')"
1413 "branch('default')"
1414 >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd'])
1414 >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd'])
1415 "root(_list('a\\x00b\\x00c\\x00d'))"
1415 "root(_list('a\\x00b\\x00c\\x00d'))"
1416 '''
1416 '''
1417
1417
1418 def quote(s):
1418 def quote(s):
1419 return repr(str(s))
1419 return repr(str(s))
1420
1420
1421 def argtype(c, arg):
1421 def argtype(c, arg):
1422 if c == 'd':
1422 if c == 'd':
1423 return str(int(arg))
1423 return str(int(arg))
1424 elif c == 's':
1424 elif c == 's':
1425 return quote(arg)
1425 return quote(arg)
1426 elif c == 'r':
1426 elif c == 'r':
1427 parse(arg) # make sure syntax errors are confined
1427 parse(arg) # make sure syntax errors are confined
1428 return '(%s)' % arg
1428 return '(%s)' % arg
1429 elif c == 'n':
1429 elif c == 'n':
1430 return quote(node.hex(arg))
1430 return quote(node.hex(arg))
1431 elif c == 'b':
1431 elif c == 'b':
1432 return quote(arg.branch())
1432 return quote(arg.branch())
1433
1433
1434 def listexp(s, t):
1434 def listexp(s, t):
1435 l = len(s)
1435 l = len(s)
1436 if l == 0:
1436 if l == 0:
1437 return "_list('')"
1437 return "_list('')"
1438 elif l == 1:
1438 elif l == 1:
1439 return argtype(t, s[0])
1439 return argtype(t, s[0])
1440 elif t == 'd':
1440 elif t == 'd':
1441 return "_list('%s')" % "\0".join(str(int(a)) for a in s)
1441 return "_list('%s')" % "\0".join(str(int(a)) for a in s)
1442 elif t == 's':
1442 elif t == 's':
1443 return "_list('%s')" % "\0".join(s)
1443 return "_list('%s')" % "\0".join(s)
1444 elif t == 'n':
1444 elif t == 'n':
1445 return "_list('%s')" % "\0".join(node.hex(a) for a in s)
1445 return "_list('%s')" % "\0".join(node.hex(a) for a in s)
1446 elif t == 'b':
1446 elif t == 'b':
1447 return "_list('%s')" % "\0".join(a.branch() for a in s)
1447 return "_list('%s')" % "\0".join(a.branch() for a in s)
1448
1448
1449 m = l // 2
1449 m = l // 2
1450 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))
1450 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))
1451
1451
1452 ret = ''
1452 ret = ''
1453 pos = 0
1453 pos = 0
1454 arg = 0
1454 arg = 0
1455 while pos < len(expr):
1455 while pos < len(expr):
1456 c = expr[pos]
1456 c = expr[pos]
1457 if c == '%':
1457 if c == '%':
1458 pos += 1
1458 pos += 1
1459 d = expr[pos]
1459 d = expr[pos]
1460 if d == '%':
1460 if d == '%':
1461 ret += d
1461 ret += d
1462 elif d in 'dsnbr':
1462 elif d in 'dsnbr':
1463 ret += argtype(d, args[arg])
1463 ret += argtype(d, args[arg])
1464 arg += 1
1464 arg += 1
1465 elif d == 'l':
1465 elif d == 'l':
1466 # a list of some type
1466 # a list of some type
1467 pos += 1
1467 pos += 1
1468 d = expr[pos]
1468 d = expr[pos]
1469 ret += listexp(list(args[arg]), d)
1469 ret += listexp(list(args[arg]), d)
1470 arg += 1
1470 arg += 1
1471 else:
1471 else:
1472 raise util.Abort('unexpected revspec format character %s' % d)
1472 raise util.Abort('unexpected revspec format character %s' % d)
1473 else:
1473 else:
1474 ret += c
1474 ret += c
1475 pos += 1
1475 pos += 1
1476
1476
1477 return ret
1477 return ret
1478
1478
1479 def prettyformat(tree):
1479 def prettyformat(tree):
1480 def _prettyformat(tree, level, lines):
1480 def _prettyformat(tree, level, lines):
1481 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
1481 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
1482 lines.append((level, str(tree)))
1482 lines.append((level, str(tree)))
1483 else:
1483 else:
1484 lines.append((level, '(%s' % tree[0]))
1484 lines.append((level, '(%s' % tree[0]))
1485 for s in tree[1:]:
1485 for s in tree[1:]:
1486 _prettyformat(s, level + 1, lines)
1486 _prettyformat(s, level + 1, lines)
1487 lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')]
1487 lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')]
1488
1488
1489 lines = []
1489 lines = []
1490 _prettyformat(tree, 0, lines)
1490 _prettyformat(tree, 0, lines)
1491 output = '\n'.join((' '*l + s) for l, s in lines)
1491 output = '\n'.join((' '*l + s) for l, s in lines)
1492 return output
1492 return output
1493
1493
1494 # tell hggettext to extract docstrings from these functions:
1494 # tell hggettext to extract docstrings from these functions:
1495 i18nfunctions = symbols.values()
1495 i18nfunctions = symbols.values()
General Comments 0
You need to be logged in to leave comments. Login now