43
from bzrlib.graph import DictParentsProvider, Graph, _StackedParentsProvider
45
from bzrlib.graph import DictParentsProvider, Graph, StackedParentsProvider
44
46
from bzrlib.transport.memory import MemoryTransport
46
48
from bzrlib.inter import InterObject
47
49
from bzrlib.registry import Registry
48
50
from bzrlib.symbol_versioning import *
49
51
from bzrlib.textmerge import TextMerge
50
from bzrlib.util import bencode
52
from bzrlib import bencode
53
55
adapter_registry = Registry()
175
177
self.parents = None
179
def get_bytes_as(self, storage_kind):
180
raise ValueError('A request was made for key: %s, but that'
181
' content is not available, and the calling'
182
' code does not handle if it is missing.'
178
186
class AdapterFactory(ContentFactory):
179
187
"""A content factory to adapt between key prefix's."""
830
838
raise NotImplementedError(self.add_lines)
840
def _add_text(self, key, parents, text, nostore_sha=None, random_id=False):
841
"""Add a text to the store.
843
This is a private function for use by CommitBuilder.
845
:param key: The key tuple of the text to add. If the last element is
846
None, a CHK string will be generated during the addition.
847
:param parents: The parents key tuples of the text to add.
848
:param text: A string containing the text to be committed.
849
:param nostore_sha: Raise ExistingContent and do not add the lines to
850
the versioned file if the digest of the lines matches this.
851
:param random_id: If True a random id has been selected rather than
852
an id determined by some deterministic process such as a converter
853
from a foreign VCS. When True the backend may choose not to check
854
for uniqueness of the resulting key within the versioned file, so
855
this should only be done when the result is expected to be unique
857
:param check_content: If True, the lines supplied are verified to be
858
bytestrings that are correctly formed lines.
859
:return: The text sha1, the number of bytes in the text, and an opaque
860
representation of the inserted version which can be provided
861
back to future _add_text calls in the parent_texts dictionary.
863
# The default implementation just thunks over to .add_lines(),
864
# inefficient, but it works.
865
return self.add_lines(key, parents, osutils.split_lines(text),
866
nostore_sha=nostore_sha,
832
870
def add_mpdiffs(self, records):
833
871
"""Add mpdiffs to this VersionedFile.
876
914
raise NotImplementedError(self.annotate)
878
916
def check(self, progress_bar=None):
879
"""Check this object for integrity."""
917
"""Check this object for integrity.
919
:param progress_bar: A progress bar to output as the check progresses.
920
:param keys: Specific keys within the VersionedFiles to check. When
921
this parameter is not None, check() becomes a generator as per
922
get_record_stream. The difference to get_record_stream is that
923
more or deeper checks will be performed.
924
:return: None, or if keys was supplied a generator as per
880
927
raise NotImplementedError(self.check)
895
942
if '\n' in line[:-1]:
896
943
raise errors.BzrBadParameterContainsNewline("lines")
945
def get_known_graph_ancestry(self, keys):
946
"""Get a KnownGraph instance with the ancestry of keys."""
947
# most basic implementation is a loop around get_parent_map
951
this_parent_map = self.get_parent_map(pending)
952
parent_map.update(this_parent_map)
954
map(pending.update, this_parent_map.itervalues())
955
pending = pending.difference(parent_map)
956
kg = _mod_graph.KnownGraph(parent_map)
898
959
def get_parent_map(self, keys):
899
960
"""Get a map of the parents of keys.
1092
1153
result.append((prefix + (origin,), line))
1095
def check(self, progress_bar=None):
1156
def get_annotator(self):
1157
return annotate.Annotator(self)
1159
def check(self, progress_bar=None, keys=None):
1096
1160
"""See VersionedFiles.check()."""
1161
# XXX: This is over-enthusiastic but as we only thunk for Weaves today
1162
# this is tolerable. Ideally we'd pass keys down to check() and
1163
# have the older VersiondFile interface updated too.
1097
1164
for prefix, vf in self._iter_all_components():
1166
if keys is not None:
1167
return self.get_record_stream(keys, 'unordered', True)
1100
1169
def get_parent_map(self, keys):
1101
1170
"""Get a map of the parents of keys.
1333
1402
result[revision.NULL_REVISION] = ()
1334
1403
self._providers = self._providers[:1] + self.fallback_versionedfiles
1336
_StackedParentsProvider(self._providers).get_parent_map(keys))
1405
StackedParentsProvider(self._providers).get_parent_map(keys))
1337
1406
for key, parents in result.iteritems():
1338
1407
if parents == ():
1339
1408
result[key] = (revision.NULL_REVISION,)
1403
1472
elif state == 'conflicted-b':
1404
1473
ch_b = ch_a = True
1405
1474
lines_b.append(line)
1475
elif state == 'killed-both':
1476
# This counts as a change, even though there is no associated
1407
1480
if state not in ('irrelevant', 'ghost-a', 'ghost-b',
1408
'killed-base', 'killed-both'):
1409
1482
raise AssertionError(state)
1410
1483
for struct in outstanding_struct():
1513
1586
record.get_bytes_as(record.storage_kind) call.
1515
1588
self._bytes_iterator = bytes_iterator
1516
self._kind_factory = {'knit-ft-gz':knit.knit_network_to_record,
1517
'knit-delta-gz':knit.knit_network_to_record,
1518
'knit-annotated-ft-gz':knit.knit_network_to_record,
1519
'knit-annotated-delta-gz':knit.knit_network_to_record,
1520
'knit-delta-closure':knit.knit_delta_closure_to_records,
1521
'fulltext':fulltext_network_to_record,
1522
'groupcompress-block':groupcompress.network_block_to_records,
1589
self._kind_factory = {
1590
'fulltext': fulltext_network_to_record,
1591
'groupcompress-block': groupcompress.network_block_to_records,
1592
'knit-ft-gz': knit.knit_network_to_record,
1593
'knit-delta-gz': knit.knit_network_to_record,
1594
'knit-annotated-ft-gz': knit.knit_network_to_record,
1595
'knit-annotated-delta-gz': knit.knit_network_to_record,
1596
'knit-delta-closure': knit.knit_delta_closure_to_records,
1525
1599
def read(self):