249
251
# yet, and are unlikely to in non-rich-root environments anyway.
250
252
root_id_order.sort(key=operator.itemgetter(0))
251
253
# Create a record stream containing the roots to create.
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())]
254
from bzrlib.graph import FrozenHeadsCache
255
graph = FrozenHeadsCache(graph)
256
new_roots_stream = _new_root_data_stream(
257
root_id_order, rev_id_to_root_id, parent_map, self.source, graph)
258
return [('texts', new_roots_stream)]
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]