~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-02-07 04:51:19 UTC
  • mfrom: (5641.2.1 bzr-dev-overview-tweaks)
  • Revision ID: pqm@pqm.ubuntu.com-20110207045119-fn3s8bol0zscqr1p
(spiv) Expand doc/developers/overview.txt a little,
 and fix some formatting nits. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
33
33
    revision as _mod_revision,
34
34
    static_tuple,
35
35
    symbol_versioning,
 
36
    urlutils,
36
37
)
37
38
from bzrlib.branch import BranchReferenceFormat, BranchWriteLockResult
38
39
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
214
215
        if len(branch_info) != 2:
215
216
            raise errors.UnexpectedSmartServerResponse(response)
216
217
        branch_ref, branch_name = branch_info
217
 
        format = bzrdir.network_format_registry.get(control_name)
 
218
        format = controldir.network_format_registry.get(control_name)
218
219
        if repo_name:
219
220
            format.repository_format = repository.network_format_registry.get(
220
221
                repo_name)
246
247
        self._ensure_real()
247
248
        self._real_bzrdir.destroy_repository()
248
249
 
249
 
    def create_branch(self, name=None):
 
250
    def create_branch(self, name=None, repository=None):
250
251
        # as per meta1 formats - just delegate to the format object which may
251
252
        # be parameterised.
252
253
        real_branch = self._format.get_branch_format().initialize(self,
253
 
            name=name)
 
254
            name=name, repository=repository)
254
255
        if not isinstance(real_branch, RemoteBranch):
255
 
            result = RemoteBranch(self, self.find_repository(), real_branch,
256
 
                                  name=name)
 
256
            if not isinstance(repository, RemoteRepository):
 
257
                raise AssertionError(
 
258
                    'need a RemoteRepository to use with RemoteBranch, got %r'
 
259
                    % (repository,))
 
260
            result = RemoteBranch(self, repository, real_branch, name=name)
257
261
        else:
258
262
            result = real_branch
259
263
        # BzrDir.clone_on_transport() uses the result of create_branch but does
271
275
        self._real_bzrdir.destroy_branch(name=name)
272
276
        self._next_open_branch_result = None
273
277
 
274
 
    def create_workingtree(self, revision_id=None, from_branch=None):
 
278
    def create_workingtree(self, revision_id=None, from_branch=None,
 
279
        accelerator_tree=None, hardlink=False):
275
280
        raise errors.NotLocalUrl(self.transport.base)
276
281
 
277
282
    def find_branch_format(self, name=None):
1343
1348
        return result
1344
1349
 
1345
1350
    @needs_read_lock
1346
 
    def search_missing_revision_ids(self, other, revision_id=None, find_ghosts=True):
 
1351
    def search_missing_revision_ids(self, other,
 
1352
            revision_id=symbol_versioning.DEPRECATED_PARAMETER,
 
1353
            find_ghosts=True, revision_ids=None, if_present_ids=None):
1347
1354
        """Return the revision ids that other has that this does not.
1348
1355
 
1349
1356
        These are returned in topological order.
1350
1357
 
1351
1358
        revision_id: only return revision ids included by revision_id.
1352
1359
        """
1353
 
        return repository.InterRepository.get(
1354
 
            other, self).search_missing_revision_ids(revision_id, find_ghosts)
 
1360
        if symbol_versioning.deprecated_passed(revision_id):
 
1361
            symbol_versioning.warn(
 
1362
                'search_missing_revision_ids(revision_id=...) was '
 
1363
                'deprecated in 2.3.  Use revision_ids=[...] instead.',
 
1364
                DeprecationWarning, stacklevel=2)
 
1365
            if revision_ids is not None:
 
1366
                raise AssertionError(
 
1367
                    'revision_ids is mutually exclusive with revision_id')
 
1368
            if revision_id is not None:
 
1369
                revision_ids = [revision_id]
 
1370
        inter_repo = repository.InterRepository.get(other, self)
 
1371
        return inter_repo.search_missing_revision_ids(
 
1372
            find_ghosts=find_ghosts, revision_ids=revision_ids,
 
1373
            if_present_ids=if_present_ids)
1355
1374
 
1356
1375
    def fetch(self, source, revision_id=None, pb=None, find_ghosts=False,
1357
1376
            fetch_spec=None):
1758
1777
        return '\n'.join((start_keys, stop_keys, count))
1759
1778
 
1760
1779
    def _serialise_search_result(self, search_result):
1761
 
        if isinstance(search_result, graph.PendingAncestryResult):
1762
 
            parts = ['ancestry-of']
1763
 
            parts.extend(search_result.heads)
1764
 
        else:
1765
 
            recipe = search_result.get_recipe()
