# HG changeset patch # User FUJIWARA Katsunori # Date 1467671151 -32400 # Node ID 3b5389ef5cfeb62c4f017a130c02f7054ab57d9c # Parent 4533f5b47949a4d0544bda9bc65c34622c560928 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 -r 4533f5b47949 -r 3b5389ef5cfe contrib/perf.py --- 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