configwizard: handle missing cmdutil.command (bug 1282293); r=glob draft
authorGregory Szorc <gps@mozilla.com>
Tue, 28 Jun 2016 07:58:06 -0700
changeset 8665 34e24c5d52353af5c57c220acb6ff08894b52cf6
parent 8657 5672b13555b0d63d6ff99745b1781143881af735
child 8666 d6581fe622466d41cec140ad70d71918480d00da
push id955
push usergszorc@mozilla.com
push dateTue, 28 Jun 2016 14:58:18 +0000
reviewersglob
bugs1282293
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
hgext/configwizard/__init__.py
--- 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')