[RFC] Hook for branch nicknames?

Neil Martinsen-Burrell nmb at wartburg.edu
Sun Sep 25 00:08:59 UTC 2011


There is a request (http://pad.lv/797578) for bzr-colo to give
branches a more helpful nick than "trunk".  It is possible to do this
by setting explicit nicknames in all of the operations that create new
colocated branches, but it would be nicer to satisfy the request in an
extensible way.  The bug suggests using hooks and I have a prototype
that does that, but I wanted feedback on whether I have the right
approach (never having used hooks much).

Default nicknames originate from BranchConfig._get_nickname where it
returns urlutils.unescape(self.branch.base.split('/')[-2].  This is
the behavior that I would like to override with a hook.  I have added
a HookPoint to Branch.hooks named 'automatic_nick'  (name follows
'automatic_tag' but could easily be 'default_nick') for callables that
take a branch as input and return the nick.  Then, we can get the
current behavior by registering the above by default and calling
Branch.hooks['automatic_nick'] from _get_nickname.

My concern is when bzr-colo or another plugin registers a different
hook for 'automatic_nick', then Branch.hooks['automatic_nick'] is now
a list of two or more possibilities.  Should we always use the first
hook in that list (presumably the most recently registered)?  Is there
a way to use the hook infrastructure for situations where we wish to
override behavior?  In bzr-colo's hook I can thunk back to the default
hook explicitly by name, but that doesn't seem to be right because the
order in which plugins are loaded seems fairly arbitrary.  I know that
we have had similar problems with command overrides, but with such an
extensible infrastructure as ours, I'm not sure how this ought to
work.  Can I get some feedback on the appropriate design for such an
idea?

-Neil



More information about the bazaar mailing list