hgext/acl.py
changeset 34829 120c5c155ba4
parent 34779 cfb054a7ecc4
child 36376 dbadf28d4db0
equal deleted inserted replaced
34828:46610c851216 34829:120c5c155ba4
   196 import getpass
   196 import getpass
   197 
   197 
   198 from mercurial.i18n import _
   198 from mercurial.i18n import _
   199 from mercurial import (
   199 from mercurial import (
   200     error,
   200     error,
       
   201     extensions,
   201     match,
   202     match,
   202     registrar,
   203     registrar,
   203     util,
   204     util,
   204 )
   205 )
   205 
   206 
   305     # Path-based ACL
   306     # Path-based ACL
   306     if pats:
   307     if pats:
   307         return match.match(repo.root, '', pats)
   308         return match.match(repo.root, '', pats)
   308     return util.never
   309     return util.never
   309 
   310 
       
   311 def ensureenabled(ui):
       
   312     """make sure the extension is enabled when used as hook
       
   313 
       
   314     When acl is used through hooks, the extension is never formally loaded and
       
   315     enabled. This has some side effect, for example the config declaration is
       
   316     never loaded. This function ensure the extension is enabled when running
       
   317     hooks.
       
   318     """
       
   319     if 'acl' in ui._knownconfig:
       
   320         return
       
   321     ui.setconfig('extensions', 'acl', '', source='internal')
       
   322     extensions.loadall(ui, ['acl'])
       
   323 
   310 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
   324 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
       
   325 
       
   326     ensureenabled(ui)
       
   327 
   311     if hooktype not in ['pretxnchangegroup', 'pretxncommit']:
   328     if hooktype not in ['pretxnchangegroup', 'pretxncommit']:
   312         raise error.Abort(_('config error - hook type "%s" cannot stop '
   329         raise error.Abort(_('config error - hook type "%s" cannot stop '
   313                            'incoming changesets nor commits') % hooktype)
   330                            'incoming changesets nor commits') % hooktype)
   314     if (hooktype == 'pretxnchangegroup' and
   331     if (hooktype == 'pretxnchangegroup' and
   315         source not in ui.configlist('acl', 'sources')):
   332         source not in ui.configlist('acl', 'sources')):