Patchwork [4,of,6,V2] perf: avoid using formatteropts for Mercurial earlier than 3.2

login
register
mail settings
Submitter Katsunori FUJIWARA
Date July 4, 2016, 10:37 p.m.
Message ID <e68fa49cf9241dd531ad.1467671825@feefifofum>
Download mbox | patch
Permalink /patch/15745/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - July 4, 2016, 10:37 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1467671151 -32400
#      Tue Jul 05 07:25:51 2016 +0900
# Node ID e68fa49cf9241dd531adbf2ee3c3a26bad5b9b57
# Parent  c44ec212a1986c6363cff76a32fe94ee0f05561e
perf: avoid using formatteropts for Mercurial 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
@@ -48,7 +48,12 @@  def safehasattr(thing, attr):
     return getattr(thing, attr, _undefined) is not _undefined
 setattr(util, 'safehasattr', safehasattr)
 
-formatteropts = commands.formatteropts
+# for "historical portability":
+# use locally defined empty option list, if formatteropts isn't
+# available, because commands.formatteropts has been available since
+# 3.2 (or 7a7eed5176a4), even though formatting itself has been
+# available since 2.2 (or ae5f92e154d3)
+formatteropts = getattr(commands, "formatteropts", [])
 
 # for "historical portability":
 # use locally defined option list, if debugrevlogopts isn't available,