~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(jameinel) Properly save ``branch.conf`` changes when unlocking a
 BzrBranch4. (Vincent Ladeuil)

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