stablerange: move standard slice point definition in main class
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Sun, 19 Mar 2017 04:43:33 +0100
changeset 2132 d77262807411
parent 2131 86dd39478638
child 2133 323480863248
stablerange: move standard slice point definition in main class More migration of code away from the doomed individual class.
hgext3rd/evolve/stablerange.py
--- a/hgext3rd/evolve/stablerange.py	Sun Mar 19 04:39:00 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Sun Mar 19 04:43:33 2017 +0100
@@ -236,6 +236,22 @@
         # this class reach.
         return self._subrangescache.get(rangeid)
 
+    def _slicepoint(self, repo, rangeid):
+        rangedepth = self.depthrev(repo, rangeid.head)
+        step = _hlp2(rangedepth)
+        standard_start = 0
+        while standard_start < rangeid.index and 0 < step:
+            if standard_start + step < rangedepth:
+                standard_start += step
+            step //= 2
+        if rangeid.index == standard_start:
+            slicesize = _hlp2(len(rangeid))
+            slicepoint = rangeid.index + slicesize
+        else:
+            assert standard_start < rangedepth
+            slicepoint = standard_start
+        return slicepoint
+
     def _slicesrangeat(self, repo, rangeid, globalindex):
         localindex = globalindex - rangeid.index
 
@@ -329,18 +345,7 @@
         cached = cache.subranges(self._repo, self)
         if cached is not None:
             return cached
-        step = _hlp2(self.depth)
-        standard_start = 0
-        while standard_start < self.index and 0 < step:
-            if standard_start + step < self.depth:
-                standard_start += step
-            step //= 2
-        if self.index == standard_start:
-            slicesize = _hlp2(len(self))
-            slicepoint = self.index + slicesize
-        else:
-            assert standard_start < self.depth
-            slicepoint = standard_start
+        slicepoint = cache._slicepoint(self._repo, self)
         result = cache._slicesrangeat(self._repo, self, slicepoint)
         self._repo.stablerange.setsubranges(self, result)
         return result