1063
1069
if self._real_repository is not None:
1064
1070
if repository not in self._real_repository._fallback_repositories:
1065
1071
self._real_repository.add_fallback_repository(repository)
1067
# They are also seen by the fallback repository. If it doesn't
1068
# exist yet they'll be added then. This implicitly copies them.
1071
1073
def add_inventory(self, revid, inv, parents):
1072
1074
self._ensure_real()
1271
1273
# We don't need to send ghosts back to the server as a position to
1273
1275
stop_keys.difference_update(self._unstacked_provider.missing_keys)
1276
key_count = len(parents_map)
1277
if (NULL_REVISION in result_parents
1278
and NULL_REVISION in self._unstacked_provider.missing_keys):
1279
# If we pruned NULL_REVISION from the stop_keys because it's also
1280
# in our cache of "missing" keys we need to increment our key count
1281
# by 1, because the reconsitituted SearchResult on the server will
1282
# still consider NULL_REVISION to be an included key.
1274
1284
included_keys = start_set.intersection(result_parents)
1275
1285
start_set.difference_update(included_keys)
1276
recipe = ('manual', start_set, stop_keys, len(parents_map))
1286
recipe = ('manual', start_set, stop_keys, key_count)
1277
1287
body = self._serialise_search_recipe(recipe)
1278
1288
path = self.bzrdir._path_for_remote_call(self._client)
1279
1289
for key in keys:
1936
1946
except (errors.NotStacked, errors.UnstackableBranchFormat,
1937
1947
errors.UnstackableRepositoryFormat), e:
1939
# it's relative to this branch...
1940
fallback_url = urlutils.join(self.base, fallback_url)
1941
transports = [self.bzrdir.root_transport]
1942
stacked_on = branch.Branch.open(fallback_url,
1943
possible_transports=transports)
1944
self.repository.add_fallback_repository(stacked_on.repository)
1949
self._activate_fallback_location(fallback_url)
1951
def _get_config(self):
1952
return RemoteBranchConfig(self)
1946
1954
def _get_real_transport(self):
1947
1955
# if we try vfs access, return the real branch's vfs transport
2289
2297
self._ensure_real()
2290
2298
return self._real_branch._set_parent_location(url)
2292
def set_stacked_on_url(self, stacked_location):
2293
"""Set the URL this branch is stacked against.
2295
:raises UnstackableBranchFormat: If the branch does not support
2297
:raises UnstackableRepositoryFormat: If the repository does not support
2301
return self._real_branch.set_stacked_on_url(stacked_location)
2303
2300
@needs_write_lock
2304
2301
def pull(self, source, overwrite=False, stop_revision=None,
2372
2369
return self._real_branch.set_push_location(location)
2372
class RemoteBranchConfig(object):
2373
"""A Config that reads from a smart branch and writes via smart methods.
2375
It is a low-level object that considers config data to be name/value pairs
2376
that may be associated with a section. Assigning meaning to the these
2377
values is done at higher levels like bzrlib.config.TreeConfig.
2380
def __init__(self, branch):
2381
self._branch = branch
2383
def get_option(self, name, section=None, default=None):
2384
"""Return the value associated with a named option.
2386
:param name: The name of the value
2387
:param section: The section the option is in (if any)
2388
:param default: The value to return if the value is not set
2389
:return: The value or default value
2391
configobj = self._get_configobj()
2393
section_obj = configobj
2396
section_obj = configobj[section]
2399
return section_obj.get(name, default)
2401
def _get_configobj(self):
2402
path = self._branch.bzrdir._path_for_remote_call(
2403
self._branch._client)
2404
response = self._branch._client.call_expecting_body(
2405
'Branch.get_config_file', path)
2406
if response[0][0] != 'ok':
2407
raise UnexpectedSmartServerResponse(response)
2408
bytes = response[1].read_body_bytes()
2409
return config.ConfigObj([bytes], encoding='utf-8')
2411
def set_option(self, value, name, section=None):
2412
"""Set the value associated with a named option.
2414
:param value: The value to set
2415
:param name: The name of the value to set
2416
:param section: The section the option is in (if any)
2418
return self._vfs_set_option(value, name, section)
2420
def _vfs_set_option(self, value, name, section=None):
2421
self._branch._ensure_real()
2422
return self._branch._real_branch._get_config().set_option(
2423
value, name, section)
2375
2426
def _extract_tar(tar, to_dir):
2376
2427
"""Extract all the contents of a tarfile object.