392
393
return self._real_bzrdir.clone(url, revision_id=revision_id,
393
394
force_new_repo=force_new_repo, preserve_stacking=preserve_stacking)
395
def get_config(self):
397
return self._real_bzrdir.get_config()
396
def _get_config(self):
397
return RemoteBzrDirConfig(self)
400
400
class RemoteRepositoryFormat(repository.RepositoryFormat):
492
492
# 1) get the network name to use.
493
493
if self._custom_format:
494
494
network_name = self._custom_format.network_name()
495
elif self._network_name:
496
network_name = self._network_name
496
498
# Select the current bzrlib default and ask for that.
497
499
reference_bzrdir_format = bzrdir.format_registry.get('default')()
603
605
self._lock_token = None
604
606
self._lock_count = 0
605
607
self._leave_lock = False
608
# Cache of revision parents; misses are cached during read locks, and
609
# write locks when no _real_repository has been set.
606
610
self._unstacked_provider = graph.CachingParentsProvider(
607
611
get_parent_map=self._get_parent_map_rpc)
608
612
self._unstacked_provider.disable_cache()
680
688
invocation. If in doubt chat to the bzr network team.
682
690
if self._real_repository is None:
691
self._unstacked_provider.missing_keys.clear()
683
692
self.bzrdir._ensure_real()
684
693
self._set_real_repository(
685
694
self.bzrdir._real_bzrdir.open_repository())
745
754
"""Return a source for streaming from this repository."""
746
755
return RemoteStreamSource(self, to_format)
748
758
def has_revision(self, revision_id):
749
"""See Repository.has_revision()."""
750
if revision_id == NULL_REVISION:
751
# The null revision is always present.
753
path = self.bzrdir._path_for_remote_call(self._client)
754
response = self._call('Repository.has_revision', path, revision_id)
755
if response[0] not in ('yes', 'no'):
756
raise errors.UnexpectedSmartServerResponse(response)
757
if response[0] == 'yes':
759
for fallback_repo in self._fallback_repositories:
760
if fallback_repo.has_revision(revision_id):
759
"""True if this repository has a copy of the revision."""
760
# Copy of bzrlib.repository.Repository.has_revision
761
return revision_id in self.has_revisions((revision_id,))
764
764
def has_revisions(self, revision_ids):
765
"""See Repository.has_revisions()."""
766
# FIXME: This does many roundtrips, particularly when there are
767
# fallback repositories. -- mbp 20080905
769
for revision_id in revision_ids:
770
if self.has_revision(revision_id):
771
result.add(revision_id)
765
"""Probe to find out the presence of multiple revisions.
767
:param revision_ids: An iterable of revision_ids.
768
:return: A set of the revision_ids that were present.
770
# Copy of bzrlib.repository.Repository.has_revisions
771
parent_map = self.get_parent_map(revision_ids)
772
result = set(parent_map)
773
if _mod_revision.NULL_REVISION in revision_ids:
774
result.add(_mod_revision.NULL_REVISION)
774
777
def has_same_location(self, other):
892
895
self._leave_lock = False
893
896
self._lock_mode = 'w'
894
897
self._lock_count = 1
895
self._unstacked_provider.enable_cache(cache_misses=False)
898
cache_misses = self._real_repository is None
899
self._unstacked_provider.enable_cache(cache_misses=cache_misses)
896
900
elif self._lock_mode == 'r':
897
901
raise errors.ReadOnlyError(self)
1606
1610
def insert_stream(self, stream, src_format, resume_tokens):
1607
1611
target = self.target_repo
1612
target._unstacked_provider.missing_keys.clear()
1608
1613
if target._lock_token:
1609
1614
verb = 'Repository.insert_stream_locked'
1610
1615
extra_args = (target._lock_token or '',)
1962
1967
except (errors.NotStacked, errors.UnstackableBranchFormat,
1963
1968
errors.UnstackableRepositoryFormat), e:
1965
self._activate_fallback_location(fallback_url)
1970
self._activate_fallback_location(fallback_url, None)
1967
1972
def _get_config(self):
1968
1973
return RemoteBranchConfig(self)
2301
2306
self._ensure_real()
2302
2307
return self._real_branch._get_parent_location()
2304
def set_parent(self, url):
2306
return self._real_branch.set_parent(url)
2308
2309
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)
2310
medium = self._client._medium
2311
if medium._is_remote_before((1, 15)):
2312
return self._vfs_set_parent_location(url)
2314
call_url = url or ''
2315
if type(call_url) is not str:
2316
raise AssertionError('url must be a str or None (%s)' % url)
2317
response = self._call('Branch.set_parent_location',
2318
self._remote_path(), self._lock_token, self._repo_lock_token,
2320
except errors.UnknownSmartMethod:
2321
medium._remember_remote_is_before((1, 15))
2322
return self._vfs_set_parent_location(url)
2324
raise errors.UnexpectedSmartServerResponse(response)
2326
def _vfs_set_parent_location(self, url):
2328
return self._real_branch._set_parent_location(url)
2316
2330
@needs_write_lock
2317
2331
def pull(self, source, overwrite=False, stop_revision=None,
2385
2399
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.
2402
class RemoteConfig(object):
2403
"""A Config that reads and writes from smart verbs.
2391
2405
It is a low-level object that considers config data to be name/value pairs
2392
2406
that may be associated with a section. Assigning meaning to the these
2393
2407
values is done at higher levels like bzrlib.config.TreeConfig.
2396
def __init__(self, branch):
2397
self._branch = branch
2399
2410
def get_option(self, name, section=None, default=None):
2400
2411
"""Return the value associated with a named option.
2404
2415
:param default: The value to return if the value is not set
2405
2416
: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)
2419
configobj = self._get_configobj()
2421
section_obj = configobj
2424
section_obj = configobj[section]
2427
return section_obj.get(name, default)
2428
except errors.UnknownSmartMethod:
2429
return self._vfs_get_option(name, section, default)
2431
def _response_to_configobj(self, response):
2432
if len(response[0]) and response[0][0] != 'ok':
2433
raise errors.UnexpectedSmartServerResponse(response)
2434
lines = response[1].read_body_bytes().splitlines()
2435
return config.ConfigObj(lines, encoding='utf-8')
2438
class RemoteBranchConfig(RemoteConfig):
2439
"""A RemoteConfig for Branches."""
2441
def __init__(self, branch):
2442
self._branch = branch
2417
2444
def _get_configobj(self):
2418
2445
path = self._branch._remote_path()
2419
2446
response = self._branch._client.call_expecting_body(
2420
2447
'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')
2448
return self._response_to_configobj(response)
2426
2450
def set_option(self, value, name, section=None):
2427
2451
"""Set the value associated with a named option.
2444
2468
if response != ():
2445
2469
raise errors.UnexpectedSmartServerResponse(response)
2471
def _real_object(self):
2472
self._branch._ensure_real()
2473
return self._branch._real_branch
2447
2475
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)
2476
return self._real_object()._get_config().set_option(
2477
value, name, section)
2480
class RemoteBzrDirConfig(RemoteConfig):
2481
"""A RemoteConfig for BzrDirs."""
2483
def __init__(self, bzrdir):
2484
self._bzrdir = bzrdir
2486
def _get_configobj(self):
2487
medium = self._bzrdir._client._medium
2488
verb = 'BzrDir.get_config_file'
2489
if medium._is_remote_before((1, 15)):
2490
raise errors.UnknownSmartMethod(verb)
2491
path = self._bzrdir._path_for_remote_call(self._bzrdir._client)
2492
response = self._bzrdir._call_expecting_body(
2494
return self._response_to_configobj(response)
2496
def _vfs_get_option(self, name, section, default):
2497
return self._real_object()._get_config().get_option(
2498
name, section, default)
2500
def set_option(self, value, name, section=None):
2501
"""Set the value associated with a named option.
2503
:param value: The value to set
2504
:param name: The name of the value to set
2505
:param section: The section the option is in (if any)
2507
return self._real_object()._get_config().set_option(
2508
value, name, section)
2510
def _real_object(self):
2511
self._bzrdir._ensure_real()
2512
return self._bzrdir._real_bzrdir
2453
2516
def _extract_tar(tar, to_dir):