comparison mercurial/templatefuncs.py @ 38427:4b73f316ba0e

templatefuncs: minimize resource requirements
author Yuya Nishihara <yuya@tcha.org>
date Thu, 14 Jun 2018 21:17:56 +0900
parents 8d6109b49b31
children aa98392eb5b0
comparison
equal deleted inserted replaced
38426:00368bc0a614 38427:4b73f316ba0e
510 the current working directory.""" 510 the current working directory."""
511 if len(args) != 1: 511 if len(args) != 1:
512 # i18n: "relpath" is a keyword 512 # i18n: "relpath" is a keyword
513 raise error.ParseError(_("relpath expects one argument")) 513 raise error.ParseError(_("relpath expects one argument"))
514 514
515 repo = context.resource(mapping, 'ctx').repo() 515 repo = context.resource(mapping, 'repo')
516 path = evalstring(context, mapping, args[0]) 516 path = evalstring(context, mapping, args[0])
517 return repo.pathto(path) 517 return repo.pathto(path)
518 518
519 @templatefunc('revset(query[, formatargs...])') 519 @templatefunc('revset(query[, formatargs...])')
520 def revset(context, mapping, args): 520 def revset(context, mapping, args):
523 if not len(args) > 0: 523 if not len(args) > 0:
524 # i18n: "revset" is a keyword 524 # i18n: "revset" is a keyword
525 raise error.ParseError(_("revset expects one or more arguments")) 525 raise error.ParseError(_("revset expects one or more arguments"))
526 526
527 raw = evalstring(context, mapping, args[0]) 527 raw = evalstring(context, mapping, args[0])
528 ctx = context.resource(mapping, 'ctx') 528 repo = context.resource(mapping, 'repo')
529 repo = ctx.repo()
530 529
531 def query(expr): 530 def query(expr):
532 m = revsetmod.match(repo.ui, expr, lookup=revsetmod.lookupfn(repo)) 531 m = revsetmod.match(repo.ui, expr, lookup=revsetmod.lookupfn(repo))
533 return m(repo) 532 return m(repo)
534 533
592 if len(args) > 1: 591 if len(args) > 1:
593 minlength = evalinteger(context, mapping, args[1], 592 minlength = evalinteger(context, mapping, args[1],
594 # i18n: "shortest" is a keyword 593 # i18n: "shortest" is a keyword
595 _("shortest() expects an integer minlength")) 594 _("shortest() expects an integer minlength"))
596 595
597 repo = context.resource(mapping, 'ctx')._repo 596 repo = context.resource(mapping, 'repo')
598 if len(hexnode) > 40: 597 if len(hexnode) > 40:
599 return hexnode 598 return hexnode
600 elif len(hexnode) == 40: 599 elif len(hexnode) == 40:
601 try: 600 try:
602 node = bin(hexnode) 601 node = bin(hexnode)