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.
Am 22/11/11 08:16, schrieb Neil Martinsen-Burrell: BzrDir. list_branches can list a BzrDir. create( '/tmp', format= bzrdir. BzrDirMetaForma t1Colo( )) repository( ) ository( 'file:/ //tmp/. bzr/repository/ ') branch( name='trunk' ) file:// /tmp/,branch= trunk) file:// /tmp/,branch= trunk)] BranchReference Format( ).initialize( dir, target_ branch= dir.open_ branch( name='trunk' )) file:// /tmp/,branch= trunk) file:// /tmp/,branch= trunk), BzrBranch7( file:// /tmp/,branch= trunk)] self): list_branches. """ self.open_ branch( )) NotBranchError, errors. NoRepositoryPre sent): [self.open_ branch( name.decode( "utf-8" )) for name in branch_ list()] )
> Public bug reported:
>
> The current implementation of bzrdir.
> 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.
>>>> dir.create_
> CHKInventoryRep
>>>> dir.create_
> BzrBranch7(
>>>> dir.list_branches()
> [BzrBranch7(
>>>> from bzrlib import branch
>>>> branch.
> BzrBranch7(
>>>> dir.list_branches()
> [BzrBranch7(
>
> The offending code in bzrlib/bzrdir.py is
>
> def list_branches(
> """See ControlDir.
> ret = []
> # Default branch
> try:
> ret.append(
> except (errors.
> pass
>
> # colocated branches
> ret.extend(
> self._read_
>
> 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