[Request] [+- ] D11475: extensions: prevent a crash on py3 when testing a bad extension minimum
mharbison72 (Matt Harbison)
phabricator at mercurial-scm.org
Tue Sep 21 15:39:28 UTC 2021
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
A `None` placeholder is populated for each missing component by
`util.versiontuple()`, which could safely be used with `>` on py2, but not py3.
I guess there's another hole here where if the string is entirely bogus (i.e no
numbers), it will be treated as 0.0, and always load. But that's always been
the case.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D11475
AFFECTED FILES
mercurial/extensions.py
tests/test-extension.t
CHANGE DETAILS
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -1692,6 +1692,25 @@
$ hg --config extensions.minversion=minversion3.py version 2>&1 | egrep '\(third'
[1]
+Don't explode on py3 with a bad version number
+
+ $ cat > minversion4.py << EOF
+ > from mercurial import util
+ > util.version = lambda: b'3.5'
+ > minimumhgversion = b'3'
+ > EOF
+ $ hg --config extensions.minversion=minversion4.py version -v
+ Mercurial Distributed SCM (version 3.5)
+ (see https://mercurial-scm.org for more information)
+
+ Copyright (C) 2005-* Olivia Mackall and others (glob)
+ This is free software; see the source for copying conditions. There is NO
+ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ Enabled extensions:
+
+ minversion external
+
Restore HGRCPATH
$ HGRCPATH=$ORGHGRCPATH
diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -224,8 +224,12 @@
minver = getattr(mod, 'minimumhgversion', None)
if minver:
curver = util.versiontuple(n=2)
+ extmin = util.versiontuple(minver, 2)
- if None in curver or util.versiontuple(minver, 2) > curver:
+ if None in extmin:
+ extmin = (extmin[0] or 0, extmin[1] or 0)
+
+ if None in curver or extmin > curver:
msg = _(
b'(third party extension %s requires version %s or newer '
b'of Mercurial (current: %s); disabling)\n'
To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210921/22d8bb40/attachment.html>
More information about the Mercurial-patches
mailing list