comparison mercurial/revset.py @ 12815:079a618ea89d stable

revset: add translator comments to i18n strings
author Martin Geisler <mg@lazybytes.net>
date Sat, 23 Oct 2010 14:59:19 +0200
parents 9aae04f4fcf6
children 165079e564f0
comparison
equal deleted inserted replaced
12814:58bc5024805d 12815:079a618ea89d
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 # i18n: "id" is a keyword
177 l = getargs(x, 1, 1, _("id requires one argument")) 178 l = getargs(x, 1, 1, _("id requires one argument"))
179 # i18n: "id" is a keyword
178 n = getstring(l[0], _("id requires a string")) 180 n = getstring(l[0], _("id requires a string"))
179 if len(n) == 40: 181 if len(n) == 40:
180 rn = repo[n].rev() 182 rn = repo[n].rev()
181 else: 183 else:
182 rn = repo.changelog.rev(repo.changelog._partialmatch(n)) 184 rn = repo.changelog.rev(repo.changelog._partialmatch(n))
183 return [r for r in subset if r == rn] 185 return [r for r in subset if r == rn]
184 186
185 def rev(repo, subset, x): 187 def rev(repo, subset, x):
188 # i18n: "rev" is a keyword
186 l = getargs(x, 1, 1, _("rev requires one argument")) 189 l = getargs(x, 1, 1, _("rev requires one argument"))
187 try: 190 try:
191 # i18n: "rev" is a keyword
188 l = int(getstring(l[0], _("rev requires a number"))) 192 l = int(getstring(l[0], _("rev requires a number")))
189 except ValueError: 193 except ValueError:
194 # i18n: "rev" is a keyword
190 raise error.ParseError(_("rev expects a number")) 195 raise error.ParseError(_("rev expects a number"))
191 return [r for r in subset if r == l] 196 return [r for r in subset if r == l]
192 197
193 def p1(repo, subset, x): 198 def p1(repo, subset, x):
194 ps = set() 199 ps = set()
226 if m in subset: 231 if m in subset:
227 return [m] 232 return [m]
228 return [] 233 return []
229 234
230 def limit(repo, subset, x): 235 def limit(repo, subset, x):
236 # i18n: "limit" is a keyword
231 l = getargs(x, 2, 2, _("limit requires two arguments")) 237 l = getargs(x, 2, 2, _("limit requires two arguments"))
232 try: 238 try:
239 # i18n: "limit" is a keyword
233 lim = int(getstring(l[1], _("limit requires a number"))) 240 lim = int(getstring(l[1], _("limit requires a number")))
234 except ValueError: 241 except ValueError:
242 # i18n: "limit" is a keyword
235 raise error.ParseError(_("limit expects a number")) 243 raise error.ParseError(_("limit expects a number"))
236 return getset(repo, subset, l[0])[:lim] 244 return getset(repo, subset, l[0])[:lim]
237 245
238 def children(repo, subset, x): 246 def children(repo, subset, x):
239 cs = set() 247 cs = set()
252 b.add(repo[r].branch()) 260 b.add(repo[r].branch())
253 s = set(s) 261 s = set(s)
254 return [r for r in subset if r in s or repo[r].branch() in b] 262 return [r for r in subset if r in s or repo[r].branch() in b]
255 263
256 def ancestor(repo, subset, x): 264 def ancestor(repo, subset, x):
265 # i18n: "ancestor" is a keyword
257 l = getargs(x, 2, 2, _("ancestor requires two arguments")) 266 l = getargs(x, 2, 2, _("ancestor requires two arguments"))
258 r = range(len(repo)) 267 r = range(len(repo))
259 a = getset(repo, r, l[0]) 268 a = getset(repo, r, l[0])
260 b = getset(repo, r, l[1]) 269 b = getset(repo, r, l[1])
261 if len(a) != 1 or len(b) != 1: 270 if len(a) != 1 or len(b) != 1:
271 # i18n: "ancestor" is a keyword
262 raise error.ParseError(_("ancestor arguments must be single revisions")) 272 raise error.ParseError(_("ancestor arguments must be single revisions"))
263 an = [repo[a[0]].ancestor(repo[b[0]]).rev()] 273 an = [repo[a[0]].ancestor(repo[b[0]]).rev()]
264 274
265 return [r for r in an if r in subset] 275 return [r for r in an if r in subset]
266 276
277 return [] 287 return []
278 s = set(repo.changelog.descendants(*args)) | set(args) 288 s = set(repo.changelog.descendants(*args)) | set(args)
279 return [r for r in subset if r in s] 289 return [r for r in subset if r in s]
280 290
281 def follow(repo, subset, x): 291 def follow(repo, subset, x):
292 # i18n: "follow" is a keyword
282 getargs(x, 0, 0, _("follow takes no arguments")) 293 getargs(x, 0, 0, _("follow takes no arguments"))
283 p = repo['.'].rev() 294 p = repo['.'].rev()
284 s = set(repo.changelog.ancestors(p)) | set([p]) 295 s = set(repo.changelog.ancestors(p)) | set([p])
285 return [r for r in subset if r in s] 296 return [r for r in subset if r in s]
286 297
287 def date(repo, subset, x): 298 def date(repo, subset, x):
299 # i18n: "date" is a keyword
288 ds = getstring(x, _("date requires a string")) 300 ds = getstring(x, _("date requires a string"))
289 dm = util.matchdate(ds) 301 dm = util.matchdate(ds)
290 return [r for r in subset if dm(repo[r].date()[0])] 302 return [r for r in subset if dm(repo[r].date()[0])]
291 303
292 def keyword(repo, subset, x): 304 def keyword(repo, subset, x):
305 # i18n: "keyword" is a keyword
293 kw = getstring(x, _("keyword requires a string")).lower() 306 kw = getstring(x, _("keyword requires a string")).lower()
294 l = [] 307 l = []
295 for r in subset: 308 for r in subset:
296 c = repo[r] 309 c = repo[r]
297 t = " ".join(c.files() + [c.user(), c.description()]) 310 t = " ".join(c.files() + [c.user(), c.description()])
299 l.append(r) 312 l.append(r)
300 return l 313 return l
301 314
302 def grep(repo, subset, x): 315 def grep(repo, subset, x):
303 try: 316 try:
317 # i18n: "grep" is a keyword
304 gr = re.compile(getstring(x, _("grep requires a string"))) 318 gr = re.compile(getstring(x, _("grep requires a string")))
305 except re.error, e: 319 except re.error, e:
306 raise error.ParseError(_('invalid match pattern: %s') % e) 320 raise error.ParseError(_('invalid match pattern: %s') % e)
307 l = [] 321 l = []
308 for r in subset: 322 for r in subset:
312 l.append(r) 326 l.append(r)
313 continue 327 continue
314 return l 328 return l
315 329
316 def author(repo, subset, x): 330 def author(repo, subset, x):
331 # i18n: "author" is a keyword
317 n = getstring(x, _("author requires a string")).lower() 332 n = getstring(x, _("author requires a string")).lower()
318 return [r for r in subset if n in repo[r].user().lower()] 333 return [r for r in subset if n in repo[r].user().lower()]
319 334
320 def hasfile(repo, subset, x): 335 def hasfile(repo, subset, x):
336 # i18n: "file" is a keyword
321 pat = getstring(x, _("file requires a pattern")) 337 pat = getstring(x, _("file requires a pattern"))
322 m = matchmod.match(repo.root, repo.getcwd(), [pat]) 338 m = matchmod.match(repo.root, repo.getcwd(), [pat])
323 s = [] 339 s = []
324 for r in subset: 340 for r in subset:
325 for f in repo[r].files(): 341 for f in repo[r].files():
327 s.append(r) 343 s.append(r)
328 continue 344 continue
329 return s 345 return s
330 346
331 def contains(repo, subset, x): 347 def contains(repo, subset, x):
348 # i18n: "contains" is a keyword
332 pat = getstring(x, _("contains requires a pattern")) 349 pat = getstring(x, _("contains requires a pattern"))
333 m = matchmod.match(repo.root, repo.getcwd(), [pat]) 350 m = matchmod.match(repo.root, repo.getcwd(), [pat])
334 s = [] 351 s = []
335 if m.files() == [pat]: 352 if m.files() == [pat]:
336 for r in subset: 353 for r in subset:
371 s.append(r) 388 s.append(r)
372 continue 389 continue
373 return s 390 return s
374 391
375 def modifies(repo, subset, x): 392 def modifies(repo, subset, x):
393 # i18n: "modifies" is a keyword
376 pat = getstring(x, _("modifies requires a pattern")) 394 pat = getstring(x, _("modifies requires a pattern"))
377 return checkstatus(repo, subset, pat, 0) 395 return checkstatus(repo, subset, pat, 0)
378 396
379 def adds(repo, subset, x): 397 def adds(repo, subset, x):
398 # i18n: "adds" is a keyword
380 pat = getstring(x, _("adds requires a pattern")) 399 pat = getstring(x, _("adds requires a pattern"))
381 return checkstatus(repo, subset, pat, 1) 400 return checkstatus(repo, subset, pat, 1)
382 401
383 def removes(repo, subset, x): 402 def removes(repo, subset, x):
403 # i18n: "removes" is a keyword
384 pat = getstring(x, _("removes requires a pattern")) 404 pat = getstring(x, _("removes requires a pattern"))
385 return checkstatus(repo, subset, pat, 2) 405 return checkstatus(repo, subset, pat, 2)
386 406
387 def merge(repo, subset, x): 407 def merge(repo, subset, x):
408 # i18n: "merge" is a keyword
388 getargs(x, 0, 0, _("merge takes no arguments")) 409 getargs(x, 0, 0, _("merge takes no arguments"))
389 cl = repo.changelog 410 cl = repo.changelog
390 return [r for r in subset if cl.parentrevs(r)[1] != -1] 411 return [r for r in subset if cl.parentrevs(r)[1] != -1]
391 412
392 def closed(repo, subset, x): 413 def closed(repo, subset, x):
414 # i18n: "closed" is a keyword
393 getargs(x, 0, 0, _("closed takes no arguments")) 415 getargs(x, 0, 0, _("closed takes no arguments"))
394 return [r for r in subset if repo[r].extra().get('close')] 416 return [r for r in subset if repo[r].extra().get('close')]
395 417
396 def head(repo, subset, x): 418 def head(repo, subset, x):
419 # i18n: "head" is a keyword
397 getargs(x, 0, 0, _("head takes no arguments")) 420 getargs(x, 0, 0, _("head takes no arguments"))
398 hs = set() 421 hs = set()
399 for b, ls in repo.branchmap().iteritems(): 422 for b, ls in repo.branchmap().iteritems():
400 hs.update(repo[h].rev() for h in ls) 423 hs.update(repo[h].rev() for h in ls)
401 return [r for r in subset if r in hs] 424 return [r for r in subset if r in hs]
410 return getset(repo, subset, x) 433 return getset(repo, subset, x)
411 except error.RepoLookupError: 434 except error.RepoLookupError:
412 return [] 435 return []
413 436
414 def sort(repo, subset, x): 437 def sort(repo, subset, x):
438 # i18n: "sort" is a keyword
415 l = getargs(x, 1, 2, _("sort requires one or two arguments")) 439 l = getargs(x, 1, 2, _("sort requires one or two arguments"))
416 keys = "rev" 440 keys = "rev"
417 if len(l) == 2: 441 if len(l) == 2:
418 keys = getstring(l[1], _("sort spec must be a string")) 442 keys = getstring(l[1], _("sort spec must be a string"))
419 443
452 l.append(e) 476 l.append(e)
453 l.sort() 477 l.sort()
454 return [e[-1] for e in l] 478 return [e[-1] for e in l]
455 479
456 def getall(repo, subset, x): 480 def getall(repo, subset, x):
481 # i18n: "all" is a keyword
457 getargs(x, 0, 0, _("all takes no arguments")) 482 getargs(x, 0, 0, _("all takes no arguments"))
458 return subset 483 return subset
459 484
460 def heads(repo, subset, x): 485 def heads(repo, subset, x):
461 s = getset(repo, subset, x) 486 s = getset(repo, subset, x)
467 cs = set(children(repo, subset, x)) 492 cs = set(children(repo, subset, x))
468 return [r for r in s if r not in cs] 493 return [r for r in s if r not in cs]
469 494
470 def outgoing(repo, subset, x): 495 def outgoing(repo, subset, x):
471 import hg # avoid start-up nasties 496 import hg # avoid start-up nasties
497 # i18n: "outgoing" is a keyword
472 l = getargs(x, 0, 1, _("outgoing requires a repository path")) 498 l = getargs(x, 0, 1, _("outgoing requires a repository path"))
499 # i18n: "outgoing" is a keyword
473 dest = l and getstring(l[0], _("outgoing requires a repository path")) or '' 500 dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
474 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') 501 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
475 dest, branches = hg.parseurl(dest) 502 dest, branches = hg.parseurl(dest)
476 revs, checkout = hg.addbranchrevs(repo, repo, branches, []) 503 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
477 if revs: 504 if revs:
483 cl = repo.changelog 510 cl = repo.changelog
484 o = set([cl.rev(r) for r in repo.changelog.nodesbetween(o, revs)[0]]) 511 o = set([cl.rev(r) for r in repo.changelog.nodesbetween(o, revs)[0]])
485 return [r for r in subset if r in o] 512 return [r for r in subset if r in o]
486 513
487 def tag(repo, subset, x): 514 def tag(repo, subset, x):
515 # i18n: "tag" is a keyword
488 args = getargs(x, 0, 1, _("tag takes one or no arguments")) 516 args = getargs(x, 0, 1, _("tag takes one or no arguments"))
489 cl = repo.changelog 517 cl = repo.changelog
490 if args: 518 if args:
491 tn = getstring(args[0], 519 tn = getstring(args[0],
520 # i18n: "tag" is a keyword
492 _('the argument to tag must be a string')) 521 _('the argument to tag must be a string'))
493 s = set([cl.rev(n) for t, n in repo.tagslist() if t == tn]) 522 s = set([cl.rev(n) for t, n in repo.tagslist() if t == tn])
494 else: 523 else:
495 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) 524 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
496 return [r for r in subset if r in s] 525 return [r for r in subset if r in s]