subranges: detach cache logic from computation logic
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Thu, 23 Mar 2017 10:19:59 +0100
changeset 2204 61a8b51348a1
parent 2203 8a2e1f6e5443
child 2205 bd5e2496e5cd
subranges: detach cache logic from computation logic Having both the logic around cache checking and setting makes is a bit harder to follow. In addition, this allow to gather the computation logic next to the other related function.
hgext3rd/evolve/stablerange.py
--- a/hgext3rd/evolve/stablerange.py	Thu Mar 23 10:07:21 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Thu Mar 23 10:19:59 2017 +0100
@@ -223,11 +223,7 @@
         cached = self._subrangescache.get(rangeid)
         if cached is not None:
             return cached
-        if self.rangelength(repo, rangeid) == 1:
-            value = []
-        else:
-            slicepoint = self._slicepoint(repo, rangeid)
-            value = self._slicesrangeat(repo, rangeid, slicepoint)
+        value = self._subranges(repo, rangeid)
         self._subrangescache[rangeid] = value
         return value
 
@@ -298,6 +294,12 @@
             revdepth += len(cl.findmissingrevs(common=[anc], heads=[rev]))
         return revdepth
 
+    def _subranges(self, repo, rangeid):
+        if self.rangelength(repo, rangeid) == 1:
+            return []
+        slicepoint = self._slicepoint(repo, rangeid)
+        return self._slicesrangeat(repo, rangeid, slicepoint)
+
     def _slicepoint(self, repo, rangeid):
         rangedepth = self.depthrev(repo, rangeid[0])
         step = _hlp2(rangedepth)