555
555
:returns: format_signature, list of (version, options, length, parents),
558
required_versions = set([osutils.safe_revision_id(v) for v in
558
if not isinstance(required_versions, set):
559
required_versions = set(required_versions)
560
560
# we don't care about inclusions, the caller cares.
561
561
# but we need to setup a list of records to visit.
562
562
for version_id in required_versions:
612
612
def get_delta(self, version_id):
613
613
"""Get a delta for constructing version from some other version."""
614
version_id = osutils.safe_revision_id(version_id)
615
614
self.check_not_reserved_id(version_id)
616
615
parents = self.get_parents(version_id)
655
654
def get_sha1s(self, version_ids):
656
655
"""See VersionedFile.get_sha1()."""
657
version_ids = [osutils.safe_revision_id(v) for v in version_ids]
658
656
record_map = self._get_record_map(version_ids)
659
657
# record entry 2 is the 'digest'.
660
658
return [record_map[v][2] for v in version_ids]
667
665
def has_ghost(self, version_id):
668
666
"""True if there is a ghost reference in the file to version_id."""
669
version_id = osutils.safe_revision_id(version_id)
670
667
# maybe we have it
671
668
if self.has_version(version_id):
732
729
"""See VersionedFile.has_version."""
733
730
if 'evil' in debug.debug_flags:
734
731
trace.mutter_callsite(2, "has_version is a LBYL scenario")
735
version_id = osutils.safe_revision_id(version_id)
736
732
return self._index.has_version(version_id)
738
734
__contains__ = has_version
914
911
options.append('fulltext')
915
# get mixed annotation + content and feed it into the
917
store_lines = self.factory.lower_fulltext(content)
918
size, bytes = self._data._record_to_data(version_id, digest,
912
# isinstance is slower and we have no hierarchy.
913
if self.factory.__class__ == KnitPlainFactory:
914
# Use the already joined bytes saving iteration time in
916
size, bytes = self._data._record_to_data(version_id, digest,
919
# get mixed annotation + content and feed it into the
921
store_lines = self.factory.lower_fulltext(content)
922
size, bytes = self._data._record_to_data(version_id, digest,
921
925
access_memo = self._data.add_raw_records([size], bytes)[0]
922
926
self._index.add_versions(
969
973
def get_line_list(self, version_ids):
970
974
"""Return the texts of listed versions as a list of strings."""
971
version_ids = [osutils.safe_revision_id(v) for v in version_ids]
972
975
for version_id in version_ids:
973
976
self.check_not_reserved_id(version_id)
974
977
text_map, content_map = self._get_content_maps(version_ids)
1042
1045
"""See VersionedFile.iter_lines_added_or_present_in_versions()."""
1043
1046
if version_ids is None:
1044
1047
version_ids = self.versions()
1046
version_ids = [osutils.safe_revision_id(v) for v in version_ids]
1048
1049
pb = progress.DummyProgress()
1049
1050
# we don't care about inclusions, the caller cares.
1086
1087
The order is undefined, allowing for different optimisations in
1087
1088
the underlying implementation.
1089
version_ids = [osutils.safe_revision_id(version_id) for
1090
version_id in version_ids]
1091
1090
return self._index.iter_parents(version_ids)
1093
1092
def num_versions(self):
1099
1098
def annotate_iter(self, version_id):
1100
1099
"""See VersionedFile.annotate_iter."""
1101
version_id = osutils.safe_revision_id(version_id)
1102
1100
return self.factory.annotate_iter(self, version_id)
1104
1102
def get_parents(self, version_id):
1115
1112
def get_parents_with_ghosts(self, version_id):
1116
1113
"""See VersionedFile.get_parents."""
1117
version_id = osutils.safe_revision_id(version_id)
1119
1115
return self._index.get_parents_with_ghosts(version_id)
1120
1116
except KeyError:
1135
1130
versions = [versions]
1136
1131
if not versions:
1138
versions = [osutils.safe_revision_id(v) for v in versions]
1139
1133
return self._index.get_ancestry_with_ghosts(versions)
1141
1135
def plan_merge(self, ver_a, ver_b):
1142
1136
"""See VersionedFile.plan_merge."""
1143
ver_a = osutils.safe_revision_id(ver_a)
1144
ver_b = osutils.safe_revision_id(ver_b)
1145
1137
ancestors_b = set(self.get_ancestry(ver_b, topo_sorted=False))
1147
1138
ancestors_a = set(self.get_ancestry(ver_a, topo_sorted=False))
1148
1139
annotated_a = self.annotate(ver_a)
1149
1140
annotated_b = self.annotate(ver_b)
1989
1980
def _open_file(self):
1990
1981
return self._access.open_file()
1992
def _record_to_data(self, version_id, digest, lines):
1983
def _record_to_data(self, version_id, digest, lines, dense_lines=None):
1993
1984
"""Convert version_id, digest, lines into a raw data block.
1986
:param dense_lines: The bytes of lines but in a denser form. For
1987
instance, if lines is a list of 1000 bytestrings each ending in \n,
1988
dense_lines may be a list with one line in it, containing all the
1989
1000's lines and their \n's. Using dense_lines if it is already
1990
known is a win because the string join to create bytes in this
1991
function spends less time resizing the final string.
1995
1992
:return: (len, a StringIO instance with the raw data ready to read.)
1997
bytes = (''.join(chain(
1994
# Note: using a string copy here increases memory pressure with e.g.
1995
# ISO's, but it is about 3 seconds faster on a 1.2Ghz intel machine
1996
# when doing the initial commit of a mozilla tree. RBC 20070921
1997
bytes = ''.join(chain(
1998
1998
["version %s %d %s\n" % (version_id,
2002
["end %s\n" % version_id])))
2001
dense_lines or lines,
2002
["end %s\n" % version_id]))
2003
2003
assert bytes.__class__ == str
2004
2004
compressed_bytes = bytes_to_gzip(bytes)
2005
2005
return len(compressed_bytes), compressed_bytes