Rev 6356: (Neil Martinsen-Burrell) Add ControlDir.get_branches. in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Mon Dec 12 12:40:19 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6356 [merge]
revision-id: pqm at pqm.ubuntu.com-20111212124019-h3252w4zq8s89k8c
parent: pqm at pqm.ubuntu.com-20111212080658-180wt6u7vgvhu9sr
parent: jelmer at samba.org-20111212120950-hrjvx7w5pqy4fc9f
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-12-12 12:40:19 +0000
message:
  (Neil Martinsen-Burrell) Add ControlDir.get_branches.
modified:
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/controldir.py           controldir.py-20100802102926-hvtvh0uae5epuibp-1
  bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
  bzrlib/tests/per_bzrdir/test_bzrdir.py test_bzrdir.py-20100829143338-2uachgod1c3liktl-1
  bzrlib/tests/per_controldir/test_controldir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
  bzrlib/tests/per_controldir_colo/test_supported.py test_supported.py-20100411192232-kawv9qu1t42gv89k-3
  bzrlib/tests/per_controldir_colo/test_unsupported.py test_unsupported.py-20100411192232-kawv9qu1t42gv89k-4
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2011-12-11 03:44:06 +0000
+++ b/bzrlib/bzrdir.py	2011-12-12 12:09:50 +0000
@@ -1054,18 +1054,16 @@
                 self.control_files.unlock()
         self.transport.delete_tree(path)
 
-    def list_branches(self):
-        """See ControlDir.list_branches."""
-        ret = []
-        # Default branch
+    def get_branches(self):
+        """See ControlDir.get_branches."""
+        ret = {}
         try:
-            ret.append(self.open_branch())
+            ret[None] = 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()])
+        for name in self._read_branch_list():
+            ret[name] = self.open_branch(name.decode('utf-8'))
 
         return ret
 

=== modified file 'bzrlib/controldir.py'
--- a/bzrlib/controldir.py	2011-12-07 14:49:51 +0000
+++ b/bzrlib/controldir.py	2011-12-12 12:09:50 +0000
@@ -106,10 +106,17 @@
         """Return a sequence of all branches local to this control directory.
 
         """
+        return self.get_branches().values()
+
+    def get_branches(self):
+        """Get all branches in this control directory, as a dictionary.
+        
+        :return: Dictionary mapping branch names to instances.
+        """
         try:
-            return [self.open_branch()]
+           return { None: self.open_branch() }
         except (errors.NotBranchError, errors.NoRepositoryPresent):
-            return []
+           return {}
 
     def is_control_filename(self, filename):
         """True if filename is the name of a path which is reserved for

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2011-11-17 19:50:38 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2011-12-11 04:16:04 +0000
@@ -78,7 +78,7 @@
         self.assertEqual('', out)
         self.assertEqual('Branched 2 revisions.\n', err)
         out, err = self.run_bzr('branches b')
-        self.assertEqual(" orig\n thiswasa\n", out)
+        self.assertEqual(" thiswasa\n orig\n", out)
         self.assertEqual('', err)
         out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
         self.assertEqual('', out)

=== modified file 'bzrlib/tests/per_bzrdir/test_bzrdir.py'
--- a/bzrlib/tests/per_bzrdir/test_bzrdir.py	2011-11-21 18:59:51 +0000
+++ b/bzrlib/tests/per_bzrdir/test_bzrdir.py	2011-12-12 12:09:50 +0000
@@ -21,6 +21,7 @@
 
 import bzrlib.branch
 from bzrlib import (
+    branch,
     bzrdir,
     errors,
     repository,
@@ -683,3 +684,14 @@
         self.assertEquals(
             branch.bzrdir.user_transport.list_dir("."),
             [".bzr"])
+
+    def test_get_branches(self):
+        repo = self.make_repository('branch-1')
+        try:
+            target_branch = repo.bzrdir.create_branch(name='foo')
+        except errors.NoColocatedBranchSupport:
+            raise TestNotApplicable('Format does not support colocation')
+        reference = branch.BranchReferenceFormat().initialize(
+            repo.bzrdir, target_branch=target_branch)
+        self.assertEqual(set([None, 'foo']),
+                         set(repo.bzrdir.get_branches().keys()))

=== modified file 'bzrlib/tests/per_controldir/test_controldir.py'
--- a/bzrlib/tests/per_controldir/test_controldir.py	2011-11-17 10:59:40 +0000
+++ b/bzrlib/tests/per_controldir/test_controldir.py	2011-12-12 12:08:58 +0000
@@ -1192,6 +1192,11 @@
         else:
             self.assertEquals([], made_control.list_branches())
 
+    def test_get_branches(self):
+        repo = self.make_repository('branch-1')
+        target_branch = repo.bzrdir.create_branch()
+        self.assertEqual([None], repo.bzrdir.get_branches().keys())
+
     def test_create_repository(self):
         # a bzrdir can construct a repository for itself.
         if not self.bzrdir_format.is_initializable():

=== modified file 'bzrlib/tests/per_controldir_colo/test_supported.py'
--- a/bzrlib/tests/per_controldir_colo/test_supported.py	2011-11-17 18:39:26 +0000
+++ b/bzrlib/tests/per_controldir_colo/test_supported.py	2011-12-12 12:08:58 +0000
@@ -127,3 +127,10 @@
         made_branch = Branch.open(made_branch.user_url)
         self.assertEquals(u"col\xe9", made_branch.name)
         made_control.destroy_branch(u"col\xe9")
+
+    def test_get_branches(self):
+        repo = self.make_repository('branch-1')
+        target_branch = repo.bzrdir.create_branch(name='foo')
+        self.assertEqual(['foo'], repo.bzrdir.get_branches().keys())
+        self.assertEqual(target_branch.base,
+                         repo.bzrdir.get_branches()['foo'].base)

=== modified file 'bzrlib/tests/per_controldir_colo/test_unsupported.py'
--- a/bzrlib/tests/per_controldir_colo/test_unsupported.py	2011-09-23 12:32:16 +0000
+++ b/bzrlib/tests/per_controldir_colo/test_unsupported.py	2011-12-11 04:07:08 +0000
@@ -68,3 +68,9 @@
         made_control = self.make_bzrdir_with_repo()
         self.assertRaises(errors.NoColocatedBranchSupport,
             made_control.get_branch_reference, "colo")
+
+    def test_get_branches(self):
+        made_control = self.make_bzrdir_with_repo()
+        made_control.create_branch()
+        self.assertEqual(made_control.get_branches().keys(),
+                         [None])

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-12-12 08:06:58 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-12-12 12:09:50 +0000
@@ -57,6 +57,11 @@
 .. Major internal changes, unlikely to be visible to users or plugin 
    developers, but interesting for bzr developers.
 
+* ControlDir now has a get_branches method that returns a dictionary
+  whose keys are the names of the branches and whose values are the
+  branches themselves. The active branch uses the key None.
+  (Neil Martinsen-Burrell)
+
 Testing
 *******
 




More information about the bazaar-commits mailing list