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):
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)
2305
return self._real_branch._set_parent_location(url)
2316
2307
@needs_write_lock
2317
2308
def pull(self, source, overwrite=False, stop_revision=None,
2385
2376
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.
2379
class RemoteConfig(object):
2380
"""A Config that reads and writes from smart verbs.
2391
2382
It is a low-level object that considers config data to be name/value pairs
2392
2383
that may be associated with a section. Assigning meaning to the these
2393
2384
values is done at higher levels like bzrlib.config.TreeConfig.
2396
def __init__(self, branch):
2397
self._branch = branch
2399
2387
def get_option(self, name, section=None, default=None):
2400
2388
"""Return the value associated with a named option.
2404
2392
:param default: The value to return if the value is not set
2405
2393
: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)
2396
configobj = self._get_configobj()
2398
section_obj = configobj
2401
section_obj = configobj[section]
2404
return section_obj.get(name, default)
2405
except errors.UnknownSmartMethod:
2406
return self._vfs_get_option(name, section, default)
2408
def _response_to_configobj(self, response):
2409
if len(response[0]) and response[0][0] != 'ok':
2410
raise errors.UnexpectedSmartServerResponse(response)
2411
lines = response[1].read_body_bytes().splitlines()
2412
return config.ConfigObj(lines, encoding='utf-8')
2415
class RemoteBranchConfig(RemoteConfig):
2416
"""A RemoteConfig for Branches."""
2418
def __init__(self, branch):
2419
self._branch = branch
2417
2421
def _get_configobj(self):
2418
2422
path = self._branch._remote_path()
2419
2423
response = self._branch._client.call_expecting_body(
2420
2424
'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')
2425
return self._response_to_configobj(response)
2426
2427
def set_option(self, value, name, section=None):
2427
2428
"""Set the value associated with a named option.
2444
2445
if response != ():
2445
2446
raise errors.UnexpectedSmartServerResponse(response)
2448
def _real_object(self):
2449
self._branch._ensure_real()
2450
return self._branch._real_branch
2447
2452
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)
2453
return self._real_object()._get_config().set_option(
2454
value, name, section)
2457
class RemoteBzrDirConfig(RemoteConfig):
2458
"""A RemoteConfig for BzrDirs."""
2460
def __init__(self, bzrdir):
2461
self._bzrdir = bzrdir
2463
def _get_configobj(self):
2464
medium = self._bzrdir._client._medium
2465
verb = 'BzrDir.get_config_file'
2466
if medium._is_remote_before((1, 15)):
2467
raise errors.UnknownSmartMethod(verb)
2468
path = self._bzrdir._path_for_remote_call(self._bzrdir._client)
2469
response = self._bzrdir._call_expecting_body(
2471
return self._response_to_configobj(response)
2473
def _vfs_get_option(self, name, section, default):
2474
return self._real_object()._get_config().get_option(
2475
name, section, default)
2477
def set_option(self, value, name, section=None):
2478
"""Set the value associated with a named option.
2480
:param value: The value to set
2481
:param name: The name of the value to set
2482
:param section: The section the option is in (if any)
2484
return self._real_object()._get_config().set_option(
2485
value, name, section)
2487
def _real_object(self):
2488
self._bzrdir._ensure_real()
2489
return self._bzrdir._real_bzrdir
2453
2493
def _extract_tar(tar, to_dir):