Patchwork [4,of,5] templatekw: have showlist() take mapping dict with no **kwargs expansion (API)

login
register
mail settings
Submitter Yuya Nishihara
Date April 14, 2017, 3:31 p.m.
Message ID <eaf7cd4f0194bd7aa186.1492183896@mimosa>
Download mbox | patch
Permalink /patch/20206/
State Accepted
Delegated to: Kevin Bullock
Headers show

Comments

Yuya Nishihara - April 14, 2017, 3:31 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1491396454 -32400
#      Wed Apr 05 21:47:34 2017 +0900
# Node ID eaf7cd4f0194bd7aa1861e06f5078f667b270fb2
# Parent  ab5a1c0708d8a6ddb81b90c8d13e05f29087722f
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)

See the previous commit for why.

splitlines() does not pass a mapping dict, which would probably mean the
legacy template didn't work from the beginning.

Patch

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -339,7 +339,7 @@  def shortdate(text):
 @templatefilter('splitlines')
 def splitlines(text):
     """Any text. Split text into a list of lines."""
-    return templatekw.showlist('line', text.splitlines(), 'lines')
+    return templatekw.showlist('line', text.splitlines(), {}, plural='lines')
 
 @templatefilter('stringescape')
 def stringescape(text):
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -78,7 +78,7 @@  def unwraphybrid(thing):
         return thing
     return thing.gen
 
-def showlist(name, values, plural=None, element=None, separator=' ', **mapping):
+def showlist(name, values, mapping, plural=None, element=None, separator=' '):
     if not element:
         element = name
     f = _showlist(name, values, mapping, plural, separator)
@@ -283,8 +283,8 @@  def showbranches(**args):
     """
     branch = args['ctx'].branch()
     if branch != 'default':
-        return showlist('branch', [branch], plural='branches', **args)
-    return showlist('branch', [], plural='branches', **args)
+        return showlist('branch', [branch], args, plural='branches')
+    return showlist('branch', [], args, plural='branches')
 
 @templatekeyword('bookmarks')
 def showbookmarks(**args):
@@ -303,7 +303,7 @@  def showchildren(**args):
     """List of strings. The children of the changeset."""
     ctx = args['ctx']
     childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
-    return showlist('children', childrevs, element='child', **args)
+    return showlist('children', childrevs, args, element='child')
 
 # Deprecated, but kept alive for help generation a purpose.
 @templatekeyword('currentbookmark')
@@ -373,8 +373,8 @@  def showextras(**args):
 def showfileadds(**args):
     """List of strings. Files added by this changeset."""
     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
-    return showlist('file_add', getfiles(repo, ctx, revcache)[1],
-                    element='file', **args)
+    return showlist('file_add', getfiles(repo, ctx, revcache)[1], args,
+                    element='file')
 
 @templatekeyword('file_copies')
 def showfilecopies(**args):
@@ -420,22 +420,22 @@  def showfilecopiesswitch(**args):
 def showfiledels(**args):
     """List of strings. Files removed by this changeset."""
     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
-    return showlist('file_del', getfiles(repo, ctx, revcache)[2],
-                    element='file', **args)
+    return showlist('file_del', getfiles(repo, ctx, revcache)[2], args,
+                    element='file')
 
 @templatekeyword('file_mods')
 def showfilemods(**args):
     """List of strings. Files modified by this changeset."""
     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
-    return showlist('file_mod', getfiles(repo, ctx, revcache)[0],
-                    element='file', **args)
+    return showlist('file_mod', getfiles(repo, ctx, revcache)[0], args,
+                    element='file')
 
 @templatekeyword('files')
 def showfiles(**args):
     """List of strings. All files modified, added, or removed by this
     changeset.
     """
-    return showlist('file', args['ctx'].files(), **args)
+    return showlist('file', args['ctx'].files(), args)
 
 @templatekeyword('graphnode')
 def showgraphnode(repo, ctx, **args):
@@ -529,7 +529,7 @@  def shownames(namespace, **args):
     repo = ctx.repo()
     ns = repo.names[namespace]
     names = ns.names(repo, ctx.node())
-    return showlist(ns.templatename, names, plural=namespace, **args)
+    return showlist(ns.templatename, names, args, plural=namespace)
 
 @templatekeyword('namespaces')
 def shownamespaces(**args):
@@ -538,7 +538,7 @@  def shownamespaces(**args):
     ctx = args['ctx']
     repo = ctx.repo()
     namespaces = util.sortdict((k, showlist('name', ns.names(repo, ctx.node()),
-                                            **args))
+                                            args))
                                for k, ns in repo.names.iteritems())
     f = _showlist('namespace', list(namespaces), args)
     return _hybrid(f, namespaces,
@@ -634,7 +634,7 @@  def showsubrepos(**args):
     ctx = args['ctx']
     substate = ctx.substate
     if not substate:
-        return showlist('subrepo', [], **args)
+        return showlist('subrepo', [], args)
     psubstate = ctx.parents()[0].substate or {}
     subrepos = []
     for sub in substate:
@@ -643,7 +643,7 @@  def showsubrepos(**args):
     for sub in psubstate:
         if sub not in substate:
             subrepos.append(sub) # removed in ctx
-    return showlist('subrepo', sorted(subrepos), **args)
+    return showlist('subrepo', sorted(subrepos), args)
 
 # don't remove "showtags" definition, even though namespaces will put
 # a helper function for "tags" keyword into "keywords" map automatically,
@@ -670,7 +670,7 @@  def showtroubles(**args):
 
     (EXPERIMENTAL)
     """
-    return showlist('trouble', args['ctx'].troubles(), **args)
+    return showlist('trouble', args['ctx'].troubles(), args)
 
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = keywords.values()
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -595,7 +595,7 @@  def files(context, mapping, args):
     ctx = mapping['ctx']
     m = ctx.match([raw])
     files = list(ctx.matches(m))
-    return templatekw.showlist("file", files, **mapping)
+    return templatekw.showlist("file", files, mapping)
 
 @templatefunc('fill(text[, width[, initialident[, hangindent]]])')
 def fill(context, mapping, args):