Patchwork [04,of,10] templatekw: switch namespace template keywords to new API

login
register
mail settings
Submitter Yuya Nishihara
Date March 2, 2018, 1:51 a.m.
Message ID <5600b9bc3e406a1523b8.1519955514@mimosa>
Download mbox | patch
Permalink /patch/28652/
State Accepted
Headers show

Comments

Yuya Nishihara - March 2, 2018, 1:51 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519552371 -32400
#      Sun Feb 25 18:52:51 2018 +0900
# Node ID 5600b9bc3e406a1523b81688fded42b090defa0d
# Parent  00b4baafd47b4fb77c7946ccadefb69bc1525e41
templatekw: switch namespace template keywords to new API

Patch

diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
--- a/mercurial/namespaces.py
+++ b/mercurial/namespaces.py
@@ -89,9 +89,9 @@  class namespaces(object):
         # 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):
         """
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -674,22 +674,22 @@  def showobsfate(**args):
 
     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):
@@ -698,10 +698,10 @@  def shownamespaces(**args):
 
     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 {
@@ -931,10 +931,10 @@  def showsubrepos(context, mapping):
 # 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):