# HG changeset patch # User Pierre-Yves David # Date 1512865600 -3600 # Node ID b63d03db0ab90eea48fe0c7a2cdde95563f0abd2 # Parent af1f8f0687e1262ccbf40ec4533ab01ce3df6eae stablerange: introduce an intermediary abstract class for caching The 'branchpoint' and 'mergepoint' based stablerange class will need similar cache, we introduce an abstract class to take care of that first. diff -r af1f8f0687e1 -r b63d03db0ab9 hgext3rd/evolve/stablerange.py --- a/hgext3rd/evolve/stablerange.py Sun Dec 10 01:06:16 2017 +0100 +++ b/hgext3rd/evolve/stablerange.py Sun Dec 10 01:26:40 2017 +0100 @@ -183,10 +183,10 @@ """warmup the stable range cache""" raise NotImplemented() + @abc.abstractmethod def rangelength(self, repo, rangeid): """number of revision in """ - headrev, index = rangeid[0], rangeid[1] - return self.depthrev(repo, headrev) - index + raise NotImplemented() def _slicepoint(self, repo, rangeid): """find the standard slicing point for a range""" @@ -292,7 +292,20 @@ def _sortfunction(self, repo, headrev): return stablesort.stablesort_mergepoint_head_basic(repo, [headrev]) -class stablerange(abstractstablerange): +class stablerangecached(abstractstablerange): + """an implementation of stablerange using caching""" + + __metaclass__ = abc.ABCMeta + + def depthrev(self, repo, rev): + return repo.depthcache.get(rev) + + def rangelength(self, repo, rangeid): + """number of revision in """ + headrev, index = rangeid[0], rangeid[1] + return self.depthrev(repo, headrev) - index + +class stablerange(stablerangecached): def __init__(self, lrusize=2000): # The point up to which we have data in cache @@ -387,9 +400,6 @@ repo.ui.log('evoext-cache', 'updated stablerange cache in %.4f seconds\n', duration) - def depthrev(self, repo, rev): - return repo.depthcache.get(rev) - def subranges(self, repo, rangeid): cached = self._getsub(rangeid) if cached is not None: