/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: Ian Clatworthy
  • Date: 2009-04-03 00:07:49 UTC
  • mfrom: (4241 +trunk)
  • mto: (4265.1.1 bbc-merge)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: ian.clatworthy@canonical.com-20090403000749-sevl9klctwfi8jml
merge bzr.dev r4241

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from bzrlib import (
23
23
    branch,
24
24
    bzrdir,
 
25
    config,
25
26
    debug,
26
27
    errors,
27
28
    graph,
854
855
                self._real_repository.lock_read()
855
856
        else:
856
857
            self._lock_count += 1
 
858
        for repo in self._fallback_repositories:
 
859
            repo.lock_read()
857
860
 
858
861
    def _remote_lock_write(self, token):
859
862
        path = self.bzrdir._path_for_remote_call(self._client)
894
897
            raise errors.ReadOnlyError(self)
895
898
        else:
896
899
            self._lock_count += 1
 
900
        for repo in self._fallback_repositories:
 
901
            # Writes don't affect fallback repos
 
902
            repo.lock_read()
897
903
        return self._lock_token or None
898
904
 
899
905
    def leave_lock_in_place(self):
1063
1069
        if self._real_repository is not None:
1064
1070
            if repository not in self._real_repository._fallback_repositories:
1065
1071
                self._real_repository.add_fallback_repository(repository)
1066
 
        else:
1067
 
            # They are also seen by the fallback repository.  If it doesn't
1068
 
            # exist yet they'll be added then.  This implicitly copies them.
1069
 
            self._ensure_real()
1070
1072
 
1071
1073
    def add_inventory(self, revid, inv, parents):
1072
1074
        self._ensure_real()
1271
1273
        # We don't need to send ghosts back to the server as a position to
1272
1274
        # stop either.
1273
1275
        stop_keys.difference_update(self._unstacked_provider.missing_keys)
 
1276
        key_count = len(parents_map)
 
1277
        if (NULL_REVISION in result_parents
 
1278
            and NULL_REVISION in self._unstacked_provider.missing_keys):
 
1279
            # If we pruned NULL_REVISION from the stop_keys because it's also
 
1280
            # in our cache of "missing" keys we need to increment our key count
 
1281
            # by 1, because the reconsitituted SearchResult on the server will
 
1282
            # still consider NULL_REVISION to be an included key.
 
1283
            key_count += 1
1274
1284
        included_keys = start_set.intersection(result_parents)
1275
1285
        start_set.difference_update(included_keys)
1276
 
        recipe = ('manual', start_set, stop_keys, len(parents_map))
 
1286
        recipe = ('manual', start_set, stop_keys, key_count)
1277
1287
        body = self._serialise_search_recipe(recipe)
1278
1288
        path = self.bzrdir._path_for_remote_call(self._client)
1279
1289
        for key in keys:
1936
1946
        except (errors.NotStacked, errors.UnstackableBranchFormat,
1937
1947
            errors.UnstackableRepositoryFormat), e:
1938
1948
            return
1939
 
        # it's relative to this branch...
1940
 
        fallback_url = urlutils.join(self.base, fallback_url)
1941
 
        transports = [self.bzrdir.root_transport]
1942
 
        stacked_on = branch.Branch.open(fallback_url,
1943
 
                                        possible_transports=transports)
1944
 
        self.repository.add_fallback_repository(stacked_on.repository)
 
1949
        self._activate_fallback_location(fallback_url)
 
1950
 
 
1951
    def _get_config(self):
 
1952
        return RemoteBranchConfig(self)
1945
1953
 
1946
1954
    def _get_real_transport(self):
1947
1955
        # if we try vfs access, return the real branch's vfs transport
2289
2297
            self._ensure_real()
2290
2298
            return self._real_branch._set_parent_location(url)
2291
2299
 
2292
 
    def set_stacked_on_url(self, stacked_location):
2293
 
        """Set the URL this branch is stacked against.
2294
 
 
2295
 
        :raises UnstackableBranchFormat: If the branch does not support
2296
 
            stacking.
2297
 
        :raises UnstackableRepositoryFormat: If the repository does not support
2298
 
            stacking.
2299
 
        """
2300
 
        self._ensure_real()
2301
 
        return self._real_branch.set_stacked_on_url(stacked_location)
2302
 
 
2303
2300
    @needs_write_lock
2304
2301
    def pull(self, source, overwrite=False, stop_revision=None,
2305
2302
             **kwargs):
2372
2369
        return self._real_branch.set_push_location(location)
2373
2370
 
2374
2371
 
 
2372
class RemoteBranchConfig(object):
 
2373
    """A Config that reads from a smart branch and writes via smart methods.
 
2374
 
 
2375
    It is a low-level object that considers config data to be name/value pairs
 
2376
    that may be associated with a section. Assigning meaning to the these
 
2377
    values is done at higher levels like bzrlib.config.TreeConfig.
 
2378
    """
 
2379
 
 
2380
    def __init__(self, branch):
 
2381
        self._branch = branch
 
2382
 
 
2383
    def get_option(self, name, section=None, default=None):
 
2384
        """Return the value associated with a named option.
 
2385
 
 
2386
        :param name: The name of the value
 
2387
        :param section: The section the option is in (if any)
 
2388
        :param default: The value to return if the value is not set
 
2389
        :return: The value or default value
 
2390
        """
 
2391
        configobj = self._get_configobj()
 
2392
        if section is None:
 
2393
            section_obj = configobj
 
2394
        else:
 
2395
            try:
 
2396
                section_obj = configobj[section]
 
2397
            except KeyError:
 
2398
                return default
 
2399
        return section_obj.get(name, default)
 
2400
 
 
2401
    def _get_configobj(self):
 
2402
        path = self._branch.bzrdir._path_for_remote_call(
 
2403
            self._branch._client)
 
2404
        response = self._branch._client.call_expecting_body(
 
2405
            'Branch.get_config_file', path)
 
2406
        if response[0][0] != 'ok':
 
2407
            raise UnexpectedSmartServerResponse(response)
 
2408
        bytes = response[1].read_body_bytes()
 
2409
        return config.ConfigObj([bytes], encoding='utf-8')
 
2410
 
 
2411
    def set_option(self, value, name, section=None):
 
2412
        """Set the value associated with a named option.
 
2413
 
 
2414
        :param value: The value to set
 
2415
        :param name: The name of the value to set
 
2416
        :param section: The section the option is in (if any)
 
2417
        """
 
2418
        return self._vfs_set_option(value, name, section)
 
2419
 
 
2420
    def _vfs_set_option(self, value, name, section=None):
 
2421
        self._branch._ensure_real()
 
2422
        return self._branch._real_branch._get_config().set_option(
 
2423
            value, name, section)
 
2424
 
 
2425
 
2375
2426
def _extract_tar(tar, to_dir):
2376
2427
    """Extract all the contents of a tarfile object.
2377
2428