~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Implement RemoteBranch.lock_write/unlock as smart operations.

Because Branch.lock_write/unlock actually also lock/unlock the repository, I've
slightly changed lock_write's interface to accept and return 'tokens' rather
than 'token'.  i.e. a 2-tuple of (branch token, repo token), or None.

Show diffs side-by-side

added added

removed removed

Lines of Context:
185
185
    def get_physical_lock_status(self):
186
186
        raise NotImplementedError(self.get_physical_lock_status)
187
187
 
 
188
    def leave_lock_in_place(self):
 
189
        """Tell this branch object not to release the physical lock when this
 
190
        object is unlocked.
 
191
        
 
192
        If lock_write doesn't return a token, then this method is not supported.
 
193
        """
 
194
        self.control_files.leave_in_place()
 
195
 
 
196
    def dont_leave_lock_in_place(self):
 
197
        """Tell this branch object to release the physical lock when this
 
198
        object is unlocked, even if it didn't originally acquire it.
 
199
 
 
200
        If lock_write doesn't return a token, then this method is not supported.
 
201
        """
 
202
        self.control_files.dont_leave_in_place()
 
203
 
188
204
    def abspath(self, name):
189
205
        """Return absolute filename for something in the branch
190
206
        
1145
1161
    def is_locked(self):
1146
1162
        return self.control_files.is_locked()
1147
1163
 
1148
 
    def lock_write(self, token=None):
1149
 
        self.repository.lock_write()
 
1164
    def lock_write(self, tokens=None):
 
1165
        if tokens is not None:
 
1166
            branch_token, repo_token = tokens
 
1167
        else:
 
1168
            branch_token = repo_token = None
 
1169
        repo_token = self.repository.lock_write(token=repo_token)
1150
1170
        try:
1151
 
            return self.control_files.lock_write(token=token)
 
1171
            branch_token = self.control_files.lock_write(token=branch_token)
1152
1172
        except:
1153
1173
            self.repository.unlock()
1154
1174
            raise
 
1175
        else:
 
1176
            tokens = (branch_token, repo_token)
 
1177
            assert tokens == (None, None) or None not in tokens, (
 
1178
                'Both branch and repository locks must return tokens, or else '
 
1179
                'neither must return tokens.  Got %r.' % (tokens,))
 
1180
            if tokens == (None, None):
 
1181
                return None
 
1182
            else:
 
1183
                return tokens
1155
1184
 
1156
1185
    def lock_read(self):
1157
1186
        self.repository.lock_read()