changeset 38229:7701c2d4a438

templater: always map over a wrapped object _checkeditermaps() is no longer necessary as the hgweb issue was resolved.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 21 Apr 2018 17:21:31 +0900
parents 8bded7eae26c
children bf901559e647
files mercurial/templateutil.py tests/test-command-template.t
diffstat 2 files changed, 5 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templateutil.py	Sat Apr 21 17:15:11 2018 +0900
+++ b/mercurial/templateutil.py	Sat Apr 21 17:21:31 2018 +0900
@@ -643,20 +643,6 @@
     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 @@
         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
--- a/tests/test-command-template.t	Sat Apr 21 17:15:11 2018 +0900
+++ b/tests/test-command-template.t	Sat Apr 21 17:21:31 2018 +0900
@@ -3212,7 +3212,7 @@
   
 
   $ 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