stablerange: move the subrange cache into our new class
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Wed, 22 Mar 2017 03:47:28 +0100
changeset 2127 e2770faac2df
parent 2126 839e96521c5a
child 2128 318aba30dec3
stablerange: move the subrange cache into our new class This is the first step toward having more logic in that class
hgext3rd/evolve/obsdiscovery.py
hgext3rd/evolve/stablerange.py
--- a/hgext3rd/evolve/obsdiscovery.py	Sun Mar 19 00:44:31 2017 +0100
+++ b/hgext3rd/evolve/obsdiscovery.py	Wed Mar 22 03:47:28 2017 +0100
@@ -601,9 +601,7 @@
         return result
 
     def subranges(self):
-        if not util.safehasattr(self._repo, '_subrangecache'):
-            self._repo._subrangecache = {}
-        cached = self._repo._subrangecache.get(self)
+        cached = self._repo.stablerange.subranges(self._repo, self)
         if cached is not None:
             return cached
         if len(self) == 1:
@@ -621,7 +619,7 @@
             assert standard_start < self.depth
             slicepoint = standard_start
         result = self._slicesat(slicepoint)
-        self._repo._subrangecache[self] = result
+        self._repo.stablerange.setsubranges(self, result)
         return result
 
     @util.propertycache
--- a/hgext3rd/evolve/stablerange.py	Sun Mar 19 00:44:31 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Wed Mar 22 03:47:28 2017 +0100
@@ -22,6 +22,7 @@
 
     def __init__(self):
         self._depthcache = {}
+        self._subrangescache = {}
 
     def depthrev(self, repo, rev):
         repo = repo.unfiltered()
@@ -102,6 +103,16 @@
             revdepth += len(cl.findmissingrevs(common=[anc], heads=[rev]))
         return revdepth
 
+    def subranges(self, repo, rangeid):
+        cached = self._subrangescache.get(rangeid)
+        if cached is not None:
+            return cached
+
+    def setsubranges(self, rangeid, value):
+        # XXX temporary cache setter as value computation are performed outside
+        # this class reach.
+        return self._subrangescache.get(rangeid)
+
 @eh.reposetup
 def setupcache(ui, repo):