/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: Andrew Bennetts
  • Date: 2009-10-08 01:50:30 UTC
  • mfrom: (4731 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4732.
  • Revision ID: andrew.bennetts@canonical.com-20091008015030-8n02kppogh8radr0
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
class RemoteBzrDir(BzrDir, _RpcHelper):
90
90
    """Control directory on a remote server, accessed via bzr:// or similar."""
91
91
 
92
 
    def __init__(self, transport, format, _client=None):
 
92
    def __init__(self, transport, format, _client=None, _force_probe=False):
93
93
        """Construct a RemoteBzrDir.
94
94
 
95
95
        :param _client: Private parameter for testing. Disables probing and the
99
99
        # this object holds a delegated bzrdir that uses file-level operations
100
100
        # to talk to the other side
101
101
        self._real_bzrdir = None
 
102
        self._has_working_tree = None
102
103
        # 1-shot cache for the call pattern 'create_branch; open_branch' - see
103
104
        # create_branch for details.
104
105
        self._next_open_branch_result = None
108
109
            self._client = client._SmartClient(medium)
109
110
        else:
110
111
            self._client = _client
111
 
            return
112
 
 
 
112
            if not _force_probe:
 
113
                return
 
114
 
 
115
        self._probe_bzrdir()
 
116
 
 
117
    def _probe_bzrdir(self):
 
118
        medium = self._client._medium
113
119
        path = self._path_for_remote_call(self._client)
 
120
        if medium._is_remote_before((2, 1)):
 
121
            self._rpc_open(path)
 
122
            return
 
123
        try:
 
124
            self._rpc_open_2_1(path)
 
125
            return
 
126
        except errors.UnknownSmartMethod:
 
127
            medium._remember_remote_is_before((2, 1))
 
128
            self._rpc_open(path)
 
129
 
 
130
    def _rpc_open_2_1(self, path):
 
131
        response = self._call('BzrDir.open_2.1', path)
 
132
        if response == ('no',):
 
133
            raise errors.NotBranchError(path=self.root_transport.base)
 
134
        elif response[0] == 'yes':
 
135
            if response[1] == 'yes':
 
136
                self._has_working_tree = True
 
137
            elif response[1] == 'no':
 
138
                self._has_working_tree = False
 
139
            else:
 
140
                raise errors.UnexpectedSmartServerResponse(response)
 
141
        else:
 
142
            raise errors.UnexpectedSmartServerResponse(response)
 
143
 
 
144
    def _rpc_open(self, path):
114
145
        response = self._call('BzrDir.open', path)
115
146
        if response not in [('yes',), ('no',)]:
116
147
            raise errors.UnexpectedSmartServerResponse(response)
117
148
        if response == ('no',):
118
 
            raise errors.NotBranchError(path=transport.base)
 
149
            raise errors.NotBranchError(path=self.root_transport.base)
119
150
 
120
151
    def _ensure_real(self):
121
152
        """Ensure that there is a _real_bzrdir set.
355
386
        else:
356
387
            raise errors.NoRepositoryPresent(self)
357
388
 
 
389
    def has_workingtree(self):
 
390
        if self._has_working_tree is None:
 
391
            self._ensure_real()
 
392
            self._has_working_tree = self._real_bzrdir.has_workingtree()
 
393
        return self._has_working_tree
 
394
 
358
395
    def open_workingtree(self, recommend_upgrade=True):
359
 
        self._ensure_real()
360
 
        if self._real_bzrdir.has_workingtree():
 
396
        if self.has_workingtree():
361
397
            raise errors.NotLocalUrl(self.root_transport)
362
398
        else:
363
399
            raise errors.NoWorkingTree(self.root_transport.base)
1888
1924
        :param search: The overall search to satisfy with streams.
1889
1925
        :param sources: A list of Repository objects to query.
1890
1926
        """
1891
 
        self.serialiser = self.to_format._serializer
 
1927
        self.from_serialiser = self.from_repository._format._serializer
1892
1928
        self.seen_revs = set()
1893
1929
        self.referenced_revs = set()
1894
1930
        # If there are heads in the search, or the key count is > 0, we are not
1911
1947
    def missing_parents_rev_handler(self, substream):
1912
1948
        for content in substream:
1913
1949
            revision_bytes = content.get_bytes_as('fulltext')
1914
 
            revision = self.serialiser.read_revision_from_string(revision_bytes)
 
1950
            revision = self.from_serialiser.read_revision_from_string(
 
1951
                revision_bytes)
1915
1952
            self.seen_revs.add(content.key[-1])
1916
1953
            self.referenced_revs.update(revision.parent_ids)
1917
1954
            yield content