281
281
to_rf.join(from_rf, version_ids=revs)
284
class Inter1and2Helper(object):
285
"""Helper for operations that convert data from model 1 and 2
287
This is for use by fetchers and converters.
290
def __init__(self, source, target):
293
:param source: The repository data comes from
294
:param target: The repository data goes to
299
def iter_rev_trees(self, revs):
300
"""Iterate through RevisionTrees efficiently.
302
Additionally, the inventory's revision_id is set if unset.
304
Trees are retrieved in batches of 100, and then yielded in the order
307
:param revs: A list of revision ids
310
for tree in self.source.revision_trees(revs[:100]):
311
if tree.inventory.revision_id is None:
312
tree.inventory.revision_id = tree.get_revision_id()
316
def generate_root_texts(self, revs):
317
"""Generate VersionedFiles for all root ids.
319
:param revs: the revisions to include
321
inventory_weave = self.source.get_inventory_weave()
324
to_store = self.target.weave_store
325
for tree in self.iter_rev_trees(revs):
326
revision_id = tree.inventory.root.revision
327
root_id = tree.inventory.root.file_id
328
parents = inventory_weave.get_parents(revision_id)
329
if root_id not in versionedfile:
330
versionedfile[root_id] = to_store.get_weave_or_empty(root_id,
331
self.target.get_transaction())
332
parent_texts[root_id] = versionedfile[root_id].add_lines(
333
revision_id, parents, [], parent_texts)
335
def regenerate_inventory(self, revs):
336
"""Generate a new inventory versionedfile in target, convertin data.
338
The inventory is retrieved from the source, (deserializing it), and
339
stored in the target (reserializing it in a different format).
340
:param revs: The revisions to include
342
inventory_weave = self.source.get_inventory_weave()
343
for tree in self.iter_rev_trees(revs):
344
parents = inventory_weave.get_parents(tree.get_revision_id())
345
self.target.add_inventory(tree.get_revision_id(), tree.inventory,
349
class Model1toKnit2Fetcher(GenericRepoFetcher):
350
"""Fetch from a Model1 repository into a Knit2 repository
352
def __init__(self, to_repository, from_repository, last_revision=None,
354
self.helper = Inter1and2Helper(from_repository, to_repository)
355
GenericRepoFetcher.__init__(self, to_repository, from_repository,
358
def _fetch_weave_texts(self, revs):
359
GenericRepoFetcher._fetch_weave_texts(self, revs)
360
# Now generate a weave for the tree root
361
self.helper.generate_root_texts(revs)
363
def _fetch_inventory_weave(self, revs):
364
self.helper.regenerate_inventory(revs)
367
class Knit1to2Fetcher(KnitRepoFetcher):
368
"""Fetch from a Knit1 repository into a Knit2 repository"""
370
def __init__(self, to_repository, from_repository, last_revision=None,
372
self.helper = Inter1and2Helper(from_repository, to_repository)
373
KnitRepoFetcher.__init__(self, to_repository, from_repository,
376
def _fetch_weave_texts(self, revs):
377
KnitRepoFetcher._fetch_weave_texts(self, revs)
378
# Now generate a weave for the tree root
379
self.helper.generate_root_texts(revs)
381
def _fetch_inventory_weave(self, revs):
382
self.helper.regenerate_inventory(revs)
284
385
class Fetcher(object):
285
386
"""Backwards compatibility glue for branch.fetch()."""