changeset 44279:e48a996d12bc

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
author Julien Cristau <jcristau@mozilla.com>
date Fri, 07 Feb 2020 15:55:21 +0100
parents 3245cdea2c63
children 93a05cb223da
files tests/hghave.py
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)])
 )