1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
4
# Johan Rydberg <jrydberg@gnu.org>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
"""Versioned text file storage api."""
23
from cStringIO import StringIO
25
from zlib import adler32
27
from bzrlib.lazy_import import lazy_import
28
lazy_import(globals(), """
41
from bzrlib.graph import DictParentsProvider, Graph, _StackedParentsProvider
42
from bzrlib.transport.memory import MemoryTransport
44
from bzrlib.inter import InterObject
45
from bzrlib.registry import Registry
46
from bzrlib.symbol_versioning import *
47
from bzrlib.textmerge import TextMerge
50
adapter_registry = Registry()
51
adapter_registry.register_lazy(('knit-delta-gz', 'fulltext'), 'bzrlib.knit',
52
'DeltaPlainToFullText')
53
adapter_registry.register_lazy(('knit-ft-gz', 'fulltext'), 'bzrlib.knit',
55
adapter_registry.register_lazy(('knit-annotated-delta-gz', 'knit-delta-gz'),
56
'bzrlib.knit', 'DeltaAnnotatedToUnannotated')
57
adapter_registry.register_lazy(('knit-annotated-delta-gz', 'fulltext'),
58
'bzrlib.knit', 'DeltaAnnotatedToFullText')
59
adapter_registry.register_lazy(('knit-annotated-ft-gz', 'knit-ft-gz'),
60
'bzrlib.knit', 'FTAnnotatedToUnannotated')
61
adapter_registry.register_lazy(('knit-annotated-ft-gz', 'fulltext'),
62
'bzrlib.knit', 'FTAnnotatedToFullText')
63
# adapter_registry.register_lazy(('knit-annotated-ft-gz', 'chunked'),
64
# 'bzrlib.knit', 'FTAnnotatedToChunked')
67
class ContentFactory(object):
68
"""Abstract interface for insertion and retrieval from a VersionedFile.
70
:ivar sha1: None, or the sha1 of the content fulltext.
71
:ivar storage_kind: The native storage kind of this factory. One of
72
'mpdiff', 'knit-annotated-ft', 'knit-annotated-delta', 'knit-ft',
73
'knit-delta', 'fulltext', 'knit-annotated-ft-gz',
74
'knit-annotated-delta-gz', 'knit-ft-gz', 'knit-delta-gz'.
75
:ivar key: The key of this content. Each key is a tuple with a single
77
:ivar parents: A tuple of parent keys for self.key. If the object has
78
no parent information, None (as opposed to () for an empty list of
83
"""Create a ContentFactory."""
85
self.storage_kind = None
90
class ChunkedContentFactory(ContentFactory):
91
"""Static data content factory.
93
This takes a 'chunked' list of strings. The only requirement on 'chunked' is
94
that ''.join(lines) becomes a valid fulltext. A tuple of a single string
95
satisfies this, as does a list of lines.
97
:ivar sha1: None, or the sha1 of the content fulltext.
98
:ivar storage_kind: The native storage kind of this factory. Always
100
:ivar key: The key of this content. Each key is a tuple with a single
102
:ivar parents: A tuple of parent keys for self.key. If the object has
103
no parent information, None (as opposed to () for an empty list of
107
def __init__(self, key, parents, sha1, chunks):
108
"""Create a ContentFactory."""
110
self.storage_kind = 'chunked'
112
self.parents = parents
113
self._chunks = chunks
115
def get_bytes_as(self, storage_kind):
116
if storage_kind == 'chunked':
118
elif storage_kind == 'fulltext':
119
return ''.join(self._chunks)
120
raise errors.UnavailableRepresentation(self.key, storage_kind,
124
class FulltextContentFactory(ContentFactory):
125
"""Static data content factory.
127
This takes a fulltext when created and just returns that during
128
get_bytes_as('fulltext').
130
:ivar sha1: None, or the sha1 of the content fulltext.
131
:ivar storage_kind: The native storage kind of this factory. Always
133
:ivar key: The key of this content. Each key is a tuple with a single
135
:ivar parents: A tuple of parent keys for self.key. If the object has
136
no parent information, None (as opposed to () for an empty list of
140
def __init__(self, key, parents, sha1, text):
141
"""Create a ContentFactory."""
143
self.storage_kind = 'fulltext'
145
self.parents = parents
148
def get_bytes_as(self, storage_kind):
149
if storage_kind == self.storage_kind:
151
elif storage_kind == 'chunked':
153
raise errors.UnavailableRepresentation(self.key, storage_kind,
157
class AbsentContentFactory(ContentFactory):
158
"""A placeholder content factory for unavailable texts.
161
:ivar storage_kind: 'absent'.
162
:ivar key: The key of this content. Each key is a tuple with a single
167
def __init__(self, key):
168
"""Create a ContentFactory."""
170
self.storage_kind = 'absent'
175
class AdapterFactory(ContentFactory):
176
"""A content factory to adapt between key prefix's."""
178
def __init__(self, key, parents, adapted):
179
"""Create an adapter factory instance."""
181
self.parents = parents
182
self._adapted = adapted
184
def __getattr__(self, attr):
185
"""Return a member from the adapted object."""
186
if attr in ('key', 'parents'):
187
return self.__dict__[attr]
189
return getattr(self._adapted, attr)
192
def filter_absent(record_stream):
193
"""Adapt a record stream to remove absent records."""
194
for record in record_stream:
195
if record.storage_kind != 'absent':
199
class VersionedFile(object):
200
"""Versioned text file storage.
202
A versioned file manages versions of line-based text files,
203
keeping track of the originating version for each line.
205
To clients the "lines" of the file are represented as a list of
206
strings. These strings will typically have terminal newline
207
characters, but this is not required. In particular files commonly
208
do not have a newline at the end of the file.
210
Texts are identified by a version-id string.
214
def check_not_reserved_id(version_id):
215
revision.check_not_reserved_id(version_id)
217
def copy_to(self, name, transport):
218
"""Copy this versioned file to name on transport."""
219
raise NotImplementedError(self.copy_to)
221
def get_record_stream(self, versions, ordering, include_delta_closure):
222
"""Get a stream of records for versions.
224
:param versions: The versions to include. Each version is a tuple
226
:param ordering: Either 'unordered' or 'topological'. A topologically
227
sorted stream has compression parents strictly before their
229
:param include_delta_closure: If True then the closure across any
230
compression parents will be included (in the data content of the
231
stream, not in the emitted records). This guarantees that
232
'fulltext' can be used successfully on every record.
233
:return: An iterator of ContentFactory objects, each of which is only
234
valid until the iterator is advanced.
236
raise NotImplementedError(self.get_record_stream)
238
def has_version(self, version_id):
239
"""Returns whether version is present."""
240
raise NotImplementedError(self.has_version)
242
def insert_record_stream(self, stream):
243
"""Insert a record stream into this versioned file.
245
:param stream: A stream of records to insert.
247
:seealso VersionedFile.get_record_stream:
249
raise NotImplementedError
251
def add_lines(self, version_id, parents, lines, parent_texts=None,
252
left_matching_blocks=None, nostore_sha=None, random_id=False,
254
"""Add a single text on top of the versioned file.
256
Must raise RevisionAlreadyPresent if the new version is
257
already present in file history.
259
Must raise RevisionNotPresent if any of the given parents are
260
not present in file history.
262
:param lines: A list of lines. Each line must be a bytestring. And all
263
of them except the last must be terminated with \n and contain no
264
other \n's. The last line may either contain no \n's or a single
265
terminated \n. If the lines list does meet this constraint the add
266
routine may error or may succeed - but you will be unable to read
267
the data back accurately. (Checking the lines have been split
268
correctly is expensive and extremely unlikely to catch bugs so it
269
is not done at runtime unless check_content is True.)
270
:param parent_texts: An optional dictionary containing the opaque
271
representations of some or all of the parents of version_id to
272
allow delta optimisations. VERY IMPORTANT: the texts must be those
273
returned by add_lines or data corruption can be caused.
274
:param left_matching_blocks: a hint about which areas are common
275
between the text and its left-hand-parent. The format is
276
the SequenceMatcher.get_matching_blocks format.
277
:param nostore_sha: Raise ExistingContent and do not add the lines to
278
the versioned file if the digest of the lines matches this.
279
:param random_id: If True a random id has been selected rather than
280
an id determined by some deterministic process such as a converter
281
from a foreign VCS. When True the backend may choose not to check
282
for uniqueness of the resulting key within the versioned file, so
283
this should only be done when the result is expected to be unique
285
:param check_content: If True, the lines supplied are verified to be
286
bytestrings that are correctly formed lines.
287
:return: The text sha1, the number of bytes in the text, and an opaque
288
representation of the inserted version which can be provided
289
back to future add_lines calls in the parent_texts dictionary.
291
self._check_write_ok()
292
return self._add_lines(version_id, parents, lines, parent_texts,
293
left_matching_blocks, nostore_sha, random_id, check_content)
295
def _add_lines(self, version_id, parents, lines, parent_texts,
296
left_matching_blocks, nostore_sha, random_id, check_content):
297
"""Helper to do the class specific add_lines."""
298
raise NotImplementedError(self.add_lines)
300
def add_lines_with_ghosts(self, version_id, parents, lines,
301
parent_texts=None, nostore_sha=None, random_id=False,
302
check_content=True, left_matching_blocks=None):
303
"""Add lines to the versioned file, allowing ghosts to be present.
305
This takes the same parameters as add_lines and returns the same.
307
self._check_write_ok()
308
return self._add_lines_with_ghosts(version_id, parents, lines,
309
parent_texts, nostore_sha, random_id, check_content, left_matching_blocks)
311
def _add_lines_with_ghosts(self, version_id, parents, lines, parent_texts,
312
nostore_sha, random_id, check_content, left_matching_blocks):
313
"""Helper to do class specific add_lines_with_ghosts."""
314
raise NotImplementedError(self.add_lines_with_ghosts)
316
def check(self, progress_bar=None):
317
"""Check the versioned file for integrity."""
318
raise NotImplementedError(self.check)
320
def _check_lines_not_unicode(self, lines):
321
"""Check that lines being added to a versioned file are not unicode."""
323
if line.__class__ is not str:
324
raise errors.BzrBadParameterUnicode("lines")
326
def _check_lines_are_lines(self, lines):
327
"""Check that the lines really are full lines without inline EOL."""
329
if '\n' in line[:-1]:
330
raise errors.BzrBadParameterContainsNewline("lines")
332
def get_format_signature(self):
333
"""Get a text description of the data encoding in this file.
337
raise NotImplementedError(self.get_format_signature)
339
def make_mpdiffs(self, version_ids):
340
"""Create multiparent diffs for specified versions."""
341
knit_versions = set()
342
knit_versions.update(version_ids)
343
parent_map = self.get_parent_map(version_ids)
344
for version_id in version_ids:
346
knit_versions.update(parent_map[version_id])
348
raise errors.RevisionNotPresent(version_id, self)
349
# We need to filter out ghosts, because we can't diff against them.
350
knit_versions = set(self.get_parent_map(knit_versions).keys())
351
lines = dict(zip(knit_versions,
352
self._get_lf_split_line_list(knit_versions)))
354
for version_id in version_ids:
355
target = lines[version_id]
357
parents = [lines[p] for p in parent_map[version_id] if p in
360
# I don't know how this could ever trigger.
361
# parent_map[version_id] was already triggered in the previous
362
# for loop, and lines[p] has the 'if p in knit_versions' check,
363
# so we again won't have a KeyError.
364
raise errors.RevisionNotPresent(version_id, self)
366
left_parent_blocks = self._extract_blocks(version_id,
369
left_parent_blocks = None
370
diffs.append(multiparent.MultiParent.from_lines(target, parents,
374
def _extract_blocks(self, version_id, source, target):
377
def add_mpdiffs(self, records):
378
"""Add mpdiffs to this VersionedFile.
380
Records should be iterables of version, parents, expected_sha1,
381
mpdiff. mpdiff should be a MultiParent instance.
383
# Does this need to call self._check_write_ok()? (IanC 20070919)
385
mpvf = multiparent.MultiMemoryVersionedFile()
387
for version, parent_ids, expected_sha1, mpdiff in records:
388
versions.append(version)
389
mpvf.add_diff(mpdiff, version, parent_ids)
390
needed_parents = set()
391
for version, parent_ids, expected_sha1, mpdiff in records:
392
needed_parents.update(p for p in parent_ids
393
if not mpvf.has_version(p))
394
present_parents = set(self.get_parent_map(needed_parents).keys())
395
for parent_id, lines in zip(present_parents,
396
self._get_lf_split_line_list(present_parents)):
397
mpvf.add_version(lines, parent_id, [])
398
for (version, parent_ids, expected_sha1, mpdiff), lines in\
399
zip(records, mpvf.get_line_list(versions)):
400
if len(parent_ids) == 1:
401
left_matching_blocks = list(mpdiff.get_matching_blocks(0,
402
mpvf.get_diff(parent_ids[0]).num_lines()))
404
left_matching_blocks = None
406
_, _, version_text = self.add_lines_with_ghosts(version,
407
parent_ids, lines, vf_parents,
408
left_matching_blocks=left_matching_blocks)
409
except NotImplementedError:
410
# The vf can't handle ghosts, so add lines normally, which will
411
# (reasonably) fail if there are ghosts in the data.
412
_, _, version_text = self.add_lines(version,
413
parent_ids, lines, vf_parents,
414
left_matching_blocks=left_matching_blocks)
415
vf_parents[version] = version_text
416
sha1s = self.get_sha1s(versions)
417
for version, parent_ids, expected_sha1, mpdiff in records:
418
if expected_sha1 != sha1s[version]:
419
raise errors.VersionedFileInvalidChecksum(version)
421
def get_text(self, version_id):
422
"""Return version contents as a text string.
424
Raises RevisionNotPresent if version is not present in
427
return ''.join(self.get_lines(version_id))
428
get_string = get_text
430
def get_texts(self, version_ids):
431
"""Return the texts of listed versions as a list of strings.
433
Raises RevisionNotPresent if version is not present in
436
return [''.join(self.get_lines(v)) for v in version_ids]
438
def get_lines(self, version_id):
439
"""Return version contents as a sequence of lines.
441
Raises RevisionNotPresent if version is not present in
444
raise NotImplementedError(self.get_lines)
446
def _get_lf_split_line_list(self, version_ids):
447
return [StringIO(t).readlines() for t in self.get_texts(version_ids)]
449
def get_ancestry(self, version_ids, topo_sorted=True):
450
"""Return a list of all ancestors of given version(s). This
451
will not include the null revision.
453
This list will not be topologically sorted if topo_sorted=False is
456
Must raise RevisionNotPresent if any of the given versions are
457
not present in file history."""
458
if isinstance(version_ids, basestring):
459
version_ids = [version_ids]
460
raise NotImplementedError(self.get_ancestry)
462
def get_ancestry_with_ghosts(self, version_ids):
463
"""Return a list of all ancestors of given version(s). This
464
will not include the null revision.
466
Must raise RevisionNotPresent if any of the given versions are
467
not present in file history.
469
Ghosts that are known about will be included in ancestry list,
470
but are not explicitly marked.
472
raise NotImplementedError(self.get_ancestry_with_ghosts)
474
def get_parent_map(self, version_ids):
475
"""Get a map of the parents of version_ids.
477
:param version_ids: The version ids to look up parents for.
478
:return: A mapping from version id to parents.
480
raise NotImplementedError(self.get_parent_map)
482
def get_parents_with_ghosts(self, version_id):
483
"""Return version names for parents of version_id.
485
Will raise RevisionNotPresent if version_id is not present
488
Ghosts that are known about will be included in the parent list,
489
but are not explicitly marked.
492
return list(self.get_parent_map([version_id])[version_id])
494
raise errors.RevisionNotPresent(version_id, self)
496
def annotate(self, version_id):
497
"""Return a list of (version-id, line) tuples for version_id.
499
:raise RevisionNotPresent: If the given version is
500
not present in file history.
502
raise NotImplementedError(self.annotate)
504
def iter_lines_added_or_present_in_versions(self, version_ids=None,
506
"""Iterate over the lines in the versioned file from version_ids.
508
This may return lines from other versions. Each item the returned
509
iterator yields is a tuple of a line and a text version that that line
510
is present in (not introduced in).
512
Ordering of results is in whatever order is most suitable for the
513
underlying storage format.
515
If a progress bar is supplied, it may be used to indicate progress.
516
The caller is responsible for cleaning up progress bars (because this
519
NOTES: Lines are normalised: they will all have \n terminators.
520
Lines are returned in arbitrary order.
522
:return: An iterator over (line, version_id).
524
raise NotImplementedError(self.iter_lines_added_or_present_in_versions)
526
def plan_merge(self, ver_a, ver_b):
527
"""Return pseudo-annotation indicating how the two versions merge.
529
This is computed between versions a and b and their common
532
Weave lines present in none of them are skipped entirely.
535
killed-base Dead in base revision
536
killed-both Killed in each revision
539
unchanged Alive in both a and b (possibly created in both)
542
ghost-a Killed in a, unborn in b
543
ghost-b Killed in b, unborn in a
544
irrelevant Not in either revision
546
raise NotImplementedError(VersionedFile.plan_merge)
548
def weave_merge(self, plan, a_marker=TextMerge.A_MARKER,
549
b_marker=TextMerge.B_MARKER):
550
return PlanWeaveMerge(plan, a_marker, b_marker).merge_lines()[0]
553
class RecordingVersionedFilesDecorator(object):
554
"""A minimal versioned files that records calls made on it.
556
Only enough methods have been added to support tests using it to date.
558
:ivar calls: A list of the calls made; can be reset at any time by
562
def __init__(self, backing_vf):
563
"""Create a RecordingVersionedFilesDecorator decorating backing_vf.
565
:param backing_vf: The versioned file to answer all methods.
567
self._backing_vf = backing_vf
570
def add_lines(self, key, parents, lines, parent_texts=None,
571
left_matching_blocks=None, nostore_sha=None, random_id=False,
573
self.calls.append(("add_lines", key, parents, lines, parent_texts,
574
left_matching_blocks, nostore_sha, random_id, check_content))
575
return self._backing_vf.add_lines(key, parents, lines, parent_texts,
576
left_matching_blocks, nostore_sha, random_id, check_content)
579
self._backing_vf.check()
581
def get_parent_map(self, keys):
582
self.calls.append(("get_parent_map", copy(keys)))
583
return self._backing_vf.get_parent_map(keys)
585
def get_record_stream(self, keys, sort_order, include_delta_closure):
586
self.calls.append(("get_record_stream", list(keys), sort_order,
587
include_delta_closure))
588
return self._backing_vf.get_record_stream(keys, sort_order,
589
include_delta_closure)
591
def get_sha1s(self, keys):
592
self.calls.append(("get_sha1s", copy(keys)))
593
return self._backing_vf.get_sha1s(keys)
595
def iter_lines_added_or_present_in_keys(self, keys, pb=None):
596
self.calls.append(("iter_lines_added_or_present_in_keys", copy(keys)))
597
return self._backing_vf.iter_lines_added_or_present_in_keys(keys, pb=pb)
600
self.calls.append(("keys",))
601
return self._backing_vf.keys()
604
class OrderingVersionedFilesDecorator(RecordingVersionedFilesDecorator):
605
"""A VF that records calls, and returns keys in specific order.
607
:ivar calls: A list of the calls made; can be reset at any time by
611
def __init__(self, backing_vf, key_priority):
612
"""Create a RecordingVersionedFilesDecorator decorating backing_vf.
614
:param backing_vf: The versioned file to answer all methods.
615
:param key_priority: A dictionary defining what order keys should be
616
returned from an 'unordered' get_record_stream request.
617
Keys with lower priority are returned first, keys not present in
618
the map get an implicit priority of 0, and are returned in
619
lexicographical order.
621
RecordingVersionedFilesDecorator.__init__(self, backing_vf)
622
self._key_priority = key_priority
624
def get_record_stream(self, keys, sort_order, include_delta_closure):
625
self.calls.append(("get_record_stream", list(keys), sort_order,
626
include_delta_closure))
627
if sort_order == 'unordered':
629
return (self._key_priority.get(key, 0), key)
630
# Use a defined order by asking for the keys one-by-one from the
632
for key in sorted(keys, key=sort_key):
633
for record in self._backing_vf.get_record_stream([key],
634
'unordered', include_delta_closure):
637
for record in self._backing_vf.get_record_stream(keys, sort_order,
638
include_delta_closure):
642
class KeyMapper(object):
643
"""KeyMappers map between keys and underlying partitioned storage."""
646
"""Map key to an underlying storage identifier.
648
:param key: A key tuple e.g. ('file-id', 'revision-id').
649
:return: An underlying storage identifier, specific to the partitioning
652
raise NotImplementedError(self.map)
654
def unmap(self, partition_id):
655
"""Map a partitioned storage id back to a key prefix.
657
:param partition_id: The underlying partition id.
658
:return: As much of a key (or prefix) as is derivable from the partition
661
raise NotImplementedError(self.unmap)
664
class ConstantMapper(KeyMapper):
665
"""A key mapper that maps to a constant result."""
667
def __init__(self, result):
668
"""Create a ConstantMapper which will return result for all maps."""
669
self._result = result
672
"""See KeyMapper.map()."""
676
class URLEscapeMapper(KeyMapper):
677
"""Base class for use with transport backed storage.
679
This provides a map and unmap wrapper that respectively url escape and
680
unescape their outputs and inputs.
684
"""See KeyMapper.map()."""
685
return urllib.quote(self._map(key))
687
def unmap(self, partition_id):
688
"""See KeyMapper.unmap()."""
689
return self._unmap(urllib.unquote(partition_id))
692
class PrefixMapper(URLEscapeMapper):
693
"""A key mapper that extracts the first component of a key.
695
This mapper is for use with a transport based backend.
699
"""See KeyMapper.map()."""
702
def _unmap(self, partition_id):
703
"""See KeyMapper.unmap()."""
704
return (partition_id,)
707
class HashPrefixMapper(URLEscapeMapper):
708
"""A key mapper that combines the first component of a key with a hash.
710
This mapper is for use with a transport based backend.
714
"""See KeyMapper.map()."""
715
prefix = self._escape(key[0])
716
return "%02x/%s" % (adler32(prefix) & 0xff, prefix)
718
def _escape(self, prefix):
719
"""No escaping needed here."""
722
def _unmap(self, partition_id):
723
"""See KeyMapper.unmap()."""
724
return (self._unescape(osutils.basename(partition_id)),)
726
def _unescape(self, basename):
727
"""No unescaping needed for HashPrefixMapper."""
731
class HashEscapedPrefixMapper(HashPrefixMapper):
732
"""Combines the escaped first component of a key with a hash.
734
This mapper is for use with a transport based backend.
737
_safe = "abcdefghijklmnopqrstuvwxyz0123456789-_@,."
739
def _escape(self, prefix):
740
"""Turn a key element into a filesystem safe string.
742
This is similar to a plain urllib.quote, except
743
it uses specific safe characters, so that it doesn't
744
have to translate a lot of valid file ids.
746
# @ does not get escaped. This is because it is a valid
747
# filesystem character we use all the time, and it looks
748
# a lot better than seeing %40 all the time.
749
r = [((c in self._safe) and c or ('%%%02x' % ord(c)))
753
def _unescape(self, basename):
754
"""Escaped names are easily unescaped by urlutils."""
755
return urllib.unquote(basename)
758
def make_versioned_files_factory(versioned_file_factory, mapper):
759
"""Create a ThunkedVersionedFiles factory.
761
This will create a callable which when called creates a
762
ThunkedVersionedFiles on a transport, using mapper to access individual
763
versioned files, and versioned_file_factory to create each individual file.
765
def factory(transport):
766
return ThunkedVersionedFiles(transport, versioned_file_factory, mapper,
771
class VersionedFiles(object):
772
"""Storage for many versioned files.
774
This object allows a single keyspace for accessing the history graph and
775
contents of named bytestrings.
777
Currently no implementation allows the graph of different key prefixes to
778
intersect, but the API does allow such implementations in the future.
780
The keyspace is expressed via simple tuples. Any instance of VersionedFiles
781
may have a different length key-size, but that size will be constant for
782
all texts added to or retrieved from it. For instance, bzrlib uses
783
instances with a key-size of 2 for storing user files in a repository, with
784
the first element the fileid, and the second the version of that file.
786
The use of tuples allows a single code base to support several different
787
uses with only the mapping logic changing from instance to instance.
790
def add_lines(self, key, parents, lines, parent_texts=None,
791
left_matching_blocks=None, nostore_sha=None, random_id=False,
793
"""Add a text to the store.
795
:param key: The key tuple of the text to add.
796
:param parents: The parents key tuples of the text to add.
797
:param lines: A list of lines. Each line must be a bytestring. And all
798
of them except the last must be terminated with \n and contain no
799
other \n's. The last line may either contain no \n's or a single
800
terminating \n. If the lines list does meet this constraint the add
801
routine may error or may succeed - but you will be unable to read
802
the data back accurately. (Checking the lines have been split
803
correctly is expensive and extremely unlikely to catch bugs so it
804
is not done at runtime unless check_content is True.)
805
:param parent_texts: An optional dictionary containing the opaque
806
representations of some or all of the parents of version_id to
807
allow delta optimisations. VERY IMPORTANT: the texts must be those
808
returned by add_lines or data corruption can be caused.
809
:param left_matching_blocks: a hint about which areas are common
810
between the text and its left-hand-parent. The format is
811
the SequenceMatcher.get_matching_blocks format.
812
:param nostore_sha: Raise ExistingContent and do not add the lines to
813
the versioned file if the digest of the lines matches this.
814
:param random_id: If True a random id has been selected rather than
815
an id determined by some deterministic process such as a converter
816
from a foreign VCS. When True the backend may choose not to check
817
for uniqueness of the resulting key within the versioned file, so
818
this should only be done when the result is expected to be unique
820
:param check_content: If True, the lines supplied are verified to be
821
bytestrings that are correctly formed lines.
822
:return: The text sha1, the number of bytes in the text, and an opaque
823
representation of the inserted version which can be provided
824
back to future add_lines calls in the parent_texts dictionary.
826
raise NotImplementedError(self.add_lines)
828
def add_mpdiffs(self, records):
829
"""Add mpdiffs to this VersionedFile.
831
Records should be iterables of version, parents, expected_sha1,
832
mpdiff. mpdiff should be a MultiParent instance.
835
mpvf = multiparent.MultiMemoryVersionedFile()
837
for version, parent_ids, expected_sha1, mpdiff in records:
838
versions.append(version)
839
mpvf.add_diff(mpdiff, version, parent_ids)
840
needed_parents = set()
841
for version, parent_ids, expected_sha1, mpdiff in records:
842
needed_parents.update(p for p in parent_ids
843
if not mpvf.has_version(p))
844
# It seems likely that adding all the present parents as fulltexts can
845
# easily exhaust memory.
846
chunks_to_lines = osutils.chunks_to_lines
847
for record in self.get_record_stream(needed_parents, 'unordered',
849
if record.storage_kind == 'absent':
851
mpvf.add_version(chunks_to_lines(record.get_bytes_as('chunked')),
853
for (key, parent_keys, expected_sha1, mpdiff), lines in\
854
zip(records, mpvf.get_line_list(versions)):
855
if len(parent_keys) == 1:
856
left_matching_blocks = list(mpdiff.get_matching_blocks(0,
857
mpvf.get_diff(parent_keys[0]).num_lines()))
859
left_matching_blocks = None
860
version_sha1, _, version_text = self.add_lines(key,
861
parent_keys, lines, vf_parents,
862
left_matching_blocks=left_matching_blocks)
863
if version_sha1 != expected_sha1:
864
raise errors.VersionedFileInvalidChecksum(version)
865
vf_parents[key] = version_text
867
def annotate(self, key):
868
"""Return a list of (version-key, line) tuples for the text of key.
870
:raise RevisionNotPresent: If the key is not present.
872
raise NotImplementedError(self.annotate)
874
def check(self, progress_bar=None):
875
"""Check this object for integrity."""
876
raise NotImplementedError(self.check)
879
def check_not_reserved_id(version_id):
880
revision.check_not_reserved_id(version_id)
882
def _check_lines_not_unicode(self, lines):
883
"""Check that lines being added to a versioned file are not unicode."""
885
if line.__class__ is not str:
886
raise errors.BzrBadParameterUnicode("lines")
888
def _check_lines_are_lines(self, lines):
889
"""Check that the lines really are full lines without inline EOL."""
891
if '\n' in line[:-1]:
892
raise errors.BzrBadParameterContainsNewline("lines")
894
def get_parent_map(self, keys):
895
"""Get a map of the parents of keys.
897
:param keys: The keys to look up parents for.
898
:return: A mapping from keys to parents. Absent keys are absent from
901
raise NotImplementedError(self.get_parent_map)
903
def get_record_stream(self, keys, ordering, include_delta_closure):
904
"""Get a stream of records for keys.
906
:param keys: The keys to include.
907
:param ordering: Either 'unordered' or 'topological'. A topologically
908
sorted stream has compression parents strictly before their
910
:param include_delta_closure: If True then the closure across any
911
compression parents will be included (in the opaque data).
912
:return: An iterator of ContentFactory objects, each of which is only
913
valid until the iterator is advanced.
915
raise NotImplementedError(self.get_record_stream)
917
def get_sha1s(self, keys):
918
"""Get the sha1's of the texts for the given keys.
920
:param keys: The names of the keys to lookup
921
:return: a dict from key to sha1 digest. Keys of texts which are not
922
present in the store are not present in the returned
925
raise NotImplementedError(self.get_sha1s)
927
has_key = index._has_key_from_parent_map
929
def get_missing_compression_parent_keys(self):
930
"""Return an iterable of keys of missing compression parents.
932
Check this after calling insert_record_stream to find out if there are
933
any missing compression parents. If there are, the records that
934
depend on them are not able to be inserted safely. The precise
935
behaviour depends on the concrete VersionedFiles class in use.
937
Classes that do not support this will raise NotImplementedError.
939
raise NotImplementedError(self.get_missing_compression_parent_keys)
941
def insert_record_stream(self, stream):
942
"""Insert a record stream into this container.
944
:param stream: A stream of records to insert.
946
:seealso VersionedFile.get_record_stream:
948
raise NotImplementedError
950
def iter_lines_added_or_present_in_keys(self, keys, pb=None):
951
"""Iterate over the lines in the versioned files from keys.
953
This may return lines from other keys. Each item the returned
954
iterator yields is a tuple of a line and a text version that that line
955
is present in (not introduced in).
957
Ordering of results is in whatever order is most suitable for the
958
underlying storage format.
960
If a progress bar is supplied, it may be used to indicate progress.
961
The caller is responsible for cleaning up progress bars (because this
965
* Lines are normalised by the underlying store: they will all have \n
967
* Lines are returned in arbitrary order.
969
:return: An iterator over (line, key).
971
raise NotImplementedError(self.iter_lines_added_or_present_in_keys)
974
"""Return a iterable of the keys for all the contained texts."""
975
raise NotImplementedError(self.keys)
977
def make_mpdiffs(self, keys):
978
"""Create multiparent diffs for specified keys."""
979
keys_order = tuple(keys)
980
keys = frozenset(keys)
981
knit_keys = set(keys)
982
parent_map = self.get_parent_map(keys)
983
for parent_keys in parent_map.itervalues():
985
knit_keys.update(parent_keys)
986
missing_keys = keys - set(parent_map)
988
raise errors.RevisionNotPresent(list(missing_keys)[0], self)
989
# We need to filter out ghosts, because we can't diff against them.
990
maybe_ghosts = knit_keys - keys
991
ghosts = maybe_ghosts - set(self.get_parent_map(maybe_ghosts))
992
knit_keys.difference_update(ghosts)
994
chunks_to_lines = osutils.chunks_to_lines
995
for record in self.get_record_stream(knit_keys, 'topological', True):
996
lines[record.key] = chunks_to_lines(record.get_bytes_as('chunked'))
997
# line_block_dict = {}
998
# for parent, blocks in record.extract_line_blocks():
999
# line_blocks[parent] = blocks
1000
# line_blocks[record.key] = line_block_dict
1002
for key in keys_order:
1004
parents = parent_map[key] or []
1005
# Note that filtering knit_keys can lead to a parent difference
1006
# between the creation and the application of the mpdiff.
1007
parent_lines = [lines[p] for p in parents if p in knit_keys]
1008
if len(parent_lines) > 0:
1009
left_parent_blocks = self._extract_blocks(key, parent_lines[0],
1012
left_parent_blocks = None
1013
diffs.append(multiparent.MultiParent.from_lines(target,
1014
parent_lines, left_parent_blocks))
1017
missing_keys = index._missing_keys_from_parent_map
1019
def _extract_blocks(self, version_id, source, target):
1023
class ThunkedVersionedFiles(VersionedFiles):
1024
"""Storage for many versioned files thunked onto a 'VersionedFile' class.
1026
This object allows a single keyspace for accessing the history graph and
1027
contents of named bytestrings.
1029
Currently no implementation allows the graph of different key prefixes to
1030
intersect, but the API does allow such implementations in the future.
1033
def __init__(self, transport, file_factory, mapper, is_locked):
1034
"""Create a ThunkedVersionedFiles."""
1035
self._transport = transport
1036
self._file_factory = file_factory
1037
self._mapper = mapper
1038
self._is_locked = is_locked
1040
def add_lines(self, key, parents, lines, parent_texts=None,
1041
left_matching_blocks=None, nostore_sha=None, random_id=False,
1042
check_content=True):
1043
"""See VersionedFiles.add_lines()."""
1044
path = self._mapper.map(key)
1045
version_id = key[-1]
1046
parents = [parent[-1] for parent in parents]
1047
vf = self._get_vf(path)
1050
return vf.add_lines_with_ghosts(version_id, parents, lines,
1051
parent_texts=parent_texts,
1052
left_matching_blocks=left_matching_blocks,
1053
nostore_sha=nostore_sha, random_id=random_id,
1054
check_content=check_content)
1055
except NotImplementedError:
1056
return vf.add_lines(version_id, parents, lines,
1057
parent_texts=parent_texts,
1058
left_matching_blocks=left_matching_blocks,
1059
nostore_sha=nostore_sha, random_id=random_id,
1060
check_content=check_content)
1061
except errors.NoSuchFile:
1062
# parent directory may be missing, try again.
1063
self._transport.mkdir(osutils.dirname(path))
1065
return vf.add_lines_with_ghosts(version_id, parents, lines,
1066
parent_texts=parent_texts,
1067
left_matching_blocks=left_matching_blocks,
1068
nostore_sha=nostore_sha, random_id=random_id,
1069
check_content=check_content)
1070
except NotImplementedError:
1071
return vf.add_lines(version_id, parents, lines,
1072
parent_texts=parent_texts,
1073
left_matching_blocks=left_matching_blocks,
1074
nostore_sha=nostore_sha, random_id=random_id,
1075
check_content=check_content)
1077
def annotate(self, key):
1078
"""Return a list of (version-key, line) tuples for the text of key.
1080
:raise RevisionNotPresent: If the key is not present.
1083
path = self._mapper.map(prefix)
1084
vf = self._get_vf(path)
1085
origins = vf.annotate(key[-1])
1087
for origin, line in origins:
1088
result.append((prefix + (origin,), line))
1091
def check(self, progress_bar=None):
1092
"""See VersionedFiles.check()."""
1093
for prefix, vf in self._iter_all_components():
1096
def get_parent_map(self, keys):
1097
"""Get a map of the parents of keys.
1099
:param keys: The keys to look up parents for.
1100
:return: A mapping from keys to parents. Absent keys are absent from
1103
prefixes = self._partition_keys(keys)
1105
for prefix, suffixes in prefixes.items():
1106
path = self._mapper.map(prefix)
1107
vf = self._get_vf(path)
1108
parent_map = vf.get_parent_map(suffixes)
1109
for key, parents in parent_map.items():
1110
result[prefix + (key,)] = tuple(
1111
prefix + (parent,) for parent in parents)
1114
def _get_vf(self, path):
1115
if not self._is_locked():
1116
raise errors.ObjectNotLocked(self)
1117
return self._file_factory(path, self._transport, create=True,
1118
get_scope=lambda:None)
1120
def _partition_keys(self, keys):
1121
"""Turn keys into a dict of prefix:suffix_list."""
1124
prefix_keys = result.setdefault(key[:-1], [])
1125
prefix_keys.append(key[-1])
1128
def _get_all_prefixes(self):
1129
# Identify all key prefixes.
1130
# XXX: A bit hacky, needs polish.
1131
if type(self._mapper) == ConstantMapper:
1132
paths = [self._mapper.map(())]
1136
for quoted_relpath in self._transport.iter_files_recursive():
1137
path, ext = os.path.splitext(quoted_relpath)
1139
paths = list(relpaths)
1140
prefixes = [self._mapper.unmap(path) for path in paths]
1141
return zip(paths, prefixes)
1143
def get_record_stream(self, keys, ordering, include_delta_closure):
1144
"""See VersionedFiles.get_record_stream()."""
1145
# Ordering will be taken care of by each partitioned store; group keys
1148
for prefix, suffixes, vf in self._iter_keys_vf(keys):
1149
suffixes = [(suffix,) for suffix in suffixes]
1150
for record in vf.get_record_stream(suffixes, ordering,
1151
include_delta_closure):
1152
if record.parents is not None:
1153
record.parents = tuple(
1154
prefix + parent for parent in record.parents)
1155
record.key = prefix + record.key
1158
def _iter_keys_vf(self, keys):
1159
prefixes = self._partition_keys(keys)
1161
for prefix, suffixes in prefixes.items():
1162
path = self._mapper.map(prefix)
1163
vf = self._get_vf(path)
1164
yield prefix, suffixes, vf
1166
def get_sha1s(self, keys):
1167
"""See VersionedFiles.get_sha1s()."""
1169
for prefix,suffixes, vf in self._iter_keys_vf(keys):
1170
vf_sha1s = vf.get_sha1s(suffixes)
1171
for suffix, sha1 in vf_sha1s.iteritems():
1172
sha1s[prefix + (suffix,)] = sha1
1175
def insert_record_stream(self, stream):
1176
"""Insert a record stream into this container.
1178
:param stream: A stream of records to insert.
1180
:seealso VersionedFile.get_record_stream:
1182
for record in stream:
1183
prefix = record.key[:-1]
1184
key = record.key[-1:]
1185
if record.parents is not None:
1186
parents = [parent[-1:] for parent in record.parents]
1189
thunk_record = AdapterFactory(key, parents, record)
1190
path = self._mapper.map(prefix)
1191
# Note that this parses the file many times; we can do better but
1192
# as this only impacts weaves in terms of performance, it is
1194
vf = self._get_vf(path)
1195
vf.insert_record_stream([thunk_record])
1197
def iter_lines_added_or_present_in_keys(self, keys, pb=None):
1198
"""Iterate over the lines in the versioned files from keys.
1200
This may return lines from other keys. Each item the returned
1201
iterator yields is a tuple of a line and a text version that that line
1202
is present in (not introduced in).
1204
Ordering of results is in whatever order is most suitable for the
1205
underlying storage format.
1207
If a progress bar is supplied, it may be used to indicate progress.
1208
The caller is responsible for cleaning up progress bars (because this
1212
* Lines are normalised by the underlying store: they will all have \n
1214
* Lines are returned in arbitrary order.
1216
:return: An iterator over (line, key).
1218
for prefix, suffixes, vf in self._iter_keys_vf(keys):
1219
for line, version in vf.iter_lines_added_or_present_in_versions(suffixes):
1220
yield line, prefix + (version,)
1222
def _iter_all_components(self):
1223
for path, prefix in self._get_all_prefixes():
1224
yield prefix, self._get_vf(path)
1227
"""See VersionedFiles.keys()."""
1229
for prefix, vf in self._iter_all_components():
1230
for suffix in vf.versions():
1231
result.add(prefix + (suffix,))
1235
class _PlanMergeVersionedFile(VersionedFiles):
1236
"""A VersionedFile for uncommitted and committed texts.
1238
It is intended to allow merges to be planned with working tree texts.
1239
It implements only the small part of the VersionedFiles interface used by
1240
PlanMerge. It falls back to multiple versionedfiles for data not stored in
1241
_PlanMergeVersionedFile itself.
1243
:ivar: fallback_versionedfiles a list of VersionedFiles objects that can be
1244
queried for missing texts.
1247
def __init__(self, file_id):
1248
"""Create a _PlanMergeVersionedFile.
1250
:param file_id: Used with _PlanMerge code which is not yet fully
1251
tuple-keyspace aware.
1253
self._file_id = file_id
1254
# fallback locations
1255
self.fallback_versionedfiles = []
1256
# Parents for locally held keys.
1258
# line data for locally held keys.
1260
# key lookup providers
1261
self._providers = [DictParentsProvider(self._parents)]
1263
def plan_merge(self, ver_a, ver_b, base=None):
1264
"""See VersionedFile.plan_merge"""
1265
from bzrlib.merge import _PlanMerge
1267
return _PlanMerge(ver_a, ver_b, self, (self._file_id,)).plan_merge()
1268
old_plan = list(_PlanMerge(ver_a, base, self, (self._file_id,)).plan_merge())
1269
new_plan = list(_PlanMerge(ver_a, ver_b, self, (self._file_id,)).plan_merge())
1270
return _PlanMerge._subtract_plans(old_plan, new_plan)
1272
def plan_lca_merge(self, ver_a, ver_b, base=None):
1273
from bzrlib.merge import _PlanLCAMerge
1275
new_plan = _PlanLCAMerge(ver_a, ver_b, self, (self._file_id,), graph).plan_merge()
1278
old_plan = _PlanLCAMerge(ver_a, base, self, (self._file_id,), graph).plan_merge()
1279
return _PlanLCAMerge._subtract_plans(list(old_plan), list(new_plan))
1281
def add_lines(self, key, parents, lines):
1282
"""See VersionedFiles.add_lines
1284
Lines are added locally, not to fallback versionedfiles. Also, ghosts
1285
are permitted. Only reserved ids are permitted.
1287
if type(key) is not tuple:
1288
raise TypeError(key)
1289
if not revision.is_reserved_id(key[-1]):
1290
raise ValueError('Only reserved ids may be used')
1292
raise ValueError('Parents may not be None')
1294
raise ValueError('Lines may not be None')
1295
self._parents[key] = tuple(parents)
1296
self._lines[key] = lines
1298
def get_record_stream(self, keys, ordering, include_delta_closure):
1301
if key in self._lines:
1302
lines = self._lines[key]
1303
parents = self._parents[key]
1305
yield ChunkedContentFactory(key, parents, None, lines)
1306
for versionedfile in self.fallback_versionedfiles:
1307
for record in versionedfile.get_record_stream(
1308
pending, 'unordered', True):
1309
if record.storage_kind == 'absent':
1312
pending.remove(record.key)
1316
# report absent entries
1318
yield AbsentContentFactory(key)
1320
def get_parent_map(self, keys):
1321
"""See VersionedFiles.get_parent_map"""
1322
# We create a new provider because a fallback may have been added.
1323
# If we make fallbacks private we can update a stack list and avoid
1324
# object creation thrashing.
1327
if revision.NULL_REVISION in keys:
1328
keys.remove(revision.NULL_REVISION)
1329
result[revision.NULL_REVISION] = ()
1330
self._providers = self._providers[:1] + self.fallback_versionedfiles
1332
_StackedParentsProvider(self._providers).get_parent_map(keys))
1333
for key, parents in result.iteritems():
1335
result[key] = (revision.NULL_REVISION,)
1339
class PlanWeaveMerge(TextMerge):
1340
"""Weave merge that takes a plan as its input.
1342
This exists so that VersionedFile.plan_merge is implementable.
1343
Most callers will want to use WeaveMerge instead.
1346
def __init__(self, plan, a_marker=TextMerge.A_MARKER,
1347
b_marker=TextMerge.B_MARKER):
1348
TextMerge.__init__(self, a_marker, b_marker)
1351
def _merge_struct(self):
1356
def outstanding_struct():
1357
if not lines_a and not lines_b:
1359
elif ch_a and not ch_b:
1362
elif ch_b and not ch_a:
1364
elif lines_a == lines_b:
1367
yield (lines_a, lines_b)
1369
# We previously considered either 'unchanged' or 'killed-both' lines
1370
# to be possible places to resynchronize. However, assuming agreement
1371
# on killed-both lines may be too aggressive. -- mbp 20060324
1372
for state, line in self.plan:
1373
if state == 'unchanged':
1374
# resync and flush queued conflicts changes if any
1375
for struct in outstanding_struct():
1381
if state == 'unchanged':
1384
elif state == 'killed-a':
1386
lines_b.append(line)
1387
elif state == 'killed-b':
1389
lines_a.append(line)
1390
elif state == 'new-a':
1392
lines_a.append(line)
1393
elif state == 'new-b':
1395
lines_b.append(line)
1396
elif state == 'conflicted-a':
1398
lines_a.append(line)
1399
elif state == 'conflicted-b':
1401
lines_b.append(line)
1403
if state not in ('irrelevant', 'ghost-a', 'ghost-b',
1404
'killed-base', 'killed-both'):
1405
raise AssertionError(state)
1406
for struct in outstanding_struct():
1410
class WeaveMerge(PlanWeaveMerge):
1411
"""Weave merge that takes a VersionedFile and two versions as its input."""
1413
def __init__(self, versionedfile, ver_a, ver_b,
1414
a_marker=PlanWeaveMerge.A_MARKER, b_marker=PlanWeaveMerge.B_MARKER):
1415
plan = versionedfile.plan_merge(ver_a, ver_b)
1416
PlanWeaveMerge.__init__(self, plan, a_marker, b_marker)
1419
class VirtualVersionedFiles(VersionedFiles):
1420
"""Dummy implementation for VersionedFiles that uses other functions for
1421
obtaining fulltexts and parent maps.
1423
This is always on the bottom of the stack and uses string keys
1424
(rather than tuples) internally.
1427
def __init__(self, get_parent_map, get_lines):
1428
"""Create a VirtualVersionedFiles.
1430
:param get_parent_map: Same signature as Repository.get_parent_map.
1431
:param get_lines: Should return lines for specified key or None if
1434
super(VirtualVersionedFiles, self).__init__()
1435
self._get_parent_map = get_parent_map
1436
self._get_lines = get_lines
1438
def check(self, progressbar=None):
1439
"""See VersionedFiles.check.
1441
:note: Always returns True for VirtualVersionedFiles.
1445
def add_mpdiffs(self, records):
1446
"""See VersionedFiles.mpdiffs.
1448
:note: Not implemented for VirtualVersionedFiles.
1450
raise NotImplementedError(self.add_mpdiffs)
1452
def get_parent_map(self, keys):
1453
"""See VersionedFiles.get_parent_map."""
1454
return dict([((k,), tuple([(p,) for p in v]))
1455
for k,v in self._get_parent_map([k for (k,) in keys]).iteritems()])
1457
def get_sha1s(self, keys):
1458
"""See VersionedFiles.get_sha1s."""
1461
lines = self._get_lines(k)
1462
if lines is not None:
1463
if not isinstance(lines, list):
1464
raise AssertionError
1465
ret[(k,)] = osutils.sha_strings(lines)
1468
def get_record_stream(self, keys, ordering, include_delta_closure):
1469
"""See VersionedFiles.get_record_stream."""
1470
for (k,) in list(keys):
1471
lines = self._get_lines(k)
1472
if lines is not None:
1473
if not isinstance(lines, list):
1474
raise AssertionError
1475
yield ChunkedContentFactory((k,), None,
1476
sha1=osutils.sha_strings(lines),
1479
yield AbsentContentFactory((k,))
1481
def iter_lines_added_or_present_in_keys(self, keys, pb=None):
1482
"""See VersionedFile.iter_lines_added_or_present_in_versions()."""
1483
for i, (key,) in enumerate(keys):
1485
pb.update("iterating texts", i, len(keys))
1486
for l in self._get_lines(key):
1490
def network_bytes_to_kind_and_offset(network_bytes):
1491
"""Strip of a record kind from the front of network_bytes.
1493
:param network_bytes: The bytes of a record.
1494
:return: A tuple (storage_kind, offset_of_remaining_bytes)
1496
line_end = network_bytes.find('\n')
1497
storage_kind = network_bytes[:line_end]
1498
return storage_kind, line_end + 1
1501
class NetworkRecordStream(object):
1502
"""A record_stream which reconstitures a serialised stream."""
1504
def __init__(self, bytes_iterator):
1505
"""Create a NetworkRecordStream.
1507
:param bytes_iterator: An iterator of bytes. Each item in this
1508
iterator should have been obtained from a record_streams'
1509
record.get_bytes_as(record.storage_kind) call.
1511
self._bytes_iterator = bytes_iterator
1512
self._kind_factory = {'knit-ft-gz':knit.knit_network_to_record,
1513
'knit-delta-gz':knit.knit_network_to_record,
1514
'knit-annotated-ft-gz':knit.knit_network_to_record,
1515
'knit-annotated-delta-gz':knit.knit_network_to_record,
1516
'knit-delta-closure':knit.knit_delta_closure_to_records,
1522
:return: An iterator as per VersionedFiles.get_record_stream().
1524
for bytes in self._bytes_iterator:
1525
storage_kind, line_end = network_bytes_to_kind_and_offset(bytes)
1526
for record in self._kind_factory[storage_kind](
1527
storage_kind, bytes, line_end):