[PATCH 2 of 7] templater: pass context to itermaps() for future extension

Yuya Nishihara yuya at tcha.org
Wed Apr 4 10:48:53 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1521383090 -32400
#      Sun Mar 18 23:24:50 2018 +0900
# Node ID 1dba3dd3243a9fd0429c2abc28271b17f1e4c097
# Parent  e4dcb782c79b3d7c286a398bc51646c244e0ce9e
templater: pass context to itermaps() for future extension

Unlike show() and tovalue(), a base mapping isn't passed to itermaps()
since it is the function to generate a partial mapping.

diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -38,7 +38,7 @@ class wrapped(object):
     __metaclass__ = abc.ABCMeta
 
     @abc.abstractmethod
-    def itermaps(self):
+    def itermaps(self, context):
         """Yield each template mapping"""
 
     @abc.abstractmethod
@@ -88,7 +88,7 @@ class hybrid(wrapped):
             if i > 0:
                 yield ' '
             yield self.joinfmt(x)
-    def itermaps(self):
+    def itermaps(self, context):
         makemap = self._makemap
         for x in self._values:
             yield makemap(x)
@@ -139,7 +139,7 @@ class mappable(wrapped):
     def tomap(self):
         return self._makemap(self._key)
 
-    def itermaps(self):
+    def itermaps(self, context):
         yield self.tomap()
 
     def show(self, context, mapping):
@@ -498,7 +498,7 @@ def runmap(context, mapping, data):
     darg, targ = data
     d = evalrawexp(context, mapping, darg)
     if isinstance(d, wrapped):
-        diter = d.itermaps()
+        diter = d.itermaps(context)
     else:
         try:
             diter = iter(d)


More information about the Mercurial-devel mailing list