~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/branch.py

  • Committer: Andrew Bennetts
  • Date: 2007-04-12 07:08:33 UTC
  • mto: (2018.18.11 hpss-faster-copy)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: andrew.bennetts@canonical.com-20070412070833-5fio6r0fkgnf10u1
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
        processed.  The physical lock state won't be changed.
53
53
        """
54
54
        # XXX: write a test for LockContention
55
 
        branch.lock_write(tokens=(branch_token, repo_token))
 
55
        branch.repository.lock_write(token=repo_token)
56
56
        try:
57
 
            return self.do_with_locked_branch(branch, *args)
 
57
            branch.lock_write(token=branch_token)
 
58
            try:
 
59
                return self.do_with_locked_branch(branch, *args)
 
60
            finally:
 
61
                branch.unlock()
58
62
        finally:
59
 
            branch.unlock()
 
63
            branch.repository.unlock()
60
64
 
61
65
 
62
66
class SmartServerBranchGetConfigFile(SmartServerBranchRequest):
118
122
            branch_token = None
119
123
        if repo_token == '':
120
124
            repo_token = None
121
 
        tokens = (branch_token, repo_token)
122
 
        if tokens == ('', ''):
123
 
            tokens = None
124
125
        try:
125
 
            branch_token, repo_token = branch.lock_write(tokens=tokens)
 
126
            repo_token = branch.repository.lock_write(token=repo_token)
 
127
            try:
 
128
                branch_token = branch.lock_write(token=branch_token)
 
129
            finally:
 
130
                branch.repository.unlock()
126
131
        except errors.LockContention:
127
132
            return SmartServerResponse(('LockContention',))
128
133
        except errors.TokenMismatch:
138
143
class SmartServerBranchRequestUnlock(SmartServerBranchRequest):
139
144
 
140
145
    def do_with_branch(self, branch, branch_token, repo_token):
141
 
        tokens = branch_token, repo_token
142
146
        try:
143
 
            tokens = branch.lock_write(tokens=tokens)
 
147
            branch.repository.lock_write(token=repo_token)
 
148
            try:
 
149
                branch.lock_write(token=branch_token)
 
150
            finally:
 
151
                branch.repository.unlock()
144
152
        except errors.TokenMismatch:
145
153
            return SmartServerResponse(('TokenMismatch',))
146
154
        branch.repository.dont_leave_lock_in_place()