diff mercurial/registrar.py @ 38428:aa98392eb5b0

templatefuncs: declare resource requirements for future use
author Yuya Nishihara <yuya@tcha.org>
date Thu, 14 Jun 2018 21:18:58 +0900
parents dfc51a482031
children 5d9749c598f0
line wrap: on
line diff
--- a/mercurial/registrar.py	Thu Jun 14 21:17:56 2018 +0900
+++ b/mercurial/registrar.py	Thu Jun 14 21:18:58 2018 +0900
@@ -351,7 +351,8 @@
 
         templatefunc = registrar.templatefunc()
 
-        @templatefunc('myfunc(arg1, arg2[, arg3])', argspec='arg1 arg2 arg3')
+        @templatefunc('myfunc(arg1, arg2[, arg3])', argspec='arg1 arg2 arg3',
+                      requires={'ctx'})
         def myfuncfunc(context, mapping, args):
             '''Explanation of this template function ....
             '''
@@ -363,6 +364,9 @@
     a dict of named arguments. Otherwise 'args' is a list of positional
     arguments.
 
+    Optional argument 'requires' should be a collection of resource names
+    which the template function depends on.
+
     'templatefunc' instance in example above can be used to
     decorate multiple functions.
 
@@ -374,8 +378,9 @@
     """
     _getname = _funcregistrarbase._parsefuncdecl
 
-    def _extrasetup(self, name, func, argspec=None):
+    def _extrasetup(self, name, func, argspec=None, requires=()):
         func._argspec = argspec
+        func._requires = requires
 
 class internalmerge(_funcregistrarbase):
     """Decorator to register in-process merge tool