stablerange: introduce an intermediary abstract class for caching
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 10 Dec 2017 01:26:40 +0100
changeset 3259 b63d03db0ab9
parent 3258 af1f8f0687e1
child 3260 2f0c113b35f8
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.
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 <range>"""
-        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 <range>"""
+        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: