~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/repository.py

  • Committer: Patch Queue Manager
  • Date: 2011-11-28 13:54:33 UTC
  • mfrom: (6280.9.12 hpss-get-revisions)
  • Revision ID: pqm@pqm.ubuntu.com-20111128135433-xoddhlxx9qgi4u5k
(jelmer) Add a ``Repository.iter_revisions`` HPSS call. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import sys
23
23
import tempfile
24
24
import threading
 
25
import zlib
25
26
 
26
27
from bzrlib import (
27
28
    bencode,
1101
1102
        finally:
1102
1103
            self._repository.unlock()
1103
1104
        return SuccessfulSmartServerResponse(("ok", ), )
 
1105
 
 
1106
 
 
1107
class SmartServerRepositoryIterRevisions(SmartServerRepositoryRequest):
 
1108
    """Stream a list of revisions.
 
1109
 
 
1110
    The client sends a list of newline-separated revision ids in the
 
1111
    body of the request and the server replies with the serializer format,
 
1112
    and a stream of bzip2-compressed revision texts (using the specified
 
1113
    serializer format).
 
1114
 
 
1115
    Any revisions the server does not have are omitted from the stream.
 
1116
 
 
1117
    New in 2.5.
 
1118
    """
 
1119
 
 
1120
    def do_repository_request(self, repository):
 
1121
        self._repository = repository
 
1122
        # Signal there is a body
 
1123
        return None
 
1124
 
 
1125
    def do_body(self, body_bytes):
 
1126
        revision_ids = body_bytes.split("\n")
 
1127
        return SuccessfulSmartServerResponse(
 
1128
            ('ok', self._repository.get_serializer_format()),
 
1129
            body_stream=self.body_stream(self._repository, revision_ids))
 
1130
 
 
1131
    def body_stream(self, repository, revision_ids):
 
1132
        self._repository.lock_read()
 
1133
        try:
 
1134
            for record in repository.revisions.get_record_stream(
 
1135
                [(revid,) for revid in revision_ids], 'unordered', True):
 
1136
                if record.storage_kind == 'absent':
 
1137
                    continue
 
1138
                yield zlib.compress(record.get_bytes_as('fulltext'))
 
1139
        finally:
 
1140
            self._repository.unlock()