mercurial/templateutil.py
changeset 37325 41a5d815d2c1
parent 37324 c2f74b8f6b7f
child 37326 9cd88dd3bf64
--- a/mercurial/templateutil.py	Sun Mar 18 23:24:50 2018 +0900
+++ b/mercurial/templateutil.py	Sat Mar 17 21:42:27 2018 +0900
@@ -75,19 +75,12 @@
     """
 
     def __init__(self, gen, values, makemap, joinfmt, keytype=None):
-        if gen is not None:
-            self._gen = gen  # generator or function returning generator
+        self._gen = gen  # generator or function returning generator
         self._values = values
         self._makemap = makemap
         self.joinfmt = joinfmt
         self.keytype = keytype  # hint for 'x in y' where type(x) is unresolved
 
-    def _gen(self):
-        """Default generator to stringify this as {join(self, ' ')}"""
-        for i, x in enumerate(self._values):
-            if i > 0:
-                yield ' '
-            yield self.joinfmt(x)
     def itermaps(self, context):
         makemap = self._makemap
         for x in self._values:
@@ -96,6 +89,8 @@
     def show(self, context, mapping):
         # TODO: switch gen to (context, mapping) API?
         gen = self._gen
+        if gen is None:
+            return joinitems((self.joinfmt(x) for x in self._values), ' ')
         if callable(gen):
             return gen()
         return gen
@@ -556,3 +551,13 @@
     if val is None:
         return
     return wraphybridvalue(dictarg, key, val)
+
+def joinitems(itemiter, sep):
+    """Join items with the separator; Returns generator of bytes"""
+    first = True
+    for x in itemiter:
+        if first:
+            first = False
+        else:
+            yield sep
+        yield x