stablerange: fallback to a more naive approach to find subrange
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 10 Dec 2017 00:20:06 +0100
changeset 3253 8dcb9e929a57
parent 3252 d57400a0f4c3
child 3254 00e20077bccf
stablerange: fallback to a more naive approach to find subrange As suspected, using "bheads" was bit good enough in some case and we have to fall back to the approach used in "basic". On the evolve repo (about 3K changeset) this approach is about 60% slower than the previous (wrong) code.
hgext3rd/evolve/stablerange.py
--- a/hgext3rd/evolve/stablerange.py	Sat Dec 09 22:49:07 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Sun Dec 10 00:20:06 2017 +0100
@@ -570,7 +570,6 @@
 
     def _slicesrangeatmerge(self, repo, rangeid, globalindex):
         localindex = globalindex - rangeid[1]
-        cl = repo.changelog
 
         result = []
         allrevs = self.revsfromrange(repo, rangeid)
@@ -581,19 +580,24 @@
             # revision we needs
             result.append((bottomrevs[-1], rangeid[1]))
         else:
-            parentrevs = cl.parentrevs
-            parents = self._parents
-            bheads = set(bottomrevs)
-            du = bheads.difference_update
-            for r in bottomrevs:
-                du(parents(r, parentrevs))
-            seen = 0
-            for r in bottomrevs:
-                seen += 1
-                # XXX bheads might not be a good enough criteria
-                if r in bheads:
-                    result.append((r, self.depthrev(repo, r) - seen))
-                    seen = 0
+            head = None
+            headrange = None
+            skip = None
+            for rev in bottomrevs[::-1]:
+                if head is None:
+                    head = rev
+                    headrange = self.revsfromrange(repo, (head, 0))
+                    skip = self.depthrev(repo, rev) - 1
+                elif rev != headrange[skip - 1]:
+                    result.append((head, skip))
+                    head = rev
+                    headrange = self.revsfromrange(repo, (head, 0))
+                    skip = self.depthrev(repo, rev) - 1
+                else:
+                    skip -= 1
+            result.append((head, skip))
+
+            result.reverse()
 
         # top part is trivial
         top = (rangeid[0], globalindex)