Patchwork [5,of,5] templater: comment that gettemplate() has different name resolution order

login
register
mail settings
Submitter Yuya Nishihara
Date June 16, 2015, 3:10 p.m.
Message ID <6ac2b6d407829c566a52.1434467440@mimosa>
Download mbox | patch
Permalink /patch/9667/
State Accepted
Headers show

Comments

Yuya Nishihara - June 16, 2015, 3:10 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1434460399 -32400
#      Tue Jun 16 22:13:19 2015 +0900
# Node ID 6ac2b6d407829c566a52d81183ccfa9a2166fe64
# Parent  84be213e8d69a915311f0a852fce13792290cc66
templater: comment that gettemplate() has different name resolution order

I've tried to unify gettemplate() with buildtemplate(), but it didn't go well
because gettemplate() have to bypass mapping dict.

For example, web templates have '{tags%changelogtag}' and 'changelogtag' is
defined in both mapping, the default, and context.cache, sourced from map file.
In general, mapping shadows context variables, but gettemplate() have to pick
it from context.cache.
Matt Mackall - June 16, 2015, 11:06 p.m.
On Wed, 2015-06-17 at 00:10 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1434460399 -32400
> #      Tue Jun 16 22:13:19 2015 +0900
> # Node ID 6ac2b6d407829c566a52d81183ccfa9a2166fe64
> # Parent  84be213e8d69a915311f0a852fce13792290cc66
> templater: comment that gettemplate() has different name resolution order

Nice work! These are queued for default, thanks.

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -147,6 +147,9 @@  def gettemplate(exp, context):
     if exp[0] == 'template':
         return compiletemplate(exp[1], context)
     if exp[0] == 'symbol':
+        # unlike runsymbol(), here 'symbol' is always taken as template name
+        # even if it exists in mapping. this allows us to override mapping
+        # by web templates, e.g. 'changelogtag' is redefined in map file.
         return context._load(exp[1])
     raise error.ParseError(_("expected template specifier"))