Lazily registering hooks?

Jelmer Vernooij jelmer at debian.org
Sun May 30 21:39:47 BST 2010


On Mon, 2010-05-31 at 07:59 +1200, Robert Collins wrote:
> A couple of things - we already have a registry of hooks, so there
> isn't a  big conceptual change there, but I would be sad to see the
> details of hooks centralised - if feels bad.
> 
> Another thing we could do is supply a hook to trigger that calls back
> when some hook point becomes available.
> 
> You wouldn't bother with it for most things: effectively all
> operations need Tree, Branch, Repository, Lock, Command etc. But to
> lazy handle info and rio:
> 
> def hook_when_used(modulename, attrname, hooks):
>     """Called when a hooks object becomes available.
> 
>     :param modulename: The module the hooks are defined in. e.g. bzrlib.smart
>     :param attrname: The attribute within the module. e.g. SmartTCPServer.hooks
>     :param hooks: The hooks object itself
>     """
>     if (modulename, attrname) == ('bzrlib.msgeditor', 'hooks'):
>         hooks.install_named_hook(....)
>     elif ...
> 
> 
> And finally, when using this api, you'd get called immediately for
> already-present hooks, so you wouldn't need to care about what order
> things happen in.
The major disadvantage of that approach though is that that means every
single plugin needs more plumbing to deal with hook registration. 

Cheers,

Jelmer



More information about the bazaar mailing list