stablerange: use rangelength in findmissingrange
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Wed, 22 Mar 2017 18:35:05 +0100
changeset 2164 cc8ae2a66b0f
parent 2163 e2dc8c4897be
child 2165 e97e9b0c9711
stablerange: use rangelength in findmissingrange We stop using the building '__len__' this get use closer to be able to use a tuple.
hgext3rd/evolve/obsdiscovery.py
--- a/hgext3rd/evolve/obsdiscovery.py	Wed Mar 22 17:59:21 2017 +0100
+++ b/hgext3rd/evolve/obsdiscovery.py	Wed Mar 22 18:35:05 2017 +0100
@@ -241,6 +241,7 @@
 
     heads = local.revs('heads(%ld)', probeset)
 
+    rangelength = local.stablerange.rangelength
     # size of slice ?
     heappop = heapq.heappop
     heappush = heapq.heappush
@@ -280,8 +281,8 @@
             sliceme = []
             heapify(sliceme)
             for entry in sample:
-                if 1 < len(entry):
-                    heappush(sliceme, (-len(entry), entry))
+                if 1 < rangelength(local, entry):
+                    heappush(sliceme, (-rangelength(local, entry), entry))
 
             while sliceme and 0 < needed:
                 _key, target = heappop(sliceme)
@@ -289,7 +290,7 @@
                     # XXX we could record hierarchy to optimise drop
                     if addentry(entry):
                         if 1 < len(entry):
-                            heappush(sliceme, (-len(entry), entry))
+                            heappush(sliceme, (-rangelength(local, entry), entry))
                         needed -= 1
                         if needed <= 0:
                             break
@@ -298,7 +299,7 @@
         samplesize = fullsamplesize
 
         nbsample = len(sample)
-        maxsize = max([len(r) for r in sample])
+        maxsize = max([rangelength(local, r) for r in sample])
         ui.debug("query %i; sample size is %i, largest range %i\n"
                  % (querycount, maxsize, nbsample))
         nbreplies = 0
@@ -309,7 +310,7 @@
             nbreplies += 1
             if remotehash == _obshashrange(local, entry):
                 continue
-            elif 1 == len(entry):
+            elif 1 == rangelength(local, entry):
                 missing.add(n(entry[0]))
             else:
                 for new in entry.subranges():