~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Jelmer Vernooij
  • Date: 2011-11-28 14:18:56 UTC
  • mfrom: (6314 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6316.
  • Revision ID: jelmer@samba.org-20111128141856-lwh2exm44dv21f2x
merge bzr.dev.

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
 
2245
2247
        self._ensure_real()
2246
2248
        return self._real_repository.texts
2247
2249
 
 
2250
    def _iter_revisions_rpc(self, revision_ids):
 
2251
        body = "\n".join(revision_ids)
 
2252
        path = self.bzrdir._path_for_remote_call(self._client)
 
2253
        response_tuple, response_handler = (
 
2254
            self._call_with_body_bytes_expecting_body(
 
2255
            "Repository.iter_revisions", (path, ), body))
 
2256
        if response_tuple[0] != "ok":
 
2257
            raise errors.UnexpectedSmartServerResponse(response_tuple)
 
2258
        serializer_format = response_tuple[1]
 
2259
        serializer = serializer_format_registry.get(serializer_format)
 
2260
        byte_stream = response_handler.read_streamed_body()
 
2261
        decompressor = zlib.decompressobj()
 
2262
        chunks = []
 
2263
        for bytes in byte_stream:
 
2264
            chunks.append(decompressor.decompress(bytes))
 
2265
            if decompressor.unused_data != "":
 
2266
                chunks.append(decompressor.flush())
 
2267
                yield serializer.read_revision_from_string("".join(chunks))
 
2268
                unused = decompressor.unused_data
 
2269
                decompressor = zlib.decompressobj()
 
2270
                chunks = [decompressor.decompress(unused)]
 
2271
        chunks.append(decompressor.flush())
 
2272
        text = "".join(chunks)
 
2273
        if text != "":
 
2274
            yield serializer.read_revision_from_string("".join(chunks))
 
2275
 
2248
2276
    @needs_read_lock
2249
2277
    def get_revisions(self, revision_ids):
2250
 
        self._ensure_real()
2251
 
        return self._real_repository.get_revisions(revision_ids)
 
2278
        if revision_ids is None:
 
2279
            revision_ids = self.all_revision_ids()
 
2280
        else:
 
2281
            for rev_id in revision_ids:
 
2282
                if not rev_id or not isinstance(rev_id, basestring):
 
2283
                    raise errors.InvalidRevisionId(
 
2284
                        revision_id=rev_id, branch=self)
 
2285
        try:
 
2286
            missing = set(revision_ids)
 
2287
            revs = {}
 
2288
            for rev in self._iter_revisions_rpc(revision_ids):
 
2289
                missing.remove(rev.revision_id)
 
2290
                revs[rev.revision_id] = rev
 
2291
        except errors.UnknownSmartMethod:
 
2292
            self._ensure_real()
 
2293
            return self._real_repository.get_revisions(revision_ids)
 
2294
        for fallback in self._fallback_repositories:
 
2295
            if not missing:
 
2296
                break
 
2297
            for revid in list(missing):
 
2298
                # XXX JRV 2011-11-20: It would be nice if there was a
 
2299
                # public method on Repository that could be used to query
 
2300
                # for revision objects *without* failing completely if one
 
2301
                # was missing. There is VersionedFileRepository._iter_revisions,
 
2302
                # but unfortunately that's private and not provided by
 
2303
                # all repository implementations.
 
2304
                try:
 
2305
                    revs[revid] = fallback.get_revision(revid)
 
2306
                except errors.NoSuchRevision:
 
2307
                    pass
 
2308
                else:
 
2309
                    missing.remove(revid)
 
2310
        if missing:
 
2311
            raise errors.NoSuchRevision(self, list(missing)[0])
 
2312
        return [revs[revid] for revid in revision_ids]
2252
2313
 
2253
2314
    def supports_rich_root(self):
2254
2315
        return self._format.rich_root_data