392
392
return self._real_bzrdir.clone(url, revision_id=revision_id,
393
393
force_new_repo=force_new_repo, preserve_stacking=preserve_stacking)
395
def get_config(self):
397
return self._real_bzrdir.get_config()
395
def _get_config(self):
396
return RemoteBzrDirConfig(self)
400
399
class RemoteRepositoryFormat(repository.RepositoryFormat):
1962
1961
except (errors.NotStacked, errors.UnstackableBranchFormat,
1963
1962
errors.UnstackableRepositoryFormat), e:
1965
self._activate_fallback_location(fallback_url)
1964
self._activate_fallback_location(fallback_url, None)
1967
1966
def _get_config(self):
1968
1967
return RemoteBranchConfig(self)
2301
2300
self._ensure_real()
2302
2301
return self._real_branch._get_parent_location()
2304
def set_parent(self, url):
2306
return self._real_branch.set_parent(url)
2308
2303
def _set_parent_location(self, url):
2309
# Used by tests, to poke bad urls into branch configurations
2311
self.set_parent(url)
2314
return self._real_branch._set_parent_location(url)
2304
medium = self._client._medium
2305
if medium._is_remote_before((1, 15)):
2306
return self._vfs_set_parent_location(url)
2308
call_url = url or ''
2309
if type(call_url) is not str:
2310
raise AssertionError('url must be a str or None (%s)' % url)
2311
response = self._call('Branch.set_parent_location',
2312
self._remote_path(), self._lock_token, self._repo_lock_token,
2314
except errors.UnknownSmartMethod:
2315
medium._remember_remote_is_before((1, 15))
2316
return self._vfs_set_parent_location(url)
2318
raise errors.UnexpectedSmartServerResponse(response)
2320
def _vfs_set_parent_location(self, url):
2322
return self._real_branch._set_parent_location(url)
2316
2324
@needs_write_lock
2317
2325
def pull(self, source, overwrite=False, stop_revision=None,
2385
2393
return self._real_branch.set_push_location(location)
2388
class RemoteBranchConfig(object):
2389
"""A Config that reads from a smart branch and writes via smart methods.
2396
class RemoteConfig(object):
2397
"""A Config that reads and writes from smart verbs.
2391
2399
It is a low-level object that considers config data to be name/value pairs
2392
2400
that may be associated with a section. Assigning meaning to the these
2393
2401
values is done at higher levels like bzrlib.config.TreeConfig.
2396
def __init__(self, branch):
2397
self._branch = branch
2399
2404
def get_option(self, name, section=None, default=None):
2400
2405
"""Return the value associated with a named option.
2404
2409
:param default: The value to return if the value is not set
2405
2410
:return: The value or default value
2407
configobj = self._get_configobj()
2409
section_obj = configobj
2412
section_obj = configobj[section]
2415
return section_obj.get(name, default)
2413
configobj = self._get_configobj()
2415
section_obj = configobj
2418
section_obj = configobj[section]
2421
return section_obj.get(name, default)
2422
except errors.UnknownSmartMethod:
2423
return self._vfs_get_option(name, section, default)
2425
def _response_to_configobj(self, response):
2426
if len(response[0]) and response[0][0] != 'ok':
2427
raise errors.UnexpectedSmartServerResponse(response)
2428
lines = response[1].read_body_bytes().splitlines()
2429
return config.ConfigObj(lines, encoding='utf-8')
2432
class RemoteBranchConfig(RemoteConfig):
2433
"""A RemoteConfig for Branches."""
2435
def __init__(self, branch):
2436
self._branch = branch
2417
2438
def _get_configobj(self):
2418
2439
path = self._branch._remote_path()
2419
2440
response = self._branch._client.call_expecting_body(
2420
2441
'Branch.get_config_file', path)
2421
if response[0][0] != 'ok':
2422
raise UnexpectedSmartServerResponse(response)
2423
lines = response[1].read_body_bytes().splitlines()
2424
return config.ConfigObj(lines, encoding='utf-8')
2442
return self._response_to_configobj(response)
2426
2444
def set_option(self, value, name, section=None):
2427
2445
"""Set the value associated with a named option.
2444
2462
if response != ():
2445
2463
raise errors.UnexpectedSmartServerResponse(response)
2465
def _real_object(self):
2466
self._branch._ensure_real()
2467
return self._branch._real_branch
2447
2469
def _vfs_set_option(self, value, name, section=None):
2448
self._branch._ensure_real()
2449
return self._branch._real_branch._get_config().set_option(
2450
value, name, section)
2470
return self._real_object()._get_config().set_option(
2471
value, name, section)
2474
class RemoteBzrDirConfig(RemoteConfig):
2475
"""A RemoteConfig for BzrDirs."""
2477
def __init__(self, bzrdir):
2478
self._bzrdir = bzrdir
2480
def _get_configobj(self):
2481
medium = self._bzrdir._client._medium
2482
verb = 'BzrDir.get_config_file'
2483
if medium._is_remote_before((1, 15)):
2484
raise errors.UnknownSmartMethod(verb)
2485
path = self._bzrdir._path_for_remote_call(self._bzrdir._client)
2486
response = self._bzrdir._call_expecting_body(
2488
return self._response_to_configobj(response)
2490
def _vfs_get_option(self, name, section, default):
2491
return self._real_object()._get_config().get_option(
2492
name, section, default)
2494
def set_option(self, value, name, section=None):
2495
"""Set the value associated with a named option.
2497
:param value: The value to set
2498
:param name: The name of the value to set
2499
:param section: The section the option is in (if any)
2501
return self._real_object()._get_config().set_option(
2502
value, name, section)
2504
def _real_object(self):
2505
self._bzrdir._ensure_real()
2506
return self._bzrdir._real_bzrdir
2453
2510
def _extract_tar(tar, to_dir):