~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

(Andrew Bennetts) Reconcile will force file versions with unreferenced parents to be stored as fulltexts (fixes bug 155730).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2658
2658
        # XXX: this loop is very similar to
2659
2659
        # bzrlib.fetch.Inter1and2Helper.iter_rev_trees.
2660
2660
        while revs:
 
2661
            mutter('%d revisions left to prepopulate', len(revs))
2661
2662
            for tree in self.repository.revision_trees(revs[:100]):
2662
2663
                if tree.inventory.revision_id is None:
2663
2664
                    tree.inventory.revision_id = tree.get_revision_id()
2672
2673
            self.revision_parents[revision_id] = parents
2673
2674
            return parents
2674
2675
 
 
2676
    def used_file_versions(self):
 
2677
        """Return a set of (revision_id, file_id) pairs for each file version
 
2678
        referenced by any inventory cached by this _RevisionTextVersionCache.
 
2679
 
 
2680
        If the entire repository has been cached, this can be used to find all
 
2681
        file versions that are actually referenced by inventories.  Thus any
 
2682
        other file version is completely unused and can be removed safely.
 
2683
        """
 
2684
        result = set()
 
2685
        for inventory_summary in self.revision_versions.itervalues():
 
2686
            result.update(inventory_summary.items())
 
2687
        return result
 
2688
 
2675
2689
 
2676
2690
class VersionedFileChecker(object):
2677
2691
 
2681
2695
        self.repository = repository
2682
2696
    
2683
2697
    def calculate_file_version_parents(self, revision_id, file_id):
 
2698
        """Calculate the correct parents for a file version according to
 
2699
        the inventories.
 
2700
        """
2684
2701
        text_revision = self.revision_versions.get_text_version(
2685
2702
            file_id, revision_id)
2686
2703
        if text_revision is None:
2703
2720
        return tuple(new_parents)
2704
2721
 
2705
2722
    def check_file_version_parents(self, weave, file_id):
2706
 
        result = {}
 
2723
        """Check the parents stored in a versioned file are correct.
 
2724
 
 
2725
        It also detects file versions that are not referenced by their
 
2726
        corresponding revision's inventory.
 
2727
 
 
2728
        :returns: A tuple of (wrong_parents, dangling_file_versions).
 
2729
            wrong_parents is a dict mapping {revision_id: (stored_parents,
 
2730
            correct_parents)} for each revision_id where the stored parents
 
2731
            are not correct.  dangling_file_versions is a set of (file_id,
 
2732
            revision_id) tuples for versions that are present in this versioned
 
2733
            file, but not used by the corresponding inventory.
 
2734
        """
 
2735
        wrong_parents = {}
 
2736
        dangling_file_versions = set()
2707
2737
        for num, revision_id in enumerate(self.planned_revisions):
2708
2738
            correct_parents = self.calculate_file_version_parents(
2709
2739
                revision_id, file_id)
2711
2741
                continue
2712
2742
            text_revision = self.revision_versions.get_text_version(
2713
2743
                file_id, revision_id)
2714
 
            knit_parents = tuple(weave.get_parents(text_revision))
 
2744
            try:
 
2745
                knit_parents = tuple(weave.get_parents(revision_id))
 
2746
            except errors.RevisionNotPresent:
 
2747
                knit_parents = None
 
2748
            if text_revision != revision_id:
 
2749
                # This file version is not referenced by its corresponding
 
2750
                # inventory!
 
2751
                dangling_file_versions.add((file_id, revision_id))
2715
2752
            if correct_parents != knit_parents:
2716
 
                result[revision_id] = (knit_parents, correct_parents)
2717
 
        return result
 
2753
                wrong_parents[revision_id] = (knit_parents, correct_parents)
 
2754
        return wrong_parents, dangling_file_versions