Patchwork [9,of,9] templatekw: add compatlist() as a replacement for showlist()

mail settings
Submitter Yuya Nishihara
Date Feb. 27, 2018, 2:58 p.m.
Message ID <1a1f7b96d833af5a29d6.1519743482@mimosa>
Download mbox | patch
Permalink /patch/28475/
State New
Headers show


Yuya Nishihara - Feb. 27, 2018, 2:58 p.m.
# HG changeset patch
# User Yuya Nishihara <>
# Date 1519542877 -32400
#      Sun Feb 25 16:14:37 2018 +0900
# Node ID 1a1f7b96d833af5a29d6d75580d083511ff388f6
# Parent  e6b41f06c7bbcbc745814ec066c7f660d63d200f
templatekw: add compatlist() as a replacement for showlist()

Just like compatdict(), this is mostly a copy of showlist(). showchildren()
is ported to the new API as an example.


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -148,6 +148,17 @@  def compatdict(context, mapping, name, d
     f = _showlist(name, c, t, mapping, plural, separator)
     return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
+def compatlist(context, mapping, name, data, element=None, fmt='%s',
+               plural=None, separator=' '):
+    """Wrap data like hybridlist(), but also supports old-style list template
+    This exists for backward compatibility with the old-style template. Use
+    hybridlist() for new template keywords.
+    """
+    t = context.resource(mapping, 'templ')
+    f = _showlist(name, data, t, mapping, plural, separator)
+    return hybridlist(data, name=element or name, fmt=fmt, gen=f)
 def showdict(name, data, mapping, plural=None, key='key', value='value',
              fmt='%s=%s', separator=' '):
     c = [{key: k, value: v} for k, v in data.iteritems()]
@@ -397,13 +408,12 @@  def showbookmarks(**args):
     f = _showlist('bookmark', bookmarks, args['templ'], args)
     return _hybrid(f, bookmarks, makemap, pycompat.identity)
-def showchildren(**args):
+@templatekeyword('children', requires={'ctx', 'templ'})
+def showchildren(context, mapping):
     """List of strings. The children of the changeset."""
-    args = pycompat.byteskwargs(args)
-    ctx = args['ctx']
+    ctx = context.resource(mapping, 'ctx')
     childrevs = ['%d:%s' % (cctx.rev(), cctx) for cctx in ctx.children()]
-    return showlist('children', childrevs, args, element='child')
+    return compatlist(context, mapping, 'children', childrevs, element='child')
 # Deprecated, but kept alive for help generation a purpose.
 @templatekeyword('currentbookmark', requires={'repo', 'ctx'})