140
140
metadata = {b'parents': parents,
141
141
b'storage_kind': b'mpdiff'}
142
142
self._add_record(bytes, {b'parents': parents,
143
b'storage_kind': b'fulltext'}, repo_kind, revision_id, None)
143
b'storage_kind': b'fulltext'}, repo_kind, revision_id, None)
145
145
def add_info_record(self, kwargs):
146
146
"""Add an info record to the bundle
155
155
def encode_name(content_kind, revision_id, file_id=None):
156
156
"""Encode semantic ids as a container name"""
157
157
if content_kind not in ('revision', 'file', 'inventory', 'signature',
159
159
raise ValueError(content_kind)
160
160
if content_kind == 'file':
161
161
if file_id is None:
334
334
"""Write bundle records for all revisions of all files"""
336
336
altered_fileids = self.repository.fileids_altered_by_revision_ids(
338
338
for file_id, revision_ids in viewitems(altered_fileids):
339
339
for revision_id in revision_ids:
340
340
text_keys.append((file_id, revision_id))
344
344
"""Write bundle records for all revisions and signatures"""
345
345
inv_vf = self.repository.inventories
346
346
topological_order = [key[-1] for key in multiparent.topo_iter_keys(
347
inv_vf, self.revision_keys)]
347
inv_vf, self.revision_keys)]
348
348
revision_order = topological_order
349
349
if self.target is not None and self.target in self.revision_ids:
350
350
# Make sure the target revision is always the last entry
390
390
parents = parent_map.get(revision_id, None)
391
391
revision_text = revision_to_bytes(revision)
392
392
self.bundle.add_fulltext_record(revision_text, parents,
393
'revision', revision_id)
393
'revision', revision_id)
395
395
self.bundle.add_fulltext_record(
396
396
self.repository.get_signature_text(
397
revision_id), parents, 'signature', revision_id)
397
revision_id), parents, 'signature', revision_id)
398
398
except errors.NoSuchRevision:
435
435
class BundleInfoV4(object):
437
437
"""Provide (most of) the BundleInfo interface"""
438
439
def __init__(self, fileobj, serializer):
439
440
self._fileobj = fileobj
440
441
self._serializer = serializer
479
480
self.__real_revisions = []
480
481
bundle_reader = self.get_bundle_reader()
481
482
for bytes, metadata, repo_kind, revision_id, file_id in \
482
bundle_reader.iter_records():
483
bundle_reader.iter_records():
483
484
if repo_kind == 'info':
485
486
self._serializer.get_source_serializer(metadata)
531
532
added_inv = set()
532
533
target_revision = None
533
534
for bytes, metadata, repo_kind, revision_id, file_id in\
534
self._container.iter_records():
535
self._container.iter_records():
535
536
if repo_kind == 'info':
536
537
if self._info is not None:
537
538
raise AssertionError()
538
539
self._handle_info(metadata)
539
540
if (pending_file_records and
540
(repo_kind, file_id) != ('file', current_file)):
541
(repo_kind, file_id) != ('file', current_file)):
541
542
# Flush the data for a single file - prevents memory
542
543
# spiking due to buffering all files in memory.
543
544
self._install_mp_records_keys(self._repository.texts,
544
pending_file_records)
545
pending_file_records)
545
546
current_file = None
546
547
del pending_file_records[:]
547
548
if len(pending_inventory_records) > 0 and repo_kind != 'inventory':
548
549
self._install_inventory_records(pending_inventory_records)
549
550
pending_inventory_records = []
550
551
if repo_kind == 'inventory':
551
pending_inventory_records.append(((revision_id,), metadata, bytes))
552
pending_inventory_records.append(
553
((revision_id,), metadata, bytes))
552
554
if repo_kind == 'revision':
553
555
target_revision = revision_id
554
556
self._install_revision(revision_id, metadata, bytes)
556
558
self._install_signature(revision_id, metadata, bytes)
557
559
if repo_kind == 'file':
558
560
current_file = file_id
559
pending_file_records.append(((file_id, revision_id), metadata, bytes))
560
self._install_mp_records_keys(self._repository.texts, pending_file_records)
561
pending_file_records.append(
562
((file_id, revision_id), metadata, bytes))
563
self._install_mp_records_keys(
564
self._repository.texts, pending_file_records)
561
565
return target_revision
563
567
def _handle_info(self, info):
625
629
to_string = self._source_serializer.write_inventory_to_string
626
630
for parent_inv in self._repository.iter_inventories(
628
632
p_text = to_string(parent_inv)
629
633
inventory_cache[parent_inv.revision_id] = parent_inv
630
634
cached_parent_texts[parent_inv.revision_id] = p_text
633
637
parent_texts = [cached_parent_texts[parent_id]
634
638
for parent_id in parent_ids
635
if parent_id not in ghosts]
639
if parent_id not in ghosts]
636
640
return parent_texts
638
642
def _install_inventory_records(self, records):
639
643
if (self._info[b'serializer'] == self._repository._serializer.format_num
640
and self._repository._serializer.support_altered_by_hack):
644
and self._repository._serializer.support_altered_by_hack):
641
645
return self._install_mp_records_keys(self._repository.inventories,
643
647
# Use a 10MB text cache, since these are string xml inventories. Note
644
648
# that 10MB is fairly small for large projects (a single inventory can
645
649
# be >5MB). Another possibility is to cache 10-20 inventory texts
647
inventory_text_cache = lru_cache.LRUSizeCache(10*1024*1024)
651
inventory_text_cache = lru_cache.LRUSizeCache(10 * 1024 * 1024)
648
652
# Also cache the in-memory representation. This allows us to create
649
653
# inventory deltas to apply rather than calling add_inventory from
650
654
# scratch each time.
665
669
# it would have to cast to a list of lines, which we get back
666
670
# as lines and then cast back to a string.
667
671
target_lines = multiparent.MultiParent.from_patch(bytes
669
673
inv_text = b''.join(target_lines)
671
675
sha1 = osutils.sha_string(inv_text)
687
691
delta = target_inv._make_delta(parent_inv)
688
692
self._repository.add_inventory_by_delta(parent_ids[0],
689
delta, revision_id, parent_ids)
693
delta, revision_id, parent_ids)
690
694
except errors.UnsupportedInventoryKind:
691
695
raise errors.IncompatibleRevision(repr(self._repository))
692
696
inventory_cache[revision_id] = target_inv
696
700
if self.update_root:
697
701
text_key = (target_inv.root.file_id, revision_id)
698
702
parent_keys = [(target_inv.root.file_id, parent) for
699
parent in parent_ids]
703
parent in parent_ids]
700
704
self._repository.texts.add_lines(text_key, parent_keys, [])
701
705
elif not self._repository.supports_rich_root():
702
706
if target_inv.root.revision != revision_id: