changeset 36594:59ee648870a7

templatekw: switch obsfate-related template keywords to new API
author Yuya Nishihara <yuya@tcha.org>
date Sun, 25 Feb 2018 19:05:57 +0900
parents 900e5ee44307
children 2da414105809
files mercurial/hgweb/webutil.py mercurial/templatekw.py
diffstat 2 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py	Sun Feb 25 18:52:51 2018 +0900
+++ b/mercurial/hgweb/webutil.py	Sun Feb 25 19:05:57 2018 +0900
@@ -352,12 +352,16 @@
 def formatlinerange(fromline, toline):
     return '%d:%d' % (fromline + 1, toline)
 
-def succsandmarkers(repo, ctx, **args):
-    for item in templatekw.showsuccsandmarkers(repo, ctx, **args):
+def succsandmarkers(context, mapping):
+    repo = context.resource(mapping, 'repo')
+    for item in templatekw.showsuccsandmarkers(context, mapping):
         item['successors'] = _siblings(repo[successor]
                                        for successor in item['successors'])
         yield item
 
+# teach templater succsandmarkers is switched to (context, mapping) API
+succsandmarkers._requires = {'repo', 'ctx', 'templ'}
+
 def commonentry(repo, ctx):
     node = ctx.node()
     return {
--- a/mercurial/templatekw.py	Sun Feb 25 18:52:51 2018 +0900
+++ b/mercurial/templatekw.py	Sun Feb 25 19:05:57 2018 +0900
@@ -658,23 +658,21 @@
     # rev and node are completely different from changeset's.
     return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': mhex})
 
-@templatekeyword('obsfate')
-def showobsfate(**args):
+@templatekeyword('obsfate', requires={'ui', 'repo', 'ctx', 'templ'})
+def showobsfate(context, mapping):
     # this function returns a list containing pre-formatted obsfate strings.
     #
     # This function will be replaced by templates fragments when we will have
     # the verbosity templatekw available.
-    succsandmarkers = showsuccsandmarkers(**args)
+    succsandmarkers = showsuccsandmarkers(context, mapping)
 
-    args = pycompat.byteskwargs(args)
-    ui = args['ui']
-
+    ui = context.resource(mapping, 'ui')
     values = []
 
     for x in succsandmarkers:
         values.append(obsutil.obsfateprinter(x['successors'], x['markers'], ui))
 
-    return showlist("fate", values, args)
+    return compatlist(context, mapping, "fate", values)
 
 def shownames(context, mapping, namespace):
     """helper method to generate a template keyword for a namespace"""
@@ -796,13 +794,16 @@
     return _hybrid(gen(data), data, lambda x: {'successorset': x},
                    pycompat.identity)
 
-@templatekeyword("succsandmarkers")
-def showsuccsandmarkers(repo, ctx, **args):
+@templatekeyword("succsandmarkers", requires={'repo', 'ctx', 'templ'})
+def showsuccsandmarkers(context, mapping):
     """Returns a list of dict for each final successor of ctx. The dict
     contains successors node id in "successors" keys and the list of
     obs-markers from ctx to the set of successors in "markers".
     (EXPERIMENTAL)
     """
+    repo = context.resource(mapping, 'repo')
+    ctx = context.resource(mapping, 'ctx')
+    templ = context.resource(mapping, 'templ')
 
     values = obsutil.successorsandmarkers(repo, ctx)
 
@@ -833,8 +834,7 @@
 
         data.append({'successors': successors, 'markers': finalmarkers})
 
-    args = pycompat.byteskwargs(args)
-    f = _showlist('succsandmarkers', data, args['templ'], args)
+    f = _showlist('succsandmarkers', data, templ, mapping)
     return _hybrid(f, data, lambda x: x, pycompat.identity)
 
 @templatekeyword('p1rev', requires={'ctx'})