templater: fix get() to evaluate arguments eagerly
authorYuya Nishihara <yuya@tcha.org>
Sun, 14 Feb 2016 00:05:58 +0900
changeset 28331 2874db5462d3
parent 28330 f3fb24e36d61
child 28332 e91371633127
templater: fix get() to evaluate arguments eagerly If a key is constructed from a template expression, it may be a generator. In that case, a key have to be stringified. A dictarg should never be a generator, but this patch also changes it to call evalfuncarg() for consistency.
mercurial/templater.py
tests/test-command-template.t
--- a/mercurial/templater.py	Wed Mar 02 15:38:54 2016 +0000
+++ b/mercurial/templater.py	Sun Feb 14 00:05:58 2016 +0900
@@ -437,12 +437,12 @@
         # i18n: "get" is a keyword
         raise error.ParseError(_("get() expects two arguments"))
 
-    dictarg = args[0][0](context, mapping, args[0][1])
+    dictarg = evalfuncarg(context, mapping, args[0])
     if not util.safehasattr(dictarg, 'get'):
         # i18n: "get" is a keyword
         raise error.ParseError(_("get() expects a dict as first argument"))
 
-    key = args[1][0](context, mapping, args[1][1])
+    key = evalfuncarg(context, mapping, args[1])
     return dictarg.get(key)
 
 def if_(context, mapping, args):
--- a/tests/test-command-template.t	Wed Mar 02 15:38:54 2016 +0000
+++ b/tests/test-command-template.t	Sun Feb 14 00:05:58 2016 +0900
@@ -3176,6 +3176,8 @@
 
   $ hg log -r 0 --template '{get(extras, "branch")}\n'
   default
+  $ hg log -r 0 --template '{get(extras, "br{"anch"}")}\n'
+  default
   $ hg log -r 0 --template '{get(files, "should_fail")}\n'
   hg: parse error: get() expects a dict as first argument
   [255]