17
17
"""Weave-era branch implementations."""
19
from __future__ import absolute_import
19
21
from bzrlib import (
26
from bzrlib.decorators import (
31
from bzrlib.lock import LogicalLockResult
24
32
from bzrlib.trace import mutter
26
34
from bzrlib.branch import (
36
BranchWriteLockResult,
38
from bzrlib.branchfmt.fullhistory import (
28
39
FullHistoryBzrBranch,
32
43
class BzrBranch4(FullHistoryBzrBranch):
33
44
"""Branch format 4."""
35
def _get_checkout_format(self):
46
def lock_write(self, token=None):
47
"""Lock the branch for write operations.
49
:param token: A token to permit reacquiring a previously held and
51
:return: A BranchWriteLockResult.
53
if not self.is_locked():
55
# All-in-one needs to always unlock/lock.
56
self.repository._warn_if_deprecated(self)
57
self.repository.lock_write()
59
return BranchWriteLockResult(self.unlock,
60
self.control_files.lock_write(token=token))
62
self.repository.unlock()
66
"""Lock the branch for read operations.
68
:return: A bzrlib.lock.LogicalLockResult.
70
if not self.is_locked():
72
# All-in-one needs to always unlock/lock.
73
self.repository._warn_if_deprecated(self)
74
self.repository.lock_read()
76
self.control_files.lock_read()
77
return LogicalLockResult(self.unlock)
79
self.repository.unlock()
82
@only_raises(errors.LockNotHeld, errors.LockBroken)
84
if self.control_files._lock_count == 2 and self.conf_store is not None:
85
self.conf_store.save_changes()
87
self.control_files.unlock()
89
# All-in-one needs to always unlock/lock.
90
self.repository.unlock()
91
if not self.control_files.is_locked():
92
# we just released the lock
93
self._clear_cached_state()
95
def _get_checkout_format(self, lightweight=False):
36
96
"""Return the most suitable metadir for a checkout of this branch.
38
98
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
39
99
from bzrlib.bzrdir import BzrDirMetaFormat1
40
100
format = BzrDirMetaFormat1()
41
format.repository_format = RepositoryFormat7()
102
format.set_branch_format(self._format)
103
format.repository_format = self.bzrdir._format.repository_format
105
format.repository_format = RepositoryFormat7()
70
134
It does not support binding.
73
def initialize(self, a_bzrdir, name=None, repository=None):
137
def initialize(self, a_bzrdir, name=None, repository=None,
138
append_revisions_only=None):
74
139
"""Create a branch of this format in a_bzrdir.
76
141
:param a_bzrdir: The bzrdir to initialize the branch in
77
142
:param name: Name of colocated branch to create, if any
78
143
:param repository: Repository for this branch (unused)
145
if append_revisions_only:
146
raise errors.UpgradeRequired(a_bzrdir.user_url)
80
147
if repository is not None:
81
148
raise NotImplementedError(
82
149
"initialize(repository=<not None>) on %r" % (self,))
127
194
return "Branch format 4"
129
196
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
130
found_repository=None):
197
found_repository=None, possible_transports=None):
131
198
"""See BranchFormat.open()."""
200
name = a_bzrdir._get_selected_branch()
133
202
raise errors.NoColocatedBranchSupport(self)
135
204
# we are being called directly and must probe.
140
209
_control_files=a_bzrdir._control_files,
141
210
a_bzrdir=a_bzrdir,
143
_repository=found_repository)
212
_repository=found_repository,
213
possible_transports=possible_transports)
145
215
def __str__(self):
146
216
return "Bazaar-NG branch format 4"