51
52
def __init__(self, to_repository, from_repository, last_revision=None,
52
find_ghosts=True, fetch_spec=None):
53
pb=None, find_ghosts=True, fetch_spec=None):
53
54
"""Create a repo fetcher.
55
56
:param last_revision: If set, try to limit to the data this revision
57
58
:param find_ghosts: If True search the entire history for ghosts.
59
:param pb: ProgressBar object to use; deprecated and ignored.
60
This method will just create one on top of the stack.
59
# repository.fetch has the responsibility for short-circuiting
60
# attempts to copy between a repository and itself.
63
symbol_versioning.warn(
64
symbol_versioning.deprecated_in((1, 14, 0))
65
% "pb parameter to RepoFetcher.__init__")
66
# and for simplicity it is in fact ignored
67
if to_repository.has_same_location(from_repository):
68
# repository.fetch should be taking care of this case.
69
raise errors.BzrError('RepoFetcher run '
70
'between two objects at the same location: '
71
'%r and %r' % (to_repository, from_repository))
61
72
self.to_repository = to_repository
62
73
self.from_repository = from_repository
63
74
self.sink = to_repository._get_sink()
243
254
# yet, and are unlikely to in non-rich-root environments anyway.
244
255
root_id_order.sort(key=operator.itemgetter(0))
245
256
# Create a record stream containing the roots to create.
247
# XXX: not covered by tests, should have a flag to always run
248
# this. -- mbp 20100129
249
graph = self.source_repo.get_known_graph_ancestry(revs)
250
257
new_roots_stream = _new_root_data_stream(
251
root_id_order, rev_id_to_root_id, parent_map, self.source, graph)
258
root_id_order, rev_id_to_root_id, parent_map, self.source)
252
259
return [('texts', new_roots_stream)]
255
def _get_rich_root_heads_graph(source_repo, revision_ids):
256
"""Get a Graph object suitable for asking heads() for new rich roots."""
260
262
def _new_root_data_stream(
261
root_keys_to_create, rev_id_to_root_id_map, parent_map, repo, graph=None):
262
"""Generate a texts substream of synthesised root entries.
264
Used in fetches that do rich-root upgrades.
266
:param root_keys_to_create: iterable of (root_id, rev_id) pairs describing
267
the root entries to create.
268
:param rev_id_to_root_id_map: dict of known rev_id -> root_id mappings for
269
calculating the parents. If a parent rev_id is not found here then it
270
will be recalculated.
271
:param parent_map: a parent map for all the revisions in
273
:param graph: a graph to use instead of repo.get_graph().
263
root_keys_to_create, rev_id_to_root_id_map, parent_map, repo):
275
264
for root_key in root_keys_to_create:
276
265
root_id, rev_id = root_key
277
266
parent_keys = _parent_keys_for_root_version(
278
root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph)
267
root_id, rev_id, rev_id_to_root_id_map, parent_map, repo)
279
268
yield versionedfile.FulltextContentFactory(
280
269
root_key, parent_keys, None, '')
283
272
def _parent_keys_for_root_version(
284
root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph=None):
285
"""Get the parent keys for a given root id.
287
A helper function for _new_root_data_stream.
273
root_id, rev_id, rev_id_to_root_id_map, parent_map, repo):
274
"""Get the parent keys for a given root id."""
289
275
# Include direct parents of the revision, but only if they used the same
290
276
# root_id and are heads.
291
277
rev_parents = parent_map[rev_id]