~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: INADA Naoki
  • Date: 2011-05-14 14:59:06 UTC
  • mto: This revision was merged to the branch mainline in revision 5874.
  • Revision ID: songofacandy@gmail.com-20110514145906-xj3xa06jihd4wapq
Notify when test_textwrap is skipped.

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,
100
101
    AbsentContentFactory,
101
102
    adapter_registry,
102
103
    ConstantMapper,
2781
2782
        return key[:-1], key[-1]
2782
2783
 
2783
2784
 
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
 
 
2842
2785
class _KnitGraphIndex(object):
2843
2786
    """A KnitVersionedFiles index layered on GraphIndex."""
2844
2787