install_hook once from multiple plugins

Martin Pool mbp at canonical.com
Wed Apr 28 03:44:37 BST 2010


On 27 April 2010 23:39, Alexander Belchenko <bialix at ukr.net> wrote:
> Hi,
>
> I'm pondering on some vague idea when I want to share some functionality
> between 2 (or may be more) plugins. This functionality is based on the usage
> of hooks. So I'm trying to understand what is the right path will be for
> this: extract the required hook into 3rd plugin and make that 3rd plugin
> mandatory for first two, or thinking about implement method in bzr like
> `install_unique_hook` and pass special argument here (some tag) to avoid the
> same hook installed twice.
>
> For example, I've added MRU commit-history list to QBzr and then realized I
> can provide access to this feature for CLI users. So CLI users don't need to
> install QBzr but can use another (lightweight) plugin, named, say,
> commit-history, or mru-history.
>
> On the other hand maybe I should make mru-history dependency for QBzr and
> therefore make MRU functionality optional in QBzr if that (imaginary) plugin
> is not installed? Something similar we do for bzr-search... But I'm not sure
> I want to create mru-history plugin right now.
>
> Or maybe I bother about such things too early?

If you want to see if a hook is already installed I think you could
reasonably either add an option saying it should be unique, or just
look at the hook list to see if it's already there.

That sounds like a useful feature.  I think it would be fine to either
keep it in qbzr and hook it into the command line if qbzr is
installed, or conversely to split it out into a separate plugin if
people want to install it without qbzr.  The first is probably easier
and many people probably have qbzr installed, so perhaps you should
just put it there.  Though people may find it a bit strange if qbzr
has non-gui effects.

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



More information about the bazaar mailing list