debugformat: speedup the "plain-cl-delta" check
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 27 Nov 2023 15:22:05 -0500
changeset 51145 ddf2b33ee388
parent 51144 9ff3d5395d6b
child 51153 976403c95ba3
debugformat: speedup the "plain-cl-delta" check Checking every single revision is too slow, let's use a sampling approach.
mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py	Tue Nov 14 22:47:17 2023 +0100
+++ b/mercurial/upgrade_utils/actions.py	Mon Nov 27 15:22:05 2023 -0500
@@ -5,6 +5,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+import random
 
 from ..i18n import _
 from .. import (
@@ -409,9 +410,17 @@
     def fromrepo(repo):
         # Mercurial 4.0 changed changelogs to not use delta chains. Search for
         # changelogs with deltas.
-        cl = repo.changelog
+        cl = repo.unfiltered().changelog
+        if len(cl) <= 1000:
+            some_rev = list(cl)
+        else:
+            # do a random sampling to speeds things up Scanning the whole
+            # repository can get really slow on bigger repo.
+            some_rev = sorted(
+                {random.randint(0, len(cl) - 1) for x in range(1000)}
+            )
         chainbase = cl.chainbase
-        return all(rev == chainbase(rev) for rev in cl)
+        return all(rev == chainbase(rev) for rev in some_rev)
 
     @staticmethod
     def fromconfig(repo):