stablerange: rearrange the reusing logic to prepare to merge
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Fri, 24 Mar 2017 08:20:36 +0100
changeset 2218 9e30934d4487
parent 2217 37fa3d83f294
child 2219 d83bf4773433
stablerange: rearrange the reusing logic to prepare to merge We'll soon be able to reuse some lower range when dealing with merge too. So we prepare the code for this in advance for clarity.
hgext3rd/evolve/stablerange.py
--- a/hgext3rd/evolve/stablerange.py	Fri Mar 24 06:24:02 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Fri Mar 24 08:20:36 2017 +0100
@@ -391,25 +391,24 @@
         p1, p2 = self._parents(rangeid[0], repo.changelog.parentrevs)
         if p2 != nodemod.nullrev:
             return self._slicesrangeatmerge(repo, rangeid, globalindex)
-        assert p1 != nodemod.nullrev
-        rangedepth = self.depthrev(repo, rangeid[0])
-        topsize = rangedepth - globalindex
+
+        reuserev = p1
 
-        parentrange = (p1, rangeid[1])
+        assert reuserev != nodemod.nullrev
+
+        reuserange = (reuserev, rangeid[1])
+        top = (rangeid[0], globalindex)
 
-        if topsize == 1:
-            top = (rangeid[0], globalindex)
-            return [parentrange, top]
-        else:
-            # This will not initiate a recursion since we took appropriate
-            # precaution in the caller of this method to ensure it will be so.
-            # It the parent is a merge that will not be the case but computing
-            # subranges from a merge will not recurse.
-            parentsubranges = self.subranges(repo, parentrange)
-            slices = parentsubranges[:-1] # pop the top
-            top = (rangeid[0], globalindex)
-            slices.append(top)
-            return slices
+        if rangeid[1] + self.rangelength(repo, reuserange) == globalindex:
+            return [reuserange, top]
+        # This will not initiate a recursion since we took appropriate
+        # precaution in the caller of this method to ensure it will be so.
+        # It the parent is a merge that will not be the case but computing
+        # subranges from a merge will not recurse.
+        reusesubranges = self.subranges(repo, reuserange)
+        slices = reusesubranges[:-1] # pop the top
+        slices.append(top)
+        return slices
 
     def _slicesrangeatmerge(self, repo, rangeid, globalindex):
         localindex = globalindex - rangeid[1]