741
741
self._lock_count += 1
743
def _remote_lock_write(self, tokens):
743
def _remote_lock_write(self, token):
745
745
branch_token = repo_token = ''
747
branch_token, repo_token = tokens
748
repo_token = self.repository.lock_write()
749
self.repository.unlock()
748
750
path = self.bzrdir._path_for_remote_call(self._client)
749
751
response = self._client.call('Branch.lock_write', path, branch_token,
754
756
elif response[0] == 'LockContention':
755
757
raise errors.LockContention('(remote lock)')
756
758
elif response[0] == 'TokenMismatch':
757
raise errors.TokenMismatch(tokens, '(remote tokens)')
759
raise errors.TokenMismatch(token, '(remote token)')
758
760
elif response[0] == 'UnlockableTransport':
759
761
raise errors.UnlockableTransport(self.bzrdir.root_transport)
760
762
elif response[0] == 'ReadOnlyError':
763
765
assert False, 'unexpected response code %r' % (response,)
765
def lock_write(self, tokens=None):
767
def lock_write(self, token=None):
766
768
if not self._lock_mode:
767
remote_tokens = self._remote_lock_write(tokens)
769
remote_tokens = self._remote_lock_write(token)
768
770
self._lock_token, self._repo_lock_token = remote_tokens
769
771
assert self._lock_token, 'Remote server did not return a token!'
770
772
# TODO: We really, really, really don't want to call _ensure_real
776
778
# -- Andrew Bennetts, 2007-02-22.
777
779
self._ensure_real()
778
780
if self._real_branch is not None:
779
self._real_branch.lock_write(tokens=remote_tokens)
780
if tokens is not None:
781
self._real_branch.repository.lock_write(
782
token=self._repo_lock_token)
784
self._real_branch.lock_write(token=self._lock_token)
786
self._real_branch.repository.unlock()
787
if token is not None:
781
788
self._leave_lock = True
783
# XXX: this case seems to be unreachable; tokens cannot be None.
790
# XXX: this case seems to be unreachable; token cannot be None.
784
791
self._leave_lock = False
785
792
self._lock_mode = 'w'
786
793
self._lock_count = 1
787
794
elif self._lock_mode == 'r':
788
795
raise errors.ReadOnlyTransaction
790
if tokens is not None:
791
# Tokens were given to lock_write, and we're relocking, so check
792
# that the given tokens actually match the ones we already have.
793
held_tokens = (self._lock_token, self._repo_lock_token)
794
if tokens != held_tokens:
795
raise errors.TokenMismatch(str(tokens), str(held_tokens))
797
if token is not None:
798
# A token was given to lock_write, and we're relocking, so check
799
# that the given token actually matches the one we already have.
800
if token != self._lock_token:
801
raise errors.TokenMismatch(token, self._lock_token)
796
802
self._lock_count += 1
797
return self._lock_token, self._repo_lock_token
803
return self._lock_token
799
805
def _unlock(self, branch_token, repo_token):
800
806
path = self.bzrdir._path_for_remote_call(self._client)