~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/repository.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Server-side repository related request implmentations."""
 
17
"""Server-side repository related request implementations."""
 
18
 
 
19
from __future__ import absolute_import
18
20
 
19
21
import bz2
20
22
import os
28
30
    bencode,
29
31
    errors,
30
32
    estimate_compressed_size,
 
33
    inventory as _mod_inventory,
 
34
    inventory_delta,
31
35
    osutils,
32
36
    pack,
33
37
    trace,
43
47
from bzrlib.repository import _strip_NULL_ghosts, network_format_registry
44
48
from bzrlib import revision as _mod_revision
45
49
from bzrlib.versionedfile import (
 
50
    ChunkedContentFactory,
46
51
    NetworkRecordStream,
47
52
    record_to_fulltext_bytes,
48
53
    )
1243
1248
                yield zlib.compress(record.get_bytes_as('fulltext'))
1244
1249
        finally:
1245
1250
            self._repository.unlock()
 
1251
 
 
1252
 
 
1253
class SmartServerRepositoryGetInventories(SmartServerRepositoryRequest):
 
1254
    """Get the inventory deltas for a set of revision ids.
 
1255
 
 
1256
    This accepts a list of revision ids, and then sends a chain
 
1257
    of deltas for the inventories of those revisions. The first
 
1258
    revision will be empty.
 
1259
 
 
1260
    The server writes back zlibbed serialized inventory deltas,
 
1261
    in the ordering specified. The base for each delta is the
 
1262
    inventory generated by the previous delta.
 
1263
 
 
1264
    New in 2.5.
 
1265
    """
 
1266
 
 
1267
    def _inventory_delta_stream(self, repository, ordering, revids):
 
1268
        prev_inv = _mod_inventory.Inventory(root_id=None,
 
1269
            revision_id=_mod_revision.NULL_REVISION)
 
1270
        serializer = inventory_delta.InventoryDeltaSerializer(
 
1271
            repository.supports_rich_root(),
 
1272
            repository._format.supports_tree_reference)
 
1273
        repository.lock_read()
 
1274
        try:
 
1275
            for inv, revid in repository._iter_inventories(revids, ordering):
 
1276
                if inv is None:
 
1277
                    continue
 
1278
                inv_delta = inv._make_delta(prev_inv)
 
1279
                lines = serializer.delta_to_lines(
 
1280
                    prev_inv.revision_id, inv.revision_id, inv_delta)
 
1281
                yield ChunkedContentFactory(inv.revision_id, None, None, lines)
 
1282
                prev_inv = inv
 
1283
        finally:
 
1284
            repository.unlock()
 
1285
 
 
1286
    def body_stream(self, repository, ordering, revids):
 
1287
        substream = self._inventory_delta_stream(repository,
 
1288
            ordering, revids)
 
1289
        return _stream_to_byte_stream([('inventory-deltas', substream)],
 
1290
            repository._format)
 
1291
 
 
1292
    def do_body(self, body_bytes):
 
1293
        return SuccessfulSmartServerResponse(('ok', ),
 
1294
            body_stream=self.body_stream(self._repository, self._ordering,
 
1295
                body_bytes.splitlines()))
 
1296
 
 
1297
    def do_repository_request(self, repository, ordering):
 
1298
        if ordering == 'unordered':
 
1299
            # inventory deltas for a topologically sorted stream
 
1300
            # are likely to be smaller
 
1301
            ordering = 'topological'
 
1302
        self._ordering = ordering
 
1303
        # Signal that we want a body
 
1304
        return None