[RFC] strawman explict object-tracking API

Robert Collins robertc at robertcollins.net
Tue Apr 17 03:21:55 BST 2007


So we have a connection cache in sftp which is undesirable because of
its lack of a guarantee that we won't prompt users for credentials
multiple times.

We have a related issue with repositories: we oftimes want to share a
repository between two branches - e.g. when doing 'update' in a branch,
where the master is in the same shared repo, or 'pull' likewise. Theres
absolutely no need for us to have two Repository objects, nor to pay the
performance cost of opening the Repository twice etc.

We could put a list of registered objects into each domain - e.g. have
'bzrlib.transport._open_transports', but I think this is pure ugly: Its
not discoverable to users of the api, its not good for threaded apps
like servers, it makes testing complex.

Instead, I propose that we create a OpenFoo series of classes that track
open objects for when we are using multiple objects.

e.g. get_transport becomes
get_transport(url, open_transports=None):
  if open_transports and is_absolute(url):
    # give each open transport the chance to own 'url' if it can.
    for transport in open_transports:
        try:
            return transport.clone(url)
        except InvalidURLJoin:
            pass
  # existing get_transport code

and similar for:
Branch.open
Repository.open
WorkingTree.open
BzrDir.open*

Finally apis like 'Branch.update' which will open another branch
*sometimes* will also accept such an object. Possibly we should allow
Branch objects to carry a referene to OpenBranches for the users state,
which would reduce the number of apis that need changing to benefit,
without making it magic and interfering with test isolation, servers,
etc.

I think we can do a reasonable job of this api using just dictionaries,
but because there will likely be common code we want to factor out we
should use a userdict from the get-go.

Thoughts?

-Rob
-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20070417/3cccced5/attachment.pgp 


More information about the bazaar mailing list