changeset 29494:3b5389ef5cfe

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
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 05 Jul 2016 07:25:51 +0900
parents 4533f5b47949
children f83445296213
files contrib/perf.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Tue Jul 05 07:25:51 2016 +0900
+++ b/contrib/perf.py	Tue Jul 05 07:25:51 2016 +0900
@@ -39,6 +39,14 @@
     util,
 )
 
+# for "historical portability":
+# 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