~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-12-11 20:23:00 UTC
  • mfrom: (3890.2.18 get_record_stream_chunked)
  • Revision ID: pqm@pqm.ubuntu.com-20081211202300-6dz1vo3phfsc23pj
(jam) Add ContentFactory.get_bytes_as('chunked') and
        osutils.chunks_to_lines()

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
    adapter_registry,
111
111
    ConstantMapper,
112
112
    ContentFactory,
113
 
    FulltextContentFactory,
 
113
    ChunkedContentFactory,
114
114
    VersionedFile,
115
115
    VersionedFiles,
116
116
    )
196
196
            [compression_parent], 'unordered', True).next()
197
197
        if basis_entry.storage_kind == 'absent':
198
198
            raise errors.RevisionNotPresent(compression_parent, self._basis_vf)
199
 
        basis_lines = split_lines(basis_entry.get_bytes_as('fulltext'))
 
199
        basis_chunks = basis_entry.get_bytes_as('chunked')
 
200
        basis_lines = osutils.chunks_to_lines(basis_chunks)
200
201
        # Manually apply the delta because we have one annotated content and
201
202
        # one plain.
202
203
        basis_content = PlainKnitContent(basis_lines, compression_parent)
229
230
            [compression_parent], 'unordered', True).next()
230
231
        if basis_entry.storage_kind == 'absent':
231
232
            raise errors.RevisionNotPresent(compression_parent, self._basis_vf)
232
 
        basis_lines = split_lines(basis_entry.get_bytes_as('fulltext'))
 
233
        basis_chunks = basis_entry.get_bytes_as('chunked')
 
234
        basis_lines = osutils.chunks_to_lines(basis_chunks)
233
235
        basis_content = PlainKnitContent(basis_lines, compression_parent)
234
236
        # Manually apply the delta because we have one annotated content and
235
237
        # one plain.
276
278
    def get_bytes_as(self, storage_kind):
277
279
        if storage_kind == self.storage_kind:
278
280
            return self._raw_record
279
 
        if storage_kind == 'fulltext' and self._knit is not None:
280
 
            return self._knit.get_text(self.key[0])
281
 
        else:
282
 
            raise errors.UnavailableRepresentation(self.key, storage_kind,
283
 
                self.storage_kind)
 
281
        if self._knit is not None:
 
282
            if storage_kind == 'chunked':
 
283
                return self._knit.get_lines(self.key[0])
 
284
            elif storage_kind == 'fulltext':
 
285
                return self._knit.get_text(self.key[0])
 
286
        raise errors.UnavailableRepresentation(self.key, storage_kind,
 
287
            self.storage_kind)
284
288
 
285
289
 
286
290
class KnitContent(object):
1020
1024
                if record.storage_kind == 'absent':
1021
1025
                    continue
1022
1026
                missing_keys.remove(record.key)
1023
 
                lines = split_lines(record.get_bytes_as('fulltext'))
 
1027
                lines = osutils.chunks_to_lines(record.get_bytes_as('chunked'))
1024
1028
                text_map[record.key] = lines
1025
1029
                content_map[record.key] = PlainKnitContent(lines, record.key)
1026
1030
                if record.key in keys:
1288
1292
                text_map, _ = self._get_content_maps(keys, non_local)
1289
1293
                for key in keys:
1290
1294
                    lines = text_map.pop(key)
1291
 
                    text = ''.join(lines)
1292
 
                    yield FulltextContentFactory(key, global_map[key], None,
1293
 
                                                 text)
 
1295
                    yield ChunkedContentFactory(key, global_map[key], None,
 
1296
                                                lines)
1294
1297
        else:
1295
1298
            for source, keys in source_keys:
1296
1299
                if source is parent_maps[0]:
1443
1446
                        buffered = True
1444
1447
                if not buffered:
1445
1448
                    self._index.add_records([index_entry])
 
1449
            elif record.storage_kind == 'chunked':
 
1450
                self.add_lines(record.key, parents,
 
1451
                    osutils.chunks_to_lines(record.get_bytes_as('chunked')))
1446
1452
            elif record.storage_kind == 'fulltext':
1447
1453
                self.add_lines(record.key, parents,
1448
1454
                    split_lines(record.get_bytes_as('fulltext')))
2952
2958
        reannotate = annotate.reannotate
2953
2959
        for record in self._knit.get_record_stream(keys, 'topological', True):
2954
2960
            key = record.key
2955
 
            fulltext = split_lines(record.get_bytes_as('fulltext'))
 
2961
            fulltext = osutils.chunks_to_lines(record.get_bytes_as('chunked'))
2956
2962
            parents = parent_map[key]
2957
2963
            if parents is not None:
2958
2964
                parent_lines = [parent_cache[parent] for parent in parent_map[key]]