/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-29 05:53:21 UTC
  • mfrom: (4311 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4312.
  • Revision ID: tanner@real-time.com-20090429055321-v2s5l1mgki9f6cgn
[merge] 1.14 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
392
392
        return self._real_bzrdir.clone(url, revision_id=revision_id,
393
393
            force_new_repo=force_new_repo, preserve_stacking=preserve_stacking)
394
394
 
395
 
    def get_config(self):
396
 
        self._ensure_real()
397
 
        return self._real_bzrdir.get_config()
 
395
    def _get_config(self):
 
396
        return RemoteBzrDirConfig(self)
398
397
 
399
398
 
400
399
class RemoteRepositoryFormat(repository.RepositoryFormat):
492
491
        # 1) get the network name to use.
493
492
        if self._custom_format:
494
493
            network_name = self._custom_format.network_name()
 
494
        elif self._network_name:
 
495
            network_name = self._network_name
495
496
        else:
496
497
            # Select the current bzrlib default and ask for that.
497
498
            reference_bzrdir_format = bzrdir.format_registry.get('default')()
666
667
        self._ensure_real()
667
668
        return self._real_repository.suspend_write_group()
668
669
 
 
670
    def get_missing_parent_inventories(self):
 
671
        self._ensure_real()
 
672
        return self._real_repository.get_missing_parent_inventories()
 
673
 
669
674
    def _ensure_real(self):
670
675
        """Ensure that there is a _real_repository set.
671
676
 
1962
1967
        except (errors.NotStacked, errors.UnstackableBranchFormat,
1963
1968
            errors.UnstackableRepositoryFormat), e:
1964
1969
            return
1965
 
        self._activate_fallback_location(fallback_url)
 
1970
        self._activate_fallback_location(fallback_url, None)
1966
1971
 
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()
2303
2308
 
2304
 
    def set_parent(self, url):
2305
 
        self._ensure_real()
2306
 
        return self._real_branch.set_parent(url)
2307
 
 
2308
2309
    def _set_parent_location(self, url):
2309
 
        # Used by tests, to poke bad urls into branch configurations
2310
 
        if url is None:
2311
 
            self.set_parent(url)
2312
 
        else:
2313
 
            self._ensure_real()
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)
 
2313
        try:
 
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,
 
2319
                call_url)
 
2320
        except errors.UnknownSmartMethod:
 
2321
            medium._remember_remote_is_before((1, 15))
 
2322
            return self._vfs_set_parent_location(url)
 
2323
        if response != ():
 
2324
            raise errors.UnexpectedSmartServerResponse(response)
 
2325
 
 
2326
    def _vfs_set_parent_location(self, url):
 
2327
        self._ensure_real()
 
2328
        return self._real_branch._set_parent_location(url)
2315
2329
 
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)
2386
2400
 
2387
2401
 
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.
2390
2404
 
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.
2394
2408
    """
2395
2409
 
2396
 
    def __init__(self, branch):
2397
 
        self._branch = branch
2398
 
 
2399
2410
    def get_option(self, name, section=None, default=None):
2400
2411
        """Return the value associated with a named option.
2401
2412
 
2404
2415
        :param default: The value to return if the value is not set
2405
2416
        :return: The value or default value
2406
2417
        """
2407
 
        configobj = self._get_configobj()
2408
 
        if section is None:
2409
 
            section_obj = configobj
2410
 
        else:
2411
 
            try:
2412
 
                section_obj = configobj[section]
2413
 
            except KeyError:
2414
 
                return default
2415
 
        return section_obj.get(name, default)
 
2418
        try:
 
2419
            configobj = self._get_configobj()
 
2420
            if section is None:
 
2421
                section_obj = configobj
 
2422
            else:
 
2423
                try:
 
2424
                    section_obj = configobj[section]
 
2425
                except KeyError:
 
2426
                    return default
 
2427
            return section_obj.get(name, default)
 
2428
        except errors.UnknownSmartMethod:
 
2429
            return self._vfs_get_option(name, section, default)
 
2430
 
 
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')
 
2436
 
 
2437
 
 
2438
class RemoteBranchConfig(RemoteConfig):
 
2439
    """A RemoteConfig for Branches."""
 
2440
 
 
2441
    def __init__(self, branch):
 
2442
        self._branch = branch
2416
2443
 
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)
2425
2449
 
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)
2446
2470
 
 
2471
    def _real_object(self):
 
2472
        self._branch._ensure_real()
 
2473
        return self._branch._real_branch
 
2474
 
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)
 
2478
 
 
2479
 
 
2480
class RemoteBzrDirConfig(RemoteConfig):
 
2481
    """A RemoteConfig for BzrDirs."""
 
2482
 
 
2483
    def __init__(self, bzrdir):
 
2484
        self._bzrdir = bzrdir
 
2485
 
 
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(
 
2493
            verb, path)
 
2494
        return self._response_to_configobj(response)
 
2495
 
 
2496
    def _vfs_get_option(self, name, section, default):
 
2497
        return self._real_object()._get_config().get_option(
 
2498
            name, section, default)
 
2499
 
 
2500
    def set_option(self, value, name, section=None):
 
2501
        """Set the value associated with a named option.
 
2502
 
 
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)
 
2506
        """
 
2507
        return self._real_object()._get_config().set_option(
 
2508
            value, name, section)
 
2509
 
 
2510
    def _real_object(self):
 
2511
        self._bzrdir._ensure_real()
 
2512
        return self._bzrdir._real_bzrdir
 
2513
 
2451
2514
 
2452
2515
 
2453
2516
def _extract_tar(tar, to_dir):