Rev 5708: (jelmer) Avoid using BzrBranchFormat4 in meta directories. (Jelmer in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Mar 8 22:44:16 UTC 2011


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

------------------------------------------------------------
revno: 5708 [merge]
revision-id: pqm at pqm.ubuntu.com-20110308224411-8ki4micmszepfnna
parent: pqm at pqm.ubuntu.com-20110308174026-cy26cy90bbt74squ
parent: jelmer at samba.org-20110308200741-owayh0up2nk5c2jq
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2011-03-08 22:44:11 +0000
message:
  (jelmer) Avoid using BzrBranchFormat4 in meta directories. (Jelmer
   Vernooij)
modified:
  bzrlib/branch_weave.py         branch_weave.py-20110303112759-greg4a9dt5pent0m-1
  bzrlib/tests/per_interbranch/__init__.py __init__.py-20090225010018-l7w4uvvt73ea2vj9-1
  bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
=== modified file 'bzrlib/branch_weave.py'
--- a/bzrlib/branch_weave.py	2011-03-08 00:59:51 +0000
+++ b/bzrlib/branch_weave.py	2011-03-08 20:07:41 +0000
@@ -49,19 +49,22 @@
      - a branch-lock lock file [ to be shared with the bzrdir ]
     """
 
-    def get_format_description(self):
-        """See BranchFormat.get_format_description()."""
-        return "Branch format 4"
-
-    def _initialize_helper(self, a_bzrdir, utf8_files, name=None):
-        """Initialize a branch in a bzrdir, with specified files
+    def initialize(self, a_bzrdir, name=None, repository=None):
+        """Create a branch of this format in a_bzrdir.
 
         :param a_bzrdir: The bzrdir to initialize the branch in
-        :param utf8_files: The files to create as a list of
-            (filename, content) tuples
         :param name: Name of colocated branch to create, if any
-        :return: a branch in this format
+        :param repository: Repository for this branch (unused)
         """
+        if repository is not None:
+            raise NotImplementedError(
+                "initialize(repository=<not None>) on %r" % (self,))
+        if not [isinstance(a_bzrdir._format, format) for format in
+                self._compatible_bzrdirs]:
+            raise errors.IncompatibleFormat(self, a_bzrdir._format)
+        utf8_files = [('revision-history', ''),
+                      ('branch-name', ''),
+                      ]
         mutter('creating branch %r in %s', self, a_bzrdir.user_url)
         branch_transport = a_bzrdir.get_branch_transport(self, name=name)
         control_files = lockable_files.LockableFiles(branch_transport,
@@ -86,25 +89,20 @@
         self._run_post_branch_init_hooks(a_bzrdir, name, branch)
         return branch
 
-    def initialize(self, a_bzrdir, name=None, repository=None):
-        """Create a branch of this format in a_bzrdir."""
-        if repository is not None:
-            raise NotImplementedError(
-                "initialize(repository=<not None>) on %r" % (self,))
-        utf8_files = [('revision-history', ''),
-                      ('branch-name', ''),
-                      ]
-        return self._initialize_helper(a_bzrdir, utf8_files, name=name)
-
     def __init__(self):
         super(BzrBranchFormat4, self).__init__()
-        from bzrlib.bzrdir import BzrDirFormat6
+        from bzrlib.bzrdir import BzrDirFormat4, BzrDirFormat5, BzrDirFormat6
         self._matchingbzrdir = BzrDirFormat6()
+        self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5,
+            BzrDirFormat6]
 
     def network_name(self):
         """The network name for this format is the control dirs disk label."""
         return self._matchingbzrdir.get_format_string()
 
+    def get_format_description(self):
+        return "Branch format 4"
+
     def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
             found_repository=None):
         """See BranchFormat.open()."""

=== modified file 'bzrlib/tests/per_interbranch/__init__.py'
--- a/bzrlib/tests/per_interbranch/__init__.py	2010-06-20 11:18:38 +0000
+++ b/bzrlib/tests/per_interbranch/__init__.py	2011-03-08 15:55:54 +0000
@@ -86,7 +86,7 @@
 class TestCaseWithInterBranch(TestCaseWithTransport):
 
     def make_from_branch(self, relpath):
-        repo = self.make_repository(relpath)
+        repo = self.make_repository(relpath, format=self.branch_format_from._matchingbzrdir)
         return self.branch_format_from.initialize(repo.bzrdir)
 
     def make_from_branch_and_memory_tree(self, relpath):
@@ -109,7 +109,7 @@
             format=format)
 
     def make_to_branch(self, relpath):
-        repo = self.make_repository(relpath)
+        repo = self.make_repository(relpath, format=self.branch_format_to._matchingbzrdir)
         return self.branch_format_to.initialize(repo.bzrdir)
 
     def make_to_branch_and_memory_tree(self, relpath):

=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py	2011-02-24 16:13:39 +0000
+++ b/bzrlib/tests/test_branch.py	2011-03-08 16:04:48 +0000
@@ -35,6 +35,10 @@
     urlutils,
     )
 
+from bzrlib.branch_weave import (
+    BzrBranchFormat4,
+    )
+
 
 class TestDefaultFormat(tests.TestCase):
 
@@ -67,6 +71,23 @@
                          _mod_branch.format_registry.get_default())
 
 
+class TestBranchFormat4(tests.TestCaseWithTransport):
+    """Tests specific to branch format 4"""
+
+    def test_no_metadir_support(self):
+        url = self.get_url()
+        bdir = bzrdir.BzrDirMetaFormat1().initialize(url)
+        bdir.create_repository()
+        self.assertRaises(errors.IncompatibleFormat,
+            BzrBranchFormat4().initialize, bdir)
+
+    def test_supports_bzrdir_6(self):
+        url = self.get_url()
+        bdir = bzrdir.BzrDirFormat6().initialize(url)
+        bdir.create_repository()
+        BzrBranchFormat4().initialize(bdir)
+
+
 class TestBranchFormat5(tests.TestCaseWithTransport):
     """Tests specific to branch format 5"""
 




More information about the bazaar-commits mailing list