/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: Jelmer Vernooij
  • Date: 2009-04-03 17:36:43 UTC
  • mfrom: (4222.2.9 ui-username)
  • mto: This revision was merged to the branch mainline in revision 4284.
  • Revision ID: jelmer@samba.org-20090403173643-xcf89aq1bn3yxipt
Merge new username ui call.

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,
844
845
                self._real_repository.lock_read()
845
846
        else:
846
847
            self._lock_count += 1
 
848
        for repo in self._fallback_repositories:
 
849
            repo.lock_read()
847
850
 
848
851
    def _remote_lock_write(self, token):
849
852
        path = self.bzrdir._path_for_remote_call(self._client)
884
887
            raise errors.ReadOnlyError(self)
885
888
        else:
886
889
            self._lock_count += 1
 
890
        for repo in self._fallback_repositories:
 
891
            # Writes don't affect fallback repos
 
892
            repo.lock_read()
887
893
        return self._lock_token or None
888
894
 
889
895
    def leave_lock_in_place(self):
1053
1059
        if self._real_repository is not None:
1054
1060
            if repository not in self._real_repository._fallback_repositories:
1055
1061
                self._real_repository.add_fallback_repository(repository)
1056
 
        else:
1057
 
            # They are also seen by the fallback repository.  If it doesn't
1058
 
            # exist yet they'll be added then.  This implicitly copies them.
1059
 
            self._ensure_real()
1060
1062
 
1061
1063
    def add_inventory(self, revid, inv, parents):
1062
1064
        self._ensure_real()
1261
1263
        # We don't need to send ghosts back to the server as a position to
1262
1264
        # stop either.
1263
1265
        stop_keys.difference_update(self._unstacked_provider.missing_keys)
 
1266
        key_count = len(parents_map)
 
1267
        if (NULL_REVISION in result_parents
 
1268
            and NULL_REVISION in self._unstacked_provider.missing_keys):
 
1269
            # If we pruned NULL_REVISION from the stop_keys because it's also
 
1270
            # in our cache of "missing" keys we need to increment our key count
 
1271
            # by 1, because the reconsitituted SearchResult on the server will
 
1272
            # still consider NULL_REVISION to be an included key.
 
1273
            key_count += 1
1264
1274
        included_keys = start_set.intersection(result_parents)
1265
1275
        start_set.difference_update(included_keys)
1266
 
        recipe = ('manual', start_set, stop_keys, len(parents_map))
 
1276
        recipe = ('manual', start_set, stop_keys, key_count)
1267
1277
        body = self._serialise_search_recipe(recipe)
1268
1278
        path = self.bzrdir._path_for_remote_call(self._client)
1269
1279
        for key in keys:
1926
1936
        except (errors.NotStacked, errors.UnstackableBranchFormat,
1927
1937
            errors.UnstackableRepositoryFormat), e:
1928
1938
            return
1929
 
        # it's relative to this branch...
1930
 
        fallback_url = urlutils.join(self.base, fallback_url)
1931
 
        transports = [self.bzrdir.root_transport]
1932
 
        stacked_on = branch.Branch.open(fallback_url,
1933
 
                                        possible_transports=transports)
1934
 
        self.repository.add_fallback_repository(stacked_on.repository)
 
1939
        self._activate_fallback_location(fallback_url)
 
1940
 
 
1941
    def _get_config(self):
 
1942
        return RemoteBranchConfig(self)
1935
1943
 
1936
1944
    def _get_real_transport(self):
1937
1945
        # if we try vfs access, return the real branch's vfs transport
2279
2287
            self._ensure_real()
2280
2288
            return self._real_branch._set_parent_location(url)
2281
2289
 
2282
 
    def set_stacked_on_url(self, stacked_location):
2283
 
        """Set the URL this branch is stacked against.
2284
 
 
2285
 
        :raises UnstackableBranchFormat: If the branch does not support
2286
 
            stacking.
2287
 
        :raises UnstackableRepositoryFormat: If the repository does not support
2288
 
            stacking.
2289
 
        """
2290
 
        self._ensure_real()
2291
 
        return self._real_branch.set_stacked_on_url(stacked_location)
2292
 
 
2293
2290
    @needs_write_lock
2294
2291
    def pull(self, source, overwrite=False, stop_revision=None,
2295
2292
             **kwargs):
2362
2359
        return self._real_branch.set_push_location(location)
2363
2360
 
2364
2361
 
 
2362
class RemoteBranchConfig(object):
 
2363
    """A Config that reads from a smart branch and writes via smart methods.
 
2364
 
 
2365
    It is a low-level object that considers config data to be name/value pairs
 
2366
    that may be associated with a section. Assigning meaning to the these
 
2367
    values is done at higher levels like bzrlib.config.TreeConfig.
 
2368
    """
 
2369
 
 
2370
    def __init__(self, branch):
 
2371
        self._branch = branch
 
2372
 
 
2373
    def get_option(self, name, section=None, default=None):
 
2374
        """Return the value associated with a named option.
 
2375
 
 
2376
        :param name: The name of the value
 
2377
        :param section: The section the option is in (if any)
 
2378
        :param default: The value to return if the value is not set
 
2379
        :return: The value or default value
 
2380
        """
 
2381
        configobj = self._get_configobj()
 
2382
        if section is None:
 
2383
            section_obj = configobj
 
2384
        else:
 
2385
            try:
 
2386
                section_obj = configobj[section]
 
2387
            except KeyError:
 
2388
                return default
 
2389
        return section_obj.get(name, default)
 
2390
 
 
2391
    def _get_configobj(self):
 
2392
        path = self._branch.bzrdir._path_for_remote_call(
 
2393
            self._branch._client)
 
2394
        response = self._branch._client.call_expecting_body(
 
2395
            'Branch.get_config_file', path)
 
2396
        if response[0][0] != 'ok':
 
2397
            raise UnexpectedSmartServerResponse(response)
 
2398
        bytes = response[1].read_body_bytes()
 
2399
        return config.ConfigObj([bytes], encoding='utf-8')
 
2400
 
 
2401
    def set_option(self, value, name, section=None):
 
2402
        """Set the value associated with a named option.
 
2403
 
 
2404
        :param value: The value to set
 
2405
        :param name: The name of the value to set
 
2406
        :param section: The section the option is in (if any)
 
2407
        """
 
2408
        return self._vfs_set_option(value, name, section)
 
2409
 
 
2410
    def _vfs_set_option(self, value, name, section=None):
 
2411
        self._branch._ensure_real()
 
2412
        return self._branch._real_branch._get_config().set_option(
 
2413
            value, name, section)
 
2414
 
 
2415
 
2365
2416
def _extract_tar(tar, to_dir):
2366
2417
    """Extract all the contents of a tarfile object.
2367
2418