[PATCH 1 of 6 RFC] perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Jun 10 19:20:15 UTC 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 5c020055f9fcf80a7e046d44287ee7be8e7785c3
# Parent  0c6dbf7019d084d0a775dc716532b5b7f24ee7ea
perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3

Before this patch, using util.safehasattr() prevents perf.py from
being loaded by Mercurial earlier than 1.9.3 (or 94b200a11cf7),
because util.safehasattr() isn't available in such Mercurial, even
though there are some code paths for Mercurial earlier than 1.9.3.

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

This patch is a preparation for using util.safehasattr() safely in
subsequent patches.

This patch defines util.safehasattr() forcibly without examining
whether it is available or not, because:

  - examining existence of "safehasattr" safely itself needs similar logic
  - safehasattr() is small enough to define locally

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -22,6 +22,13 @@ from mercurial import (
     util,
 )
 
+# define util.safehasattr forcibly, because util.safehasattr has been
+# available since 1.9.3 (or 94b200a11cf7)
+_undefined = object()
+def safehasattr(thing, attr):
+    return getattr(thing, attr, _undefined) is not _undefined
+setattr(util, 'safehasattr', safehasattr)
+
 formatteropts = commands.formatteropts
 revlogopts = commands.debugrevlogopts
 


More information about the Mercurial-devel mailing list