Patchwork [01,of,10] templatekw: switch showdict template keywords to new API

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

Comments

Yuya Nishihara - March 2, 2018, 1:51 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519543375 -32400
#      Sun Feb 25 16:22:55 2018 +0900
# Node ID 503e54575af502019158b1bcbf877029a6b601fe
# Parent  d40cfe72b79d3f6e548990faf98ba9b6fbe5027c
templatekw: switch showdict template keywords to new API

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -493,17 +493,19 @@  def showfileadds(**args):
     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():
@@ -512,22 +514,23 @@  def showfilecopies(**args):
                 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):