[PATCH] Singleton Branches

John A Meinel john at arbash-meinel.com
Wed May 25 20:55:33 BST 2005


John A Meinel wrote:

> Anyway, I'm okay with the BranchLocker/Unlocker setup. I think Aaron
> Bentley's idea of having a wrapper object is okay, but it isn't quite as
> clean.

Well, I went ahead and wrote a Branch() wrapper which handles a
singleton dictionary based on the base path. This ensures that you only
have one Branch() object in existence for a given directory, and thus
only one file lock.

I think the interface could be improved slightly since the is some
redundancy in passing parameters.

The wrapper just overloads "__getattr__" and "__setattr__" so that
functions transparently go to the _locked_branch if they don't exist
locally.

All tests pass, so I think it is worth something.

Because the __del__ is in a weakptr dictionary, and is only referenced
from the wrapper, I think we won't have problems with cyclical references.

I also tested to make sure that flock() works, so it does indeed only
gather one lock.

John
=:->


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: singleton-branch.patch
Url: https://lists.ubuntu.com/archives/bazaar/attachments/20050525/0e08bf66/attachment.diff 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050525/0e08bf66/attachment.pgp 


More information about the bazaar mailing list