##// END OF EJS Templates
revset: fix #branch in urls for outgoing()...
Adrian Buehlmann -
r12614:f314723f stable
parent child Browse files
Show More
@@ -0,0 +1,92 b''
1 $ cat >> $HGRCPATH <<EOF
2 > [extensions]
3 > graphlog=
4 >
5 > [alias]
6 > tlog = log --template "{rev}:{node|short}: '{desc}' {branches}\n"
7 > tglog = tlog -G
8 > tout = out --template "{rev}:{node|short}: '{desc}' {branches}\n"
9 > EOF
10
11 $ hg init a
12 $ cd a
13
14 $ echo a > a
15 $ hg ci -Aqm0
16
17 $ echo foo >> a
18 $ hg ci -Aqm1
19
20 $ hg up -q 0
21
22 $ hg branch stable
23 marked working directory as branch stable
24 $ echo bar >> a
25 $ hg ci -qm2
26
27 $ hg tglog
28 @ 2:7bee6c3bea3a: '2' stable
29 |
30 | o 1:3560197d8331: '1'
31 |/
32 o 0:f7b1eb17ad24: '0'
33
34
35 $ cd ..
36
37 $ hg clone -q a#stable b
38
39 $ cd b
40 $ cat .hg/hgrc
41 [paths]
42 default = */a#stable (glob)
43
44 $ echo red >> a
45 $ hg ci -qm3
46
47 $ hg up -q default
48
49 $ echo blue >> a
50 $ hg ci -qm4
51
52 $ hg tglog
53 @ 3:f0461977a3db: '4'
54 |
55 | o 2:1d4099801a4e: '3' stable
56 | |
57 | o 1:7bee6c3bea3a: '2' stable
58 |/
59 o 0:f7b1eb17ad24: '0'
60
61
62 $ hg tout
63 comparing with */a (glob)
64 searching for changes
65 2:1d4099801a4e: '3' stable
66
67 $ hg tlog -r 'outgoing()'
68 2:1d4099801a4e: '3' stable
69
70 $ hg tout ../a#default
71 comparing with ../a
72 searching for changes
73 3:f0461977a3db: '4'
74
75 $ hg tlog -r 'outgoing("../a#default")'
76 3:f0461977a3db: '4'
77
78 $ echo "green = ../a#default" >> .hg/hgrc
79
80 $ cat .hg/hgrc
81 [paths]
82 default = */a#stable (glob)
83 green = ../a#default
84
85 $ hg tout green
86 comparing with */a (glob)
87 searching for changes
88 3:f0461977a3db: '4'
89
90 $ hg tlog -r 'outgoing("green")'
91 3:f0461977a3db: '4'
92
@@ -1,575 +1,578 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, discovery
9 import parser, util, error, discovery
10 import match as _match
10 import match as _match
11 from i18n import _
11 from i18n import _
12
12
13 elements = {
13 elements = {
14 "(": (20, ("group", 1, ")"), ("func", 1, ")")),
14 "(": (20, ("group", 1, ")"), ("func", 1, ")")),
15 "-": (19, ("negate", 19), ("minus", 19)),
15 "-": (19, ("negate", 19), ("minus", 19)),
16 "::": (17, ("dagrangepre", 17), ("dagrange", 17),
16 "::": (17, ("dagrangepre", 17), ("dagrange", 17),
17 ("dagrangepost", 17)),
17 ("dagrangepost", 17)),
18 "..": (17, ("dagrangepre", 17), ("dagrange", 17),
18 "..": (17, ("dagrangepre", 17), ("dagrange", 17),
19 ("dagrangepost", 17)),
19 ("dagrangepost", 17)),
20 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
20 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
21 "not": (10, ("not", 10)),
21 "not": (10, ("not", 10)),
22 "!": (10, ("not", 10)),
22 "!": (10, ("not", 10)),
23 "and": (5, None, ("and", 5)),
23 "and": (5, None, ("and", 5)),
24 "&": (5, None, ("and", 5)),
24 "&": (5, None, ("and", 5)),
25 "or": (4, None, ("or", 4)),
25 "or": (4, None, ("or", 4)),
26 "|": (4, None, ("or", 4)),
26 "|": (4, None, ("or", 4)),
27 "+": (4, None, ("or", 4)),
27 "+": (4, None, ("or", 4)),
28 ",": (2, None, ("list", 2)),
28 ",": (2, None, ("list", 2)),
29 ")": (0, None, None),
29 ")": (0, None, None),
30 "symbol": (0, ("symbol",), None),
30 "symbol": (0, ("symbol",), None),
31 "string": (0, ("string",), None),
31 "string": (0, ("string",), None),
32 "end": (0, None, None),
32 "end": (0, None, None),
33 }
33 }
34
34
35 keywords = set(['and', 'or', 'not'])
35 keywords = set(['and', 'or', 'not'])
36
36
37 def tokenize(program):
37 def tokenize(program):
38 pos, l = 0, len(program)
38 pos, l = 0, len(program)
39 while pos < l:
39 while pos < l:
40 c = program[pos]
40 c = program[pos]
41 if c.isspace(): # skip inter-token whitespace
41 if c.isspace(): # skip inter-token whitespace
42 pass
42 pass
43 elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
43 elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
44 yield ('::', None, pos)
44 yield ('::', None, pos)
45 pos += 1 # skip ahead
45 pos += 1 # skip ahead
46 elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully
46 elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully
47 yield ('..', None, pos)
47 yield ('..', None, pos)
48 pos += 1 # skip ahead
48 pos += 1 # skip ahead
49 elif c in "():,-|&+!": # handle simple operators
49 elif c in "():,-|&+!": # handle simple operators
50 yield (c, None, pos)
50 yield (c, None, pos)
51 elif c in '"\'': # handle quoted strings
51 elif c in '"\'': # handle quoted strings
52 pos += 1
52 pos += 1
53 s = pos
53 s = pos
54 while pos < l: # find closing quote
54 while pos < l: # find closing quote
55 d = program[pos]
55 d = program[pos]
56 if d == '\\': # skip over escaped characters
56 if d == '\\': # skip over escaped characters
57 pos += 2
57 pos += 2
58 continue
58 continue
59 if d == c:
59 if d == c:
60 yield ('string', program[s:pos].decode('string-escape'), s)
60 yield ('string', program[s:pos].decode('string-escape'), s)
61 break
61 break
62 pos += 1
62 pos += 1
63 else:
63 else:
64 raise error.ParseError(_("unterminated string"), s)
64 raise error.ParseError(_("unterminated string"), s)
65 elif c.isalnum() or c in '._' or ord(c) > 127: # gather up a symbol/keyword
65 elif c.isalnum() or c in '._' or ord(c) > 127: # gather up a symbol/keyword
66 s = pos
66 s = pos
67 pos += 1
67 pos += 1
68 while pos < l: # find end of symbol
68 while pos < l: # find end of symbol
69 d = program[pos]
69 d = program[pos]
70 if not (d.isalnum() or d in "._" or ord(d) > 127):
70 if not (d.isalnum() or d in "._" or ord(d) > 127):
71 break
71 break
72 if d == '.' and program[pos - 1] == '.': # special case for ..
72 if d == '.' and program[pos - 1] == '.': # special case for ..
73 pos -= 1
73 pos -= 1
74 break
74 break
75 pos += 1
75 pos += 1
76 sym = program[s:pos]
76 sym = program[s:pos]
77 if sym in keywords: # operator keywords
77 if sym in keywords: # operator keywords
78 yield (sym, None, s)
78 yield (sym, None, s)
79 else:
79 else:
80 yield ('symbol', sym, s)
80 yield ('symbol', sym, s)
81 pos -= 1
81 pos -= 1
82 else:
82 else:
83 raise error.ParseError(_("syntax error"), pos)
83 raise error.ParseError(_("syntax error"), pos)
84 pos += 1
84 pos += 1
85 yield ('end', None, pos)
85 yield ('end', None, pos)
86
86
87 # helpers
87 # helpers
88
88
89 def getstring(x, err):
89 def getstring(x, err):
90 if x and (x[0] == 'string' or x[0] == 'symbol'):
90 if x and (x[0] == 'string' or x[0] == 'symbol'):
91 return x[1]
91 return x[1]
92 raise error.ParseError(err)
92 raise error.ParseError(err)
93
93
94 def getlist(x):
94 def getlist(x):
95 if not x:
95 if not x:
96 return []
96 return []
97 if x[0] == 'list':
97 if x[0] == 'list':
98 return getlist(x[1]) + [x[2]]
98 return getlist(x[1]) + [x[2]]
99 return [x]
99 return [x]
100
100
101 def getargs(x, min, max, err):
101 def getargs(x, min, max, err):
102 l = getlist(x)
102 l = getlist(x)
103 if len(l) < min or len(l) > max:
103 if len(l) < min or len(l) > max:
104 raise error.ParseError(err)
104 raise error.ParseError(err)
105 return l
105 return l
106
106
107 def getset(repo, subset, x):
107 def getset(repo, subset, x):
108 if not x:
108 if not x:
109 raise error.ParseError(_("missing argument"))
109 raise error.ParseError(_("missing argument"))
110 return methods[x[0]](repo, subset, *x[1:])
110 return methods[x[0]](repo, subset, *x[1:])
111
111
112 # operator methods
112 # operator methods
113
113
114 def stringset(repo, subset, x):
114 def stringset(repo, subset, x):
115 x = repo[x].rev()
115 x = repo[x].rev()
116 if x == -1 and len(subset) == len(repo):
116 if x == -1 and len(subset) == len(repo):
117 return [-1]
117 return [-1]
118 if x in subset:
118 if x in subset:
119 return [x]
119 return [x]
120 return []
120 return []
121
121
122 def symbolset(repo, subset, x):
122 def symbolset(repo, subset, x):
123 if x in symbols:
123 if x in symbols:
124 raise error.ParseError(_("can't use %s here") % x)
124 raise error.ParseError(_("can't use %s here") % x)
125 return stringset(repo, subset, x)
125 return stringset(repo, subset, x)
126
126
127 def rangeset(repo, subset, x, y):
127 def rangeset(repo, subset, x, y):
128 m = getset(repo, subset, x)
128 m = getset(repo, subset, x)
129 if not m:
129 if not m:
130 m = getset(repo, range(len(repo)), x)
130 m = getset(repo, range(len(repo)), x)
131
131
132 n = getset(repo, subset, y)
132 n = getset(repo, subset, y)
133 if not n:
133 if not n:
134 n = getset(repo, range(len(repo)), y)
134 n = getset(repo, range(len(repo)), y)
135
135
136 if not m or not n:
136 if not m or not n:
137 return []
137 return []
138 m, n = m[0], n[-1]
138 m, n = m[0], n[-1]
139
139
140 if m < n:
140 if m < n:
141 r = range(m, n + 1)
141 r = range(m, n + 1)
142 else:
142 else:
143 r = range(m, n - 1, -1)
143 r = range(m, n - 1, -1)
144 s = set(subset)
144 s = set(subset)
145 return [x for x in r if x in s]
145 return [x for x in r if x in s]
146
146
147 def andset(repo, subset, x, y):
147 def andset(repo, subset, x, y):
148 return getset(repo, getset(repo, subset, x), y)
148 return getset(repo, getset(repo, subset, x), y)
149
149
150 def orset(repo, subset, x, y):
150 def orset(repo, subset, x, y):
151 s = set(getset(repo, subset, x))
151 s = set(getset(repo, subset, x))
152 s |= set(getset(repo, [r for r in subset if r not in s], y))
152 s |= set(getset(repo, [r for r in subset if r not in s], y))
153 return [r for r in subset if r in s]
153 return [r for r in subset if r in s]
154
154
155 def notset(repo, subset, x):
155 def notset(repo, subset, x):
156 s = set(getset(repo, subset, x))
156 s = set(getset(repo, subset, x))
157 return [r for r in subset if r not in s]
157 return [r for r in subset if r not in s]
158
158
159 def listset(repo, subset, a, b):
159 def listset(repo, subset, a, b):
160 raise error.ParseError(_("can't use a list in this context"))
160 raise error.ParseError(_("can't use a list in this context"))
161
161
162 def func(repo, subset, a, b):
162 def func(repo, subset, a, b):
163 if a[0] == 'symbol' and a[1] in symbols:
163 if a[0] == 'symbol' and a[1] in symbols:
164 return symbols[a[1]](repo, subset, b)
164 return symbols[a[1]](repo, subset, b)
165 raise error.ParseError(_("not a function: %s") % a[1])
165 raise error.ParseError(_("not a function: %s") % a[1])
166
166
167 # functions
167 # functions
168
168
169 def p1(repo, subset, x):
169 def p1(repo, subset, x):
170 ps = set()
170 ps = set()
171 cl = repo.changelog
171 cl = repo.changelog
172 for r in getset(repo, subset, x):
172 for r in getset(repo, subset, x):
173 ps.add(cl.parentrevs(r)[0])
173 ps.add(cl.parentrevs(r)[0])
174 return [r for r in subset if r in ps]
174 return [r for r in subset if r in ps]
175
175
176 def p2(repo, subset, x):
176 def p2(repo, subset, x):
177 ps = set()
177 ps = set()
178 cl = repo.changelog
178 cl = repo.changelog
179 for r in getset(repo, subset, x):
179 for r in getset(repo, subset, x):
180 ps.add(cl.parentrevs(r)[1])
180 ps.add(cl.parentrevs(r)[1])
181 return [r for r in subset if r in ps]
181 return [r for r in subset if r in ps]
182
182
183 def parents(repo, subset, x):
183 def parents(repo, subset, x):
184 ps = set()
184 ps = set()
185 cl = repo.changelog
185 cl = repo.changelog
186 for r in getset(repo, subset, x):
186 for r in getset(repo, subset, x):
187 ps.update(cl.parentrevs(r))
187 ps.update(cl.parentrevs(r))
188 return [r for r in subset if r in ps]
188 return [r for r in subset if r in ps]
189
189
190 def maxrev(repo, subset, x):
190 def maxrev(repo, subset, x):
191 s = getset(repo, subset, x)
191 s = getset(repo, subset, x)
192 if s:
192 if s:
193 m = max(s)
193 m = max(s)
194 if m in subset:
194 if m in subset:
195 return [m]
195 return [m]
196 return []
196 return []
197
197
198 def limit(repo, subset, x):
198 def limit(repo, subset, x):
199 l = getargs(x, 2, 2, _("limit wants two arguments"))
199 l = getargs(x, 2, 2, _("limit wants two arguments"))
200 try:
200 try:
201 lim = int(getstring(l[1], _("limit wants a number")))
201 lim = int(getstring(l[1], _("limit wants a number")))
202 except ValueError:
202 except ValueError:
203 raise error.ParseError(_("limit expects a number"))
203 raise error.ParseError(_("limit expects a number"))
204 return getset(repo, subset, l[0])[:lim]
204 return getset(repo, subset, l[0])[:lim]
205
205
206 def children(repo, subset, x):
206 def children(repo, subset, x):
207 cs = set()
207 cs = set()
208 cl = repo.changelog
208 cl = repo.changelog
209 s = set(getset(repo, subset, x))
209 s = set(getset(repo, subset, x))
210 for r in xrange(0, len(repo)):
210 for r in xrange(0, len(repo)):
211 for p in cl.parentrevs(r):
211 for p in cl.parentrevs(r):
212 if p in s:
212 if p in s:
213 cs.add(r)
213 cs.add(r)
214 return [r for r in subset if r in cs]
214 return [r for r in subset if r in cs]
215
215
216 def branch(repo, subset, x):
216 def branch(repo, subset, x):
217 s = getset(repo, range(len(repo)), x)
217 s = getset(repo, range(len(repo)), x)
218 b = set()
218 b = set()
219 for r in s:
219 for r in s:
220 b.add(repo[r].branch())
220 b.add(repo[r].branch())
221 s = set(s)
221 s = set(s)
222 return [r for r in subset if r in s or repo[r].branch() in b]
222 return [r for r in subset if r in s or repo[r].branch() in b]
223
223
224 def ancestor(repo, subset, x):
224 def ancestor(repo, subset, x):
225 l = getargs(x, 2, 2, _("ancestor wants two arguments"))
225 l = getargs(x, 2, 2, _("ancestor wants two arguments"))
226 r = range(len(repo))
226 r = range(len(repo))
227 a = getset(repo, r, l[0])
227 a = getset(repo, r, l[0])
228 b = getset(repo, r, l[1])
228 b = getset(repo, r, l[1])
229 if len(a) != 1 or len(b) != 1:
229 if len(a) != 1 or len(b) != 1:
230 raise error.ParseError(_("ancestor arguments must be single revisions"))
230 raise error.ParseError(_("ancestor arguments must be single revisions"))
231 an = [repo[a[0]].ancestor(repo[b[0]]).rev()]
231 an = [repo[a[0]].ancestor(repo[b[0]]).rev()]
232
232
233 return [r for r in an if r in subset]
233 return [r for r in an if r in subset]
234
234
235 def ancestors(repo, subset, x):
235 def ancestors(repo, subset, x):
236 args = getset(repo, range(len(repo)), x)
236 args = getset(repo, range(len(repo)), x)
237 if not args:
237 if not args:
238 return []
238 return []
239 s = set(repo.changelog.ancestors(*args)) | set(args)
239 s = set(repo.changelog.ancestors(*args)) | set(args)
240 return [r for r in subset if r in s]
240 return [r for r in subset if r in s]
241
241
242 def descendants(repo, subset, x):
242 def descendants(repo, subset, x):
243 args = getset(repo, range(len(repo)), x)
243 args = getset(repo, range(len(repo)), x)
244 if not args:
244 if not args:
245 return []
245 return []
246 s = set(repo.changelog.descendants(*args)) | set(args)
246 s = set(repo.changelog.descendants(*args)) | set(args)
247 return [r for r in subset if r in s]
247 return [r for r in subset if r in s]
248
248
249 def follow(repo, subset, x):
249 def follow(repo, subset, x):
250 getargs(x, 0, 0, _("follow takes no arguments"))
250 getargs(x, 0, 0, _("follow takes no arguments"))
251 p = repo['.'].rev()
251 p = repo['.'].rev()
252 s = set(repo.changelog.ancestors(p)) | set([p])
252 s = set(repo.changelog.ancestors(p)) | set([p])
253 return [r for r in subset if r in s]
253 return [r for r in subset if r in s]
254
254
255 def date(repo, subset, x):
255 def date(repo, subset, x):
256 ds = getstring(x, _("date wants a string"))
256 ds = getstring(x, _("date wants a string"))
257 dm = util.matchdate(ds)
257 dm = util.matchdate(ds)
258 return [r for r in subset if dm(repo[r].date()[0])]
258 return [r for r in subset if dm(repo[r].date()[0])]
259
259
260 def keyword(repo, subset, x):
260 def keyword(repo, subset, x):
261 kw = getstring(x, _("keyword wants a string")).lower()
261 kw = getstring(x, _("keyword wants a string")).lower()
262 l = []
262 l = []
263 for r in subset:
263 for r in subset:
264 c = repo[r]
264 c = repo[r]
265 t = " ".join(c.files() + [c.user(), c.description()])
265 t = " ".join(c.files() + [c.user(), c.description()])
266 if kw in t.lower():
266 if kw in t.lower():
267 l.append(r)
267 l.append(r)
268 return l
268 return l
269
269
270 def grep(repo, subset, x):
270 def grep(repo, subset, x):
271 try:
271 try:
272 gr = re.compile(getstring(x, _("grep wants a string")))
272 gr = re.compile(getstring(x, _("grep wants a string")))
273 except re.error, e:
273 except re.error, e:
274 raise error.ParseError(_('invalid match pattern: %s') % e)
274 raise error.ParseError(_('invalid match pattern: %s') % e)
275 l = []
275 l = []
276 for r in subset:
276 for r in subset:
277 c = repo[r]
277 c = repo[r]
278 for e in c.files() + [c.user(), c.description()]:
278 for e in c.files() + [c.user(), c.description()]:
279 if gr.search(e):
279 if gr.search(e):
280 l.append(r)
280 l.append(r)
281 continue
281 continue
282 return l
282 return l
283
283
284 def author(repo, subset, x):
284 def author(repo, subset, x):
285 n = getstring(x, _("author wants a string")).lower()
285 n = getstring(x, _("author wants a string")).lower()
286 return [r for r in subset if n in repo[r].user().lower()]
286 return [r for r in subset if n in repo[r].user().lower()]
287
287
288 def hasfile(repo, subset, x):
288 def hasfile(repo, subset, x):
289 pat = getstring(x, _("file wants a pattern"))
289 pat = getstring(x, _("file wants a pattern"))
290 m = _match.match(repo.root, repo.getcwd(), [pat])
290 m = _match.match(repo.root, repo.getcwd(), [pat])
291 s = []
291 s = []
292 for r in subset:
292 for r in subset:
293 for f in repo[r].files():
293 for f in repo[r].files():
294 if m(f):
294 if m(f):
295 s.append(r)
295 s.append(r)
296 continue
296 continue
297 return s
297 return s
298
298
299 def contains(repo, subset, x):
299 def contains(repo, subset, x):
300 pat = getstring(x, _("contains wants a pattern"))
300 pat = getstring(x, _("contains wants a pattern"))
301 m = _match.match(repo.root, repo.getcwd(), [pat])
301 m = _match.match(repo.root, repo.getcwd(), [pat])
302 s = []
302 s = []
303 if m.files() == [pat]:
303 if m.files() == [pat]:
304 for r in subset:
304 for r in subset:
305 if pat in repo[r]:
305 if pat in repo[r]:
306 s.append(r)
306 s.append(r)
307 continue
307 continue
308 else:
308 else:
309 for r in subset:
309 for r in subset:
310 for f in repo[r].manifest():
310 for f in repo[r].manifest():
311 if m(f):
311 if m(f):
312 s.append(r)
312 s.append(r)
313 continue
313 continue
314 return s
314 return s
315
315
316 def checkstatus(repo, subset, pat, field):
316 def checkstatus(repo, subset, pat, field):
317 m = _match.match(repo.root, repo.getcwd(), [pat])
317 m = _match.match(repo.root, repo.getcwd(), [pat])
318 s = []
318 s = []
319 fast = (m.files() == [pat])
319 fast = (m.files() == [pat])
320 for r in subset:
320 for r in subset:
321 c = repo[r]
321 c = repo[r]
322 if fast:
322 if fast:
323 if pat not in c.files():
323 if pat not in c.files():
324 continue
324 continue
325 else:
325 else:
326 for f in c.files():
326 for f in c.files():
327 if m(f):
327 if m(f):
328 break
328 break
329 else:
329 else:
330 continue
330 continue
331 files = repo.status(c.p1().node(), c.node())[field]
331 files = repo.status(c.p1().node(), c.node())[field]
332 if fast:
332 if fast:
333 if pat in files:
333 if pat in files:
334 s.append(r)
334 s.append(r)
335 continue
335 continue
336 else:
336 else:
337 for f in files:
337 for f in files:
338 if m(f):
338 if m(f):
339 s.append(r)
339 s.append(r)
340 continue
340 continue
341 return s
341 return s
342
342
343 def modifies(repo, subset, x):
343 def modifies(repo, subset, x):
344 pat = getstring(x, _("modifies wants a pattern"))
344 pat = getstring(x, _("modifies wants a pattern"))
345 return checkstatus(repo, subset, pat, 0)
345 return checkstatus(repo, subset, pat, 0)
346
346
347 def adds(repo, subset, x):
347 def adds(repo, subset, x):
348 pat = getstring(x, _("adds wants a pattern"))
348 pat = getstring(x, _("adds wants a pattern"))
349 return checkstatus(repo, subset, pat, 1)
349 return checkstatus(repo, subset, pat, 1)
350
350
351 def removes(repo, subset, x):
351 def removes(repo, subset, x):
352 pat = getstring(x, _("removes wants a pattern"))
352 pat = getstring(x, _("removes wants a pattern"))
353 return checkstatus(repo, subset, pat, 2)
353 return checkstatus(repo, subset, pat, 2)
354
354
355 def merge(repo, subset, x):
355 def merge(repo, subset, x):
356 getargs(x, 0, 0, _("merge takes no arguments"))
356 getargs(x, 0, 0, _("merge takes no arguments"))
357 cl = repo.changelog
357 cl = repo.changelog
358 return [r for r in subset if cl.parentrevs(r)[1] != -1]
358 return [r for r in subset if cl.parentrevs(r)[1] != -1]
359
359
360 def closed(repo, subset, x):
360 def closed(repo, subset, x):
361 getargs(x, 0, 0, _("closed takes no arguments"))
361 getargs(x, 0, 0, _("closed takes no arguments"))
362 return [r for r in subset if repo[r].extra().get('close')]
362 return [r for r in subset if repo[r].extra().get('close')]
363
363
364 def head(repo, subset, x):
364 def head(repo, subset, x):
365 getargs(x, 0, 0, _("head takes no arguments"))
365 getargs(x, 0, 0, _("head takes no arguments"))
366 hs = set()
366 hs = set()
367 for b, ls in repo.branchmap().iteritems():
367 for b, ls in repo.branchmap().iteritems():
368 hs.update(repo[h].rev() for h in ls)
368 hs.update(repo[h].rev() for h in ls)
369 return [r for r in subset if r in hs]
369 return [r for r in subset if r in hs]
370
370
371 def reverse(repo, subset, x):
371 def reverse(repo, subset, x):
372 l = getset(repo, subset, x)
372 l = getset(repo, subset, x)
373 l.reverse()
373 l.reverse()
374 return l
374 return l
375
375
376 def sort(repo, subset, x):
376 def sort(repo, subset, x):
377 l = getargs(x, 1, 2, _("sort wants one or two arguments"))
377 l = getargs(x, 1, 2, _("sort wants one or two arguments"))
378 keys = "rev"
378 keys = "rev"
379 if len(l) == 2:
379 if len(l) == 2:
380 keys = getstring(l[1], _("sort spec must be a string"))
380 keys = getstring(l[1], _("sort spec must be a string"))
381
381
382 s = l[0]
382 s = l[0]
383 keys = keys.split()
383 keys = keys.split()
384 l = []
384 l = []
385 def invert(s):
385 def invert(s):
386 return "".join(chr(255 - ord(c)) for c in s)
386 return "".join(chr(255 - ord(c)) for c in s)
387 for r in getset(repo, subset, s):
387 for r in getset(repo, subset, s):
388 c = repo[r]
388 c = repo[r]
389 e = []
389 e = []
390 for k in keys:
390 for k in keys:
391 if k == 'rev':
391 if k == 'rev':
392 e.append(r)
392 e.append(r)
393 elif k == '-rev':
393 elif k == '-rev':
394 e.append(-r)
394 e.append(-r)
395 elif k == 'branch':
395 elif k == 'branch':
396 e.append(c.branch())
396 e.append(c.branch())
397 elif k == '-branch':
397 elif k == '-branch':
398 e.append(invert(c.branch()))
398 e.append(invert(c.branch()))
399 elif k == 'desc':
399 elif k == 'desc':
400 e.append(c.description())
400 e.append(c.description())
401 elif k == '-desc':
401 elif k == '-desc':
402 e.append(invert(c.description()))
402 e.append(invert(c.description()))
403 elif k in 'user author':
403 elif k in 'user author':
404 e.append(c.user())
404 e.append(c.user())
405 elif k in '-user -author':
405 elif k in '-user -author':
406 e.append(invert(c.user()))
406 e.append(invert(c.user()))
407 elif k == 'date':
407 elif k == 'date':
408 e.append(c.date()[0])
408 e.append(c.date()[0])
409 elif k == '-date':
409 elif k == '-date':
410 e.append(-c.date()[0])
410 e.append(-c.date()[0])
411 else:
411 else:
412 raise error.ParseError(_("unknown sort key %r") % k)
412 raise error.ParseError(_("unknown sort key %r") % k)
413 e.append(r)
413 e.append(r)
414 l.append(e)
414 l.append(e)
415 l.sort()
415 l.sort()
416 return [e[-1] for e in l]
416 return [e[-1] for e in l]
417
417
418 def getall(repo, subset, x):
418 def getall(repo, subset, x):
419 getargs(x, 0, 0, _("all takes no arguments"))
419 getargs(x, 0, 0, _("all takes no arguments"))
420 return subset
420 return subset
421
421
422 def heads(repo, subset, x):
422 def heads(repo, subset, x):
423 s = getset(repo, subset, x)
423 s = getset(repo, subset, x)
424 ps = set(parents(repo, subset, x))
424 ps = set(parents(repo, subset, x))
425 return [r for r in s if r not in ps]
425 return [r for r in s if r not in ps]
426
426
427 def roots(repo, subset, x):
427 def roots(repo, subset, x):
428 s = getset(repo, subset, x)
428 s = getset(repo, subset, x)
429 cs = set(children(repo, subset, x))
429 cs = set(children(repo, subset, x))
430 return [r for r in s if r not in cs]
430 return [r for r in s if r not in cs]
431
431
432 def outgoing(repo, subset, x):
432 def outgoing(repo, subset, x):
433 import hg # avoid start-up nasties
433 import hg # avoid start-up nasties
434 l = getargs(x, 0, 1, _("outgoing wants a repository path"))
434 l = getargs(x, 0, 1, _("outgoing wants a repository path"))
435 dest = l and getstring(l[0], _("outgoing wants a repository path")) or ''
435 dest = l and getstring(l[0], _("outgoing wants a repository path")) or ''
436 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
436 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
437 dest, branches = hg.parseurl(dest)
437 dest, branches = hg.parseurl(dest)
438 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
439 if revs:
440 revs = [repo.lookup(rev) for rev in revs]
438 other = hg.repository(hg.remoteui(repo, {}), dest)
441 other = hg.repository(hg.remoteui(repo, {}), dest)
439 repo.ui.pushbuffer()
442 repo.ui.pushbuffer()
440 o = discovery.findoutgoing(repo, other)
443 o = discovery.findoutgoing(repo, other)
441 repo.ui.popbuffer()
444 repo.ui.popbuffer()
442 cl = repo.changelog
445 cl = repo.changelog
443 o = set([cl.rev(r) for r in repo.changelog.nodesbetween(o, None)[0]])
446 o = set([cl.rev(r) for r in repo.changelog.nodesbetween(o, revs)[0]])
444 return [r for r in subset if r in o]
447 return [r for r in subset if r in o]
445
448
446 def tagged(repo, subset, x):
449 def tagged(repo, subset, x):
447 getargs(x, 0, 0, _("tagged takes no arguments"))
450 getargs(x, 0, 0, _("tagged takes no arguments"))
448 cl = repo.changelog
451 cl = repo.changelog
449 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
452 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
450 return [r for r in subset if r in s]
453 return [r for r in subset if r in s]
451
454
452 symbols = {
455 symbols = {
453 "adds": adds,
456 "adds": adds,
454 "all": getall,
457 "all": getall,
455 "ancestor": ancestor,
458 "ancestor": ancestor,
456 "ancestors": ancestors,
459 "ancestors": ancestors,
457 "author": author,
460 "author": author,
458 "branch": branch,
461 "branch": branch,
459 "children": children,
462 "children": children,
460 "closed": closed,
463 "closed": closed,
461 "contains": contains,
464 "contains": contains,
462 "date": date,
465 "date": date,
463 "descendants": descendants,
466 "descendants": descendants,
464 "file": hasfile,
467 "file": hasfile,
465 "follow": follow,
468 "follow": follow,
466 "grep": grep,
469 "grep": grep,
467 "head": head,
470 "head": head,
468 "heads": heads,
471 "heads": heads,
469 "keyword": keyword,
472 "keyword": keyword,
470 "limit": limit,
473 "limit": limit,
471 "max": maxrev,
474 "max": maxrev,
472 "merge": merge,
475 "merge": merge,
473 "modifies": modifies,
476 "modifies": modifies,
474 "outgoing": outgoing,
477 "outgoing": outgoing,
475 "p1": p1,
478 "p1": p1,
476 "p2": p2,
479 "p2": p2,
477 "parents": parents,
480 "parents": parents,
478 "removes": removes,
481 "removes": removes,
479 "reverse": reverse,
482 "reverse": reverse,
480 "roots": roots,
483 "roots": roots,
481 "sort": sort,
484 "sort": sort,
482 "tagged": tagged,
485 "tagged": tagged,
483 "user": author,
486 "user": author,
484 }
487 }
485
488
486 methods = {
489 methods = {
487 "range": rangeset,
490 "range": rangeset,
488 "string": stringset,
491 "string": stringset,
489 "symbol": symbolset,
492 "symbol": symbolset,
490 "and": andset,
493 "and": andset,
491 "or": orset,
494 "or": orset,
492 "not": notset,
495 "not": notset,
493 "list": listset,
496 "list": listset,
494 "func": func,
497 "func": func,
495 }
498 }
496
499
497 def optimize(x, small):
500 def optimize(x, small):
498 if x == None:
501 if x == None:
499 return 0, x
502 return 0, x
500
503
501 smallbonus = 1
504 smallbonus = 1
502 if small:
505 if small:
503 smallbonus = .5
506 smallbonus = .5
504
507
505 op = x[0]
508 op = x[0]
506 if op == 'minus':
509 if op == 'minus':
507 return optimize(('and', x[1], ('not', x[2])), small)
510 return optimize(('and', x[1], ('not', x[2])), small)
508 elif op == 'dagrange':
511 elif op == 'dagrange':
509 return optimize(('and', ('func', ('symbol', 'descendants'), x[1]),
512 return optimize(('and', ('func', ('symbol', 'descendants'), x[1]),
510 ('func', ('symbol', 'ancestors'), x[2])), small)
513 ('func', ('symbol', 'ancestors'), x[2])), small)
511 elif op == 'dagrangepre':
514 elif op == 'dagrangepre':
512 return optimize(('func', ('symbol', 'ancestors'), x[1]), small)
515 return optimize(('func', ('symbol', 'ancestors'), x[1]), small)
513 elif op == 'dagrangepost':
516 elif op == 'dagrangepost':
514 return optimize(('func', ('symbol', 'descendants'), x[1]), small)
517 return optimize(('func', ('symbol', 'descendants'), x[1]), small)
515 elif op == 'rangepre':
518 elif op == 'rangepre':
516 return optimize(('range', ('string', '0'), x[1]), small)
519 return optimize(('range', ('string', '0'), x[1]), small)
517 elif op == 'rangepost':
520 elif op == 'rangepost':
518 return optimize(('range', x[1], ('string', 'tip')), small)
521 return optimize(('range', x[1], ('string', 'tip')), small)
519 elif op == 'negate':
522 elif op == 'negate':
520 return optimize(('string',
523 return optimize(('string',
521 '-' + getstring(x[1], _("can't negate that"))), small)
524 '-' + getstring(x[1], _("can't negate that"))), small)
522 elif op in 'string symbol negate':
525 elif op in 'string symbol negate':
523 return smallbonus, x # single revisions are small
526 return smallbonus, x # single revisions are small
524 elif op == 'and' or op == 'dagrange':
527 elif op == 'and' or op == 'dagrange':
525 wa, ta = optimize(x[1], True)
528 wa, ta = optimize(x[1], True)
526 wb, tb = optimize(x[2], True)
529 wb, tb = optimize(x[2], True)
527 w = min(wa, wb)
530 w = min(wa, wb)
528 if wa > wb:
531 if wa > wb:
529 return w, (op, tb, ta)
532 return w, (op, tb, ta)
530 return w, (op, ta, tb)
533 return w, (op, ta, tb)
531 elif op == 'or':
534 elif op == 'or':
532 wa, ta = optimize(x[1], False)
535 wa, ta = optimize(x[1], False)
533 wb, tb = optimize(x[2], False)
536 wb, tb = optimize(x[2], False)
534 if wb < wa:
537 if wb < wa:
535 wb, wa = wa, wb
538 wb, wa = wa, wb
536 return max(wa, wb), (op, ta, tb)
539 return max(wa, wb), (op, ta, tb)
537 elif op == 'not':
540 elif op == 'not':
538 o = optimize(x[1], not small)
541 o = optimize(x[1], not small)
539 return o[0], (op, o[1])
542 return o[0], (op, o[1])
540 elif op == 'group':
543 elif op == 'group':
541 return optimize(x[1], small)
544 return optimize(x[1], small)
542 elif op in 'range list':
545 elif op in 'range list':
543 wa, ta = optimize(x[1], small)
546 wa, ta = optimize(x[1], small)
544 wb, tb = optimize(x[2], small)
547 wb, tb = optimize(x[2], small)
545 return wa + wb, (op, ta, tb)
548 return wa + wb, (op, ta, tb)
546 elif op == 'func':
549 elif op == 'func':
547 f = getstring(x[1], _("not a symbol"))
550 f = getstring(x[1], _("not a symbol"))
548 wa, ta = optimize(x[2], small)
551 wa, ta = optimize(x[2], small)
549 if f in "grep date user author keyword branch file":
552 if f in "grep date user author keyword branch file":
550 w = 10 # slow
553 w = 10 # slow
551 elif f in "modifies adds removes outgoing":
554 elif f in "modifies adds removes outgoing":
552 w = 30 # slower
555 w = 30 # slower
553 elif f == "contains":
556 elif f == "contains":
554 w = 100 # very slow
557 w = 100 # very slow
555 elif f == "ancestor":
558 elif f == "ancestor":
556 w = 1 * smallbonus
559 w = 1 * smallbonus
557 elif f == "reverse limit":
560 elif f == "reverse limit":
558 w = 0
561 w = 0
559 elif f in "sort":
562 elif f in "sort":
560 w = 10 # assume most sorts look at changelog
563 w = 10 # assume most sorts look at changelog
561 else:
564 else:
562 w = 1
565 w = 1
563 return w + wa, (op, x[1], ta)
566 return w + wa, (op, x[1], ta)
564 return 1, x
567 return 1, x
565
568
566 parse = parser.parser(tokenize, elements).parse
569 parse = parser.parser(tokenize, elements).parse
567
570
568 def match(spec):
571 def match(spec):
569 if not spec:
572 if not spec:
570 raise error.ParseError(_("empty query"))
573 raise error.ParseError(_("empty query"))
571 tree = parse(spec)
574 tree = parse(spec)
572 weight, tree = optimize(tree, True)
575 weight, tree = optimize(tree, True)
573 def mfunc(repo, subset):
576 def mfunc(repo, subset):
574 return getset(repo, subset, tree)
577 return getset(repo, subset, tree)
575 return mfunc
578 return mfunc
General Comments 0
You need to be logged in to leave comments. Login now