~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: 2011-04-16 01:09:56 UTC
  • mfrom: (5784.1.4 760435-less-fail)
  • Revision ID: pqm@pqm.ubuntu.com-20110416010956-5wrpm136qq2hz5f3
(mbp) rename and deprecate failUnlessExists and failIfExists (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
    split_lines,
98
98
    )
99
99
from bzrlib.versionedfile import (
100
 
    _KeyRefs,
101
100
    AbsentContentFactory,
102
101
    adapter_registry,
103
102
    ConstantMapper,
2782
2781
        return key[:-1], key[-1]
2783
2782
 
2784
2783
 
 
2784
class _KeyRefs(object):
 
2785
 
 
2786
    def __init__(self, track_new_keys=False):
 
2787
        # dict mapping 'key' to 'set of keys referring to that key'
 
2788
        self.refs = {}
 
2789
        if track_new_keys:
 
2790
            # set remembering all new keys
 
2791
            self.new_keys = set()
 
2792
        else:
 
2793
            self.new_keys = None
 
2794
 
 
2795
    def clear(self):
 
2796
        if self.refs:
 
2797
            self.refs.clear()
 
2798
        if self.new_keys:
 
2799
            self.new_keys.clear()
 
2800
 
 
2801
    def add_references(self, key, refs):
 
2802
        # Record the new references
 
2803
        for referenced in refs:
 
2804
            try:
 
2805
                needed_by = self.refs[referenced]
 
2806
            except KeyError:
 
2807
                needed_by = self.refs[referenced] = set()
 
2808
            needed_by.add(key)
 
2809
        # Discard references satisfied by the new key
 
2810
        self.add_key(key)
 
2811
 
 
2812
    def get_new_keys(self):
 
2813
        return self.new_keys
 
2814
    
 
2815
    def get_unsatisfied_refs(self):
 
2816
        return self.refs.iterkeys()
 
2817
 
 
2818
    def _satisfy_refs_for_key(self, key):
 
2819
        try:
 
2820
            del self.refs[key]
 
2821
        except KeyError:
 
2822
            # No keys depended on this key.  That's ok.
 
2823
            pass
 
2824
 
 
2825
    def add_key(self, key):
 
2826
        # satisfy refs for key, and remember that we've seen this key.
 
2827
        self._satisfy_refs_for_key(key)
 
2828
        if self.new_keys is not None:
 
2829
            self.new_keys.add(key)
 
2830
 
 
2831
    def satisfy_refs_for_keys(self, keys):
 
2832
        for key in keys:
 
2833
            self._satisfy_refs_for_key(key)
 
2834
 
 
2835
    def get_referrers(self):
 
2836
        result = set()
 
2837
        for referrers in self.refs.itervalues():
 
2838
            result.update(referrers)
 
2839
        return result
 
2840
 
 
2841
 
2785
2842
class _KnitGraphIndex(object):
2786
2843
    """A KnitVersionedFiles index layered on GraphIndex."""
2787
2844