917
917
if isinstance(repository, RemoteRepository):
918
918
raise AssertionError()
919
919
self._real_repository = repository
920
# If the _real_repository has _fallback_repositories, clear them out,
921
# because we want it to have the same set as this repository. This is
922
# reasonable to do because the fallbacks we clear here are from a
923
# "real" branch, and we're about to replace them with the equivalents
924
# from a RemoteBranch.
925
self._real_repository._fallback_repositories = []
920
# three code paths happen here:
921
# 1) old servers, RemoteBranch.open() calls _ensure_real before setting
922
# up stacking. In this case self._fallback_repositories is [], and the
923
# real repo is already setup. Preserve the real repo and
924
# RemoteRepository.add_fallback_repository will avoid adding
926
# 2) new servers, RemoteBranch.open() sets up stacking, and when
927
# ensure_real is triggered from a branch, the real repository to
928
# set already has a matching list with separate instances, but
929
# as they are also RemoteRepositories we don't worry about making the
930
# lists be identical.
931
# 3) new servers, RemoteRepository.ensure_real is triggered before
932
# RemoteBranch.ensure real, in this case we get a repo with no fallbacks
933
# and need to populate it.
934
if (self._fallback_repositories and
935
len(self._real_repository._fallback_repositories) !=
936
len(self._fallback_repositories)):
937
if len(self._real_repository._fallback_repositories):
938
raise AssertionError(
939
"cannot cleanly remove existing _fallback_repositories")
926
940
for fb in self._fallback_repositories:
927
941
self._real_repository.add_fallback_repository(fb)
928
942
if self._lock_mode == 'w':
1057
1071
# _real_branch had its get_stacked_on_url method called), then the
1058
1072
# repository to be added may already be in the _real_repositories list.
1059
1073
if self._real_repository is not None:
1060
if repository not in self._real_repository._fallback_repositories:
1074
fallback_locations = [repo.bzrdir.root_transport.base for repo in
1075
self._real_repository._fallback_repositories]
1076
if repository.bzrdir.root_transport.base not in fallback_locations:
1061
1077
self._real_repository.add_fallback_repository(repository)
1063
1079
def add_inventory(self, revid, inv, parents):
2389
2405
return section_obj.get(name, default)
2391
2407
def _get_configobj(self):
2392
path = self._branch.bzrdir._path_for_remote_call(
2393
self._branch._client)
2408
path = self._branch._remote_path()
2394
2409
response = self._branch._client.call_expecting_body(
2395
2410
'Branch.get_config_file', path)
2396
2411
if response[0][0] != 'ok':
2397
2412
raise UnexpectedSmartServerResponse(response)
2398
bytes = response[1].read_body_bytes()
2399
return config.ConfigObj([bytes], encoding='utf-8')
2413
lines = response[1].read_body_bytes().splitlines()
2414
return config.ConfigObj(lines, encoding='utf-8')
2401
2416
def set_option(self, value, name, section=None):
2402
2417
"""Set the value associated with a named option.
2405
2420
:param name: The name of the value to set
2406
2421
:param section: The section the option is in (if any)
2408
return self._vfs_set_option(value, name, section)
2423
medium = self._branch._client._medium
2424
if medium._is_remote_before((1, 14)):
2425
return self._vfs_set_option(value, name, section)
2427
path = self._branch._remote_path()
2428
response = self._branch._client.call('Branch.set_config_option',
2429
path, self._branch._lock_token, self._branch._repo_lock_token,
2430
value.encode('utf8'), name, section or '')
2431
except errors.UnknownSmartMethod:
2432
medium._remember_remote_is_before((1, 14))
2433
return self._vfs_set_option(value, name, section)
2435
raise errors.UnexpectedSmartServerResponse(response)
2410
2437
def _vfs_set_option(self, value, name, section=None):
2411
2438
self._branch._ensure_real()