~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.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:
1872
1872
    for prefix in sorted(per_prefix_map):
1873
1873
        present_keys.extend(reversed(tsort.topo_sort(per_prefix_map[prefix])))
1874
1874
    return present_keys
1875
 
 
1876
 
 
1877
 
class _KeyRefs(object):
1878
 
 
1879
 
    def __init__(self, track_new_keys=False):
1880
 
        # dict mapping 'key' to 'set of keys referring to that key'
1881
 
        self.refs = {}
1882
 
        if track_new_keys:
1883
 
            # set remembering all new keys
1884
 
            self.new_keys = set()
1885
 
        else:
1886
 
            self.new_keys = None
1887
 
 
1888
 
    def clear(self):
1889
 
        if self.refs:
1890
 
            self.refs.clear()
1891
 
        if self.new_keys:
1892
 
            self.new_keys.clear()
1893
 
 
1894
 
    def add_references(self, key, refs):
1895
 
        # Record the new references
1896
 
        for referenced in refs:
1897
 
            try:
1898
 
                needed_by = self.refs[referenced]
1899
 
            except KeyError:
1900
 
                needed_by = self.refs[referenced] = set()
1901
 
            needed_by.add(key)
1902
 
        # Discard references satisfied by the new key
1903
 
        self.add_key(key)
1904
 
 
1905
 
    def get_new_keys(self):
1906
 
        return self.new_keys
1907
 
    
1908
 
    def get_unsatisfied_refs(self):
1909
 
        return self.refs.iterkeys()
1910
 
 
1911
 
    def _satisfy_refs_for_key(self, key):
1912
 
        try:
1913
 
            del self.refs[key]
1914
 
        except KeyError:
1915
 
            # No keys depended on this key.  That's ok.
1916
 
            pass
1917
 
 
1918
 
    def add_key(self, key):
1919
 
        # satisfy refs for key, and remember that we've seen this key.
1920
 
        self._satisfy_refs_for_key(key)
1921
 
        if self.new_keys is not None:
1922
 
            self.new_keys.add(key)
1923
 
 
1924
 
    def satisfy_refs_for_keys(self, keys):
1925
 
        for key in keys:
1926
 
            self._satisfy_refs_for_key(key)
1927
 
 
1928
 
    def get_referrers(self):
1929
 
        result = set()
1930
 
        for referrers in self.refs.itervalues():
1931
 
            result.update(referrers)
1932
 
        return result
1933
 
 
1934
 
 
1935