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