changeset 42359:832c59d1196e

templater: drop support for old style keywords (API) These changes originated from several commits over a period of time, so I'm slightly unsure if this is correct. But the tests pass.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 18 May 2019 19:56:06 -0400
parents fa4b13e81f60
children 78530404d00b
files mercurial/hgweb/webutil.py mercurial/registrar.py mercurial/templateutil.py
diffstat 3 files changed, 6 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py	Sat May 18 19:38:47 2019 -0400
+++ b/mercurial/hgweb/webutil.py	Sat May 18 19:56:06 2019 -0400
@@ -409,12 +409,6 @@
 
 whyunstable._requires = {'repo', 'ctx'}
 
-# helper to mark a function as a new-style template keyword; can be removed
-# once old-style function gets unsupported and new-style becomes the default
-def _kwfunc(f):
-    f._requires = ()
-    return f
-
 def commonentry(repo, ctx):
     node = scmutil.binnode(ctx)
     return {
@@ -439,8 +433,8 @@
         'branches': nodebranchdict(repo, ctx),
         'tags': nodetagsdict(repo, node),
         'bookmarks': nodebookmarksdict(repo, node),
-        'parent': _kwfunc(lambda context, mapping: parents(ctx)),
-        'child': _kwfunc(lambda context, mapping: children(ctx)),
+        'parent': lambda context, mapping: parents(ctx),
+        'child': lambda context, mapping: children(ctx),
     }
 
 def changelistentry(web, ctx):
@@ -457,9 +451,9 @@
 
     entry = commonentry(repo, ctx)
     entry.update({
-        'allparents': _kwfunc(lambda context, mapping: parents(ctx)),
-        'parent': _kwfunc(lambda context, mapping: parents(ctx, rev - 1)),
-        'child': _kwfunc(lambda context, mapping: children(ctx, rev + 1)),
+        'allparents': lambda context, mapping: parents(ctx),
+        'parent': lambda context, mapping: parents(ctx, rev - 1),
+        'child': lambda context, mapping: children(ctx, rev + 1),
         'changelogtag': showtags,
         'files': files,
     })
@@ -529,7 +523,7 @@
         changesetbranch=showbranch,
         files=templateutil.mappedgenerator(_listfilesgen,
                                            args=(ctx, web.stripecount)),
-        diffsummary=_kwfunc(lambda context, mapping: diffsummary(diffstatsgen)),
+        diffsummary=lambda context, mapping: diffsummary(diffstatsgen),
         diffstat=diffstats,
         archives=web.archivelist(ctx.hex()),
         **pycompat.strkwargs(commonentry(web.repo, ctx)))
--- a/mercurial/registrar.py	Sat May 18 19:38:47 2019 -0400
+++ b/mercurial/registrar.py	Sat May 18 19:56:06 2019 -0400
@@ -338,13 +338,6 @@
             '''
             pass
 
-        # old API (DEPRECATED)
-        @templatekeyword('mykeyword')
-        def mykeywordfunc(repo, ctx, templ, cache, revcache, **args):
-            '''Explanation of this template keyword ....
-            '''
-            pass
-
     The first string argument is used also in online help.
 
     Optional argument 'requires' should be a collection of resource names
--- a/mercurial/templateutil.py	Sat May 18 19:38:47 2019 -0400
+++ b/mercurial/templateutil.py	Sat May 18 19:56:06 2019 -0400
@@ -874,7 +874,6 @@
 def _recursivesymbolblocker(key):
     def showrecursion(context, mapping):
         raise error.Abort(_("recursive reference '%s' in template") % key)
-    showrecursion._requires = ()  # mark as new-style templatekw
     return showrecursion
 
 def runsymbol(context, mapping, key, default=''):
@@ -888,19 +887,6 @@
             v = context.process(key, safemapping)
         except TemplateNotFound:
             v = default
-    if callable(v) and getattr(v, '_requires', None) is None:
-        # old templatekw: expand all keywords and resources
-        # (TODO: drop support for old-style functions. 'f._requires = ()'
-        #  can be removed.)
-        props = {k: context._resources.lookup(mapping, k)
-                 for k in context._resources.knownkeys()}
-        # pass context to _showcompatlist() through templatekw._showlist()
-        props['templ'] = context
-        props.update(mapping)
-        ui = props.get('ui')
-        if ui:
-            ui.deprecwarn("old-style template keyword '%s'" % key, '4.8')
-        return v(**pycompat.strkwargs(props))
     if callable(v):
         # new templatekw
         try: