~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Andrew Bennetts
  • Date: 2008-05-16 06:06:35 UTC
  • mto: This revision was merged to the branch mainline in revision 3428.
  • Revision ID: andrew.bennetts@canonical.com-20080516060635-fzhwv0conhmjo7jq
Unpack call_expecting_body's return value into variables, to avoid lots of ugly subscripting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
386
386
            if err.error_verb == 'nosuchrevision':
387
387
                raise NoSuchRevision(self, revision_id)
388
388
            raise
389
 
        if response[0][0] != 'ok':
390
 
            raise errors.UnexpectedSmartServerResponse(response[0])
391
 
        coded = response[1].read_body_bytes()
 
389
        response_tuple, response_handler = response
 
390
        if response_tuple[0] != 'ok':
 
391
            raise errors.UnexpectedSmartServerResponse(response_tuple)
 
392
        coded = response_handler.read_body_bytes()
392
393
        if coded == '':
393
394
            # no revisions in this repository!
394
395
            return {}
406
407
            # The null revision is always present.
407
408
            return True
408
409
        path = self.bzrdir._path_for_remote_call(self._client)
409
 
        response = self._client.call('Repository.has_revision', path, revision_id)
 
410
        response = self._client.call(
 
411
            'Repository.has_revision', path, revision_id)
410
412
        if response[0] not in ('yes', 'no'):
411
 
            raise SmartProtocolError('unexpected response code %s' % (response,))
 
413
            raise errors.UnexpectedSmartServerResponse(response)
412
414
        return response[0] == 'yes'
413
415
 
414
416
    def has_revisions(self, revision_ids):
445
447
            fmt_committers = 'no'
446
448
        else:
447
449
            fmt_committers = 'yes'
448
 
        response = self._client.call_expecting_body(
 
450
        response_tuple, response_handler = self._client.call_expecting_body(
449
451
            'Repository.gather_stats', path, fmt_revid, fmt_committers)
450
 
        if response[0][0] != 'ok':
451
 
            raise SmartProtocolError('unexpected response code %s'
452
 
                % (response[0],))
 
452
        if response_tuple[0] != 'ok':
 
453
            raise errors.UnexpectedSmartServerResponse(response_tuple)
453
454
 
454
 
        body = response[1].read_body_bytes()
 
455
        body = response_handler.read_body_bytes()
455
456
        result = {}
456
457
        for line in body.split('\n'):
457
458
            if not line:
913
914
            # fact the server doesn't understand remote methods added in 1.2.
914
915
            medium._remote_is_at_least_1_2 = False
915
916
            return self.get_revision_graph(None)
916
 
        if response[0][0] not in ['ok']:
917
 
            response[1].cancel_read_body()
918
 
            raise errors.UnexpectedSmartServerResponse(response[0])
919
 
        if response[0][0] == 'ok':
920
 
            coded = bz2.decompress(response[1].read_body_bytes())
 
917
        response_tuple, response_handler = response
 
918
        if response_tuple[0] not in ['ok']:
 
919
            response_handler.cancel_read_body()
 
920
            raise errors.UnexpectedSmartServerResponse(response_tuple)
 
921
        if response_tuple[0] == 'ok':
 
922
            coded = bz2.decompress(response_handler.read_body_bytes())
921
923
            if coded == '':
922
924
                # no revisions found
923
925
                return {}
1441
1443
    def _gen_revision_history(self):
1442
1444
        """See Branch._gen_revision_history()."""
1443
1445
        path = self.bzrdir._path_for_remote_call(self._client)
1444
 
        response = self._client.call_expecting_body(
 
1446
        response_tuple, response_handler = self._client.call_expecting_body(
1445
1447
            'Branch.revision_history', path)
1446
 
        if response[0][0] != 'ok':
1447
 
            raise SmartProtocolError('unexpected response code %s' % (response,))
1448
 
        result = response[1].read_body_bytes().split('\x00')
 
1448
        if response_tuple[0] != 'ok':
 
1449
            raise UnexpectedSmartServerResponse(response_tuple)
 
1450
        result = response_handler.read_body_bytes().split('\x00')
1449
1451
        if result == ['']:
1450
1452
            return []
1451
1453
        return result