~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/graph.py

  • Committer: Robert Collins
  • Date: 2009-03-24 07:09:11 UTC
  • mto: This revision was merged to the branch mainline in revision 4199.
  • Revision ID: robertc@robertcollins.net-20090324070911-w59etn9q3f9xj4fu
Cache ghosts when we can get them from a RemoteRepository in get_parent_map.

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
            raise AssertionError('Cache enabled when already enabled.')
134
134
        self._cache = {}
135
135
        self._cache_misses = cache_misses
136
 
        self._missing_keys = set()
 
136
        self.missing_keys = set()
137
137
 
138
138
    def disable_cache(self):
139
139
        """Disable and clear the cache."""
140
140
        self._cache = None
141
141
        self._cache_misses = None
142
 
        self._missing_keys = set()
 
142
        self.missing_keys = set()
143
143
 
144
144
    def get_cached_map(self):
145
145
        """Return any cached get_parent_map values."""
157
157
            # better.
158
158
            needed_revisions = set(key for key in keys if key not in cache)
159
159
            # Do not ask for negatively cached keys
160
 
            needed_revisions.difference_update(self._missing_keys)
 
160
            needed_revisions.difference_update(self.missing_keys)
161
161
            if needed_revisions:
162
162
                parent_map = self._get_parent_map(needed_revisions)
163
163
                cache.update(parent_map)
164
164
                if self._cache_misses:
165
165
                    for key in needed_revisions:
166
166
                        if key not in parent_map:
167
 
                            self._missing_keys.add(key)
 
167
                            self.note_missing_key(key)
168
168
        result = {}
169
169
        for key in keys:
170
170
            value = cache.get(key)
172
172
                result[key] = value
173
173
        return result
174
174
 
 
175
    def note_missing_key(self, key):
 
176
        """Note that key is a missing key."""
 
177
        if self._cache_misses:
 
178
            self.missing_keys.add(key)
 
179
 
175
180
 
176
181
class Graph(object):
177
182
    """Provide incremental access to revision graphs.