[PATCH STABLE] util: better handle '-' in version string (issue5302)
Gregory Szorc
gregory.szorc at gmail.com
Tue Jul 19 17:16:58 UTC 2016
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1468948535 25200
# Tue Jul 19 10:15:35 2016 -0700
# Branch stable
# Node ID 755d17c65ebbc4e9734ea9e39ca4af83c9bdf639
# Parent 02a8fea4289b51992b2495a06d4b12cbda876cf1
util: better handle '-' in version string (issue5302)
versiontuple() was previously only splitting on '+' and strings
like "3.9-rc" were causing it to misreport the version as
(3, None). By splitting on either '+' or '-' we can handle
our version strings with "-rc" in them.
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -391,20 +391,36 @@ def versiontuple(v=None, n=4):
>>> v = '3.6'
>>> versiontuple(v, 2)
(3, 6)
>>> versiontuple(v, 3)
(3, 6, None)
>>> versiontuple(v, 4)
(3, 6, None, None)
+
+ >>> v = '3.9-rc'
+ >>> versiontuple(v, 2)
+ (3, 9)
+ >>> versiontuple(v, 3)
+ (3, 9, None)
+ >>> versiontuple(v, 4)
+ (3, 9, None, 'rc')
+
+ >>> v = '3.9-rc+2-02a8fea4289b'
+ >>> versiontuple(v, 2)
+ (3, 9)
+ >>> versiontuple(v, 3)
+ (3, 9, None)
+ >>> versiontuple(v, 4)
+ (3, 9, None, 'rc+2-02a8fea4289b')
"""
if not v:
v = version()
- parts = v.split('+', 1)
+ parts = remod.split('[\+-]', v, 1)
if len(parts) == 1:
vparts, extra = parts[0], None
else:
vparts, extra = parts
vints = []
for i in vparts.split('.'):
try:
More information about the Mercurial-devel
mailing list