~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Andrew Bennetts
  • Date: 2009-09-01 06:32:42 UTC
  • mto: (4634.6.23 2.0)
  • mto: This revision was merged to the branch mainline in revision 4676.
  • Revision ID: andrew.bennetts@canonical.com-20090901063242-96on706kiblvtnsf
Put new key tracking in _KeyRefs rather than alongside it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2770
2770
 
2771
2771
class _KeyRefs(object):
2772
2772
 
2773
 
    def __init__(self):
 
2773
    def __init__(self, track_new_keys=False):
2774
2774
        # dict mapping 'key' to 'set of keys referring to that key'
2775
2775
        self.refs = {}
 
2776
        if track_new_keys:
 
2777
            self.new_keys = set()
 
2778
        else:
 
2779
            self.new_keys = None
 
2780
 
 
2781
    def clear(self):
 
2782
        if self.refs:
 
2783
            self.refs.clear()
 
2784
        if self.new_keys:
 
2785
            self.new_keys.clear()
2776
2786
 
2777
2787
    def add_references(self, key, refs):
2778
2788
        # Record the new references
2785
2795
        # Discard references satisfied by the new key
2786
2796
        self.add_key(key)
2787
2797
 
 
2798
    def get_new_keys(self):
 
2799
        return self.new_keys
 
2800
    
2788
2801
    def get_unsatisfied_refs(self):
2789
2802
        return self.refs.iterkeys()
2790
2803
 
2791
 
    def add_key(self, key):
 
2804
    def _satisfy_refs_for_key(self, key):
2792
2805
        try:
2793
2806
            del self.refs[key]
2794
2807
        except KeyError:
2795
2808
            # No keys depended on this key.  That's ok.
2796
2809
            pass
2797
2810
 
2798
 
    def add_keys(self, keys):
 
2811
    def add_key(self, key):
 
2812
        # satisfy refs for key, and remember that we've seen this key.
 
2813
        self._satisfy_refs_for_key(key)
 
2814
        if self.new_keys is not None:
 
2815
            self.new_keys.add(key)
 
2816
 
 
2817
    def satisfy_refs_for_keys(self, keys):
2799
2818
        for key in keys:
2800
 
            self.add_key(key)
 
2819
            self._satisfy_refs_for_key(key)
2801
2820
 
2802
2821
    def get_referrers(self):
2803
2822
        result = set()
2965
2984
        # If updating this, you should also update
2966
2985
        # groupcompress._GCGraphIndex.get_missing_parents
2967
2986
        # We may have false positives, so filter those out.
2968
 
        self._key_dependencies.add_keys(
 
2987
        self._key_dependencies.satisfy_refs_for_keys(
2969
2988
            self.get_parent_map(self._key_dependencies.get_unsatisfied_refs()))
2970
2989
        return frozenset(self._key_dependencies.get_unsatisfied_refs())
2971
2990