changeset 28225:5c11702fe2a3

templater: fix list templating bug High-level use case: printing a list of objects with formatter when each object in turn contains a list of properties (like when % template symbol is used in {things % '{thing}'} Let the top-level list contain one thing with two properties: objs = [{ 'props': [ { 'value': 1, 'show': 1 }, { 'value': 2 }] }] (please note that second property does not have 'show' key) If a templateformatter is used to print this with template "{props % '{if(show, value)}'}" current implementation will print value for both properties, which is a bug. This happens because in `templater.runmap` function we only rewrite mapping values with existing new values for each item. If some mapping value is missing in the item, it will not be removed.
author Kostia Balytskyi <ikostia@fb.com>
date Wed, 24 Feb 2016 19:31:55 +0000
parents 8ec5478aa0d6
children 377f0d8ff874
files mercurial/templater.py
diffstat 1 files changed, 1 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Wed Feb 24 16:58:07 2016 +0100
+++ b/mercurial/templater.py	Wed Feb 24 19:31:55 2016 +0000
@@ -296,9 +296,8 @@
     if util.safehasattr(d, 'itermaps'):
         d = d.itermaps()
 
-    lm = mapping.copy()
-
     for i in d:
+        lm = mapping.copy()
         if isinstance(i, dict):
             lm.update(i)
             lm['originalnode'] = mapping.get('node')