~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-11 16:55:31 UTC
  • mto: (2520.5.2 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: abentley@panoramicfeedback.com-20070611165531-7t13giwn5srpnemf
Serialize inventory

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
                text = ''.join(vf.make_mpdiff(file_revision_id).to_patch())
18
18
                container_name = self.encode_name('file', file_revision_id,
19
19
                                                  file_id)
20
 
                container.add_record('M', len(text), [container_name], text)
 
20
                parents = self.encode_parents(vf.get_parents(file_revision_id))
 
21
                text = parents + text
 
22
                container.add_record('M', len(text), [container_name],
 
23
                                     text)
 
24
        for revision_id in revision_ids:
 
25
            container_name = self.encode_name('inventory', revision_id)
 
26
            parents = self.encode_parents(repository.revision_parents(
 
27
                revision_id))
 
28
            inventory_text = parents + \
 
29
                repository.get_inventory_xml(revision_id)
 
30
            container.add_record('B', len(inventory_text), [container_name],
 
31
                                 inventory_text)
21
32
        container.finish()
22
33
 
 
34
    def encode_parents(self, parents):
 
35
        return ' '.join(parents) + '\n'
 
36
 
 
37
    def decode_parents(self, parents_line):
 
38
        parents = parents_line.rstrip('\n').split(' ')
 
39
        if parents == ['']:
 
40
            parents = []
 
41
        return parents
 
42
 
23
43
    def read(self, file):
24
44
        container = _RecordReader(file, self)
25
45
        return container
26
46
 
27
47
    @staticmethod
28
48
    def encode_name(name_kind, revision_id, file_id=None):
29
 
        assert name_kind in ('revision', 'file')
30
 
        if name_kind in ('revision',):
 
49
        assert name_kind in ('revision', 'file', 'inventory')
 
50
        if name_kind in ('revision', 'inventory'):
31
51
            assert file_id is None
32
52
        else:
33
53
            assert file_id is not None
83
103
        current_file = None
84
104
        current_versionedfile = None
85
105
        pending_file_records = []
 
106
        added_inv = set()
86
107
        for type_, size, names  in self.iter_records():
87
108
            if type_ == 'E':
88
109
                self._install_file_records(current_versionedfile,
93
114
            if  kind != 'file':
94
115
                self._install_file_records(current_versionedfile,
95
116
                    pending_file_records)
 
117
                current_file = None
 
118
                current_versionedfile = None
 
119
                pending_file_records = []
 
120
                if kind == 'inventory':
 
121
                    self._install_inventory(repository, type_, revision_id,
 
122
                        self.read_record(), added_inv)
 
123
                    added_inv.add(revision_id)
96
124
            if kind == 'file':
97
125
                if file_id != current_file:
98
126
                    self._install_file_records(current_versionedfile,
104
132
                    pending_file_records = []
105
133
                if revision_id in current_versionedfile:
106
134
                    continue
107
 
                pending_file_records.append((type_, revision_id, [],
 
135
                pending_file_records.append((type_, revision_id,
108
136
                                            self.read_record()))
109
137
 
110
138
 
111
139
    def _install_file_records(self, current_versionedfile,
112
140
                              pending_file_records):
113
 
        for type_, revision, parents, text in pending_file_records:
 
141
        for type_, revision, text in pending_file_records:
114
142
            assert type_ == 'M'
115
 
            mpdiff = multiparent.MultiParent.from_patch(text.splitlines(True))
 
143
            mpdiff_text = text.splitlines(True)
 
144
            parents, mpdiff_text = mpdiff_text[0], mpdiff_text[1:]
 
145
            parents = self._serializer.decode_parents(parents)
 
146
            mpdiff = multiparent.MultiParent.from_patch(mpdiff_text)
116
147
            current_versionedfile.add_mpdiff(revision, parents, mpdiff)
 
148
 
 
149
    def _install_inventory(self, repository, type_, revision_id, text, added):
 
150
        lines = text.splitlines(True)
 
151
        parents = self._serializer.decode_parents(lines[0])
 
152
        present_parents = [p for p in parents if
 
153
            (p in added or repository.has_revision(p))]
 
154
        text = ''.join(lines[1:])
 
155
        inv = repository.deserialise_inventory(revision_id, text)
 
156
        repository.add_inventory(revision_id, inv, present_parents)