~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-05-12 04:54:04 UTC
  • mfrom: (4309.1.8 all-referenced-texts-check)
  • Revision ID: pqm@pqm.ubuntu.com-20090512045404-3gjp1vrdmrjpwjgh
(andrew) Pass missing parent inventories check if all referenced texts are present

Show diffs side-by-side

added added

removed removed

Lines of Context:
2688
2688
        return key[:-1], key[-1]
2689
2689
 
2690
2690
 
 
2691
class _KeyRefs(object):
 
2692
 
 
2693
    def __init__(self):
 
2694
        # dict mapping 'key' to 'set of keys referring to that key'
 
2695
        self.refs = {}
 
2696
 
 
2697
    def add_references(self, key, refs):
 
2698
        # Record the new references
 
2699
        for referenced in refs:
 
2700
            try:
 
2701
                needed_by = self.refs[referenced]
 
2702
            except KeyError:
 
2703
                needed_by = self.refs[referenced] = set()
 
2704
            needed_by.add(key)
 
2705
        # Discard references satisfied by the new key
 
2706
        self.add_key(key)
 
2707
 
 
2708
    def get_unsatisfied_refs(self):
 
2709
        return self.refs.iterkeys()
 
2710
 
 
2711
    def add_key(self, key):
 
2712
        try:
 
2713
            del self.refs[key]
 
2714
        except KeyError:
 
2715
            # No keys depended on this key.  That's ok.
 
2716
            pass
 
2717
 
 
2718
    def add_keys(self, keys):
 
2719
        for key in keys:
 
2720
            self.add_key(key)
 
2721
 
 
2722
    def get_referrers(self):
 
2723
        result = set()
 
2724
        for referrers in self.refs.itervalues():
 
2725
            result.update(referrers)
 
2726
        return result
 
2727
 
 
2728
 
2691
2729
class _KnitGraphIndex(object):
2692
2730
    """A KnitVersionedFiles index layered on GraphIndex."""
2693
2731
 
2723
2761
        self._is_locked = is_locked
2724
2762
        self._missing_compression_parents = set()
2725
2763
        if track_external_parent_refs:
2726
 
            self._external_parent_refs = set()
 
2764
            self._key_dependencies = _KeyRefs()
2727
2765
        else:
2728
 
            self._external_parent_refs = None
 
2766
            self._key_dependencies = None
2729
2767
 
2730
2768
    def __repr__(self):
2731
2769
        return "%s(%r)" % (self.__class__.__name__, self._graph_index)
2755
2793
 
2756
2794
        keys = {}
2757
2795
        compression_parents = set()
2758
 
        parent_refs = self._external_parent_refs
 
2796
        key_dependencies = self._key_dependencies
2759
2797
        for (key, options, access_memo, parents) in records:
2760
2798
            if self._parents:
2761
2799
                parents = tuple(parents)
2762
 
                if parent_refs is not None:
2763
 
                    parent_refs.update(parents)
2764
 
                    parent_refs.discard(key)
 
2800
                if key_dependencies is not None:
 
2801
                    key_dependencies.add_references(key, parents)
2765
2802
            index, pos, size = access_memo
2766
2803
            if 'no-eol' in options:
2767
2804
                value = 'N'
2829
2866
            new_missing = graph_index.external_references(ref_list_num=1)
2830
2867
            new_missing.difference_update(self.get_parent_map(new_missing))
2831
2868
            self._missing_compression_parents.update(new_missing)
2832
 
        if self._external_parent_refs is not None:
 
2869
        if self._key_dependencies is not None:
2833
2870
            # Add parent refs from graph_index (and discard parent refs that
2834
2871
            # the graph_index has).
2835
2872
            for node in graph_index.iter_all_entries():
2836
 
                self._external_parent_refs.update(node[3][0])
2837
 
                self._external_parent_refs.discard(node[1])
 
2873
                self._key_dependencies.add_references(node[1], node[3][0])
2838
2874
 
2839
2875
    def get_missing_compression_parents(self):
2840
2876
        """Return the keys of missing compression parents.
2847
2883
    def get_missing_parents(self):
2848
2884
        """Return the keys of missing parents."""
2849
2885
        # We may have false positives, so filter those out.
2850
 
        self._external_parent_refs.difference_update(
2851
 
            self.get_parent_map(self._external_parent_refs))
2852
 
        return frozenset(self._external_parent_refs)
 
2886
        self._key_dependencies.add_keys(
 
2887
            self.get_parent_map(self._key_dependencies.get_unsatisfied_refs()))
 
2888
        return frozenset(self._key_dependencies.get_unsatisfied_refs())
2853
2889
 
2854
2890
    def _check_read(self):
2855
2891
        """raise if reads are not permitted."""