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 ...decorators import (
29
from ...lock import LogicalLockResult
30
from ...trace import mutter
32
from ...branch import (
34
BranchWriteLockResult,
36
from ...bzr.fullhistory import (
41
class BzrBranch4(FullHistoryBzrBranch):
42
"""Branch format 4."""
44
def lock_write(self, token=None):
45
"""Lock the branch for write operations.
47
:param token: A token to permit reacquiring a previously held and
49
:return: A BranchWriteLockResult.
51
if not self.is_locked():
53
# All-in-one needs to always unlock/lock.
54
self.repository._warn_if_deprecated(self)
55
self.repository.lock_write()
57
return BranchWriteLockResult(self.unlock,
58
self.control_files.lock_write(token=token))
60
self.repository.unlock()
64
"""Lock the branch for read operations.
66
:return: A breezy.lock.LogicalLockResult.
68
if not self.is_locked():
70
# All-in-one needs to always unlock/lock.
71
self.repository._warn_if_deprecated(self)
72
self.repository.lock_read()
74
self.control_files.lock_read()
75
return LogicalLockResult(self.unlock)
77
self.repository.unlock()
80
@only_raises(errors.LockNotHeld, errors.LockBroken)
82
if self.control_files._lock_count == 2 and self.conf_store is not None:
83
self.conf_store.save_changes()
85
self.control_files.unlock()
87
# All-in-one needs to always unlock/lock.
88
self.repository.unlock()
89
if not self.control_files.is_locked():
90
# we just released the lock
91
self._clear_cached_state()
93
def _get_checkout_format(self, lightweight=False):
94
"""Return the most suitable metadir for a checkout of this branch.
96
from .repository import RepositoryFormat7
97
from ...bzr.bzrdir import BzrDirMetaFormat1
98
format = BzrDirMetaFormat1()
100
format.set_branch_format(self._format)
101
format.repository_format = self.controldir._format.repository_format
103
format.repository_format = RepositoryFormat7()
107
raise errors.UpgradeRequired(self.user_url)
109
def bind(self, other):
110
raise errors.UpgradeRequired(self.user_url)
112
def set_bound_location(self, location):
113
raise NotImplementedError(self.set_bound_location)
115
def get_bound_location(self):
121
def get_master_branch(self, possible_transports=None):
125
class BzrBranchFormat4(BranchFormat):
126
"""Bzr branch format 4.
129
- a revision-history file.
130
- a branch-lock lock file [ to be shared with the bzrdir ]
132
It does not support binding.
135
def initialize(self, a_controldir, name=None, repository=None,
136
append_revisions_only=None):
137
"""Create a branch of this format in a_controldir.
139
:param a_controldir: The bzrdir to initialize the branch in
140
:param name: Name of colocated branch to create, if any
141
:param repository: Repository for this branch (unused)
143
if append_revisions_only:
144
raise errors.UpgradeRequired(a_controldir.user_url)
145
if repository is not None:
146
raise NotImplementedError(
147
"initialize(repository=<not None>) on %r" % (self,))
148
if not [isinstance(a_controldir._format, format) for format in
149
self._compatible_bzrdirs]:
150
raise errors.IncompatibleFormat(self, a_controldir._format)
151
utf8_files = [('revision-history', b''),
152
('branch-name', b''),
154
mutter('creating branch %r in %s', self, a_controldir.user_url)
155
branch_transport = a_controldir.get_branch_transport(self, name=name)
156
control_files = lockable_files.LockableFiles(branch_transport,
157
'branch-lock', lockable_files.TransportLock)
158
control_files.create_lock()
160
control_files.lock_write()
161
except errors.LockContention:
166
for (filename, content) in utf8_files:
167
branch_transport.put_bytes(
169
mode=a_controldir._get_file_mode())
172
control_files.unlock()
173
branch = self.open(a_controldir, name, _found=True,
174
found_repository=None)
175
self._run_post_branch_init_hooks(a_controldir, name, branch)
179
super(BzrBranchFormat4, self).__init__()
180
from .bzrdir import (
181
BzrDirFormat4, BzrDirFormat5, BzrDirFormat6,
183
self._matchingcontroldir = BzrDirFormat6()
184
self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5,
187
def network_name(self):
188
"""The network name for this format is the control dirs disk label."""
189
return self._matchingcontroldir.get_format_string()
191
def get_format_description(self):
192
return "Branch format 4"
194
def open(self, a_controldir, name=None, _found=False, ignore_fallbacks=False,
195
found_repository=None, possible_transports=None):
196
"""See BranchFormat.open()."""
198
name = a_controldir._get_selected_branch()
200
raise errors.NoColocatedBranchSupport(self)
202
# we are being called directly and must probe.
203
raise NotImplementedError
204
if found_repository is None:
205
found_repository = a_controldir.open_repository()
206
return BzrBranch4(_format=self,
207
_control_files=a_controldir._control_files,
208
a_controldir=a_controldir,
210
_repository=found_repository,
211
possible_transports=possible_transports)
214
return "Bazaar-NG branch format 4"
216
def supports_leaving_lock(self):
219
supports_reference_locations = False