# HG changeset patch # User FUJIWARA Katsunori # Date 1467671151 -32400 # Node ID ee2027195847c389e64ab2ed9714f7a938a8d42d # Parent 7299370cf30445023645f9aa012c0b2ae9f34c69 perf: define command annotation locally for Mercurial earlier than 3.1 Before this patch, using cmdutil.command() for "@command" annotation prevents perf.py from being loaded by Mercurial earlier than 1.9 (or 2daa5179e73f), because cmdutil.command() isn't available in such Mercurial, even though there are some code paths for Mercurial earlier than 1.9. For example, setting "_prereadsize" attribute in perfindex() and perfnodelookup() is effective only with hg earlier than 1.8 (or 61c9bc3da402). In addition to it, "norepo" option of command annotation has been available since 3.1 (or 75a96326cecb), and this is another blocker for loading perf.py with earlier Mercurial. ============ ============ ====== command of hg version cmdutil norepo ============ ============ ====== 3.1 or later o o 1.9 or later o x earlier x x ============ ============ ====== This patch defines "command()" for annotation locally as below: - define wrapper of existing cmdutil.command(), if cmdutil.command() doesn't support "norepo" (for Mercurial earlier than 3.1) - define full command() locally with minimum function, if cmdutil.command() isn't available at runtime (for Mercurial earlier than 1.9) This patch also defines parsealiases() locally without examining whether it is available or not, because it is small enough to define locally. diff -r 7299370cf304 -r ee2027195847 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 @@ -67,7 +67,39 @@ ]) cmdtable = {} -command = cmdutil.command(cmdtable) + +# for "historical portability": +# define parsealiases locally, because cmdutil.parsealiases has been +# available since 1.5 (or 6252852b4332) +def parsealiases(cmd): + return cmd.lstrip("^").split("|") + +if safehasattr(cmdutil, 'command'): + import inspect + command = cmdutil.command(cmdtable) + if 'norepo' not in inspect.getargspec(command)[0]: + # for "historical portability": + # wrap original cmdutil.command, because "norepo" option has + # been available since 3.1 (or 75a96326cecb) + _command = command + def command(name, options=(), synopsis=None, norepo=False): + if norepo: + commands.norepo += ' %s' % ' '.join(parsealiases(name)) + return _command(name, list(options), synopsis) +else: + # for "historical portability": + # define "@command" annotation locally, because cmdutil.command + # has been available since 1.9 (or 2daa5179e73f) + def command(name, options=(), synopsis=None, norepo=False): + def decorator(func): + if synopsis: + cmdtable[name] = func, list(options), synopsis + else: + cmdtable[name] = func, list(options) + if norepo: + commands.norepo += ' %s' % ' '.join(parsealiases(name)) + return func + return decorator def getlen(ui): if ui.configbool("perf", "stub"):