mercurial/templatekw.py
changeset 24239 31f9b1b16d1e
parent 24238 49cee6d8573d
child 24240 bd504d90588d
--- a/mercurial/templatekw.py	Sun Mar 08 14:38:50 2015 +0900
+++ b/mercurial/templatekw.py	Sun Mar 08 14:46:42 2015 +0900
@@ -14,9 +14,10 @@
 #  "{files % '{file}\n'}" (hgweb-style with inlining and function support)
 
 class _hybrid(object):
-    def __init__(self, gen, values, joinfmt=None):
+    def __init__(self, gen, values, makemap, joinfmt=None):
         self.gen = gen
         self.values = values
+        self._makemap = makemap
         if joinfmt:
             self.joinfmt = joinfmt
         else:
@@ -24,8 +25,9 @@
     def __iter__(self):
         return self.gen
     def __call__(self):
+        makemap = self._makemap
         for x in self.values:
-            yield x
+            yield makemap(x)
     def __len__(self):
         return len(self.values)
 
@@ -33,7 +35,7 @@
     if not element:
         element = name
     f = _showlist(name, values, plural, **args)
-    return _hybrid(f, [{element: x} for x in values])
+    return _hybrid(f, values, lambda x: {element: x})
 
 def _showlist(name, values, plural=None, **args):
     '''expand set of values.
@@ -201,9 +203,8 @@
     bookmarks = args['ctx'].bookmarks()
     current = repo._bookmarkcurrent
     makemap = lambda v: {'bookmark': v, 'current': current}
-    c = [makemap(v) for v in bookmarks]
     f = _showlist('bookmark', bookmarks, **args)
-    return _hybrid(f, c, lambda x: x['bookmark'])
+    return _hybrid(f, bookmarks, makemap, lambda x: x['bookmark'])
 
 def showchildren(**args):
     """:children: List of strings. The children of the changeset."""
@@ -246,7 +247,8 @@
     makemap = lambda k: {'key': k, 'value': extras[k]}
     c = [makemap(k) for k in extras]
     f = _showlist('extra', c, plural='extras', **args)
-    return _hybrid(f, c, lambda x: '%s=%s' % (x['key'], x['value']))
+    return _hybrid(f, extras, makemap,
+                   lambda x: '%s=%s' % (x['key'], x['value']))
 
 def showfileadds(**args):
     """:file_adds: List of strings. Files added by this changeset."""
@@ -274,7 +276,8 @@
     makemap = lambda k: {'name': k, 'source': copies[k]}
     c = [makemap(k) for k in copies]
     f = _showlist('file_copy', c, plural='file_copies', **args)
-    return _hybrid(f, c, lambda x: '%s (%s)' % (x['name'], x['source']))
+    return _hybrid(f, copies, makemap,
+                   lambda x: '%s (%s)' % (x['name'], x['source']))
 
 # showfilecopiesswitch() displays file copies only if copy records are
 # provided before calling the templater, usually with a --copies
@@ -288,7 +291,8 @@
     makemap = lambda k: {'name': k, 'source': copies[k]}
     c = [makemap(k) for k in copies]
     f = _showlist('file_copy', c, plural='file_copies', **args)
-    return _hybrid(f, c, lambda x: '%s (%s)' % (x['name'], x['source']))
+    return _hybrid(f, copies, makemap,
+                   lambda x: '%s (%s)' % (x['name'], x['source']))
 
 def showfiledels(**args):
     """:file_dels: List of strings. Files removed by this changeset."""