configwizard: backport util.versiontuple (
bug 1281920); r?glob
util.versiontuple was added in Mercurial 3.7. The lack of it was
causing test failures when executed on hg < 3.7. Backport it if
necessary so the config wizard runs on older hg versions.
With this change, tests appear to pass on 3.5 and 3.6 with only
cosmetic differences (whitespace differences after prompt text
for reasons unknown to me).
MozReview-Commit-ID: FnzZ554Ut1X
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -828,8 +828,40 @@ def uisetup(ui):
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
+
+
+def extsetup(ui):
+ # util.versiontuple was added in 3.6. Backport it.
+ def versiontuple(v=None, n=4):
+ if not v:
+ v = util.version()
+ parts = v.split('+', 1)
+ if len(parts) == 1:
+ vparts, extra = parts[0], None
+ else:
+ vparts, extra = parts
+
+ vints = []
+ for i in vparts.split('.'):
+ try:
+ vints.append(int(i))
+ except ValueError:
+ break
+ # (3, 6) -> (3, 6, None)
+ while len(vints) < 3:
+ vints.append(None)
+
+ if n == 2:
+ return (vints[0], vints[1])
+ if n == 3:
+ return (vints[0], vints[1], vints[2])
+ if n == 4:
+ return (vints[0], vints[1], vints[2], extra)
+
+ if not util.safehasattr(util, 'versiontuple'):
+ util.versiontuple = versiontuple