Plugin Development Help

Jelmer Vernooij jelmer at samba.org
Wed Jul 25 09:40:05 UTC 2012


On Wed, Jul 25, 2012 at 09:31:23AM +0000, Alex Lewis wrote:
> Thanks Jelmer!
> 
> Jelmer Vernooij <jelmer <at> samba.org> writes:
> > That's probably the easiest thing to do. You could also just override
> > the implementation of the entire commands, as bzr-loom is doing for
> > some commands. That works, but may break if other plugins are trying
> > to do the same thing.
> 
> If possible I think I'd like to avoid having to copy the implementation of 
> cmd_commit into my plugin. It just feels a bit brittle when Bazaar is changed, 
> incompatibility with other plugins, etc. I'd like to keep my plugin as simple 
> and compatible as possible.
I'm not sure if there is an easy way around that. If your plugin is
just transforming one option into another, or adding some extra
behaviour before or after the command is run, then you don't need to
copy the implementation.

It seems what you are trying to do requires modification of one of the
local variables of cmd_commit.run, so I don't see any other way at the
moment to avoid copying the body of cmd_commit.run.

Of course, another option would be for the bzr implementation to be
extended to allow properties to be passed in.

> > Adding it to Commit.revprops sounds reasonable to me. I'm a bit unsure
> > though how you would want to do this exactly. If you're overriding
> > cmd_commit anyway to add a new option, wouldn't it make more sense to
> > update the revprops dictionary in cmd_commit.run ?
> Ok this is probably my lack of python knowledge showing here. I've overridden 
> cmd_commit, added my new option to the "takes_options" dictionary, overridden 
> "run" which processes **kw to find the value for my new option, then calls 
> super(cmd_commit, self).run(*args, **kw) to finish off the command. Obviously at 
> this point my task-id value is lost as it isn't passed in any way to the super 
> implementation. 
It shouldn't be passed to the super implementation - it doesn't know
anything about your task-id option. You would instead want to do
something specific in your implementation which uses that option.

> The super implementation of cmd_commit defines the "properties" dictionary 
> within the run() function, which it populates with 'bugs' if present and passes 
> that into tree.commit(...) as the revprops argument. As "properties" is 
> defined/initialised inside cmd_commit.run() I thought I wouldn't be able to add 
> my task-id to that dictionary. Is that correct? If I'm wrong how do I add my 
> task-id to properties/revprops before it gets sent to tree.commit?
No, you can't access that dictionary from your implementation (at
least not without a significant amount of introspection, which is due
to breakage too).

Cheers,

Jelmer



More information about the bazaar mailing list