332
332
((version_id, options, access_memo, parents),),
333
333
random_id=random_id)
334
334
return digest, text_length, content
337
class ImportRevisionLoader2(RevisionLoader2):
338
"""A RevisionLoader (new Repository API) optimised for importing.
340
This implementation caches serialised inventory texts.
341
Fine-grained control over when inventories are stored as fulltexts
345
def __init__(self, repo, parent_texts_to_cache=1, fulltext_when=None,
347
"""See AbstractRevisionLoader.__init__.
349
:param repository: the target repository
350
:param parent_text_to_cache: the number of parent texts to cache
351
:para fulltext_when: if non None, a function to call to decide
352
whether to fulltext the inventory or not. The revision count
353
is passed as a parameter and the result is treated as a boolean.
355
RevisionLoader2.__init__(self, repo)
356
self.inv_parent_texts = lru_cache.LRUCache(parent_texts_to_cache)
357
self.fulltext_when = fulltext_when
358
self.random_ids = random_ids
359
self.revision_count = 0
361
def _add_inventory(self, revision_id, inv, parents):
362
"""See RevisionLoader._add_inventory."""
363
# Code taken from bzrlib.repository.add_inventory
365
if not repo.is_in_write_group():
366
raise AssertionError("%r not in write group" % (repo,))
367
_mod_revision.check_not_reserved_id(revision_id)
368
if not (inv.revision_id is None or inv.revision_id == revision_id):
369
raise AssertionError(
370
"Mismatch between inventory revision"
371
" id and insertion revid (%r, %r)"
372
% (inv.revision_id, revision_id))
374
raise AssertionError()
375
inv_lines = repo._serialise_inventory_to_lines(inv)
376
parents = [(parent,) for parent in parents]
377
sha1, num_bytes, parent_text = repo.inventories.add_lines(
378
(revision_id,), parents, inv_lines, check_content=False)
379
self.inv_parent_texts[revision_id] = parent_text