subranges: migrate handling of single element range
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Wed, 22 Mar 2017 03:49:40 +0100
changeset 2128 318aba30dec3
parent 2127 e2770faac2df
child 2129 d07bb7cbae2f
subranges: migrate handling of single element range This is the simplest case by far, so we start with that one. We still use the rich object as an argument, but we'll do our best to not relying on that. This is important for performance reason.
hgext3rd/evolve/obsdiscovery.py
hgext3rd/evolve/stablerange.py
--- a/hgext3rd/evolve/obsdiscovery.py	Wed Mar 22 03:47:28 2017 +0100
+++ b/hgext3rd/evolve/obsdiscovery.py	Wed Mar 22 03:49:40 2017 +0100
@@ -604,8 +604,6 @@
         cached = self._repo.stablerange.subranges(self._repo, self)
         if cached is not None:
             return cached
-        if len(self) == 1:
-            return []
         step = _hlp2(self.depth)
         standard_start = 0
         while standard_start < self.index and 0 < step:
--- a/hgext3rd/evolve/stablerange.py	Wed Mar 22 03:47:28 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Wed Mar 22 03:49:40 2017 +0100
@@ -103,10 +103,19 @@
             revdepth += len(cl.findmissingrevs(common=[anc], heads=[rev]))
         return revdepth
 
+    def rangelength(self, repo, rangeid):
+        headrev, index = rangeid.head, rangeid.index
+        return self.depthrev(repo, headrev) - index
+
     def subranges(self, repo, rangeid):
         cached = self._subrangescache.get(rangeid)
         if cached is not None:
             return cached
+        if self.rangelength(repo, rangeid) == 1:
+            value = []
+            self._subrangescache[rangeid] = value
+            return value
+        return None
 
     def setsubranges(self, rangeid, value):
         # XXX temporary cache setter as value computation are performed outside