13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
121
121
self._get_parent_map = self._real_provider.get_parent_map
123
123
self._get_parent_map = get_parent_map
125
self._cache_misses = True
125
self.enable_cache(True)
127
127
def __repr__(self):
128
128
return "%s(%r)" % (self.__class__.__name__, self._real_provider)
133
133
raise AssertionError('Cache enabled when already enabled.')
135
135
self._cache_misses = cache_misses
136
self.missing_keys = set()
137
138
def disable_cache(self):
138
139
"""Disable and clear the cache."""
139
140
self._cache = None
141
self._cache_misses = None
142
self.missing_keys = set()
141
144
def get_cached_map(self):
142
145
"""Return any cached get_parent_map values."""
143
146
if self._cache is None:
145
return dict((k, v) for k, v in self._cache.items()
148
return dict(self._cache)
148
150
def get_parent_map(self, keys):
149
151
"""See _StackedParentsProvider.get_parent_map."""
150
# Hack to build up the caching logic.
151
ancestry = self._cache
153
# Caching is disabled.
154
missing_revisions = set(keys)
154
cache = self._get_parent_map(keys)
157
missing_revisions = set(key for key in keys if key not in ancestry)
158
if missing_revisions:
159
parent_map = self._get_parent_map(missing_revisions)
160
ancestry.update(parent_map)
161
if self._cache_misses:
162
# None is never a valid parents list, so it can be used to
164
ancestry.update(dict((k, None) for k in missing_revisions
165
if k not in parent_map))
166
present_keys = [k for k in keys if ancestry.get(k) is not None]
167
return dict((k, ancestry[k]) for k in present_keys)
156
needed_revisions = set(key for key in keys if key not in cache)
157
# Do not ask for negatively cached keys
158
needed_revisions.difference_update(self.missing_keys)
160
parent_map = self._get_parent_map(needed_revisions)
161
cache.update(parent_map)
162
if self._cache_misses:
163
for key in needed_revisions:
164
if key not in parent_map:
165
self.note_missing_key(key)
168
value = cache.get(key)
169
if value is not None:
173
def note_missing_key(self, key):
174
"""Note that key is a missing key."""
175
if self._cache_misses:
176
self.missing_keys.add(key)
170
179
class Graph(object):
600
609
all_unique_searcher._iterations)
601
610
unique_tip_searchers = next_unique_searchers
603
@symbol_versioning.deprecated_method(symbol_versioning.one_one)
604
def get_parents(self, revisions):
605
"""Find revision ids of the parents of a list of revisions
607
A list is returned of the same length as the input. Each entry
608
is a list of parent ids for the corresponding input revision.
610
[NULL_REVISION] is used as the parent of the first user-committed
611
revision. Its parent list is empty.
613
If the revision is not present (i.e. a ghost), None is used in place
614
of the list of parents.
616
Deprecated in bzr 1.2 - please see get_parent_map.
618
parents = self.get_parent_map(revisions)
619
return [parents.get(r, None) for r in revisions]
621
612
def get_parent_map(self, revisions):
622
613
"""Get a map of key:parent_list for revisions.