Patchwork [STABLE] util: better handle '-' in version string (issue5302)

login
register
mail settings
Submitter Gregory Szorc
Date July 19, 2016, 5:16 p.m.
Message ID <755d17c65ebbc4e9734e.1468948618@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/15957/
State Accepted
Headers show

Comments

Gregory Szorc - July 19, 2016, 5:16 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@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.
Matt Mackall - July 19, 2016, 5:57 p.m.
On Tue, 2016-07-19 at 10:16 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@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)

Queued for stable, thanks.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

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: