perf: add historical support of ui.load()
authorPhilippe Pepiot <philippe.pepiot@logilab.fr>
Thu, 15 Dec 2016 12:17:08 +0100
changeset 30588 be0e7af80543
parent 30587 b3643bfc7fcb
child 30589 182cacaa4c32
perf: add historical support of ui.load() ui.load() has been available since d83ca854 and at the time of writing isn't available on stable branch breaking benchmarking newer stable revisions. Add historical portability policy note on contrib/benchmarks
contrib/benchmarks/__init__.py
--- a/contrib/benchmarks/__init__.py	Wed Dec 14 02:17:59 2016 +0000
+++ b/contrib/benchmarks/__init__.py	Thu Dec 15 12:17:08 2016 +0100
@@ -5,6 +5,11 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+# "historical portability" policy of contrib/benchmarks:
+#
+# We have to make this code work correctly with current mercurial stable branch
+# and if possible with reasonable cost with early Mercurial versions.
+
 '''ASV (https://asv.readthedocs.io) benchmark suite
 
 Benchmark are parameterized against reference repositories found in the
@@ -36,6 +41,7 @@
     extensions,
     hg,
     ui as uimod,
+    util,
 )
 
 basedir = os.path.abspath(os.path.join(os.path.dirname(__file__),
@@ -50,7 +56,12 @@
 
 def runperfcommand(reponame, command, *args, **kwargs):
     os.environ["HGRCPATH"] = os.environ.get("ASVHGRCPATH", "")
-    ui = uimod.ui.load()
+    # for "historical portability"
+    # ui.load() has been available since d83ca85
+    if util.safehasattr(uimod.ui, "load"):
+        ui = uimod.ui.load()
+    else:
+        ui = uimod.ui()
     repo = hg.repository(ui, os.path.join(reposdir, reponame))
     perfext = extensions.load(ui, 'perfext',
                               os.path.join(basedir, 'contrib', 'perf.py'))