~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-16 02:42:33 UTC
  • mfrom: (2906.1.1 reconcile-speed)
  • Revision ID: pqm@pqm.ubuntu.com-20071016024233-6fmmyqoh0cfnsni8
(Andrew Bennetts) Speed up reconcile by not repeatedly fetching the full inventories, by cache heads and parents queries, and by fetching revision trees in batches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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()
 
2498
        self.rev_heads = {}
2496
2499
 
2497
2500
    def add_revision_text_versions(self, tree):
2498
2501
        """Cache text version data from the supplied revision tree"""
2507
2510
        try:
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)
 
2513
            try:
 
2514
                tree = self.repository.revision_tree(revision_id)
 
2515
            except errors.RevisionNotPresent:
 
2516
                self.revision_versions[revision_id] = inv_revisions = {}
 
2517
            else:
 
2518
                inv_revisions = self.add_revision_text_versions(tree)
2512
2519
        return inv_revisions.get(file_id)
2513
2520
 
 
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.
 
2528
        while revs:
 
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)
 
2533
            revs = revs[100:]
 
2534
 
 
2535
    def get_parents(self, revision_id):
 
2536
        try:
 
2537
            return self.revision_parents[revision_id]
 
2538
        except KeyError:
 
2539
            parents = self.repository.get_parents([revision_id])[0]
 
2540
            self.revision_parents[revision_id] = parents
 
2541
            return parents
 
2542
 
 
2543
    def heads(self, revision_ids):
 
2544
        revision_ids = tuple(revision_ids)
 
2545
        try:
 
2546
            return self.rev_heads[revision_ids]
 
2547
        except KeyError:
 
2548
            heads = self.repo_graph.heads(revision_ids)
 
2549
            self.rev_heads[revision_ids] = heads
 
2550
            return heads
2514
2551
 
2515
2552
class VersionedFileChecker(object):
2516
2553
 
2524
2561
            file_id, revision_id)
2525
2562
        if text_revision is None:
2526
2563
            return None
2527
 
        parents_of_text_revision = self.repository.get_parents(
2528
 
            [text_revision])[0]
 
2564
        parents_of_text_revision = self.revision_versions.get_parents(
 
2565
            text_revision)
2529
2566
        parents_from_inventories = []
2530
2567
        for parent in parents_of_text_revision:
2531
2568
            if parent == _mod_revision.NULL_REVISION:
2532
2569
                continue
2533
 
            try:
2534
 
                inventory = self.repository.get_inventory(parent)
2535
 
            except errors.RevisionNotPresent:
2536
 
                pass
2537
 
            else:
2538
 
                try:
2539
 
                    introduced_in = inventory[file_id].revision
2540
 
                except errors.NoSuchId:
2541
 
                    pass
2542
 
                else:
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,
 
2571
                    parent)
 
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: