changeset 2136:086a85c37e9e

stablerange: compute subranges from parent when possible Unless we are a merge, we can infer the standard subranges of a range by reusing the subranger of its parent. We update the implementation to do so. We still needs the "old way" for merge. We move that code in a dedicated function for the sake of simplicity.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sun, 19 Mar 2017 05:33:52 +0100
parents 8f63f4b1c33e
children dd8ed58bf79c
files hgext3rd/evolve/stablerange.py
diffstat 1 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablerange.py	Wed Mar 22 04:27:42 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Sun Mar 19 05:33:52 2017 +0100
@@ -255,8 +255,33 @@
         return slicepoint
 
     def _slicesrangeat(self, repo, rangeid, globalindex):
+        p1, p2 = repo.changelog.parentrevs(rangeid.head)
+        if p2 != nodemod.nullrev:
+            return self._slicesrangeatmerge(repo, rangeid, globalindex)
+        assert p1 != nodemod.nullrev
+        rangedepth = self.depthrev(repo, rangeid.head)
+        topsize = rangedepth - globalindex
+
+        parentrange = stablerange(repo, p1, rangeid.index, rangeid._revs[:-1])
+        if topsize == 1:
+            top = stablerange(repo, rangeid.head, globalindex, [rangeid.head])
+            return [parentrange, top]
+        else:
+            # XXX recursive call, python have issue with them
+            # The best way to break it would be directly 'self.subranges'
+            # In that other method we could make sure subrangess for
+            # (p1(rev), idx) are available before slicing (rev, idx). But the
+            # heavy object approach makes it a bit inconvenient so that will
+            # wait for that heavy object to be gone.
+            parentsubranges = self.subranges(repo, parentrange)
+            slices = parentsubranges[:-1] # pop the top
+            top = stablerange(repo, rangeid.head, globalindex, rangeid._revs[-topsize:])
+            slices.append(top)
+            return slices
+
+    @staticmethod
+    def _slicesrangeatmerge(repo, rangeid, globalindex):
         localindex = globalindex - rangeid.index
-
         cl = repo.changelog
 
         result = []