Comment 4 for bug 893470

Am 22/11/11 08:16, schrieb Neil Martinsen-Burrell:
> Public bug reported:
>
> The current implementation of bzrdir.BzrDir.list_branches can list a
> single branch twice if the BzrDir contains a branch reference to a
> branch that it contains. Consider:
>
>>>> import bzrlib
>>>> from bzrlib import bzrdir
>>>> dir = bzrdir.BzrDir.create('/tmp', format=bzrdir.BzrDirMetaFormat1Colo())
>>>> dir.create_repository()
> CHKInventoryRepository('file:///tmp/.bzr/repository/')
>>>> dir.create_branch(name='trunk')
> BzrBranch7(file:///tmp/,branch=trunk)
>>>> dir.list_branches()
> [BzrBranch7(file:///tmp/,branch=trunk)]
>>>> from bzrlib import branch
>>>> branch.BranchReferenceFormat().initialize(dir, target_branch=dir.open_branch(name='trunk'))
> BzrBranch7(file:///tmp/,branch=trunk)
>>>> dir.list_branches()
> [BzrBranch7(file:///tmp/,branch=trunk), BzrBranch7(file:///tmp/,branch=trunk)]
>
> The offending code in bzrlib/bzrdir.py is
>
> def list_branches(self):
> """See ControlDir.list_branches."""
> ret = []
> # Default branch
> try:
> ret.append(self.open_branch())
> except (errors.NotBranchError, errors.NoRepositoryPresent):
> pass
>
> # colocated branches
> ret.extend([self.open_branch(name.decode("utf-8")) for name in
> self._read_branch_list()])
>
> which adds the branch once as the default branch and once from
> _read_branch_list. For a colocated workspace, the default branch will
> always be in the branch list, so list_branches will always return a list
> with a repeat.
The problem isn't really in that code, but in the fact that branches can
be branch references, and those are resolved when the branch is opened.
The default branch doesn't have to be a branch reference, which is why
it's being opened. Likewise, any of the other colocated branches can be
references of any of the other colocated branches.

Cheers,

Jelmer