~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/serializer/v10.py

  • Committer: Aaron Bentley
  • Date: 2007-06-20 12:00:21 UTC
  • mto: (2520.5.2 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: aaron.bentley@utoronto.ca-20070620120021-cbroj10ks0grvz62
Begin adding support for arbitrary metadata

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    trace,
17
17
    )
18
18
from bzrlib.bundle import bundle_data, serializer
 
19
from bzrlib.util import bencode
19
20
 
20
21
 
21
22
class BundleWriter(object):
56
57
 
57
58
    def add_multiparent_record(self, mp_bytes, parents, repo_kind,
58
59
                               revision_id, file_id):
59
 
        self._add_record(mp_bytes, parents, repo_kind, revision_id, file_id)
 
60
        self._add_record(mp_bytes, {'parents': parents}, repo_kind,
 
61
                         revision_id, file_id)
60
62
 
61
63
    def add_fulltext_record(self, bytes, parents, repo_kind, revision_id,
62
64
                            file_id):
63
 
        self._add_record(bytes, parents, repo_kind, revision_id, file_id)
 
65
        self._add_record(bytes, {'parents': parents}, repo_kind, revision_id,
 
66
                         file_id)
64
67
 
65
68
    @staticmethod
66
69
    def encode_parents(parents):
80
83
            file_tail = ''
81
84
        return name_kind + ':' + revision_id + file_tail
82
85
 
83
 
    def _add_record(self, bytes, parents, repo_kind, revision_id, file_id):
 
86
    def _add_record(self, bytes, metadata, repo_kind, revision_id, file_id):
84
87
        name = self.encode_name(repo_kind, revision_id, file_id)
85
 
        parents = self.encode_parents(parents)
86
 
        bytes = parents + bytes
 
88
        bytes = bencode.bencode(metadata) + '\n' + bytes
87
89
        self._container.add_bytes_record(bytes, [name])
88
90
 
89
91
 
132
134
        for (name,), bytes in self._container.iter_records():
133
135
            lines = bytes(None).splitlines(True)
134
136
            parents, lines = lines[0], lines[1:]
135
 
            parents = self.decode_parents(parents)
 
137
            parents = bencode.bdecode(parents.rstrip('\n')).get('parents')
136
138
            yield (''.join(lines), parents) + self.decode_name(name)
137
139
 
138
140