26
from bzrlib.decorators import (
31
from bzrlib.lock import LogicalLockResult
26
32
from bzrlib.trace import mutter
28
34
from bzrlib.branch import (
36
BranchWriteLockResult,
31
38
from bzrlib.branchfmt.fullhistory import (
32
39
FullHistoryBzrBranch,
36
43
class BzrBranch4(FullHistoryBzrBranch):
37
44
"""Branch format 4."""
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()
39
95
def _get_checkout_format(self, lightweight=False):
40
96
"""Return the most suitable metadir for a checkout of this branch.