templatekw: switch showdict template keywords to new API
authorYuya Nishihara <yuya@tcha.org>
Sun, 25 Feb 2018 16:22:55 +0900
changeset 36619 0083e373e5f5
parent 36618 3790610c2793
child 36620 121a20e5da56
templatekw: switch showdict template keywords to new API
mercurial/templatekw.py
--- a/mercurial/templatekw.py	Fri Mar 02 15:37:57 2018 -0500
+++ b/mercurial/templatekw.py	Sun Feb 25 16:22:55 2018 +0900
@@ -495,17 +495,19 @@
     args = pycompat.byteskwargs(args)
     return _showfilesbystat(args, 'file_add', 1)
 
-@templatekeyword('file_copies')
-def showfilecopies(**args):
+@templatekeyword('file_copies',
+                 requires={'repo', 'ctx', 'cache', 'revcache', 'templ'})
+def showfilecopies(context, mapping):
     """List of strings. Files copied in this changeset with
     their sources.
     """
-    args = pycompat.byteskwargs(args)
-    cache, ctx = args['cache'], args['ctx']
-    copies = args['revcache'].get('copies')
+    repo = context.resource(mapping, 'repo')
+    ctx = context.resource(mapping, 'ctx')
+    cache = context.resource(mapping, 'cache')
+    copies = context.resource(mapping, 'revcache').get('copies')
     if copies is None:
         if 'getrenamed' not in cache:
-            cache['getrenamed'] = getrenamedfn(args['repo'])
+            cache['getrenamed'] = getrenamedfn(repo)
         copies = []
         getrenamed = cache['getrenamed']
         for fn in ctx.files():
@@ -514,22 +516,23 @@
                 copies.append((fn, rename[0]))
 
     copies = util.sortdict(copies)
-    return showdict('file_copy', copies, args, plural='file_copies',
-                    key='name', value='source', fmt='%s (%s)')
+    return compatdict(context, mapping, 'file_copy', copies,
+                      key='name', value='source', fmt='%s (%s)',
+                      plural='file_copies')
 
 # showfilecopiesswitch() displays file copies only if copy records are
 # provided before calling the templater, usually with a --copies
 # command line switch.
-@templatekeyword('file_copies_switch')
-def showfilecopiesswitch(**args):
+@templatekeyword('file_copies_switch', requires={'revcache', 'templ'})
+def showfilecopiesswitch(context, mapping):
     """List of strings. Like "file_copies" but displayed
     only if the --copied switch is set.
     """
-    args = pycompat.byteskwargs(args)
-    copies = args['revcache'].get('copies') or []
+    copies = context.resource(mapping, 'revcache').get('copies') or []
     copies = util.sortdict(copies)
-    return showdict('file_copy', copies, args, plural='file_copies',
-                    key='name', value='source', fmt='%s (%s)')
+    return compatdict(context, mapping, 'file_copy', copies,
+                      key='name', value='source', fmt='%s (%s)',
+                      plural='file_copies')
 
 @templatekeyword('file_dels')
 def showfiledels(**args):