Patchwork [5,of,7,evolve-ext] exthelper: simplify the ability to register templates

login
register
mail settings
Submitter Matt Harbison
Date Jan. 3, 2019, 5:30 a.m.
Message ID <b7614af59abdce791694.1546493452@Envy>
Download mbox | patch
Permalink /patch/37436/
State Accepted
Headers show

Comments

Matt Harbison - Jan. 3, 2019, 5:30 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1545965722 18000
#      Thu Dec 27 21:55:22 2018 -0500
# Node ID b7614af59abdce79169487c8887ccb404e411ddf
# Parent  7ece13eda58b2ff4641a626188fb3ddeac88db17
exthelper: simplify the ability to register templates

Same mechanism as revsets earlier in this series.

Patch

diff --git a/hgext3rd/evolve/__init__.py b/hgext3rd/evolve/__init__.py
--- a/hgext3rd/evolve/__init__.py
+++ b/hgext3rd/evolve/__init__.py
@@ -370,6 +370,7 @@ 
 cmdtable = eh.cmdtable
 configtable = eh.configtable
 revsetpredicate = eh.revsetpredicate
+templatekeyword = eh.templatekeyword
 
 # Configuration
 eh.configitem('experimental', 'evolutioncommands')
diff --git a/hgext3rd/evolve/exthelper.py b/hgext3rd/evolve/exthelper.py
--- a/hgext3rd/evolve/exthelper.py
+++ b/hgext3rd/evolve/exthelper.py
@@ -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
 
diff --git a/hgext3rd/evolve/templatekw.py b/hgext3rd/evolve/templatekw.py
--- a/hgext3rd/evolve/templatekw.py
+++ b/hgext3rd/evolve/templatekw.py
@@ -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)