~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.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:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import bz2
 
18
import zlib
18
19
 
19
20
from bzrlib import (
20
21
    bencode,
51
52
from bzrlib.revision import NULL_REVISION
52
53
from bzrlib.revisiontree import InventoryRevisionTree
53
54
from bzrlib.repository import RepositoryWriteLockResult, _LazyListJoin
 
55
from bzrlib.serializer import format_registry as serializer_format_registry
54
56
from bzrlib.trace import mutter, note, warning, log_exception_quietly
55
57
 
56
58
 
2229
2231
        self._ensure_real()
2230
2232
        return self._real_repository.texts
2231
2233
 
 
2234
    def _iter_revisions_rpc(self, revision_ids):
 
2235
        body = "\n".join(revision_ids)
 
2236
        path = self.bzrdir._path_for_remote_call(self._client)
 
2237
        response_tuple, response_handler = (
 
2238
            self._call_with_body_bytes_expecting_body(
 
2239
            "Repository.iter_revisions", (path, ), body))
 
2240
        if response_tuple[0] != "ok":
 
2241
            raise errors.UnexpectedSmartServerResponse(response_tuple)
 
2242
        serializer_format = response_tuple[1]
 
2243
        serializer = serializer_format_registry.get(serializer_format)
 
2244
        byte_stream = response_handler.read_streamed_body()
 
2245
        decompressor = zlib.decompressobj()
 
2246
        chunks = []
 
2247
        for bytes in byte_stream:
 
2248
            chunks.append(decompressor.decompress(bytes))
 
2249
            if decompressor.unused_data != "":
 
2250
                chunks.append(decompressor.flush())
 
2251
                yield serializer.read_revision_from_string("".join(chunks))
 
2252
                unused = decompressor.unused_data
 
2253
                decompressor = zlib.decompressobj()
 
2254
                chunks = [decompressor.decompress(unused)]
 
2255
        chunks.append(decompressor.flush())
 
2256
        text = "".join(chunks)
 
2257
        if text != "":
 
2258
            yield serializer.read_revision_from_string("".join(chunks))
 
2259
 
2232
2260
    @needs_read_lock
2233
2261
    def get_revisions(self, revision_ids):
2234
 
        self._ensure_real()
2235
 
        return self._real_repository.get_revisions(revision_ids)
 
2262
        if revision_ids is None:
 
2263
            revision_ids = self.all_revision_ids()
 
2264
        else:
 
2265
            for rev_id in revision_ids:
 
2266
                if not rev_id or not isinstance(rev_id, basestring):
 
2267
                    raise errors.InvalidRevisionId(
 
2268
                        revision_id=rev_id, branch=self)
 
2269
        try:
 
2270
            missing = set(revision_ids)
 
2271
            revs = {}
 
2272
            for rev in self._iter_revisions_rpc(revision_ids):
 
2273
                missing.remove(rev.revision_id)
 
2274
                revs[rev.revision_id] = rev
 
2275
        except errors.UnknownSmartMethod:
 
2276
            self._ensure_real()
 
2277
            return self._real_repository.get_revisions(revision_ids)
 
2278
        for fallback in self._fallback_repositories:
 
2279
            if not missing:
 
2280
                break
 
2281
            for revid in list(missing):
 
2282
                # XXX JRV 2011-11-20: It would be nice if there was a
 
2283
                # public method on Repository that could be used to query
 
2284
                # for revision objects *without* failing completely if one
 
2285
                # was missing. There is VersionedFileRepository._iter_revisions,
 
2286
                # but unfortunately that's private and not provided by
 
2287
                # all repository implementations.
 
2288
                try:
 
2289
                    revs[revid] = fallback.get_revision(revid)
 
2290
                except errors.NoSuchRevision:
 
2291
                    pass
 
2292
                else:
 
2293
                    missing.remove(revid)
 
2294
        if missing:
 
2295
            raise errors.NoSuchRevision(self, list(missing)[0])
 
2296
        return [revs[revid] for revid in revision_ids]
2236
2297
 
2237
2298
    def supports_rich_root(self):
2238
2299
        return self._format.rich_root_data