changeset 37801:5cab6f5016fa stable

version: make parser more robust for rc variants and ill-formed strings
author Yuya Nishihara <yuya@tcha.org>
date Fri, 20 Apr 2018 20:38:29 +0900
parents 6cf5f5b4eb57
children 090c89a8db32
files mercurial/util.py
diffstat 1 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Wed Apr 18 19:02:44 2018 -0600
+++ b/mercurial/util.py	Fri Apr 20 20:38:29 2018 +0900
@@ -1037,14 +1037,27 @@
     (3, 9, None)
     >>> versiontuple(v, 4)
     (3, 9, None, 'rc+2-02a8fea4289b')
+
+    >>> versiontuple(b'4.6rc0')
+    (4, 6, None, 'rc0')
+    >>> versiontuple(b'4.6rc0+12-425d55e54f98')
+    (4, 6, None, 'rc0+12-425d55e54f98')
+    >>> versiontuple(b'.1.2.3')
+    (None, None, None, '.1.2.3')
+    >>> versiontuple(b'12.34..5')
+    (12, 34, None, '..5')
+    >>> versiontuple(b'1.2.3.4.5.6')
+    (1, 2, 3, '.4.5.6')
     """
     if not v:
         v = version()
-    parts = remod.split('[\+-]', v, 1)
-    if len(parts) == 1:
-        vparts, extra = parts[0], None
+    m = remod.match(br'(\d+(?:\.\d+){,2})[\+-]?(.*)', v)
+    if not m:
+        vparts, extra = '', v
+    elif m.group(2):
+        vparts, extra = m.groups()
     else:
-        vparts, extra = parts
+        vparts, extra = m.group(1), None
 
     vints = []
     for i in vparts.split('.'):