configwizard: implement ui.hasconfig (
bug 1281920); r?glob
ui.hasconfig() was added in 3.7. Rather than port consumers to use
old APIs, just implement the function when it isn't present.
This fixes a number of test failures on 3.5 and 3.6 but exposes
another test failure related to versiontuple being missing.
MozReview-Commit-ID: BQZJzu6oTm7
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -11,16 +11,17 @@ import subprocess
import sys
import uuid
from mercurial import (
cmdutil,
demandimport,
error,
scmutil,
+ ui as uimod,
util,
)
from mercurial.i18n import _
OUR_DIR = os.path.dirname(__file__)
execfile(os.path.join(OUR_DIR, '..', 'bootstrap.py'))
from configobj import ConfigObj
@@ -815,8 +816,20 @@ class configobjwrapper(object):
def write(self, fh):
lines = self.c.write()
for line in lines:
if line.startswith('#%s ' % self._random):
line = line[2 + len(self._random):]
fh.write('%s\n' % line)
+
+def uisetup(ui):
+ # hasconfig() was added in 3.7. Backport until we require 3.7.
+ if util.safehasattr(ui, 'hasconfig'):
+ return
+
+ class configui(ui.__class__):
+ def hasconfig(self, section, name, untrusted=False):
+ return name in self._data(untrusted)._data.get(section, {})
+
+ ui.__class__ = configui
+ uimod.ui = configui