1053
1059
if self._real_repository is not None:
1054
1060
if repository not in self._real_repository._fallback_repositories:
1055
1061
self._real_repository.add_fallback_repository(repository)
1057
# They are also seen by the fallback repository. If it doesn't
1058
# exist yet they'll be added then. This implicitly copies them.
1061
1063
def add_inventory(self, revid, inv, parents):
1062
1064
self._ensure_real()
1261
1263
# We don't need to send ghosts back to the server as a position to
1263
1265
stop_keys.difference_update(self._unstacked_provider.missing_keys)
1266
key_count = len(parents_map)
1267
if (NULL_REVISION in result_parents
1268
and NULL_REVISION in self._unstacked_provider.missing_keys):
1269
# If we pruned NULL_REVISION from the stop_keys because it's also
1270
# in our cache of "missing" keys we need to increment our key count
1271
# by 1, because the reconsitituted SearchResult on the server will
1272
# still consider NULL_REVISION to be an included key.
1264
1274
included_keys = start_set.intersection(result_parents)
1265
1275
start_set.difference_update(included_keys)
1266
recipe = ('manual', start_set, stop_keys, len(parents_map))
1276
recipe = ('manual', start_set, stop_keys, key_count)
1267
1277
body = self._serialise_search_recipe(recipe)
1268
1278
path = self.bzrdir._path_for_remote_call(self._client)
1269
1279
for key in keys:
1926
1936
except (errors.NotStacked, errors.UnstackableBranchFormat,
1927
1937
errors.UnstackableRepositoryFormat), e:
1929
# it's relative to this branch...
1930
fallback_url = urlutils.join(self.base, fallback_url)
1931
transports = [self.bzrdir.root_transport]
1932
stacked_on = branch.Branch.open(fallback_url,
1933
possible_transports=transports)
1934
self.repository.add_fallback_repository(stacked_on.repository)
1939
self._activate_fallback_location(fallback_url)
1941
def _get_config(self):
1942
return RemoteBranchConfig(self)
1936
1944
def _get_real_transport(self):
1937
1945
# if we try vfs access, return the real branch's vfs transport
2279
2287
self._ensure_real()
2280
2288
return self._real_branch._set_parent_location(url)
2282
def set_stacked_on_url(self, stacked_location):
2283
"""Set the URL this branch is stacked against.
2285
:raises UnstackableBranchFormat: If the branch does not support
2287
:raises UnstackableRepositoryFormat: If the repository does not support
2291
return self._real_branch.set_stacked_on_url(stacked_location)
2293
2290
@needs_write_lock
2294
2291
def pull(self, source, overwrite=False, stop_revision=None,
2362
2359
return self._real_branch.set_push_location(location)
2362
class RemoteBranchConfig(object):
2363
"""A Config that reads from a smart branch and writes via smart methods.
2365
It is a low-level object that considers config data to be name/value pairs
2366
that may be associated with a section. Assigning meaning to the these
2367
values is done at higher levels like bzrlib.config.TreeConfig.
2370
def __init__(self, branch):
2371
self._branch = branch
2373
def get_option(self, name, section=None, default=None):
2374
"""Return the value associated with a named option.
2376
:param name: The name of the value
2377
:param section: The section the option is in (if any)
2378
:param default: The value to return if the value is not set
2379
:return: The value or default value
2381
configobj = self._get_configobj()
2383
section_obj = configobj
2386
section_obj = configobj[section]
2389
return section_obj.get(name, default)
2391
def _get_configobj(self):
2392
path = self._branch.bzrdir._path_for_remote_call(
2393
self._branch._client)
2394
response = self._branch._client.call_expecting_body(
2395
'Branch.get_config_file', path)
2396
if response[0][0] != 'ok':
2397
raise UnexpectedSmartServerResponse(response)
2398
bytes = response[1].read_body_bytes()
2399
return config.ConfigObj([bytes], encoding='utf-8')
2401
def set_option(self, value, name, section=None):
2402
"""Set the value associated with a named option.
2404
:param value: The value to set
2405
:param name: The name of the value to set
2406
:param section: The section the option is in (if any)
2408
return self._vfs_set_option(value, name, section)
2410
def _vfs_set_option(self, value, name, section=None):
2411
self._branch._ensure_real()
2412
return self._branch._real_branch._get_config().set_option(
2413
value, name, section)
2365
2416
def _extract_tar(tar, to_dir):
2366
2417
"""Extract all the contents of a tarfile object.