[PATCH 1 of 2] templatekw: allow the caller of showlist() to specify the join() separator

Matt Harbison mharbison72 at gmail.com
Tue Jul 7 17:14:52 CDT 2015

# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1436238744 14400
#      Mon Jul 06 23:12:24 2015 -0400
# Node ID 4234e8fdb6e672a065a2727347608ff2a91bfc9c
# Parent  c10f33a78d3f0e92771f750890acd9f53e9ac102
templatekw: allow the caller of showlist() to specify the join() separator

The keyword {latesttag} currently manually joins the list of tags using ':',
which prevents a transparent switch over to a hybrid list.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -40,24 +40,25 @@
             raise AttributeError(name)
         return getattr(self.values, name)
-def showlist(name, values, plural=None, element=None, **args):
+def showlist(name, values, plural=None, element=None, separator=' ', **args):
     if not element:
         element = name
-    f = _showlist(name, values, plural, **args)
+    f = _showlist(name, values, plural, separator, **args)
     return _hybrid(f, values, lambda x: {element: x})
-def _showlist(name, values, plural=None, **args):
+def _showlist(name, values, plural=None, separator=' ', **args):
     '''expand set of values.
     name is name of key in template map.
     values is list of strings or dicts.
     plural is plural of name, if not simply name + 's'.
+    separator is used to join values as a string
     expansion works like this, given name 'foo'.
     if values is empty, expand 'no_foos'.
     if 'foo' not in template map, return values as a string,
-    joined by space.
+    joined by 'separator'.
     expand 'start_foos'.
@@ -77,7 +78,7 @@
     if name not in templ:
         if isinstance(values[0], str):
-            yield ' '.join(values)
+            yield separator.join(values)
             for v in values:
                 yield dict(v, **args)

More information about the Mercurial-devel mailing list