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

login
register
mail settings
Submitter Matt Harbison
Date Jan. 3, 2019, 5:30 a.m.
Message ID <7ece13eda58b2ff4641a.1546493451@Envy>
Download mbox | patch
Permalink /patch/37435/
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 1545963977 18000
#      Thu Dec 27 21:26:17 2018 -0500
# Node ID 7ece13eda58b2ff4641a626188fb3ddeac88db17
# Parent  f1f44dddfd78833595529ebce0c347ad467b6673
exthelper: simplify the ability to register revsets

I think this is what Yuya and Boris agreed on.[1]  This happens *after* the
extsetup phase now (and after the _aftercallback notifications).  But this is
trivial, mergeable between exthelper instances, and doesn't need to have the
extension name supplied when registering.

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-December/125888.html

Patch

diff --git a/hgext3rd/evolve/__init__.py b/hgext3rd/evolve/__init__.py
--- a/hgext3rd/evolve/__init__.py
+++ b/hgext3rd/evolve/__init__.py
@@ -369,6 +369,7 @@ 
 reposetup = eh.finalreposetup
 cmdtable = eh.cmdtable
 configtable = eh.configtable
+revsetpredicate = eh.revsetpredicate
 
 # Configuration
 eh.configitem('experimental', 'evolutioncommands')
@@ -516,7 +517,7 @@ 
 
 ### Troubled revset symbol
 
-@eh.revset('troubled()')
+@eh.revsetpredicate('troubled()')
 def revsettroubled(repo, subset, x):
     """Changesets with troubles.
     """
@@ -624,7 +625,7 @@ 
 
 
 ### XXX I'm not sure this revset is useful
-@eh.revset('suspended()')
+@eh.revsetpredicate('suspended()')
 def revsetsuspended(repo, subset, x):
     """Obsolete changesets with non-obsolete descendants.
     """
@@ -634,7 +635,7 @@ 
     return subset & suspended
 
 
-@eh.revset('precursors(set)')
+@eh.revsetpredicate('precursors(set)')
 def revsetprecursors(repo, subset, x):
     """Immediate precursors of changesets in set.
     """
@@ -644,7 +645,7 @@ 
     return subset & s
 
 
-@eh.revset('allprecursors(set)')
+@eh.revsetpredicate('allprecursors(set)')
 def revsetallprecursors(repo, subset, x):
     """Transitive precursors of changesets in set.
     """
@@ -654,7 +655,7 @@ 
     return subset & s
 
 
-@eh.revset('successors(set)')
+@eh.revsetpredicate('successors(set)')
 def revsetsuccessors(repo, subset, x):
     """Immediate successors of changesets in set.
     """
@@ -663,7 +664,7 @@ 
     s.sort()
     return subset & s
 
-@eh.revset('allsuccessors(set)')
+@eh.revsetpredicate('allsuccessors(set)')
 def revsetallsuccessors(repo, subset, x):
     """Transitive successors of changesets in set.
     """
diff --git a/hgext3rd/evolve/compat.py b/hgext3rd/evolve/compat.py
--- a/hgext3rd/evolve/compat.py
+++ b/hgext3rd/evolve/compat.py
@@ -77,17 +77,17 @@ 
     context.basectx.isunstable = context.basectx.troubled
 
 if not util.safehasattr(revset, 'orphan'):
-    @eh.revset('orphan')
+    @eh.revsetpredicate('orphan')
     def oprhanrevset(*args, **kwargs):
         return revset.unstable(*args, **kwargs)
 
 if not util.safehasattr(revset, 'contentdivergent'):
-    @eh.revset('contentdivergent')
+    @eh.revsetpredicate('contentdivergent')
     def contentdivergentrevset(*args, **kwargs):
         return revset.divergent(*args, **kwargs)
 
 if not util.safehasattr(revset, 'phasedivergent'):
-    @eh.revset('phasedivergent')
+    @eh.revsetpredicate('phasedivergent')
     def phasedivergentrevset(*args, **kwargs):
         return revset.bumped(*args, **kwargs)
 
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,
-    revset as revsetmod,
     templatekw as templatekwmod,
 )
 
@@ -33,7 +32,6 @@ 
         self._uicallables = []
         self._extcallables = []
         self._repocallables = []
-        self._revsetsymbols = []
         self._filesetsymbols = []
         self._templatekws = []
         self._commandwrappers = []
@@ -53,13 +51,14 @@ 
 
         self.configtable = {}
         self.configitem = registrar.configitem(self.configtable)
+        self.revsetpredicate = registrar.revsetpredicate()
 
     def merge(self, other):
         self._uicallables.extend(other._uicallables)
         self._uipopulatecallables.extend(other._uipopulatecallables)
         self._extcallables.extend(other._extcallables)
         self._repocallables.extend(other._repocallables)
-        self._revsetsymbols.extend(other._revsetsymbols)
+        self.revsetpredicate._table.update(other.revsetpredicate._table)
         self._filesetsymbols.extend(other._filesetsymbols)
         self._templatekws.extend(other._templatekws)
         self._commandwrappers.extend(other._commandwrappers)
@@ -124,15 +123,9 @@ 
         - Changes depending on the status of other extensions. (if
           extensions.find('mq'))
         - Add a global option to all commands
-        - Register revset functions
         """
         knownexts = {}
 
-        revsetpredicate = registrar.revsetpredicate()
-        for name, symbol in self._revsetsymbols:
-            revsetpredicate(name)(symbol)
-        revsetmod.loadpredicate(ui, 'evolve', revsetpredicate)
-
         filesetpredicate = registrar.filesetpredicate()
         for name, symbol in self._filesetsymbols:
             filesetpredicate(name)(symbol)
@@ -224,24 +217,6 @@ 
         self._repocallables.append(call)
         return call
 
-    def revset(self, symbolname):
-        """Decorated function is a revset symbol
-
-        The name of the symbol must be given as the decorator argument.
-        The symbol is added during `extsetup`.
-
-        example::
-
-            @eh.revset('hidden')
-            def revsetbabar(repo, subset, x):
-                args = revset.getargs(x, 0, 0, 'babar accept no argument')
-                return [r for r in subset if 'babar' in repo[r].description()]
-        """
-        def dec(symbol):
-            self._revsetsymbols.append((symbolname, symbol))
-            return symbol
-        return dec
-
     def fileset(self, symbolname):
         """Decorated function is a fileset symbol