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

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


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

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/ b/contrib/
--- a/contrib/
+++ b/contrib/
@@ -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)