templatekw: switch namespace template keywords to new API
authorYuya Nishihara <yuya@tcha.org>
Sun, 25 Feb 2018 18:52:51 +0900
changeset 36593 900e5ee44307
parent 36592 b0054f3c055a
child 36594 59ee648870a7
templatekw: switch namespace template keywords to new API
mercurial/namespaces.py
mercurial/templatekw.py
--- a/mercurial/namespaces.py	Sun Feb 25 18:56:06 2018 +0900
+++ b/mercurial/namespaces.py	Sun Feb 25 18:52:51 2018 +0900
@@ -89,9 +89,9 @@
         # we only generate a template keyword if one does not already exist
         if namespace.name not in templatekw.keywords:
             templatekeyword = registrar.templatekeyword(templatekw.keywords)
-            @templatekeyword(namespace.name)
-            def generatekw(**args):
-                return templatekw.shownames(namespace.name, **args)
+            @templatekeyword(namespace.name, requires={'repo', 'ctx', 'templ'})
+            def generatekw(context, mapping):
+                return templatekw.shownames(context, mapping, namespace.name)
 
     def singlenode(self, repo, name):
         """
--- a/mercurial/templatekw.py	Sun Feb 25 18:56:06 2018 +0900
+++ b/mercurial/templatekw.py	Sun Feb 25 18:52:51 2018 +0900
@@ -676,22 +676,22 @@
 
     return showlist("fate", values, args)
 
-def shownames(namespace, **args):
+def shownames(context, mapping, namespace):
     """helper method to generate a template keyword for a namespace"""
-    args = pycompat.byteskwargs(args)
-    ctx = args['ctx']
-    repo = ctx.repo()
+    repo = context.resource(mapping, 'repo')
+    ctx = context.resource(mapping, 'ctx')
     ns = repo.names[namespace]
     names = ns.names(repo, ctx.node())
-    return showlist(ns.templatename, names, args, plural=namespace)
+    return compatlist(context, mapping, ns.templatename, names,
+                      plural=namespace)
 
-@templatekeyword('namespaces')
-def shownamespaces(**args):
+@templatekeyword('namespaces', requires={'repo', 'ctx', 'templ'})
+def shownamespaces(context, mapping):
     """Dict of lists. Names attached to this changeset per
     namespace."""
-    args = pycompat.byteskwargs(args)
-    ctx = args['ctx']
-    repo = ctx.repo()
+    repo = context.resource(mapping, 'repo')
+    ctx = context.resource(mapping, 'ctx')
+    templ = context.resource(mapping, 'templ')
 
     namespaces = util.sortdict()
     def makensmapfn(ns):
@@ -700,10 +700,10 @@
 
     for k, ns in repo.names.iteritems():
         names = ns.names(repo, ctx.node())
-        f = _showlist('name', names, args['templ'], args)
+        f = _showlist('name', names, templ, mapping)
         namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity)
 
-    f = _showlist('namespace', list(namespaces), args['templ'], args)
+    f = _showlist('namespace', list(namespaces), templ, mapping)
 
     def makemap(ns):
         return {
@@ -933,10 +933,10 @@
 # don't remove "showtags" definition, even though namespaces will put
 # a helper function for "tags" keyword into "keywords" map automatically,
 # because online help text is built without namespaces initialization
-@templatekeyword('tags')
-def showtags(**args):
+@templatekeyword('tags', requires={'repo', 'ctx', 'templ'})
+def showtags(context, mapping):
     """List of strings. Any tags associated with the changeset."""
-    return shownames('tags', **args)
+    return shownames(context, mapping, 'tags')
 
 @templatekeyword('termwidth', requires={'ui'})
 def showtermwidth(context, mapping):