Lazily registering hooks?

Martin Pool mbp at canonical.com
Mon May 31 02:07:03 BST 2010


On 31 May 2010 05:01, John Arbash Meinel <john at arbash-meinel.com> wrote:
> Right, so the plugin would do:
>
> from bzrlib import hooks
>
> hooks.register_me(
>        'bzrlib.branch.Branch.hooks', 'post_branch_tip_changed',
>        'bzrlib.plugins.myplugin.module', 'hook_function',
>        'hook_name')
>
> And the Branch.hooks would do something like:
>  to_run = hooks.get_hooks_for('bzrlib.branch.Branch.hooks')
>
> Something along those lines. Note that typos fail silently here, which
> isn't great. But that is what test suites are for :).

I'd like that.

Note that you could of course implement this on top of the 'hook was
registered' hook, by having register_me remember that hook_function
ought to be registered when post_branch_tip_changed appears.  But I
probably would not; it might be simpler to just keep a central
registry.

The fact that we have a different class for every collection of hooks,
and that they each get saved and restored separately seems a bit
longwinded to me.  I wouldn't be surprised if having just one registry
made things smaller and simpler.

-- 
Martin <http://launchpad.net/~mbp/>



More information about the bazaar mailing list