Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 11339:744d5b73f776
revset: improve filter argument handling
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 11 Jun 2010 15:30:12 -0500 |
parents | 8c377f2feee1 |
children | cf8a9154a362 |
comparison
equal
deleted
inserted
replaced
11338:285bcf40e04b | 11339:744d5b73f776 |
---|---|
95 return [] | 95 return [] |
96 if x[0] == 'list': | 96 if x[0] == 'list': |
97 return getlist(x[1]) + [x[2]] | 97 return getlist(x[1]) + [x[2]] |
98 return [x] | 98 return [x] |
99 | 99 |
100 def getpair(x, err): | 100 def getargs(x, min, max, err): |
101 l = getlist(x) | 101 l = getlist(x) |
102 if len(l) != 2: | 102 if len(l) < min or len(l) > max: |
103 raise error.ParseError(err) | 103 raise error.ParseError(err) |
104 return l | 104 return l |
105 | 105 |
106 def getset(repo, subset, x): | 106 def getset(repo, subset, x): |
107 if not x: | 107 if not x: |
184 if m in subset: | 184 if m in subset: |
185 return [m] | 185 return [m] |
186 return [] | 186 return [] |
187 | 187 |
188 def limit(repo, subset, x): | 188 def limit(repo, subset, x): |
189 l = getpair(x, "limit wants two args") | 189 l = getargs(x, 2, 2, "limit wants two args") |
190 try: | 190 try: |
191 lim = int(getstring(l[1], "limit wants a number")) | 191 lim = int(getstring(l[1], "limit wants a number")) |
192 except ValueError: | 192 except ValueError: |
193 raise error.ParseError("limit expects a number") | 193 raise error.ParseError("limit expects a number") |
194 return getset(repo, subset, l[0])[:lim] | 194 return getset(repo, subset, l[0])[:lim] |
210 b.add(repo[r].branch()) | 210 b.add(repo[r].branch()) |
211 s = set(s) | 211 s = set(s) |
212 return [r for r in subset if r in s or repo[r].branch() in b] | 212 return [r for r in subset if r in s or repo[r].branch() in b] |
213 | 213 |
214 def ancestor(repo, subset, x): | 214 def ancestor(repo, subset, x): |
215 l = getpair(x, "ancestor wants two args") | 215 l = getargs(x, 2, 2, "ancestor wants two args") |
216 a = getset(repo, subset, l[0]) | 216 a = getset(repo, subset, l[0]) |
217 b = getset(repo, subset, l[1]) | 217 b = getset(repo, subset, l[1]) |
218 if len(a) > 1 or len(b) > 1: | 218 if len(a) > 1 or len(b) > 1: |
219 raise error.ParseError("ancestor args must be single revisions") | 219 raise error.ParseError("ancestor args must be single revisions") |
220 return [repo[a[0]].ancestor(repo[b[0]]).rev()] | 220 return [repo[a[0]].ancestor(repo[b[0]]).rev()] |
228 args = getset(repo, range(len(repo)), x) | 228 args = getset(repo, range(len(repo)), x) |
229 s = set(repo.changelog.descendants(*args)) | set(args) | 229 s = set(repo.changelog.descendants(*args)) | set(args) |
230 return [r for r in subset if r in s] | 230 return [r for r in subset if r in s] |
231 | 231 |
232 def follow(repo, subset, x): | 232 def follow(repo, subset, x): |
233 if x: | 233 getargs(x, 0, 0, "follow takes no arguments") |
234 raise error.ParseError("follow takes no args") | |
235 p = repo['.'].rev() | 234 p = repo['.'].rev() |
236 s = set(repo.changelog.ancestors(p)) | set([p]) | 235 s = set(repo.changelog.ancestors(p)) | set([p]) |
237 return [r for r in subset if r in s] | 236 return [r for r in subset if r in s] |
238 | 237 |
239 def date(repo, subset, x): | 238 def date(repo, subset, x): |
332 def removes(repo, subset, x): | 331 def removes(repo, subset, x): |
333 pat = getstring(x, "removes wants a pattern") | 332 pat = getstring(x, "removes wants a pattern") |
334 return checkstatus(repo, subset, pat, 2) | 333 return checkstatus(repo, subset, pat, 2) |
335 | 334 |
336 def merge(repo, subset, x): | 335 def merge(repo, subset, x): |
337 if x: | 336 getargs(x, 0, 0, "merge takes no arguments") |
338 raise error.ParseError("merge takes no args") | |
339 cl = repo.changelog | 337 cl = repo.changelog |
340 return [r for r in subset if cl.parentrevs(r)[1] != -1] | 338 return [r for r in subset if cl.parentrevs(r)[1] != -1] |
341 | 339 |
342 def closed(repo, subset, x): | 340 def closed(repo, subset, x): |
341 getargs(x, 0, 0, "closed takes no arguments") | |
343 return [r for r in subset if repo[r].extra('close')] | 342 return [r for r in subset if repo[r].extra('close')] |
344 | 343 |
345 def head(repo, subset, x): | 344 def head(repo, subset, x): |
345 getargs(x, 0, 0, "head takes no arguments") | |
346 hs = set() | 346 hs = set() |
347 for b, ls in repo.branchmap().iteritems(): | 347 for b, ls in repo.branchmap().iteritems(): |
348 hs.update(repo[h].rev() for h in ls) | 348 hs.update(repo[h].rev() for h in ls) |
349 return [r for r in subset if r in hs] | 349 return [r for r in subset if r in hs] |
350 | 350 |
352 l = getset(repo, subset, x) | 352 l = getset(repo, subset, x) |
353 l.reverse() | 353 l.reverse() |
354 return l | 354 return l |
355 | 355 |
356 def sort(repo, subset, x): | 356 def sort(repo, subset, x): |
357 l = getlist(x) | 357 l = getargs(x, 1, 2, "sort wants one or two arguments") |
358 keys = "rev" | 358 keys = "rev" |
359 if len(l) == 2: | 359 if len(l) == 2: |
360 keys = getstring(l[1], "sort spec must be a string") | 360 keys = getstring(l[1], "sort spec must be a string") |
361 | 361 |
362 s = l[0] | 362 s = l[0] |
394 l.append(e) | 394 l.append(e) |
395 l.sort() | 395 l.sort() |
396 return [e[-1] for e in l] | 396 return [e[-1] for e in l] |
397 | 397 |
398 def getall(repo, subset, x): | 398 def getall(repo, subset, x): |
399 getargs(x, 0, 0, "all takes no arguments") | |
399 return subset | 400 return subset |
400 | 401 |
401 def heads(repo, subset, x): | 402 def heads(repo, subset, x): |
402 s = getset(repo, subset, x) | 403 s = getset(repo, subset, x) |
403 ps = set(parents(repo, subset, x)) | 404 ps = set(parents(repo, subset, x)) |
408 cs = set(children(repo, subset, x)) | 409 cs = set(children(repo, subset, x)) |
409 return [r for r in s if r not in cs] | 410 return [r for r in s if r not in cs] |
410 | 411 |
411 def outgoing(repo, subset, x): | 412 def outgoing(repo, subset, x): |
412 import hg # avoid start-up nasties | 413 import hg # avoid start-up nasties |
413 l = getlist(x) | 414 l = getargs(x, 0, 1, "outgoing wants a repo path") |
414 if len(l) == 1: | 415 dest = l[1:] or '' |
415 dest = getstring(l[0], "outgoing wants a repo path") | |
416 else: | |
417 dest = '' | |
418 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') | 416 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') |
419 dest, branches = hg.parseurl(dest) | 417 dest, branches = hg.parseurl(dest) |
420 other = hg.repository(hg.remoteui(repo, {}), dest) | 418 other = hg.repository(hg.remoteui(repo, {}), dest) |
421 repo.ui.pushbuffer() | 419 repo.ui.pushbuffer() |
422 o = discovery.findoutgoing(repo, other) | 420 o = discovery.findoutgoing(repo, other) |
425 o = set([cl.rev(r) for r in repo.changelog.nodesbetween(o, None)[0]]) | 423 o = set([cl.rev(r) for r in repo.changelog.nodesbetween(o, None)[0]]) |
426 print 'out', dest, o | 424 print 'out', dest, o |
427 return [r for r in subset if r in o] | 425 return [r for r in subset if r in o] |
428 | 426 |
429 def tagged(repo, subset, x): | 427 def tagged(repo, subset, x): |
428 getargs(x, 0, 0, "tagged takes no arguments") | |
430 cl = repo.changelog | 429 cl = repo.changelog |
431 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) | 430 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) |
432 return [r for r in subset if r in s] | 431 return [r for r in subset if r in s] |
433 | 432 |
434 symbols = { | 433 symbols = { |