Rev 5036: (Jelmer) Add BzrDir.list_branches(). in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Feb 16 00:53:07 GMT 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5036 [merge]
revision-id: pqm at pqm.ubuntu.com-20100216005304-1p8xafkhiizh6ugi
parent: pqm at pqm.ubuntu.com-20100212163206-uvs9ck67uqw2901y
parent: jelmer at samba.org-20100215234919-6oznlpuwu3rzn8ie
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2010-02-16 00:53:04 +0000
message:
  (Jelmer) Add BzrDir.list_branches().
modified:
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/per_bzrdir/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2010-02-10 17:52:08 +0000
+++ b/bzrlib/bzrdir.py	2010-02-16 00:53:04 +0000
@@ -355,6 +355,15 @@
                 for subdir in sorted(subdirs, reverse=True):
                     pending.append(current_transport.clone(subdir))
 
+    def list_branches(self):
+        """Return a sequence of all branches local to this control directory.
+
+        """
+        try:
+            return [self.open_branch()]
+        except errors.NotBranchError:
+            return []
+
     @staticmethod
     def find_branches(transport):
         """Find all branches under a transport.
@@ -372,20 +381,16 @@
             except errors.NoRepositoryPresent:
                 pass
             else:
-                return False, (None, repository)
-            try:
-                branch = bzrdir.open_branch()
-            except errors.NotBranchError:
-                return True, (None, None)
-            else:
-                return True, (branch, None)
-        branches = []
-        for branch, repo in BzrDir.find_bzrdirs(transport, evaluate=evaluate):
+                return False, ([], repository)
+            return True, (bzrdir.list_branches(), None)
+        ret = []
+        for branches, repo in BzrDir.find_bzrdirs(transport,
+                                                  evaluate=evaluate):
             if repo is not None:
-                branches.extend(repo.find_branches())
-            if branch is not None:
-                branches.append(branch)
-        return branches
+                ret.extend(repo.find_branches())
+            if branches is not None:
+                ret.extend(branches)
+        return ret
 
     def destroy_repository(self):
         """Destroy the repository in this BzrDir"""
@@ -3054,11 +3059,7 @@
                 ui.ui_factory.note('starting repository conversion')
                 converter = CopyConverter(self.target_format.repository_format)
                 converter.convert(repo, pb)
-        try:
-            branch = self.bzrdir.open_branch()
-        except errors.NotBranchError:
-            pass
-        else:
+        for branch in self.bzrdir.list_branches():
             # TODO: conversions of Branch and Tree should be done by
             # InterXFormat lookups/some sort of registry.
             # Avoid circular imports

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2010-02-10 18:29:50 +0000
+++ b/bzrlib/repository.py	2010-02-16 00:53:04 +0000
@@ -1484,10 +1484,7 @@
         :param using: If True, list only branches using this repository.
         """
         if using and not self.is_shared():
-            try:
-                return [self.bzrdir.open_branch()]
-            except errors.NotBranchError:
-                return []
+            return self.bzrdir.list_branches()
         class Evaluator(object):
 
             def __init__(self):
@@ -1502,22 +1499,19 @@
                     except errors.NoRepositoryPresent:
                         pass
                     else:
-                        return False, (None, repository)
+                        return False, ([], repository)
                 self.first_call = False
-                try:
-                    value = (bzrdir.open_branch(), None)
-                except errors.NotBranchError:
-                    value = (None, None)
+                value = (bzrdir.list_branches(), None)
                 return True, value
 
-        branches = []
-        for branch, repository in bzrdir.BzrDir.find_bzrdirs(
+        ret = []
+        for branches, repository in bzrdir.BzrDir.find_bzrdirs(
                 self.bzrdir.root_transport, evaluate=Evaluator()):
-            if branch is not None:
-                branches.append(branch)
+            if branches is not None:
+                ret.extend(branches)
             if not using and repository is not None:
-                branches.extend(repository.find_branches())
-        return branches
+                ret.extend(repository.find_branches())
+        return ret
 
     @needs_read_lock
     def search_missing_revision_ids(self, other, revision_id=None, find_ghosts=True):

=== modified file 'bzrlib/tests/per_bzrdir/test_bzrdir.py'
--- a/bzrlib/tests/per_bzrdir/test_bzrdir.py	2010-01-25 17:48:22 +0000
+++ b/bzrlib/tests/per_bzrdir/test_bzrdir.py	2010-02-15 22:58:59 +0000
@@ -21,7 +21,6 @@
 from itertools import izip
 import os
 from stat import S_ISDIR
-import sys
 
 import bzrlib.branch
 from bzrlib import (
@@ -1426,6 +1425,26 @@
         self.failUnless(isinstance(opened_branch, made_branch.__class__))
         self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
 
+    def test_list_branches(self):
+        if not self.bzrdir_format.is_supported():
+            # unsupported formats are not loopback testable
+            # because the default open will not open them and
+            # they may not be initializable.
+            return
+        t = get_transport(self.get_url())
+        made_control = self.bzrdir_format.initialize(t.base)
+        made_repo = made_control.create_repository()
+        made_branch = made_control.create_branch()
+        branches = made_control.list_branches()
+        self.assertEquals(1, len(branches))
+        self.assertEquals(made_branch.base, branches[0].base)
+        try:
+            made_control.destroy_branch()
+        except errors.UnsupportedOperation:
+            pass # Not all bzrdirs support destroying directories
+        else:
+            self.assertEquals([], made_control.list_branches())
+
     def test_create_repository(self):
         # a bzrdir can construct a repository for itself.
         if not self.bzrdir_format.is_supported():




More information about the bazaar-commits mailing list