Re: [PATCH 6 of 6] templater: always map over a wrapped object

2018-06-04 Thread Augie Fackler
On Mon, Jun 04, 2018 at 10:10:13PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara 
> # 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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2018-06-04 Thread Yuya Nishihara
# HG changeset patch
# User Yuya Nishihara 
# 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.

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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel