/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Andrew Bennetts
  • Date: 2008-11-26 11:35:37 UTC
  • mto: This revision was merged to the branch mainline in revision 3981.
  • Revision ID: andrew.bennetts@canonical.com-20081126113537-9vn1v1yo4gkxi05o
TestStacking.test_fetch_copies_from_stacked_on now passes using the VersionedFile.insert_record_stream RPC; lots of debugging cruft needs removal though.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
from bzrlib.smart import client, vfs
42
42
from bzrlib.revision import ensure_null, NULL_REVISION
43
43
from bzrlib.trace import mutter, note, warning
 
44
from bzrlib.util import bencode
44
45
from bzrlib.versionedfile import VersionedFiles
45
46
 
46
47
 
1222
1223
    return '\n'.join((start_keys, stop_keys, count))
1223
1224
 
1224
1225
 
 
1226
def _serialise_record_stream(stream):
 
1227
    """Takes a record stream as returned by get_record_stream and yields bytes.
 
1228
    """
 
1229
    # Yields bencode of (sha1, storage_kind, key, parents, build_details,
 
1230
    #                    record_bytes)
 
1231
    # Note that:
 
1232
    #  - if sha1 is None, sha1 is ''
 
1233
    #  - if parents is None, parents is 'nil' (to distinguish it from empty
 
1234
    # tuple).
 
1235
    #  - if record has no _build_details, build_details is ()
 
1236
    for record in stream:
 
1237
        sha1 = record.sha1
 
1238
        if sha1 is None:
 
1239
            sha1 = ''
 
1240
        parents = record.parents
 
1241
        if record.parents is None:
 
1242
            parents = 'nil'
 
1243
        if record.storage_kind.startswith('knit-'):
 
1244
            build_details = record._build_details
 
1245
        else:
 
1246
            build_details = ()
 
1247
        struct = (sha1, record.storage_kind, record.key, parents,
 
1248
                  build_details, record.get_bytes_as(record.storage_kind))
 
1249
        bencode.bdecode(bencode.bencode(struct))
 
1250
        #print struct
 
1251
        yield bencode.bencode(struct)
 
1252
 
 
1253
 
1225
1254
class RemoteVersionedFiles(VersionedFiles):
1226
1255
 
1227
1256
    def __init__(self, remote_repo, vf_name):
1267
1296
        return real_vf.get_sha1s(keys)
1268
1297
 
1269
1298
    def insert_record_stream(self, stream):
1270
 
        real_vf = self._get_real_vf()
1271
 
        return real_vf.insert_record_stream(stream)
 
1299
        lock_token = self.remote_repo._lock_token
 
1300
        if lock_token is None:
 
1301
            lock_token = ''
 
1302
        from bzrlib.trace import mutter
 
1303
        stream = list(stream)
 
1304
        mutter('record stream: %r', [s.__dict__ for s in stream])
 
1305
        byte_stream = _serialise_record_stream(stream)
 
1306
        byte_stream = list(byte_stream)
 
1307
        mutter('byte stream: %r', byte_stream)
 
1308
        if byte_stream == []:
 
1309
            return
 
1310
        client = self.remote_repo._client
 
1311
        path = self.remote_repo.bzrdir._path_for_remote_call(client)
 
1312
        response = client.call_with_body_stream(
 
1313
            ('VersionedFile.insert_record_stream', path, self.vf_name,
 
1314
             lock_token), byte_stream)
 
1315
        response_tuple, response_handler = response
 
1316
#        real_vf = self._get_real_vf()
 
1317
#        return real_vf.insert_record_stream(stream)
1272
1318
 
1273
1319
    def iter_lines_added_or_present_in_keys(self, keys, pb=None):
1274
1320
        real_vf = self._get_real_vf()