changeset 4329:798298fda3be

exthelper: simplify the ability to register templates Same mechanism as revsets earlier in this series.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 27 Dec 2018 21:55:22 -0500
parents 392f1a6a0763
children 9d2d0ebc6456
files hgext3rd/evolve/__init__.py hgext3rd/evolve/exthelper.py hgext3rd/evolve/templatekw.py
diffstat 3 files changed, 6 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py	Thu Dec 27 21:26:17 2018 -0500
+++ b/hgext3rd/evolve/__init__.py	Thu Dec 27 21:55:22 2018 -0500
@@ -370,6 +370,7 @@
 cmdtable = eh.cmdtable
 configtable = eh.configtable
 revsetpredicate = eh.revsetpredicate
+templatekeyword = eh.templatekeyword
 
 # Configuration
 eh.configitem('experimental', 'evolutioncommands', [])
--- a/hgext3rd/evolve/exthelper.py	Thu Dec 27 21:26:17 2018 -0500
+++ b/hgext3rd/evolve/exthelper.py	Thu Dec 27 21:55:22 2018 -0500
@@ -15,7 +15,6 @@
     extensions,
     fileset as filesetmod,
     registrar,
-    templatekw as templatekwmod,
 )
 
 class exthelper(object):
@@ -33,7 +32,6 @@
         self._extcallables = []
         self._repocallables = []
         self._filesetsymbols = []
-        self._templatekws = []
         self._commandwrappers = []
         self._extcommandwrappers = []
         self._functionwrappers = []
@@ -52,6 +50,7 @@
         self.configtable = {}
         self.configitem = registrar.configitem(self.configtable)
         self.revsetpredicate = registrar.revsetpredicate()
+        self.templatekeyword = registrar.templatekeyword()
 
     def merge(self, other):
         self._uicallables.extend(other._uicallables)
@@ -60,7 +59,7 @@
         self._repocallables.extend(other._repocallables)
         self.revsetpredicate._table.update(other.revsetpredicate._table)
         self._filesetsymbols.extend(other._filesetsymbols)
-        self._templatekws.extend(other._templatekws)
+        self.templatekeyword._table.update(other.templatekeyword._table)
         self._commandwrappers.extend(other._commandwrappers)
         self._extcommandwrappers.extend(other._extcommandwrappers)
         self._functionwrappers.extend(other._functionwrappers)
@@ -132,14 +131,6 @@
         # TODO: Figure out the calling extension name
         filesetmod.loadpredicate(ui, 'exthelper', filesetpredicate)
 
-        templatekeyword = registrar.templatekeyword()
-        for name, kw, requires in self._templatekws:
-            if requires is not None:
-                templatekeyword(name, requires=requires)(kw)
-            else:
-                templatekeyword(name)(kw)
-        templatekwmod.loadkeyword(ui, 'evolve', templatekeyword)
-
         for ext, command, wrapper, opts in self._extcommandwrappers:
             if ext not in knownexts:
                 try:
@@ -234,23 +225,6 @@
             return symbol
         return dec
 
-    def templatekw(self, keywordname, requires=None):
-        """Decorated function is a template keyword
-
-        The name of the keyword must be given as the decorator argument.
-        The symbol is added during `extsetup`.
-
-        example::
-
-            @eh.templatekw('babar')
-            def kwbabar(ctx):
-                return 'babar'
-        """
-        def dec(keyword):
-            self._templatekws.append((keywordname, keyword, requires))
-            return keyword
-        return dec
-
     def wrapcommand(self, command, extension=None, opts=None):
         """Decorated function is a command wrapper
 
--- a/hgext3rd/evolve/templatekw.py	Thu Dec 27 21:26:17 2018 -0500
+++ b/hgext3rd/evolve/templatekw.py	Thu Dec 27 21:55:22 2018 -0500
@@ -24,14 +24,14 @@
 ### template keywords
 
 if util.safehasattr(templatekw, 'compatlist'):
-    @eh.templatekw('troubles', requires=set(['ctx', 'templ']))
+    @eh.templatekeyword('troubles', requires=set(['ctx', 'templ']))
     def showtroubles(context, mapping):
         ctx = context.resource(mapping, 'ctx')
         return templatekw.compatlist(context, mapping, 'trouble',
                                      ctx.instabilities(), plural='troubles')
 else:
     # older template API in hg < 4.6
-    @eh.templatekw('troubles')
+    @eh.templatekeyword('troubles')
     def showtroubles(**args):
         """List of strings. Evolution troubles affecting the changeset
         (zero or more of "unstable", "divergent" or "bumped")."""
@@ -175,7 +175,7 @@
     return "\n".join(lines)
 
 if not util.safehasattr(templatekw, 'obsfateverb'): # <= hg-4.5
-    @eh.templatekw("obsfatedata")
+    @eh.templatekeyword("obsfatedata")
     def showobsfatedata(repo, ctx, **args):
         # Get the needed obsfate data
         values = obsfatedata(repo, ctx)