282
281
to_rf.join(from_rf, version_ids=revs)
285
class Inter1and2Helper(object):
286
"""Helper for operations that convert data from model 1 and 2
288
This is for use by fetchers and converters.
291
def __init__(self, source, target):
294
:param source: The repository data comes from
295
:param target: The repository data goes to
300
def iter_rev_trees(self, revs):
301
"""Iterate through RevisionTrees efficiently.
303
Additionally, the inventory's revision_id is set if unset.
305
Trees are retrieved in batches of 100, and then yielded in the order
308
:param revs: A list of revision ids
311
for tree in self.source.revision_trees(revs[:100]):
312
if tree.inventory.revision_id is None:
313
tree.inventory.revision_id = tree.get_revision_id()
317
def generate_root_texts(self, revs):
318
"""Generate VersionedFiles for all root ids.
320
:param revs: the revisions to include
322
inventory_weave = self.source.get_inventory_weave()
325
to_store = self.target.weave_store
326
for tree in self.iter_rev_trees(revs):
327
revision_id = tree.inventory.root.revision
328
root_id = tree.inventory.root.file_id
329
parents = inventory_weave.get_parents(revision_id)
330
if root_id not in versionedfile:
331
versionedfile[root_id] = to_store.get_weave_or_empty(root_id,
332
self.target.get_transaction())
333
parent_texts[root_id] = versionedfile[root_id].add_lines(
334
revision_id, parents, [], parent_texts)
336
def regenerate_inventory(self, revs):
337
"""Generate a new inventory versionedfile in target, convertin data.
339
The inventory is retrieved from the source, (deserializing it), and
340
stored in the target (reserializing it in a different format).
341
:param revs: The revisions to include
343
inventory_weave = self.source.get_inventory_weave()
344
for tree in self.iter_rev_trees(revs):
345
parents = inventory_weave.get_parents(tree.get_revision_id())
346
self.target.add_inventory(tree.get_revision_id(), tree.inventory,
350
class Model1toKnit2Fetcher(GenericRepoFetcher):
351
"""Fetch from a Model1 repository into a Knit2 repository
353
def __init__(self, to_repository, from_repository, last_revision=None,
355
self.helper = Inter1and2Helper(from_repository, to_repository)
356
GenericRepoFetcher.__init__(self, to_repository, from_repository,
359
def _fetch_weave_texts(self, revs):
360
GenericRepoFetcher._fetch_weave_texts(self, revs)
361
# Now generate a weave for the tree root
362
self.helper.generate_root_texts(revs)
364
def _fetch_inventory_weave(self, revs):
365
self.helper.regenerate_inventory(revs)
368
class Knit1to2Fetcher(KnitRepoFetcher):
369
"""Fetch from a Knit1 repository into a Knit2 repository"""
371
def __init__(self, to_repository, from_repository, last_revision=None,
373
self.helper = Inter1and2Helper(from_repository, to_repository)
374
KnitRepoFetcher.__init__(self, to_repository, from_repository,
377
def _fetch_weave_texts(self, revs):
378
KnitRepoFetcher._fetch_weave_texts(self, revs)
379
# Now generate a weave for the tree root
380
self.helper.generate_root_texts(revs)
382
def _fetch_inventory_weave(self, revs):
383
self.helper.regenerate_inventory(revs)
386
284
class Fetcher(object):
387
285
"""Backwards compatibility glue for branch.fetch()."""