configwizard: handle missing cmdutil.command (
bug 1282293); r=glob
cmdutil.command was introduced in hg 1.9. Working around it being
missing allows the extension to load on hg 1.7 and 1.8.
It might run on earlier versions. However, I'm unable to run hg
1.6 and earlier on my machine when building hg from source. I
think compatibility down to 1.7 should be fine. So unless someone
complains, I'm inclined to leave this as our cut-off.
MozReview-Commit-ID: 1Vpy5V10Tj6
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -254,17 +254,23 @@ stolen if others have access to this fil
Would you like to fix the file permissions (Yn) $$ &Yes $$ &No
'''.strip()
testedwith = '3.5 3.6 3.7 3.8'
buglink = 'https://bugzilla.mozilla.org/enter_bug.cgi?product=Developer%20Services&component=Mercurial%3A%20configwizard'
cmdtable = {}
-command = cmdutil.command(cmdtable)
+
+# We want the extension to load on ancient versions of Mercurial.
+# cmdutil.command was introduced in 1.9.
+try:
+ command = cmdutil.command(cmdtable)
+except AttributeError:
+ command = None
wizardsteps = {
'hgversion',
'username',
'diff',
'color',
'pager',
'curses',
@@ -365,18 +371,31 @@ def configwizard(ui, repo, statedir=None
cwargs = [
('s', 'statedir', '', _('directory to store state')),
]
try:
configwizard = command('configwizard', cwargs, _('hg configwizard'),
optionalrepo=True)(configwizard)
except TypeError:
from mercurial import commands
- configwizard = command('configwizard', cwargs, _('hg configwizard'))(configwizard)
- commands.optionalrepo += ' configwizard'
+
+ # We can get TypeError for multiple reasons:
+ #
+ # 1. optionalrepo named argument not accepted
+ # 2. command is None
+
+ if command:
+ configwizard = command('configwizard', cwargs, _('hg configwizard'))(configwizard)
+ commands.optionalrepo += ' configwizard'
+ else:
+ commands.table['configwizard'] = (
+ configwizard, cwargs, _('hg configwizard')
+ )
+ commands.optionalrepo += ' configwizard'
+
def _checkhgversion(ui, hgversion):
if hgversion >= OLDEST_NON_LEGACY_VERSION:
return
ui.warn(LEGACY_MERCURIAL_MESSAGE % util.version())
ui.warn('\n')