2493
2493
def __init__(self, repository):
2494
2494
self.repository = repository
2495
2495
self.revision_versions = {}
2496
self.revision_parents = {}
2497
self.repo_graph = self.repository.get_graph()
2497
2500
def add_revision_text_versions(self, tree):
2498
2501
"""Cache text version data from the supplied revision tree"""
2508
2511
inv_revisions = self.revision_versions[revision_id]
2509
2512
except KeyError:
2510
tree = self.repository.revision_tree(revision_id)
2511
inv_revisions = self.add_revision_text_versions(tree)
2514
tree = self.repository.revision_tree(revision_id)
2515
except errors.RevisionNotPresent:
2516
self.revision_versions[revision_id] = inv_revisions = {}
2518
inv_revisions = self.add_revision_text_versions(tree)
2512
2519
return inv_revisions.get(file_id)
2521
def prepopulate_revs(self, revision_ids):
2522
# Filter out versions that we don't have an inventory for, so that the
2523
# revision_trees() call won't fail.
2524
inv_weave = self.repository.get_inventory_weave()
2525
revs = [r for r in revision_ids if inv_weave.has_version(r)]
2526
# XXX: this loop is very similar to
2527
# bzrlib.fetch.Inter1and2Helper.iter_rev_trees.
2529
for tree in self.repository.revision_trees(revs[:100]):
2530
if tree.inventory.revision_id is None:
2531
tree.inventory.revision_id = tree.get_revision_id()
2532
self.add_revision_text_versions(tree)
2535
def get_parents(self, revision_id):
2537
return self.revision_parents[revision_id]
2539
parents = self.repository.get_parents([revision_id])[0]
2540
self.revision_parents[revision_id] = parents
2543
def heads(self, revision_ids):
2544
revision_ids = tuple(revision_ids)
2546
return self.rev_heads[revision_ids]
2548
heads = self.repo_graph.heads(revision_ids)
2549
self.rev_heads[revision_ids] = heads
2515
2552
class VersionedFileChecker(object):
2524
2561
file_id, revision_id)
2525
2562
if text_revision is None:
2527
parents_of_text_revision = self.repository.get_parents(
2564
parents_of_text_revision = self.revision_versions.get_parents(
2529
2566
parents_from_inventories = []
2530
2567
for parent in parents_of_text_revision:
2531
2568
if parent == _mod_revision.NULL_REVISION:
2534
inventory = self.repository.get_inventory(parent)
2535
except errors.RevisionNotPresent:
2539
introduced_in = inventory[file_id].revision
2540
except errors.NoSuchId:
2543
parents_from_inventories.append(introduced_in)
2544
graph = self.repository.get_graph()
2545
heads = set(graph.heads(parents_from_inventories))
2570
introduced_in = self.revision_versions.get_text_version(file_id,
2572
if introduced_in is not None:
2573
parents_from_inventories.append(introduced_in)
2574
heads = set(self.revision_versions.heads(parents_from_inventories))
2546
2575
new_parents = []
2547
2576
for parent in parents_from_inventories:
2548
2577
if parent in heads and parent not in new_parents: