Patchwork [2,of,8] exthelper: reintroduce the ability to register revsets

login
register
mail settings
Submitter Matt Harbison
Date Dec. 28, 2018, 6:47 a.m.
Message ID <fed98646d0421021268e.1545979636@Envy>
Download mbox | patch
Permalink /patch/37371/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 28, 2018, 6:47 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 fed98646d0421021268ea0b4f91e0d1870bc4bde
# Parent  7598b362dfbf7cb43a14fdd9296f0d1f4fd67627
exthelper: reintroduce 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.

The test needed updating so that extsetup() takes a `ui` argument, as exthelper
isn't trying to be backward compatible with 1.3.1.

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-December/125888.html
Yuya Nishihara - Dec. 30, 2018, 7:54 a.m.
On Fri, 28 Dec 2018 01:47:16 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1545963977 18000
> #      Thu Dec 27 21:26:17 2018 -0500
> # Node ID fed98646d0421021268ea0b4f91e0d1870bc4bde
> # Parent  7598b362dfbf7cb43a14fdd9296f0d1f4fd67627
> exthelper: reintroduce the ability to register revsets

Queued the series, thanks.

>      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.revsetpredicate._table.update(other.revsetpredicate._table)

We might need some merge mechanism in registrar itself, so name duplicates
are reported properly.

Patch

diff --git a/mercurial/exthelper.py b/mercurial/exthelper.py
--- a/mercurial/exthelper.py
+++ b/mercurial/exthelper.py
@@ -40,12 +40,14 @@  class exthelper(object):
         self.command = registrar.command(self.cmdtable)
         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.revsetpredicate._table.update(other.revsetpredicate._table)
         self._commandwrappers.extend(other._commandwrappers)
         self._extcommandwrappers.extend(other._extcommandwrappers)
         self._functionwrappers.extend(other._functionwrappers)
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -151,25 +151,35 @@  Check that extensions are loaded in phas
   $ cat > foo.py <<EOF
   > from __future__ import print_function
   > import os
+  > from mercurial import exthelper
   > name = os.path.basename(__file__).rsplit('.', 1)[0]
   > print("1) %s imported" % name, flush=True)
-  > def uisetup(ui):
+  > eh = exthelper.exthelper()
+  > @eh.uisetup
+  > def _uisetup(ui):
   >     print("2) %s uisetup" % name, flush=True)
-  > def extsetup():
+  > @eh.extsetup
+  > def _extsetup(ui):
   >     print("3) %s extsetup" % name, flush=True)
-  > def uipopulate(ui):
+  > @eh.uipopulate
+  > def _uipopulate(ui):
   >     print("4) %s uipopulate" % name, flush=True)
-  > def reposetup(ui, repo):
+  > @eh.reposetup
+  > def _reposetup(ui, repo):
   >     print("5) %s reposetup" % name, flush=True)
   > 
+  > extsetup = eh.finalextsetup
+  > reposetup = eh.finalreposetup
+  > uipopulate = eh.finaluipopulate
+  > uisetup = eh.finaluisetup
+  > revsetpredicate = eh.revsetpredicate
+  > 
   > bytesname = name.encode('utf-8')
   > # custom predicate to check registration of functions at loading
   > from mercurial import (
-  >     registrar,
   >     smartset,
   > )
-  > revsetpredicate = registrar.revsetpredicate()
-  > @revsetpredicate(bytesname, safe=True) # safe=True for query via hgweb
+  > @eh.revsetpredicate(bytesname, safe=True) # safe=True for query via hgweb
   > def custompredicate(repo, subset, x):
   >     return smartset.baseset([r for r in subset if r in {0}])
   > EOF