[PATCH evolve-ext] directaccess: add mechanism to load directaccess after some other extensions

Laurent Charignon lcharignon at fb.com
Thu Jun 4 18:12:37 UTC 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1433437262 25200
#      Thu Jun 04 10:01:02 2015 -0700
# Node ID d28e6e0bad3dfa0f982508ae155b6a0a9161eb75
# Parent  5a953dbde9901afc56885f5b270a2b54c1efe67d
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.

diff --git a/hgext/directaccess.py b/hgext/directaccess.py
--- a/hgext/directaccess.py
+++ b/hgext/directaccess.py
@@ -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()
diff --git a/tests/test-inhibit.t b/tests/test-inhibit.t
--- a/tests/test-inhibit.t
+++ b/tests/test-inhibit.t
@@ -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]
 
+


More information about the Mercurial-devel mailing list