Command lookup hooks
Robert Collins
robertc at robertcollins.net
Tue Feb 10 01:48:26 GMT 2009
So thinking about the performance implications of my command decoration
thing last night, I came up with an overhaul of command discovery/setup.
In short:
Three hooks, in Commands.hooks:
cmd = get_command(cmd_or_None, command_name)
extend_command(cmd)
list_commands()
A registered implementation of these hooks in the Plugin class (as a
static method), which will scan all plugins in the same way builtins is
today, and satisfy list_commands in the same way. The Plugin
implementation would also look for a __no_bzr_command_scan__ or similar
attribute in the plugin, to disable doing this scan.
These hooks would be invoked during running a command, or listing
commands for help.
This has the following characteristics:
- plugins get to decorate built in commands as they do today (via the
get_builtin call).
- plugins that want to can use this api natively and still decorate
entire commands.
- its very lazy: we only create any objects related to a command when
that command is invoked.
- we can add more extension points easily
- its not -quite- backwards compatible - the __no_bzr_command_scan__
attribute has its sense inverted from the behaviour today - however
I'd rather make it easier for plugin authors at the cost of potential
minor glitches in those commands that decorate commands. Plugins that
subclass commands should just work (there would be a discarded
unused command instance), and plugins whose commands are in submodules
wouldn't be affected by a command scan anyway.
The core worker for this in bzrlib would look something like:
def get_command(self, command_name):
"Get a command object for the command called command_name"
# Older interface: get a command object from the registry, may
# have decorated classes already etc.
cmd = _get_builtin(command_name)
for hook in Command.hooks['get_command']:
cmd = hook(cmd, command_name)
if cmd is None:
# No command available
raise NoSuchCommand(command_name)
for hook in Command.hooks['extend_command']:
hook(cmd)
return cmd
(extend_command is the little thing I babbled on about yesterday for
adding an option without having to decorate the entire command, and
discussion on which prompted this idea).
-Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20090210/ccc169ae/attachment.pgp
More information about the bazaar
mailing list