# HG changeset patch # User Julien Cristau # Date 2020-02-07 14:55:21 # Node ID e48a996d12bcb9594270e608c4fe2c1534ed7fd7 # Parent 3245cdea2c63f4803a38c1c8ac2244540e2b70dc 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 diff --git a/tests/hghave.py b/tests/hghave.py --- a/tests/hghave.py +++ b/tests/hghave.py @@ -307,13 +307,23 @@ def has_lsprof(): 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)]) )