Patchwork [4,of,7] acl: make sure the extensions is enabled when the acl-hooks run

login
register
mail settings
Submitter Boris Feld
Date Oct. 16, 2017, 4:53 p.m.
Message ID <637d309714d8f4e9b254.1508172809@FB>
Download mbox | patch
Permalink /patch/25010/
State Accepted
Headers show

Comments

Boris Feld - Oct. 16, 2017, 4:53 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1507936563 -7200
#      Sat Oct 14 01:16:03 2017 +0200
# Node ID 637d309714d8f4e9b25479eef1ad5c6de418a004
# Parent  1d8be35f0dbac0caca48f0feae19a0ca221bc7b3
# EXP-Topic config.register.ready
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 637d309714d8
acl: make sure the extensions is enabled when the acl-hooks run

The acl extension is usually setup through hooks and never directly activated.
This means the config item declared in the extension are not loaded.
We add the necessary logic to make sure the extensions are loaded before the hook
run.

Patch

diff --git a/hgext/acl.py b/hgext/acl.py
--- a/hgext/acl.py
+++ b/hgext/acl.py
@@ -198,6 +198,7 @@ 
 from mercurial.i18n import _
 from mercurial import (
     error,
+    extensions,
     match,
     registrar,
     util,
@@ -307,7 +308,23 @@ 
         return match.match(repo.root, '', pats)
     return util.never
 
+def ensureenabled(ui):
+    """make sure the extension is enabled when used as hook
+
+    When acl is used through hooks, the extension is never formally loaded and
+    enabled. This has some side effect, for example the config declaration is
+    never loaded. This function ensure the extension is enabled when running
+    hooks.
+    """
+    if 'acl' in ui._knownconfig:
+        return
+    ui.setconfig('extensions', 'acl', '', source='internal')
+    extensions.loadall(ui, ['acl'])
+
 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
+
+    ensureenabled(ui)
+
     if hooktype not in ['pretxnchangegroup', 'pretxncommit']:
         raise error.Abort(_('config error - hook type "%s" cannot stop '
                            'incoming changesets nor commits') % hooktype)