Patchwork [6,of,6] templater: always map over a wrapped object

login
register
mail settings
Submitter Yuya Nishihara
Date June 4, 2018, 1:10 p.m.
Message ID <c2ef13743679487c1963.1528117813@mimosa>
Download mbox | patch
Permalink /patch/31965/
State Accepted
Headers show

Comments

Yuya Nishihara - June 4, 2018, 1:10 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1524298891 -32400
#      Sat Apr 21 17:21:31 2018 +0900
# Node ID c2ef13743679487c1963e5e8eecdab2799213194
# Parent  481042701ff874ba7b8c6af18e4ef71f87f35c65
templater: always map over a wrapped object

_checkeditermaps() is no longer necessary as the hgweb issue was resolved.
Augie Fackler - June 4, 2018, 10:25 p.m.
On Mon, Jun 04, 2018 at 10:10:13PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1524298891 -32400
> #      Sat Apr 21 17:21:31 2018 +0900
> # Node ID c2ef13743679487c1963e5e8eecdab2799213194
> # Parent  481042701ff874ba7b8c6af18e4ef71f87f35c65
> templater: always map over a wrapped object

queued, thanks

Patch

diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -643,20 +643,6 @@  def _formatfiltererror(arg, filt):
     return (_("template filter '%s' is not compatible with keyword '%s'")
             % (fn, sym))
 
-def _checkeditermaps(darg, d):
-    try:
-        for v in d:
-            if not isinstance(v, dict):
-                raise TypeError
-            yield v
-    except TypeError:
-        sym = findsymbolicname(darg)
-        if sym:
-            raise error.ParseError(_("keyword '%s' is not iterable of mappings")
-                                   % sym)
-        else:
-            raise error.ParseError(_("%r is not iterable of mappings") % d)
-
 def _iteroverlaymaps(context, origmapping, newmappings):
     """Generate combined mappings from the original mapping and an iterable
     of partial mappings to override the original"""
@@ -665,23 +651,14 @@  def _iteroverlaymaps(context, origmappin
         lm['index'] = i
         yield lm
 
-def _applymap(context, mapping, diter, targ):
-    for lm in _iteroverlaymaps(context, mapping, diter):
+def _applymap(context, mapping, d, targ):
+    for lm in _iteroverlaymaps(context, mapping, d.itermaps(context)):
         yield evalrawexp(context, lm, targ)
 
 def runmap(context, mapping, data):
     darg, targ = data
-    d = evalrawexp(context, mapping, darg)
-    # TODO: a generator should be rejected because it is a thunk of lazy
-    # string, but we can't because hgweb abuses generator as a keyword
-    # that returns a list of dicts.
-    # TODO: drop _checkeditermaps() and pass 'd' to mappedgenerator so it
-    # can be restarted.
-    if isinstance(d, wrapped):
-        diter = d.itermaps(context)
-    else:
-        diter = _checkeditermaps(darg, d)
-    return mappedgenerator(_applymap, args=(mapping, diter, targ))
+    d = evalwrapped(context, mapping, darg)
+    return mappedgenerator(_applymap, args=(mapping, d, targ))
 
 def runmember(context, mapping, data):
     darg, memb = data
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
@@ -3212,7 +3212,7 @@  Test new-style inline templating:
   
 
   $ hg log -R latesttag -r tip -T '{rev % "a"}\n'
-  hg: parse error: keyword 'rev' is not iterable of mappings
+  hg: parse error: 11 is not iterable of mappings
   [255]
   $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "a"}\n'
   hg: parse error: None is not iterable of mappings