Mercurial > hg
changeset 29567:7e2b389418da
perf: import newer modules separately for earlier Mercurial
demandimport of early Mercurial loads an imported module immediately,
if a module is imported absolutely by "from a import b" style. Recent
perf.py satisfies this condition, because it does:
- have "from __future__ import absolute_import" line
- use "from a import b" style for modules in "mercurial" package
Before this patch, importing modules below prevents perf.py from being
loaded by earlier Mercurial, because these aren't available in such
Mercurial, even though there are some code paths for Mercurial earlier
than 1.9.
- branchmap 2.5 (or bcee63733aad)
- repoview 2.5 (or 3a6ddacb7198)
- obsolete 2.3 (or ad0d6c2b3279)
- scmutil 1.9 (or 8b252e826c68)
For example, setting "_prereadsize" attribute in perfindex() and
perfnodelookup() is effective only with Mercurial earlier than 1.8 (or
61c9bc3da402).
After this patch, "mercurial.error" is the only blocker in "from
mercurial import" statement for loading perf.py with Mercurial earlier
than 1.2. This patch ignores it, because just importing it separately
isn't enough.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Fri, 20 May 2016 09:47:35 +0900 |
parents | 075146e85bb6 |
children | 7825f6154a65 |
files | contrib/perf.py |
diffstat | 1 files changed, 20 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/perf.py Wed Jul 13 23:38:29 2016 +0530 +++ b/contrib/perf.py Fri May 20 09:47:35 2016 +0900 @@ -25,7 +25,6 @@ import sys import time from mercurial import ( - branchmap, cmdutil, commands, copies, @@ -33,14 +32,31 @@ extensions, mdiff, merge, - obsolete, - repoview, revlog, - scmutil, util, ) # for "historical portability": +# try to import modules separately (in dict order), and ignore +# failure, because these aren't available with early Mercurial +try: + from mercurial import branchmap # since 2.5 (or bcee63733aad) +except ImportError: + pass +try: + from mercurial import obsolete # since 2.3 (or ad0d6c2b3279) +except ImportError: + pass +try: + from mercurial import repoview # since 2.5 (or 3a6ddacb7198) +except ImportError: + pass +try: + from mercurial import scmutil # since 1.9 (or 8b252e826c68) +except ImportError: + pass + +# for "historical portability": # define util.safehasattr forcibly, because util.safehasattr has been # available since 1.9.3 (or 94b200a11cf7) _undefined = object()