directaccess: add mechanism to load directaccess after some other extensions
directaccess needs to load after some extensions to avoid interfering with them.
This patch adds a mechanism to specify what extension directaccess needs to load
after.
--- a/hgext/directaccess.py Tue Jun 02 15:24:12 2015 -0700
+++ b/hgext/directaccess.py Thu Jun 04 10:01:02 2015 -0700
@@ -64,6 +64,27 @@
repo = repo.filtered("visible-directaccess-warn")
return orig(ui, repo, *args, **kwargs)
+def uisetup(ui):
+ """ Change ordering of extensions to ensure that directaccess extsetup comes
+ after the one of the extensions in the loadsafter list """
+ loadsafter = ui.configlist('directaccess','loadsafter')
+ order = list(extensions._order)
+ directaccesidx = order.index('directaccess')
+
+ # The min idx for directaccess to load after all the extensions in loadafter
+ minidxdirectaccess = directaccesidx
+
+ for ext in loadsafter:
+ try:
+ minidxdirectaccess = max(minidxdirectaccess, order.index(ext))
+ except ValueError:
+ pass # extension not loaded
+
+ if minidxdirectaccess > directaccesidx:
+ order.insert(minidxdirectaccess + 1, 'directaccess')
+ order.remove('directaccess')
+ extensions._order = order
+
def extsetup(ui):
extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook)
setupdirectaccess()
--- a/tests/test-inhibit.t Tue Jun 02 15:24:12 2015 -0700
+++ b/tests/test-inhibit.t Thu Jun 04 10:01:02 2015 -0700
@@ -687,12 +687,39 @@
nothing changed
[1]
+Directaccess should load after some extensions precised in the conf
+With no extension specified:
+
+ $ cat >$TESTTMP/test_extension.py << EOF
+ > from mercurial import extensions
+ > def uisetup(ui):
+ > print extensions._order
+ > EOF
+ $ cat >> $HGRCPATH << EOF
+ > [extensions]
+ > testextension=$TESTTMP/test_extension.py
+ > EOF
+ $ hg id
+ ['rebase', 'strip', 'evolve', 'directaccess', 'inhibit', 'testextension']
+ 721c3c279519 tip
+
+With test_extension specified:
+ $ cat >> $HGRCPATH << EOF
+ > [directaccess]
+ > loadsafter=testextension
+ > EOF
+ $ hg id
+ ['rebase', 'strip', 'evolve', 'inhibit', 'testextension', 'directaccess']
+ 721c3c279519 tip
+
Inhibit should not work without directaccess
$ cat >> $HGRCPATH <<EOF
> [extensions]
> directaccess=!
+ > testextension=!
> EOF
$ hg up 15
abort: Cannot use inhibit without the direct access extension
[255]
+