Help with RemoteBzrDir.open_branch()

Wouter van Heyst larstiq at larstiq.dyndns.org
Tue Apr 26 20:21:43 UTC 2011


On Mon, Apr 25, 2011 at 08:41:13 +0300, Alexander Belchenko wrote:
> Neil Martinsen-Burrell пишет:
> > I need some help with the Bazaar API.  I have a lightweight checkout
> > on a remote machine (part of a colocated workspace) and I would like
> > to get the branch object that it refers to.  My first try at this
> > (which apparently has never worked: http://pad.lv/768784) was
> > essentially
> > 
> > REMOTE = 'remote.example.com'
> > from bzrlib import bzrdir
> > a_bzrdir, relpath =
> > bzrdir.BzrDir.open_containing('bzr+ssh://%s/Users/nmb/tmp/blech' %
> > REMOTE)
> > branch = a_bzrdir.open_branch()
> > 
> > which fails with

...

> > bzrlib.errors.NotBranchError: Not a branch:
> > "/Users/nmb/tmp/blech/.bzr/branches/trunk/".
> 
> > Any ideas on why open_branch() is telling me that something is not a
> > branch, even though it clearly is?  The remote host runs bzr.dev r5809
> > and the same on the client.  I think I am making a simple mistake
> > here, but I can't figure out what it is.
> 
> absolute paths vs relative paths problem?
> 
> I think this is because light checkouts use absolute paths to point to
> the real branch, and for colo workspace this is always local path. So,
> IUC, bzr sees local path pointer to the branch and tries to open it on
> your local machine, not on remote host.

I think Alexander is spot on here. At first I tried Neil's code snippet
with a lightweight checkout of ~/src/bzr/bzr.dev on the remote host.  

That opened fine, but on my local host the exact same path is populated
by a branch of bzr.dev too.

Next, using a branch that doesn't exist locally does indeed give the
NotBranchError.  Further changing the .bzr/branch/location of the remote
checkout to refer to the branch via bzr+ssh://host/, and that does work.


RemoteBzrDir.open_branch() calls:
    
        response = self._get_branch_reference()   
        if response[0] == 'ref':       
            # a branch reference, use the existing BranchReference logic.
            format = BranchReferenceFormat()
            return format.open(self, _found=True, location=response[1],
                ignore_fallbacks=ignore_fallbacks)


and doesn't take into account that response[1] might very well refer to
something unavailable locally.

The next step is BranchReferenceFormat.open(), which does:

        if location is None:
            location = self.get_reference(a_bzrdir)
        real_bzrdir = bzrdir.BzrDir.open(
            location, possible_transports=possible_transports)
        result = real_bzrdir.open_branch(ignore_fallbacks=ignore_fallbacks)


Where location is 'file:///tmp/remote_branch' and we proceed to open a
"real" bzrdir which gets us nowhere.


Wouter van Heyst



More information about the bazaar mailing list