Merge lp:~jelmer/bzr/branch4-no-metadir into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 5708
Proposed branch: lp:~jelmer/bzr/branch4-no-metadir
Merge into: lp:bzr
Diff against target: 127 lines (+41/-22)
3 files modified
bzrlib/branch_weave.py (+18/-20)
bzrlib/tests/per_interbranch/__init__.py (+2/-2)
bzrlib/tests/test_branch.py (+21/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/branch4-no-metadir
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+52575@code.launchpad.net

Commit message

Avoid using BzrBranchFormat4 in meta directories.

Description of the change

It was possible to initialize format 4 branches in meta directories, even
though it wasn't possible to open them again later.

The per_interbranch tests relied on this behaviour.

This MP:

 * Fixes BzrBranchFormat4 to check that it's initialized in a BzrDir it supports, and tests it behaves that way
 * Fixes per_interbranch to initialize branch formats in BranchFormat._matchingbzrdir
 * Adds an apparently missing implementation of BzrBranchFormat4.get_format_description()

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Looks straightforward, land ! :)

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/branch_weave.py'
2--- bzrlib/branch_weave.py 2011-03-08 00:59:51 +0000
3+++ bzrlib/branch_weave.py 2011-03-08 20:10:37 +0000
4@@ -49,19 +49,22 @@
5 - a branch-lock lock file [ to be shared with the bzrdir ]
6 """
7
8- def get_format_description(self):
9- """See BranchFormat.get_format_description()."""
10- return "Branch format 4"
11-
12- def _initialize_helper(self, a_bzrdir, utf8_files, name=None):
13- """Initialize a branch in a bzrdir, with specified files
14+ def initialize(self, a_bzrdir, name=None, repository=None):
15+ """Create a branch of this format in a_bzrdir.
16
17 :param a_bzrdir: The bzrdir to initialize the branch in
18- :param utf8_files: The files to create as a list of
19- (filename, content) tuples
20 :param name: Name of colocated branch to create, if any
21- :return: a branch in this format
22+ :param repository: Repository for this branch (unused)
23 """
24+ if repository is not None:
25+ raise NotImplementedError(
26+ "initialize(repository=<not None>) on %r" % (self,))
27+ if not [isinstance(a_bzrdir._format, format) for format in
28+ self._compatible_bzrdirs]:
29+ raise errors.IncompatibleFormat(self, a_bzrdir._format)
30+ utf8_files = [('revision-history', ''),
31+ ('branch-name', ''),
32+ ]
33 mutter('creating branch %r in %s', self, a_bzrdir.user_url)
34 branch_transport = a_bzrdir.get_branch_transport(self, name=name)
35 control_files = lockable_files.LockableFiles(branch_transport,
36@@ -86,25 +89,20 @@
37 self._run_post_branch_init_hooks(a_bzrdir, name, branch)
38 return branch
39
40- def initialize(self, a_bzrdir, name=None, repository=None):
41- """Create a branch of this format in a_bzrdir."""
42- if repository is not None:
43- raise NotImplementedError(
44- "initialize(repository=<not None>) on %r" % (self,))
45- utf8_files = [('revision-history', ''),
46- ('branch-name', ''),
47- ]
48- return self._initialize_helper(a_bzrdir, utf8_files, name=name)
49-
50 def __init__(self):
51 super(BzrBranchFormat4, self).__init__()
52- from bzrlib.bzrdir import BzrDirFormat6
53+ from bzrlib.bzrdir import BzrDirFormat4, BzrDirFormat5, BzrDirFormat6
54 self._matchingbzrdir = BzrDirFormat6()
55+ self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5,
56+ BzrDirFormat6]
57
58 def network_name(self):
59 """The network name for this format is the control dirs disk label."""
60 return self._matchingbzrdir.get_format_string()
61
62+ def get_format_description(self):
63+ return "Branch format 4"
64+
65 def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
66 found_repository=None):
67 """See BranchFormat.open()."""
68
69=== modified file 'bzrlib/tests/per_interbranch/__init__.py'
70--- bzrlib/tests/per_interbranch/__init__.py 2010-06-20 11:18:38 +0000
71+++ bzrlib/tests/per_interbranch/__init__.py 2011-03-08 20:10:37 +0000
72@@ -86,7 +86,7 @@
73 class TestCaseWithInterBranch(TestCaseWithTransport):
74
75 def make_from_branch(self, relpath):
76- repo = self.make_repository(relpath)
77+ repo = self.make_repository(relpath, format=self.branch_format_from._matchingbzrdir)
78 return self.branch_format_from.initialize(repo.bzrdir)
79
80 def make_from_branch_and_memory_tree(self, relpath):
81@@ -109,7 +109,7 @@
82 format=format)
83
84 def make_to_branch(self, relpath):
85- repo = self.make_repository(relpath)
86+ repo = self.make_repository(relpath, format=self.branch_format_to._matchingbzrdir)
87 return self.branch_format_to.initialize(repo.bzrdir)
88
89 def make_to_branch_and_memory_tree(self, relpath):
90
91=== modified file 'bzrlib/tests/test_branch.py'
92--- bzrlib/tests/test_branch.py 2011-02-24 16:13:39 +0000
93+++ bzrlib/tests/test_branch.py 2011-03-08 20:10:37 +0000
94@@ -35,6 +35,10 @@
95 urlutils,
96 )
97
98+from bzrlib.branch_weave import (
99+ BzrBranchFormat4,
100+ )
101+
102
103 class TestDefaultFormat(tests.TestCase):
104
105@@ -67,6 +71,23 @@
106 _mod_branch.format_registry.get_default())
107
108
109+class TestBranchFormat4(tests.TestCaseWithTransport):
110+ """Tests specific to branch format 4"""
111+
112+ def test_no_metadir_support(self):
113+ url = self.get_url()
114+ bdir = bzrdir.BzrDirMetaFormat1().initialize(url)
115+ bdir.create_repository()
116+ self.assertRaises(errors.IncompatibleFormat,
117+ BzrBranchFormat4().initialize, bdir)
118+
119+ def test_supports_bzrdir_6(self):
120+ url = self.get_url()
121+ bdir = bzrdir.BzrDirFormat6().initialize(url)
122+ bdir.create_repository()
123+ BzrBranchFormat4().initialize(bdir)
124+
125+
126 class TestBranchFormat5(tests.TestCaseWithTransport):
127 """Tests specific to branch format 5"""
128