34
34
from bzrlib.branch import BranchReferenceFormat
35
35
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
36
from bzrlib.decorators import needs_read_lock, needs_write_lock
36
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
37
37
from bzrlib.errors import (
39
39
SmartProtocolError,
89
89
class RemoteBzrDir(BzrDir, _RpcHelper):
90
90
"""Control directory on a remote server, accessed via bzr:// or similar."""
92
def __init__(self, transport, format, _client=None):
92
def __init__(self, transport, format, _client=None, _force_probe=False):
93
93
"""Construct a RemoteBzrDir.
95
95
:param _client: Private parameter for testing. Disables probing and the
99
99
# this object holds a delegated bzrdir that uses file-level operations
100
100
# to talk to the other side
101
101
self._real_bzrdir = None
102
self._has_working_tree = None
102
103
# 1-shot cache for the call pattern 'create_branch; open_branch' - see
103
104
# create_branch for details.
104
105
self._next_open_branch_result = None
108
109
self._client = client._SmartClient(medium)
110
111
self._client = _client
117
def _probe_bzrdir(self):
118
medium = self._client._medium
113
119
path = self._path_for_remote_call(self._client)
120
if medium._is_remote_before((2, 1)):
124
self._rpc_open_2_1(path)
126
except errors.UnknownSmartMethod:
127
medium._remember_remote_is_before((2, 1))
130
def _rpc_open_2_1(self, path):
131
response = self._call('BzrDir.open_2.1', path)
132
if response == ('no',):
133
raise errors.NotBranchError(path=self.root_transport.base)
134
elif response[0] == 'yes':
135
if response[1] == 'yes':
136
self._has_working_tree = True
137
elif response[1] == 'no':
138
self._has_working_tree = False
140
raise errors.UnexpectedSmartServerResponse(response)
142
raise errors.UnexpectedSmartServerResponse(response)
144
def _rpc_open(self, path):
114
145
response = self._call('BzrDir.open', path)
115
146
if response not in [('yes',), ('no',)]:
116
147
raise errors.UnexpectedSmartServerResponse(response)
117
148
if response == ('no',):
118
raise errors.NotBranchError(path=transport.base)
149
raise errors.NotBranchError(path=self.root_transport.base)
120
151
def _ensure_real(self):
121
152
"""Ensure that there is a _real_bzrdir set.
123
154
Used before calls to self._real_bzrdir.
125
156
if not self._real_bzrdir:
157
if 'hpssvfs' in debug.debug_flags:
159
warning('VFS BzrDir access triggered\n%s',
160
''.join(traceback.format_stack()))
126
161
self._real_bzrdir = BzrDir.open_from_transport(
127
162
self.root_transport, _server_formats=False)
128
163
self._format._network_name = \
356
391
raise errors.NoRepositoryPresent(self)
393
def has_workingtree(self):
394
if self._has_working_tree is None:
396
self._has_working_tree = self._real_bzrdir.has_workingtree()
397
return self._has_working_tree
358
399
def open_workingtree(self, recommend_upgrade=True):
360
if self._real_bzrdir.has_workingtree():
400
if self.has_workingtree():
361
401
raise errors.NotLocalUrl(self.root_transport)
363
403
raise errors.NoWorkingTree(self.root_transport.base)
561
601
return self._custom_format._fetch_reconcile
563
603
def get_format_description(self):
564
return 'bzr remote repository'
605
return 'Remote: ' + self._custom_format.get_format_description()
566
607
def __eq__(self, other):
567
608
return self.__class__ is other.__class__
583
624
return self._custom_format._serializer
586
class RemoteRepository(_RpcHelper):
627
class RemoteRepository(_RpcHelper, lock._RelockDebugMixin):
587
628
"""Repository accessed over rpc.
589
630
For the moment most operations are performed using local transport-backed
2045
2090
return self._custom_format.supports_set_append_revisions_only()
2048
class RemoteBranch(branch.Branch, _RpcHelper):
2093
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2049
2094
"""Branch stored on a server accessed by HPSS RPC.
2051
2096
At the moment most operations are mapped down to simple file operations.
2308
2354
def lock_write(self, token=None):
2309
2355
if not self._lock_mode:
2356
self._note_lock('w')
2310
2357
# Lock the branch and repo in one remote call.
2311
2358
remote_tokens = self._remote_lock_write(token)
2312
2359
self._lock_token, self._repo_lock_token = remote_tokens