1
# Copyright (C) 2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Weave-era branch implementations."""
19
from __future__ import absolute_import
26
from bzrlib.trace import mutter
28
from bzrlib.branch import (
34
class BzrBranch4(FullHistoryBzrBranch):
35
"""Branch format 4."""
37
def _get_checkout_format(self, lightweight=False):
38
"""Return the most suitable metadir for a checkout of this branch.
40
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
41
from bzrlib.bzrdir import BzrDirMetaFormat1
42
format = BzrDirMetaFormat1()
44
format.set_branch_format(self._format)
45
format.repository_format = self.bzrdir._format.repository_format
47
format.repository_format = RepositoryFormat7()
51
raise errors.UpgradeRequired(self.user_url)
53
def bind(self, other):
54
raise errors.UpgradeRequired(self.user_url)
56
def set_bound_location(self, location):
57
raise NotImplementedError(self.set_bound_location)
59
def get_bound_location(self):
65
def get_master_branch(self, possible_transports=None):
69
class BzrBranchFormat4(BranchFormat):
70
"""Bzr branch format 4.
73
- a revision-history file.
74
- a branch-lock lock file [ to be shared with the bzrdir ]
76
It does not support binding.
79
def initialize(self, a_bzrdir, name=None, repository=None,
80
append_revisions_only=None):
81
"""Create a branch of this format in a_bzrdir.
83
:param a_bzrdir: The bzrdir to initialize the branch in
84
:param name: Name of colocated branch to create, if any
85
:param repository: Repository for this branch (unused)
87
if append_revisions_only:
88
raise errors.UpgradeRequired(a_bzrdir.user_url)
89
if repository is not None:
90
raise NotImplementedError(
91
"initialize(repository=<not None>) on %r" % (self,))
92
if not [isinstance(a_bzrdir._format, format) for format in
93
self._compatible_bzrdirs]:
94
raise errors.IncompatibleFormat(self, a_bzrdir._format)
95
utf8_files = [('revision-history', ''),
98
mutter('creating branch %r in %s', self, a_bzrdir.user_url)
99
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
100
control_files = lockable_files.LockableFiles(branch_transport,
101
'branch-lock', lockable_files.TransportLock)
102
control_files.create_lock()
104
control_files.lock_write()
105
except errors.LockContention:
110
for (filename, content) in utf8_files:
111
branch_transport.put_bytes(
113
mode=a_bzrdir._get_file_mode())
116
control_files.unlock()
117
branch = self.open(a_bzrdir, name, _found=True,
118
found_repository=None)
119
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
123
super(BzrBranchFormat4, self).__init__()
124
from bzrlib.plugins.weave_fmt.bzrdir import (
125
BzrDirFormat4, BzrDirFormat5, BzrDirFormat6,
127
self._matchingbzrdir = BzrDirFormat6()
128
self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5,
131
def network_name(self):
132
"""The network name for this format is the control dirs disk label."""
133
return self._matchingbzrdir.get_format_string()
135
def get_format_description(self):
136
return "Branch format 4"
138
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
139
found_repository=None, possible_transports=None):
140
"""See BranchFormat.open()."""
142
raise errors.NoColocatedBranchSupport(self)
144
# we are being called directly and must probe.
145
raise NotImplementedError
146
if found_repository is None:
147
found_repository = a_bzrdir.open_repository()
148
return BzrBranch4(_format=self,
149
_control_files=a_bzrdir._control_files,
152
_repository=found_repository,
153
possible_transports=possible_transports)
156
return "Bazaar-NG branch format 4"
158
def supports_leaving_lock(self):