Patchwork [2,of,8,V2] perf: get subsettable from appropriate module for Mercurial earlier than 2.9

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Oct. 8, 2016, 4:18 p.m.
Message ID <ab2d4d5e7821c321017c.1475943502@feefifofum>
Download mbox | patch
Permalink /patch/16943/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Oct. 8, 2016, 4:18 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1475942597 -32400
#      Sun Oct 09 01:03:17 2016 +0900
# Node ID ab2d4d5e7821c321017cdbdae7743824c0da76ff
# Parent  a03b967913dd881f750a5848f567d1e0a1d0e7ea
perf: get subsettable from appropriate module for Mercurial earlier than 2.9

Before this patch, using branchmap.subsettable prevents perfbranchmap
from measuring performance of Mercurial earlier than 2.9 (or
175c6fd8cacc), because 175c6fd8cacc moved subsettable from repoview.py
to branchmap.py, even though there are some code paths for Mercurial
earlier than 2.9 in perf.py.

For example, setting "_prereadsize" attribute in perfindex() and
perfnodelookup() is effective only with hg earlier than 1.8 (or
61c9bc3da402).

To get subsettable from appropriate module, this patch examines
existence of subsettable in branchmap and repoview.

This patch also adds check-perf-code.py an extra check entry to detect
direct usage of subsettable attribute in perf.py.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -214,6 +214,24 @@  def safeattrsetter(obj, name, ignoremiss
 
     return attrutil()
 
+# utilities to examine each internal API changes
+
+def getbranchmapsubsettable():
+    # for "historical portability":
+    # subsettable is defined in:
+    # - branchmap since 2.9 (or 175c6fd8cacc)
+    # - repoview since 2.5 (or 59a9f18d4587)
+    for mod in (branchmap, repoview):
+        subsettable = getattr(mod, 'subsettable', None)
+        if subsettable:
+            return subsettable
+
+    # bisecting in bcee63733aad::59a9f18d4587 can reach here (both
+    # branchmap and repoview modules exist, but subsettable attribute
+    # doesn't)
+    raise error.Abort(("perfbranchmap not available with this Mercurial"),
+                      hint="use 2.5 or later")
+
 # perf commands
 
 @command('perfwalk', formatteropts)
@@ -848,10 +866,11 @@  def perfbranchmap(ui, repo, full=False, 
         return d
     # add filter in smaller subset to bigger subset
     possiblefilters = set(repoview.filtertable)
+    subsettable = getbranchmapsubsettable()
     allfilters = []
     while possiblefilters:
         for name in possiblefilters:
-            subset = branchmap.subsettable.get(name)
+            subset = subsettable.get(name)
             if subset not in possiblefilters:
                 break
         else:
diff --git a/tests/check-perf-code.py b/tests/check-perf-code.py
--- a/tests/check-perf-code.py
+++ b/tests/check-perf-code.py
@@ -10,6 +10,8 @@  import sys
 # write static check patterns here
 perfpypats = [
   [
+    (r'(branchmap|repoview)\.subsettable',
+     "use getbranchmapsubsettable() for early Mercurial"),
   ],
   # warnings
   [