configwizard: support loading extension on older Mercurial versions (
bug 1282293); r=glob
See the inline comment for why we do this.
With this change, the extension now loads with Mercurial versions
down to 2.0.
MozReview-Commit-ID: G6cVOHtERvs
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -276,19 +276,17 @@ wizardsteps = {
'firefoxtree',
'codereview',
'pushtotry',
'multiplevct',
'configchange',
'permissions',
}
-@command('configwizard', [
- ('s', 'statedir', '', _('directory to store state')),
- ], _('hg configwizard'), optionalrepo=True)
+
def configwizard(ui, repo, statedir=None, **opts):
"""Ensure your Mercurial configuration is up to date."""
runsteps = set(wizardsteps)
if ui.hasconfig('configwizard', 'steps'):
runsteps = set(ui.configlist('configwizard', 'steps'))
hgversion = util.versiontuple(n=3)
@@ -354,16 +352,32 @@ def configwizard(ui, repo, statedir=None
_handleconfigchange(ui, cw)
if 'permissions' in runsteps:
_checkpermissions(ui, cw)
return 0
+# Older versions of Mercurial don't support the "optionalrepo" named
+# argument on the command decorator. While we don't support these older
+# versions of Mercurial, this could cause extension loading to fail.
+# So we handle the error to enable the extension to load and the command
+# to run.
+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'
+
def _checkhgversion(ui, hgversion):
if hgversion >= OLDEST_NON_LEGACY_VERSION:
return
ui.warn(LEGACY_MERCURIAL_MESSAGE % util.version())
ui.warn('\n')
if os.name == 'nt':