stablerange: fix slicing of arbitrary ranges
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 25 Sep 2018 12:19:41 +0200
changeset 4137 21a3c051ca6c
parent 4136 be3a94d3105f
child 4138 cfdc6f55599b
stablerange: fix slicing of arbitrary ranges Pull bundle trigger slicing from range with arbitrary initial skip. We have to adjust the current slicing to take this into account.
hgext3rd/evolve/stablerange.py
hgext3rd/evolve/stablerangecache.py
--- a/hgext3rd/evolve/stablerange.py	Mon Sep 24 01:16:00 2018 +0200
+++ b/hgext3rd/evolve/stablerange.py	Tue Sep 25 12:19:41 2018 +0200
@@ -390,6 +390,12 @@
         # find were we need to slice
         slicepoint = self._slicepoint(repo, rangeid)
 
+        ret = self._slicesrangeat(repo, rangeid, slicepoint)
+
+        return ret
+
+    def _slicesrangeat(self, repo, rangeid, slicepoint):
+        headrev, initial_index = rangeid
         self._warmcachefor(repo, rangeid, slicepoint)
 
         stable_parent_data = self._parentrange(repo, rangeid)
@@ -411,7 +417,13 @@
             # The parent is above the slice point,
             # it's lower subrange will be the same so we just get them,
             # (and the top range is always the same)
-            subranges = self.subranges(repo, stable_parent_range)[:-1]
+            subranges = self.subranges(repo, stable_parent_range)[:]
+            parenttop = subranges.pop()
+            if (stable_parent_depth - slicepoint) < self.rangelength(repo, parenttop):
+                # possible case when we reduce an arbitrary range to its
+                # canonical parts
+                midranges = self._slicesrangeat(repo, parenttop, slicepoint)
+                subranges.extend(midranges[:-1])
             subranges.append(top_range)
         elif initial_index < stable_parent_depth < slicepoint:
             # the parent is below the range we are considering, we need to
@@ -428,6 +440,13 @@
                                                     slicepoint))
             subranges.append(top_range)
 
+        ### slow code block to validated the slicing works as expected
+        # toprevs = self.revsfromrange(repo, rangeid)
+        # subrevs = []
+        # for s in subranges:
+        #     subrevs.extend(self.revsfromrange(repo, s))
+        # assert toprevs == subrevs, (rangeid, slicepoint, stable_parent_range, stable_parent_depth, toprevs, subrevs)
+
         return subranges
 
     def _unique_subranges(self, repo, headrev, initial_index, slicepoint):
--- a/hgext3rd/evolve/stablerangecache.py	Mon Sep 24 01:16:00 2018 +0200
+++ b/hgext3rd/evolve/stablerangecache.py	Tue Sep 25 12:19:41 2018 +0200
@@ -388,7 +388,7 @@
 
 class mergepointsql(stablerangesql, stablerange.stablerange_mergepoint):
 
-    _schemaversion = 2
+    _schemaversion = 3
     _cachefile = 'cache/evoext_stablerange_v2.sqlite'
     _cachename = 'evo-ext-stablerange-mergepoint'