1766
 
            parts = [recipe[0], self._serialise_search_recipe(recipe)]
 
1780
        parts = search_result.get_network_struct()
1767
1781
        return '\n'.join(parts)
1768
1782
 
1769
1783
    def autopack(self):
1963
1977
        candidate_verbs = [
1964
1978
            ('Repository.get_stream_1.19', (1, 19)),
1965
1979
            ('Repository.get_stream', (1, 13))]
 
1980
 
1966
1981
        found_verb = False
1967
1982
        for verb, version in candidate_verbs:
1968
1983
            if medium._is_remote_before(version):
1972
1987
                    verb, args, search_bytes)
1973
1988
            except errors.UnknownSmartMethod:
1974
1989
                medium._remember_remote_is_before(version)
 
1990
            except errors.UnknownErrorFromSmartServer, e:
 
1991
                if isinstance(search, graph.EverythingResult):
 
1992
                    error_verb = e.error_from_smart_server.error_verb
 
1993
                    if error_verb == 'BadSearch':
 
1994
                        # Pre-2.3 servers don't support this sort of search.
 
1995
                        # XXX: perhaps falling back to VFS on BadSearch is a
 
1996
                        # good idea in general?  It might provide a little bit
 
1997
                        # of protection against client-side bugs.
 
1998
                        medium._remember_remote_is_before((2, 3))
 
1999
                        break
 
2000
                raise
1975
2001
            else:
1976
2002
                response_tuple, response_handler = response
1977
2003
                found_verb = True
2092
2118
                                  name=name)
2093
2119
        return result
2094
2120
 
2095
 
    def initialize(self, a_bzrdir, name=None):
 
2121
    def initialize(self, a_bzrdir, name=None, repository=None):
2096
2122
        # 1) get the network name to use.
2097
2123
        if self._custom_format:
2098
2124
            network_name = self._custom_format.network_name()
2126
2152
        # Turn the response into a RemoteRepository object.
2127
2153
        format = RemoteBranchFormat(network_name=response[1])
2128
2154
        repo_format = response_tuple_to_repo_format(response[3:])
2129
 
        if response[2] == '':
2130
 
            repo_bzrdir = a_bzrdir
 
2155
        repo_path = response[2]
 
2156
        if repository is not None:
 
2157
            remote_repo_url = urlutils.join(medium.base, repo_path)
 
2158
            url_diff = urlutils.relative_url(repository.user_url,
 
2159
                    remote_repo_url)
 
2160
            if url_diff != '.':
 
2161
                raise AssertionError(
 
2162
                    'repository.user_url %r does not match URL from server '
 
2163
                    'response (%r + %r)'
 
2164
                    % (repository.user_url, medium.base, repo_path))
 
2165
            remote_repo = repository
2131
2166
        else:
2132
 
            repo_bzrdir = RemoteBzrDir(
2133
 
                a_bzrdir.root_transport.clone(response[2]), a_bzrdir._format,
2134
 
                a_bzrdir._client)
2135
 
        remote_repo = RemoteRepository(repo_bzrdir, repo_format)
 
2167
            if repo_path == '':
 
2168
                repo_bzrdir = a_bzrdir
 
2169
            else:
 
2170
                repo_bzrdir = RemoteBzrDir(
 
2171
                    a_bzrdir.root_transport.clone(repo_path), a_bzrdir._format,
 
2172
                    a_bzrdir._client)
 
2173
            remote_repo = RemoteRepository(repo_bzrdir, repo_format)
2136
2174
        remote_branch = RemoteBranch(a_bzrdir, remote_repo,
2137
2175
            format=format, setup_stacking=False, name=name)
2138
2176
        # XXX: We know this is a new branch, so it must have revno 0, revid
2368
2406
        self._ensure_real()
2369
2407
        return self._real_branch._get_tags_bytes()
2370
2408
 
 
2409
    @needs_read_lock
2371
2410
    def _get_tags_bytes(self):
 
2411
        if self._tags_bytes is None:
 
2412
            self._tags_bytes = self._get_tags_bytes_via_hpss()
 
2413
        return self._tags_bytes
 
2414
 
 
2415
    def _get_tags_bytes_via_hpss(self):
2372
2416
        medium = self._client._medium
2373
2417
        if medium._is_remote_before((1, 13)):
2374
2418
            return self._vfs_get_tags_bytes()
2384
2428
        return self._real_branch._set_tags_bytes(bytes)
2385
2429
 
2386
2430
    def _set_tags_bytes(self, bytes):
 
2431
        if self.is_locked():
 
2432
            self._tags_bytes = bytes
2387
2433
        medium = self._client._medium
2388
2434
        if medium._is_remote_before((1, 18)):
2389
2435
            self._vfs_set_tags_bytes(bytes)