51
47
def __init__(self, to_repository, from_repository, last_revision=None,
52
find_ghosts=True, fetch_spec=None):
48
pb=None, find_ghosts=True, fetch_spec=None):
53
49
"""Create a repo fetcher.
55
51
:param last_revision: If set, try to limit to the data this revision
57
53
:param find_ghosts: If True search the entire history for ghosts.
54
:param pb: ProgressBar object to use; deprecated and ignored.
55
This method will just create one on top of the stack.
58
symbol_versioning.warn(
59
symbol_versioning.deprecated_in((1, 14, 0))
60
% "pb parameter to RepoFetcher.__init__")
61
# and for simplicity it is in fact ignored
59
62
# repository.fetch has the responsibility for short-circuiting
60
63
# attempts to copy between a repository and itself.
61
64
self.to_repository = to_repository
243
249
# yet, and are unlikely to in non-rich-root environments anyway.
244
250
root_id_order.sort(key=operator.itemgetter(0))
245
251
# 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
new_roots_stream = _new_root_data_stream(
251
root_id_order, rev_id_to_root_id, parent_map, self.source, graph)
252
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
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().
275
for root_key in root_keys_to_create:
276
root_id, rev_id = root_key
277
parent_keys = _parent_keys_for_root_version(
278
root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph)
279
yield versionedfile.FulltextContentFactory(
280
root_key, parent_keys, None, '')
283
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.
289
# Include direct parents of the revision, but only if they used the same
290
# root_id and are heads.
291
rev_parents = parent_map[rev_id]
293
for parent_id in rev_parents:
294
if parent_id == NULL_REVISION:
296
if parent_id not in rev_id_to_root_id_map:
297
# We probably didn't read this revision, go spend the extra effort
300
tree = repo.revision_tree(parent_id)
301
except errors.NoSuchRevision:
302
# Ghost, fill out rev_id_to_root_id in case we encounter this
304
# But set parent_root_id to None since we don't really know
305
parent_root_id = None
307
parent_root_id = tree.get_root_id()
308
rev_id_to_root_id_map[parent_id] = None
310
# rev_id_to_root_id_map[parent_id] = parent_root_id
311
# memory consumption maybe?
313
parent_root_id = rev_id_to_root_id_map[parent_id]
314
if root_id == parent_root_id:
315
# With stacking we _might_ want to refer to a non-local revision,
316
# but this code path only applies when we have the full content
317
# available, so ghosts really are ghosts, not just the edge of
319
parent_ids.append(parent_id)
321
# root_id may be in the parent anyway.
323
tree = repo.revision_tree(parent_id)
324
except errors.NoSuchRevision:
325
# ghost, can't refer to it.
329
parent_ids.append(tree.inventory[root_id].revision)
330
except errors.NoSuchId:
333
# Drop non-head parents
335
graph = repo.get_graph()
336
heads = graph.heads(parent_ids)
338
for parent_id in parent_ids:
339
if parent_id in heads and parent_id not in selected_ids:
340
selected_ids.append(parent_id)
341
parent_keys = [(root_id, parent_id) for parent_id in selected_ids]
253
for key in root_id_order:
254
root_id, rev_id = key
255
rev_parents = parent_map[rev_id]
256
# We drop revision parents with different file-ids, because
257
# that represents a rename of the root to a different location
258
# - its not actually a parent for us. (We could look for that
259
# file id in the revision tree at considerably more expense,
260
# but for now this is sufficient (and reconcile will catch and
261
# correct this anyway).
262
# When a parent revision is a ghost, we guess that its root id
263
# was unchanged (rather than trimming it from the parent list).
264
parent_keys = tuple((root_id, parent) for parent in rev_parents
265
if parent != NULL_REVISION and
266
rev_id_to_root_id.get(parent, root_id) == root_id)
267
yield FulltextContentFactory(key, parent_keys, None, '')
268
return [('texts', yield_roots())]