[PATCH] python plugins in BZRPATH using Command structure

John A Meinel john at arbash-meinel.com
Wed May 11 06:10:34 BST 2005


mbp at sourcefrog.net wrote:
> On 10 May 2005, John A Meinel <john at arbash-meinel.com> wrote:
>
>>The attached path adds support for searching the BZRPATH env variable,
>>and finding .py, .pyc, .pyo files therein.
>
>
> My first reaction is that this is a bit too magical, but I suppose
> it's OK.
>

I'm not sure what you consider too magical, just that putting a file in
a directory and the command shows up? (after setting BZRPATH).

We could put them under a separate namespaces, like:
bzr plugin myplugin ...

But as abentley pointed out, doing pre/post commit hooks can be done
with an overload script. It would basically let you customize bzr to do
anything you want by using plugins. python __import__ is basically the
same as dlopen, it just has a very nice introspective api (called the
python language).

If you have any specific critiques, I'm flexible.

>
>>It will load them, and it
>>expects them to have classes of the form "cmd_" the same as in commands.py
>>If it finds them, then it adds that command the same as the ones in
>>globals(). One little tidbit is that it is possible to override a
>>builtin function with a customized one. And due to the grace of python,
>>you can actually call the original one in the middle.
>>
>>This also includes an update to "testbzr". It does 2 things one, any
>>function in that file named "test_" is automatically run with an
>>unmunged name (similar to how cmd_* is done).
>>
>>If you look in the test code, you can see an example of how to override
>>a builtin function and still call the original.
>>
>>It does what Aaron Bentley desired, which is to recurse 1 level of
>>directory, so that you can put revctl'd plugins into your path.
>
>
> Why not just list them directly on your path?
>

I'm not sure what his critique was exactly. Perhaps he was thinking that
you couldn't include more than one directory in your path.

Putting it in wasn't very difficult, but it does clutter it slightly.
It's very easy to remove. Simply take out the if .. isdir() portion, but
leave if .. isfile().

>
>>I didn't overwrite the ExternalCommand portion, so if you have a shell
>>function, it will be executed by that route.
>>
>>John
>>=:->
>>
>>PS> Not having revert is *really* causing me problems, I keep catching
>>small things that should be changed while I work on other things. But I
>>assume bzr has to define a changeset format first, so that you can undo,
>>and then redo. Is there an official arch branch for bzr? I know I saw
>>abentley submitting some of his patches from an arch location.
>
>
> For the moment I've just been using this recipe, which is a lame
> version of tla undo/redo:
>
>   bzr diff foo > deferred.diff
>   patch -R <deferred.diff
>   bzr commit
>   patch < deferred.diff
>
> I agree a revert command that sets aside the modifications would
> be very nice.

Well, with arch, it creates a directory structure, but since bzr is
planning on having a plaintext changeset for emailing around, it seems
like that same format could be used for the undo log.

Also, if you ignore renames, adds, and deletes (things not directly
handled by diff + patch), probably this could be a revert implementation:

i = 1
name = os.path.join(tree_root, '.bzr', 'revert-' + str(i))
while os.path.exists(name):
	i += 1
	name = os.path.join(tree_root, '.bzr', 'revert-' + str(i))
f = open(name, 'wb')
diff = bzrlib.diff([extra args go here])
f.write(diff)
f.close()

p = os.popen('patch -R', 'w')
p.write(diff)
p.close()

But I haven't looked at the guts yet. I know abentley created merge,
which requires some form of in-memory changeset to apply. Worst case you
could just Pickle that.

Why the name "revert". The nice thing about "undo" is that it has an
opposite with "redo". you could say revert/redo I guess, or have some
sort of flag for revert to say put back the things I reverted. But I
can't figure out a nice name for that flag.

John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050511/fb22a83f/attachment.pgp 


More information about the bazaar mailing list