~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Robert Collins
  • Date: 2009-02-20 08:26:50 UTC
  • mto: This revision was merged to the branch mainline in revision 4028.
  • Revision ID: robertc@robertcollins.net-20090220082650-wmzch4en338bymkm
Cherrypick and polish the RemoteSink for streaming push.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from copy import copy
23
23
from cStringIO import StringIO
24
24
import os
 
25
import struct
25
26
from zlib import adler32
26
27
 
27
28
from bzrlib.lazy_import import lazy_import
45
46
from bzrlib.registry import Registry
46
47
from bzrlib.symbol_versioning import *
47
48
from bzrlib.textmerge import TextMerge
 
49
from bzrlib.util import bencode
48
50
 
49
51
 
50
52
adapter_registry = Registry()
1502
1504
            'knit-annotated-ft-gz':knit.knit_network_to_record,
1503
1505
            'knit-annotated-delta-gz':knit.knit_network_to_record,
1504
1506
            'knit-delta-closure':knit.knit_delta_closure_to_records,
 
1507
            'fulltext':fulltext_network_to_record,
1505
1508
            }
1506
1509
 
1507
1510
    def read(self):
1514
1517
            for record in self._kind_factory[storage_kind](
1515
1518
                storage_kind, bytes, line_end):
1516
1519
                yield record
 
1520
 
 
1521
 
 
1522
def fulltext_network_to_record(kind, bytes, line_end):
 
1523
    """Convert a network fulltext record to record."""
 
1524
    meta_len, = struct.unpack('!L', bytes[line_end:line_end+4])
 
1525
    record_meta = record_bytes[line_end+4:line_end+4+meta_len]
 
1526
    key, parents = bencode.bdecode_as_tuple(record_meta)
 
1527
    if parents == 'nil':
 
1528
        parents = None
 
1529
    fulltext = record_bytes[line_end+4+meta_len:]
 
1530
    return FulltextContentFactory(key, parents, None, fulltext)
 
1531
 
 
1532
 
 
1533
def _length_prefix(bytes):
 
1534
    return struct.pack('!L', len(bytes))
 
1535
 
 
1536
 
 
1537
def record_to_fulltext_bytes(self, record):
 
1538
    if record.parents is None:
 
1539
        parents = 'nil'
 
1540
    else:
 
1541
        parents = record.parents
 
1542
    record_meta = bencode.bencode((record.key, parents))
 
1543
    record_content = record.get_bytes_as('fulltext')
 
1544
    return "fulltext\n%s%s%s" % (
 
1545
        _length_prefix(record_meta), record_meta, record_content)