hghave: cache the result of gethgversion
hghave --test-features calls it 90 times, each one calling hg --version
which takes a tenth of a second on my workstation, adding up to about
10s win on test-hghave.t.
Fixes https://bugs.debian.org/939756
Differential Revision: https://phab.mercurial-scm.org/D8092
--- a/tests/hghave.py Fri Jan 24 14:11:43 2020 -0800
+++ b/tests/hghave.py Fri Feb 07 15:55:21 2020 +0100
@@ -307,13 +307,23 @@
return False
-def gethgversion():
+def _gethgversion():
m = matchoutput('hg --version --quiet 2>&1', br'(\d+)\.(\d+)')
if not m:
return (0, 0)
return (int(m.group(1)), int(m.group(2)))
+_hgversion = None
+
+
+def gethgversion():
+ global _hgversion
+ if _hgversion is None:
+ _hgversion = _gethgversion()
+ return _hgversion
+
+
@checkvers(
"hg", "Mercurial >= %s", list([(1.0 * x) / 10 for x in range(9, 99)])
)