47
51
def __init__(self, to_repository, from_repository, last_revision=None,
48
pb=None, find_ghosts=True, fetch_spec=None):
52
find_ghosts=True, fetch_spec=None):
49
53
"""Create a repo fetcher.
51
55
:param last_revision: If set, try to limit to the data this revision
53
57
:param find_ghosts: If True search the entire history for ghosts.
54
:param _write_group_acquired_callable: Don't use; this parameter only
55
exists to facilitate a hack done in InterPackRepo.fetch. We would
56
like to remove this parameter.
57
:param pb: ProgressBar object to use; deprecated and ignored.
58
This method will just create one on top of the stack.
61
symbol_versioning.warn(
62
symbol_versioning.deprecated_in((1, 14, 0))
63
% "pb parameter to RepoFetcher.__init__")
64
# and for simplicity it is in fact ignored
65
if to_repository.has_same_location(from_repository):
66
# repository.fetch should be taking care of this case.
67
raise errors.BzrError('RepoFetcher run '
68
'between two objects at the same location: '
69
'%r and %r' % (to_repository, from_repository))
59
# repository.fetch has the responsibility for short-circuiting
60
# attempts to copy between a repository and itself.
70
61
self.to_repository = to_repository
71
62
self.from_repository = from_repository
72
63
self.sink = to_repository._get_sink()
255
246
# yet, and are unlikely to in non-rich-root environments anyway.
256
247
root_id_order.sort(key=operator.itemgetter(0))
257
248
# Create a record stream containing the roots to create.
259
for key in root_id_order:
260
root_id, rev_id = key
261
rev_parents = parent_map[rev_id]
262
# We drop revision parents with different file-ids, because
263
# that represents a rename of the root to a different location
264
# - its not actually a parent for us. (We could look for that
265
# file id in the revision tree at considerably more expense,
266
# but for now this is sufficient (and reconcile will catch and
267
# correct this anyway).
268
# When a parent revision is a ghost, we guess that its root id
269
# was unchanged (rather than trimming it from the parent list).
270
parent_keys = tuple((root_id, parent) for parent in rev_parents
271
if parent != NULL_REVISION and
272
rev_id_to_root_id.get(parent, root_id) == root_id)
273
yield FulltextContentFactory(key, parent_keys, None, '')
274
return [('texts', yield_roots())]
249
if len(revs) > self.known_graph_threshold:
250
graph = self.source.get_known_graph_ancestry(revs)
251
new_roots_stream = _new_root_data_stream(
252
root_id_order, rev_id_to_root_id, parent_map, self.source, graph)
253
return [('texts', new_roots_stream)]
256
def _get_rich_root_heads_graph(source_repo, revision_ids):
257
"""Get a Graph object suitable for asking heads() for new rich roots."""
261
def _new_root_data_stream(
262
root_keys_to_create, rev_id_to_root_id_map, parent_map, repo, graph=None):
263
"""Generate a texts substream of synthesised root entries.
265
Used in fetches that do rich-root upgrades.
267
:param root_keys_to_create: iterable of (root_id, rev_id) pairs describing
268
the root entries to create.
269
:param rev_id_to_root_id_map: dict of known rev_id -> root_id mappings for
270
calculating the parents. If a parent rev_id is not found here then it
271
will be recalculated.
272
:param parent_map: a parent map for all the revisions in
274
:param graph: a graph to use instead of repo.get_graph().
276
for root_key in root_keys_to_create:
277
root_id, rev_id = root_key
278
parent_keys = _parent_keys_for_root_version(
279
root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph)
280
yield versionedfile.FulltextContentFactory(
281
root_key, parent_keys, None, '')
284
def _parent_keys_for_root_version(
285
root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph=None):
286
"""Get the parent keys for a given root id.
288
A helper function for _new_root_data_stream.
290
# Include direct parents of the revision, but only if they used the same
291
# root_id and are heads.
292
rev_parents = parent_map[rev_id]
294
for parent_id in rev_parents:
295
if parent_id == NULL_REVISION:
297
if parent_id not in rev_id_to_root_id_map:
298
# We probably didn't read this revision, go spend the extra effort
301
tree = repo.revision_tree(parent_id)
302
except errors.NoSuchRevision:
303
# Ghost, fill out rev_id_to_root_id in case we encounter this
305
# But set parent_root_id to None since we don't really know
306
parent_root_id = None
308
parent_root_id = tree.get_root_id()
309
rev_id_to_root_id_map[parent_id] = None
311
# rev_id_to_root_id_map[parent_id] = parent_root_id
312
# memory consumption maybe?
314
parent_root_id = rev_id_to_root_id_map[parent_id]
315
if root_id == parent_root_id:
316
# With stacking we _might_ want to refer to a non-local revision,
317
# but this code path only applies when we have the full content
318
# available, so ghosts really are ghosts, not just the edge of
320
parent_ids.append(parent_id)
322
# root_id may be in the parent anyway.
324
tree = repo.revision_tree(parent_id)
325
except errors.NoSuchRevision:
326
# ghost, can't refer to it.
330
parent_ids.append(tree.inventory[root_id].revision)
331
except errors.NoSuchId:
334
# Drop non-head parents
336
graph = repo.get_graph()
337
heads = graph.heads(parent_ids)
339
for parent_id in parent_ids:
340
if parent_id in heads and parent_id not in selected_ids:
341
selected_ids.append(parent_id)
342
parent_keys = [(root_id, parent_id) for parent_id in selected_ids]