[PATCH 4 of 9] templatekw: add default implementation of _hybrid.gen

Yuya Nishihara yuya at tcha.org
Wed Apr 12 15:53:20 UTC 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1491999047 -32400
#      Wed Apr 12 21:10:47 2017 +0900
# Node ID e7257a6a6fd5cc5565fb7e4bfe0b0a8a780c1285
# Parent  a773ef212277598db714833be5c21297021a26ab
templatekw: add default implementation of _hybrid.gen

This is convenient for new template keyword, which doesn't need to support
the legacy list hack (provided by _showlist()), but still wants to have
a string representation.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -32,10 +32,20 @@ class _hybrid(object):
     """
 
     def __init__(self, gen, values, makemap, joinfmt):
-        self.gen = gen
+        if gen is not None:
+            self.gen = gen
         self._values = values
         self._makemap = makemap
         self.joinfmt = joinfmt
+    @util.propertycache
+    def gen(self):
+        return self._defaultgen()
+    def _defaultgen(self):
+        """Generator to stringify this as {join(self, ' ')}"""
+        for i, d in enumerate(self.itermaps()):
+            if i > 0:
+                yield ' '
+            yield self.joinfmt(d)
     def itermaps(self):
         makemap = self._makemap
         for x in self._values:



More information about the Mercurial-devel mailing list