diff hgext/directaccess.py @ 1360:5c13945b32fc

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.
author Laurent Charignon <lcharignon@fb.com>
date Thu, 04 Jun 2015 10:01:02 -0700
parents b00c2fe51ac8
children 2eaa2943f9f3
line wrap: on
line diff
--- 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()