[PATCH 1 of 4] templatefuncs: minimize resource requirements
Yuya Nishihara
yuya at tcha.org
Mon Jun 18 13:37:05 UTC 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1528978676 -32400
# Thu Jun 14 21:17:56 2018 +0900
# Node ID 6d021282f5c6b39c4f3af64e3ed0a658253974d3
# Parent ed4f41dd0fdb2e5396830084805223ca334bee3b
templatefuncs: minimize resource requirements
diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py
--- a/mercurial/templatefuncs.py
+++ b/mercurial/templatefuncs.py
@@ -512,7 +512,7 @@ def relpath(context, mapping, args):
# i18n: "relpath" is a keyword
raise error.ParseError(_("relpath expects one argument"))
- repo = context.resource(mapping, 'ctx').repo()
+ repo = context.resource(mapping, 'repo')
path = evalstring(context, mapping, args[0])
return repo.pathto(path)
@@ -525,8 +525,7 @@ def revset(context, mapping, args):
raise error.ParseError(_("revset expects one or more arguments"))
raw = evalstring(context, mapping, args[0])
- ctx = context.resource(mapping, 'ctx')
- repo = ctx.repo()
+ repo = context.resource(mapping, 'repo')
def query(expr):
m = revsetmod.match(repo.ui, expr, lookup=revsetmod.lookupfn(repo))
@@ -594,7 +593,7 @@ def shortest(context, mapping, args):
# i18n: "shortest" is a keyword
_("shortest() expects an integer minlength"))
- repo = context.resource(mapping, 'ctx')._repo
+ repo = context.resource(mapping, 'repo')
if len(hexnode) > 40:
return hexnode
elif len(hexnode) == 40:
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -229,7 +229,7 @@ Internal resources shouldn't be exposed
Never crash on internal resource not available:
$ hg --cwd .. debugtemplate '{"c0bebeef"|shortest}\n'
- abort: template resource not available: ctx
+ abort: template resource not available: repo
[255]
$ hg config -T '{author}'
More information about the Mercurial-devel
mailing list