[PATCH 3 of 6 RFC] perf: avoid using formatteropts if Mercurial is earlier than 3.2

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Jun 10 15:20:17 EDT 2016


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1465585985 -32400
#      Sat Jun 11 04:13:05 2016 +0900
# Node ID 7c22b492f189110d98fae2b133a8456c5ff3ccf3
# Parent  681f9db37b058e584fa5a97446161c677d8892f3
perf: avoid using formatteropts if Mercurial is earlier than 3.2

Before this patch, referring commands.formatteropts prevents perf.py
from being loaded by Mercurial earlier than 3.2 (or 7a7eed5176a4),
because it isn't available in such Mercurial, even though formatting
itself has been available since 2.2 (or ae5f92e154d3).

In addition to it, there are some code paths for Mercurial earlier
than 3.2. For example, setting "_prereadsize" attribute in perfindex()
and perfnodelookup() is effective only with hg earlier than 1.8 (or
61c9bc3da402).

This patch uses empty option list as formatteropts, if it isn't
available in commands module at runtime.

Disabling -T/--template option for earlier Mercurial should be
reasonable, because:

  - since 427e80a18ef8, -T/--template for formatter has been available
  - since 7a7eed5176a4, commands.formatteropts has been available
  - the latter revision is direct child of the former

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -30,7 +30,9 @@ def safehasattr(thing, attr):
     return getattr(thing, attr, _undefined) is not _undefined
 setattr(util, 'safehasattr', safehasattr)
 
-formatteropts = commands.formatteropts
+# commands.formatteropts has been available since 3.2 (or 7a7eed5176a4),
+# but formatting itself has been available since 2.2 (or ae5f92e154d3)
+formatteropts = getattr(commands, "formatteropts", [])
 
 # commands.debugrevlogopts has been available since 3.7 (or 5606f7d0d063),
 # but cmdutil.openrevlog() has been available since 1.9 (or a79fea6b3e77)


More information about the Mercurial-devel mailing list