# HG changeset patch # User Yuya Nishihara # Date 1491999047 -32400 # Node ID 68c910fa9ee2b016052513fca3d783179094e17b # Parent 0f41f1e3c75c07022acc158ce4113aca62656195 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 -r 0f41f1e3c75c -r 68c910fa9ee2 mercurial/templatekw.py --- a/mercurial/templatekw.py Sun Apr 09 11:58:27 2017 +0900 +++ b/mercurial/templatekw.py Wed Apr 12 21:10:47 2017 +0900 @@ -32,10 +32,20 @@ """ 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: