comparison mercurial/revset.py @ 12736:7e14e67e6622

revset: use 'requires' instead of 'wants' in error message
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sat, 16 Oct 2010 18:50:53 +0200
parents 098dfb2b7596
children 9aae04f4fcf6
comparison
equal deleted inserted replaced
12735:8888e56ac417 12736:7e14e67e6622
172 raise error.ParseError(_("not a function: %s") % a[1]) 172 raise error.ParseError(_("not a function: %s") % a[1])
173 173
174 # functions 174 # functions
175 175
176 def node(repo, subset, x): 176 def node(repo, subset, x):
177 l = getargs(x, 1, 1, _("id wants one argument")) 177 l = getargs(x, 1, 1, _("id requires one argument"))
178 n = getstring(l[0], _("id wants a string")) 178 n = getstring(l[0], _("id requires a string"))
179 if len(n) == 40: 179 if len(n) == 40:
180 rn = repo[n].rev() 180 rn = repo[n].rev()
181 else: 181 else:
182 rn = repo.changelog.rev(repo.changelog._partialmatch(n)) 182 rn = repo.changelog.rev(repo.changelog._partialmatch(n))
183 return [r for r in subset if r == rn] 183 return [r for r in subset if r == rn]
184 184
185 def rev(repo, subset, x): 185 def rev(repo, subset, x):
186 l = getargs(x, 1, 1, _("rev wants one argument")) 186 l = getargs(x, 1, 1, _("rev requires one argument"))
187 try: 187 try:
188 l = int(getstring(l[0], _("rev wants a number"))) 188 l = int(getstring(l[0], _("rev requires a number")))
189 except ValueError: 189 except ValueError:
190 raise error.ParseError(_("rev expects a number")) 190 raise error.ParseError(_("rev expects a number"))
191 return [r for r in subset if r == l] 191 return [r for r in subset if r == l]
192 192
193 def p1(repo, subset, x): 193 def p1(repo, subset, x):
226 if m in subset: 226 if m in subset:
227 return [m] 227 return [m]
228 return [] 228 return []
229 229
230 def limit(repo, subset, x): 230 def limit(repo, subset, x):
231 l = getargs(x, 2, 2, _("limit wants two arguments")) 231 l = getargs(x, 2, 2, _("limit requires two arguments"))
232 try: 232 try:
233 lim = int(getstring(l[1], _("limit wants a number"))) 233 lim = int(getstring(l[1], _("limit requires a number")))
234 except ValueError: 234 except ValueError:
235 raise error.ParseError(_("limit expects a number")) 235 raise error.ParseError(_("limit expects a number"))
236 return getset(repo, subset, l[0])[:lim] 236 return getset(repo, subset, l[0])[:lim]
237 237
238 def children(repo, subset, x): 238 def children(repo, subset, x):
252 b.add(repo[r].branch()) 252 b.add(repo[r].branch())
253 s = set(s) 253 s = set(s)
254 return [r for r in subset if r in s or repo[r].branch() in b] 254 return [r for r in subset if r in s or repo[r].branch() in b]
255 255
256 def ancestor(repo, subset, x): 256 def ancestor(repo, subset, x):
257 l = getargs(x, 2, 2, _("ancestor wants two arguments")) 257 l = getargs(x, 2, 2, _("ancestor requires two arguments"))
258 r = range(len(repo)) 258 r = range(len(repo))
259 a = getset(repo, r, l[0]) 259 a = getset(repo, r, l[0])
260 b = getset(repo, r, l[1]) 260 b = getset(repo, r, l[1])
261 if len(a) != 1 or len(b) != 1: 261 if len(a) != 1 or len(b) != 1:
262 raise error.ParseError(_("ancestor arguments must be single revisions")) 262 raise error.ParseError(_("ancestor arguments must be single revisions"))
283 p = repo['.'].rev() 283 p = repo['.'].rev()
284 s = set(repo.changelog.ancestors(p)) | set([p]) 284 s = set(repo.changelog.ancestors(p)) | set([p])
285 return [r for r in subset if r in s] 285 return [r for r in subset if r in s]
286 286
287 def date(repo, subset, x): 287 def date(repo, subset, x):
288 ds = getstring(x, _("date wants a string")) 288 ds = getstring(x, _("date requires a string"))
289 dm = util.matchdate(ds) 289 dm = util.matchdate(ds)
290 return [r for r in subset if dm(repo[r].date()[0])] 290 return [r for r in subset if dm(repo[r].date()[0])]
291 291
292 def keyword(repo, subset, x): 292 def keyword(repo, subset, x):
293 kw = getstring(x, _("keyword wants a string")).lower() 293 kw = getstring(x, _("keyword requires a string")).lower()
294 l = [] 294 l = []
295 for r in subset: 295 for r in subset:
296 c = repo[r] 296 c = repo[r]
297 t = " ".join(c.files() + [c.user(), c.description()]) 297 t = " ".join(c.files() + [c.user(), c.description()])
298 if kw in t.lower(): 298 if kw in t.lower():
299 l.append(r) 299 l.append(r)
300 return l 300 return l
301 301
302 def grep(repo, subset, x): 302 def grep(repo, subset, x):
303 try: 303 try:
304 gr = re.compile(getstring(x, _("grep wants a string"))) 304 gr = re.compile(getstring(x, _("grep requires a string")))
305 except re.error, e: 305 except re.error, e:
306 raise error.ParseError(_('invalid match pattern: %s') % e) 306 raise error.ParseError(_('invalid match pattern: %s') % e)
307 l = [] 307 l = []
308 for r in subset: 308 for r in subset:
309 c = repo[r] 309 c = repo[r]
312 l.append(r) 312 l.append(r)
313 continue 313 continue
314 return l 314 return l
315 315
316 def author(repo, subset, x): 316 def author(repo, subset, x):
317 n = getstring(x, _("author wants a string")).lower() 317 n = getstring(x, _("author requires a string")).lower()
318 return [r for r in subset if n in repo[r].user().lower()] 318 return [r for r in subset if n in repo[r].user().lower()]
319 319
320 def hasfile(repo, subset, x): 320 def hasfile(repo, subset, x):
321 pat = getstring(x, _("file wants a pattern")) 321 pat = getstring(x, _("file requires a pattern"))
322 m = matchmod.match(repo.root, repo.getcwd(), [pat]) 322 m = matchmod.match(repo.root, repo.getcwd(), [pat])
323 s = [] 323 s = []
324 for r in subset: 324 for r in subset:
325 for f in repo[r].files(): 325 for f in repo[r].files():
326 if m(f): 326 if m(f):
327 s.append(r) 327 s.append(r)
328 continue 328 continue
329 return s 329 return s
330 330
331 def contains(repo, subset, x): 331 def contains(repo, subset, x):
332 pat = getstring(x, _("contains wants a pattern")) 332 pat = getstring(x, _("contains requires a pattern"))
333 m = matchmod.match(repo.root, repo.getcwd(), [pat]) 333 m = matchmod.match(repo.root, repo.getcwd(), [pat])
334 s = [] 334 s = []
335 if m.files() == [pat]: 335 if m.files() == [pat]:
336 for r in subset: 336 for r in subset:
337 if pat in repo[r]: 337 if pat in repo[r]:
371 s.append(r) 371 s.append(r)
372 continue 372 continue
373 return s 373 return s
374 374
375 def modifies(repo, subset, x): 375 def modifies(repo, subset, x):
376 pat = getstring(x, _("modifies wants a pattern")) 376 pat = getstring(x, _("modifies requires a pattern"))
377 return checkstatus(repo, subset, pat, 0) 377 return checkstatus(repo, subset, pat, 0)
378 378
379 def adds(repo, subset, x): 379 def adds(repo, subset, x):
380 pat = getstring(x, _("adds wants a pattern")) 380 pat = getstring(x, _("adds requires a pattern"))
381 return checkstatus(repo, subset, pat, 1) 381 return checkstatus(repo, subset, pat, 1)
382 382
383 def removes(repo, subset, x): 383 def removes(repo, subset, x):
384 pat = getstring(x, _("removes wants a pattern")) 384 pat = getstring(x, _("removes requires a pattern"))
385 return checkstatus(repo, subset, pat, 2) 385 return checkstatus(repo, subset, pat, 2)
386 386
387 def merge(repo, subset, x): 387 def merge(repo, subset, x):
388 getargs(x, 0, 0, _("merge takes no arguments")) 388 getargs(x, 0, 0, _("merge takes no arguments"))
389 cl = repo.changelog 389 cl = repo.changelog
410 return getset(repo, subset, x) 410 return getset(repo, subset, x)
411 except error.RepoLookupError: 411 except error.RepoLookupError:
412 return [] 412 return []
413 413
414 def sort(repo, subset, x): 414 def sort(repo, subset, x):
415 l = getargs(x, 1, 2, _("sort wants one or two arguments")) 415 l = getargs(x, 1, 2, _("sort requires one or two arguments"))
416 keys = "rev" 416 keys = "rev"
417 if len(l) == 2: 417 if len(l) == 2:
418 keys = getstring(l[1], _("sort spec must be a string")) 418 keys = getstring(l[1], _("sort spec must be a string"))
419 419
420 s = l[0] 420 s = l[0]
467 cs = set(children(repo, subset, x)) 467 cs = set(children(repo, subset, x))
468 return [r for r in s if r not in cs] 468 return [r for r in s if r not in cs]
469 469
470 def outgoing(repo, subset, x): 470 def outgoing(repo, subset, x):
471 import hg # avoid start-up nasties 471 import hg # avoid start-up nasties
472 l = getargs(x, 0, 1, _("outgoing wants a repository path")) 472 l = getargs(x, 0, 1, _("outgoing requires a repository path"))
473 dest = l and getstring(l[0], _("outgoing wants a repository path")) or '' 473 dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
474 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') 474 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
475 dest, branches = hg.parseurl(dest) 475 dest, branches = hg.parseurl(dest)
476 revs, checkout = hg.addbranchrevs(repo, repo, branches, []) 476 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
477 if revs: 477 if revs:
478 revs = [repo.lookup(rev) for rev in revs] 478 revs = [repo.lookup(rev) for rev in revs]