From patchwork Wed Mar 2 15:35:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1,of,4] templater: fix get() to evaluate arguments eagerly From: Yuya Nishihara X-Patchwork-Id: 13534 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Thu, 03 Mar 2016 00:35:01 +0900 # HG changeset patch # User Yuya Nishihara # Date 1455375958 -32400 # Sun Feb 14 00:05:58 2016 +0900 # Node ID fa4f3eb5bd1ea8682cba631c824fb4e6838ed297 # Parent 4f7a5e4f2daff0a65aa470d9f70365ad55aaa100 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. diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -437,12 +437,12 @@ def get(context, mapping, args): # 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): 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 @@ -3176,6 +3176,8 @@ Test get function: $ 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]