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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date June 10, 2016, 7:20 p.m.
Message ID <7c22b492f189110d98fa.1465586417@feefifofum>
Download mbox | patch
Permalink /patch/15463/
State Changes Requested
Headers show

Comments

Katsunori FUJIWARA - June 10, 2016, 7:20 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@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

Patch

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)