137
137
return parent_map
140
class CachingExtraParentsProvider(object):
141
"""ParentsProvider that allows extra parents.
143
This class takes a callback that acts like get_parent_map, except that it
144
may return un-asked-for parents. These extras are cached, but filtered
145
out of get_parent_map.
147
def __init__(self, get_parent_map, debug=False):
148
self._get_parent_map = get_parent_map
149
self._parents_map = None
152
self._requested_parents = None
154
def enable_cache(self):
156
self._parents_map = {}
158
self._requested_parents = set()
160
def disable_cache(self):
162
self._parents_map = None
164
self._requested_parents = None
166
def get_cached_map(self):
167
"""Return any cached get_parent_map values."""
168
return self._parents_map
170
def get_parent_map(self, keys):
171
"""See RemoteRepository.get_parent_map."""
172
# Hack to build up the caching logic.
173
ancestry = self._parents_map
175
# Caching is disabled.
176
missing_revisions = set(keys)
179
missing_revisions = set(key for key in keys if key not in ancestry)
180
if missing_revisions:
181
parent_map = self._get_parent_map(missing_revisions)
183
mutter('re-retrieved revisions: %d of %d',
184
len(set(ancestry).intersection(parent_map)),
186
ancestry.update(parent_map)
187
present_keys = [k for k in keys if k in ancestry]
189
if self._requested_parents is not None and len(ancestry) != 0:
190
self._requested_parents.update(present_keys)
191
mutter('Current hit rate: %d%%',
192
100.0 * len(self._requested_parents) / len(ancestry))
193
return dict((k, ancestry[k]) for k in present_keys)
140
196
class Graph(object):
141
197
"""Provide incremental access to revision graphs.