~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/weave_fmt/branch.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    lockable_files,
24
24
    )
25
25
 
 
26
from bzrlib.decorators import (
 
27
    needs_read_lock,
 
28
    needs_write_lock,
 
29
    only_raises,
 
30
    )
 
31
from bzrlib.lock import LogicalLockResult
26
32
from bzrlib.trace import mutter
27
33
 
28
34
from bzrlib.branch import (
29
35
    BranchFormat,
 
36
    BranchWriteLockResult,
 
37
    )
 
38
from bzrlib.branchfmt.fullhistory import (
30
39
    FullHistoryBzrBranch,
31
40
    )
32
41
 
34
43
class BzrBranch4(FullHistoryBzrBranch):
35
44
    """Branch format 4."""
36
45
 
 
46
    def lock_write(self, token=None):
 
47
        """Lock the branch for write operations.
 
48
 
 
49
        :param token: A token to permit reacquiring a previously held and
 
50
            preserved lock.
 
51
        :return: A BranchWriteLockResult.
 
52
        """
 
53
        if not self.is_locked():
 
54
            self._note_lock('w')
 
55
        # All-in-one needs to always unlock/lock.
 
56
        self.repository._warn_if_deprecated(self)
 
57
        self.repository.lock_write()
 
58
        try:
 
59
            return BranchWriteLockResult(self.unlock,
 
60
                self.control_files.lock_write(token=token))
 
61
        except:
 
62
            self.repository.unlock()
 
63
            raise
 
64
 
 
65
    def lock_read(self):
 
66
        """Lock the branch for read operations.
 
67
 
 
68
        :return: A bzrlib.lock.LogicalLockResult.
 
69
        """
 
70
        if not self.is_locked():
 
71
            self._note_lock('r')
 
72
        # All-in-one needs to always unlock/lock.
 
73
        self.repository._warn_if_deprecated(self)
 
74
        self.repository.lock_read()
 
75
        try:
 
76
            self.control_files.lock_read()
 
77
            return LogicalLockResult(self.unlock)
 
78
        except:
 
79
            self.repository.unlock()
 
80
            raise
 
81
 
 
82
    @only_raises(errors.LockNotHeld, errors.LockBroken)
 
83
    def unlock(self):
 
84
        if self.control_files._lock_count == 2 and self.conf_store is not None:
 
85
            self.conf_store.save_changes()
 
86
        try:
 
87
            self.control_files.unlock()
 
88
        finally:
 
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()
 
94
 
37
95
    def _get_checkout_format(self, lightweight=False):
38
96
        """Return the most suitable metadir for a checkout of this branch.
39
97
        """