~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/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:
92
92
            branch.generate_revision_history(unicode_new_last_revision_id)
93
93
        return SmartServerResponse(('ok',))
94
94
 
 
95
 
 
96
class SmartServerBranchRequestLockWrite(SmartServerBranchRequest):
 
97
    
 
98
    def do_with_branch(self, branch, branch_token='', repo_token=''):
 
99
        if branch_token == '':
 
100
            branch_token = None
 
101
        if repo_token == '':
 
102
            repo_token = None
 
103
        tokens = (branch_token, repo_token)
 
104
        if tokens == ('', ''):
 
105
            tokens = None
 
106
        try:
 
107
            branch_token, repo_token = branch.lock_write(tokens=tokens)
 
108
        except errors.LockContention:
 
109
            return SmartServerResponse(('LockContention',))
 
110
        except errors.TokenMismatch:
 
111
            return SmartServerResponse(('TokenMismatch',))
 
112
        branch.repository.leave_lock_in_place()
 
113
        branch.leave_lock_in_place()
 
114
        branch.unlock()
 
115
        return SmartServerResponse(('ok', branch_token, repo_token))
 
116
 
 
117
 
 
118
class SmartServerBranchRequestUnlock(SmartServerBranchRequest):
 
119
 
 
120
    def do_with_branch(self, branch, branch_token, repo_token):
 
121
        tokens = branch_token, repo_token
 
122
        try:
 
123
            tokens = branch.lock_write(tokens=tokens)
 
124
        except errors.TokenMismatch:
 
125
            return SmartServerResponse(('TokenMismatch',))
 
126
        branch.repository.dont_leave_lock_in_place()
 
127
        branch.dont_leave_lock_in_place()
 
128
        branch.unlock()
 
129
        return SmartServerResponse(('ok',))
 
130