# HG changeset patch # User FUJIWARA Katsunori # Date 2016-07-04 22:25:51 # Node ID f83445296213378a7996417c387b4a84e743b53b # Parent 3b5389ef5cfeb62c4f017a130c02f7054ab57d9c perf: use locally defined revlog option list for Mercurial earlier than 3.7 Before this patch, referring commands.debugrevlogopts prevents perf.py from being loaded by Mercurial earlier than 3.7 (or 5606f7d0d063), because it isn't available in such Mercurial, even though cmdutil.openrevlog(), a user of these options, has been available since 1.9 (or a79fea6b3e77). In addition to it, there are some code paths for Mercurial earlier than 3.7. For example, setting "_prereadsize" attribute in perfindex() and perfnodelookup() is effective only with hg earlier than 1.8 (or 61c9bc3da402). But just "using locally defined revlog option list" might cause unexpected behavior at runtime. If --dir option is specified to cmdutil.openrevlog() of Mercurial earlier than 3.5 (or 49c583ca48c4), it is silently ignored without any warning or so. ============ ============ ===== =============== debugrevlogopts hg version openrevlog() --dir of commands ============ ============ ===== =============== 3.7 or later o o o 3.5 or later o o x 1.9 or later o x x earlier x x x ============ ============ ===== =============== Therefore, this patch does: - use locally defined option list, if commands.debugrevlogopts isn't available (for Mercurial earlier than 3.7) - wrap cmdutil.openrevlog(), if it is ambiguous whether cmdutil.openrevlog() can recognize --dir option correctly (for Mercurial earlier than 3.5) This wrapper function aborts execution, if: - --dir option is specified, and - localrepository doesn't have "dirlog" attribute, which indicates that localrepository has a function for '--dir' BTW, extensions.wrapfunction() has been available since 1.1 (or 0ab5f21c390b), and this seems old enough for "historical portability" of perf.py, which has been available since 1.1 (or eb240755386d). diff --git a/contrib/perf.py b/contrib/perf.py --- a/contrib/perf.py +++ b/contrib/perf.py @@ -30,6 +30,7 @@ from mercurial import ( commands, copies, error, + extensions, mdiff, merge, obsolete, @@ -48,7 +49,17 @@ def safehasattr(thing, attr): setattr(util, 'safehasattr', safehasattr) formatteropts = commands.formatteropts -revlogopts = commands.debugrevlogopts + +# for "historical portability": +# use locally defined option list, if debugrevlogopts isn't available, +# because commands.debugrevlogopts has been available since 3.7 (or +# 5606f7d0d063), even though cmdutil.openrevlog() has been available +# since 1.9 (or a79fea6b3e77). +revlogopts = getattr(commands, "debugrevlogopts", [ + ('c', 'changelog', False, ('open changelog')), + ('m', 'manifest', False, ('open manifest')), + ('', 'dir', False, ('open directory manifest')), + ]) cmdtable = {} command = cmdutil.command(cmdtable) @@ -821,3 +832,18 @@ def perflrucache(ui, size=4, gets=10000, timer, fm = gettimer(ui, opts) timer(fn, title=title) fm.end() + +def uisetup(ui): + if (util.safehasattr(cmdutil, 'openrevlog') and + not util.safehasattr(commands, 'debugrevlogopts')): + # for "historical portability": + # In this case, Mercurial should be 1.9 (or a79fea6b3e77) - + # 3.7 (or 5606f7d0d063). Therefore, '--dir' option for + # openrevlog() should cause failure, because it has been + # available since 3.5 (or 49c583ca48c4). + def openrevlog(orig, repo, cmd, file_, opts): + if opts.get('dir') and not util.safehasattr(repo, 'dirlog'): + raise error.Abort("This version doesn't support --dir option", + hint="use 3.5 or later") + return orig(repo, cmd, file_, opts) + extensions.wrapfunction(cmdutil, 'openrevlog', openrevlog)