[PATCH 2 of 3] dispatch: use versiontuple()

Gregory Szorc gregory.szorc at gmail.com
Tue Nov 24 17:19:09 CST 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1448403826 28800
#      Tue Nov 24 14:23:46 2015 -0800
# Node ID ed2e8713d5f11c64bf9d5c9b6a0d802b5d534fbe
# Parent  9a38b970471b77e566d28f95643d9d21213f97a8
dispatch: use versiontuple()

We have a new generic function for this. Use it.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -319,18 +319,16 @@ def _runcatch(req):
         return inst.code
     except socket.error as inst:
         ui.warn(_("abort: %s\n") % inst.args[-1])
     except: # re-raises
-        myver = util.version()
         # For compatibility checking, we discard the portion of the hg
         # version after the + on the assumption that if a "normal
         # user" is running a build with a + in it the packager
         # probably built from fairly close to a tag and anyone with a
         # 'make local' copy of hg (where the version number can be out
         # of date) will be clueful enough to notice the implausible
         # version number and try updating.
-        compare = myver.split('+')[0]
-        ct = tuplever(compare)
+        ct = util.versiontuple(n=2)
         worst = None, ct, ''
         if ui.config('ui', 'supportcontact', None) is None:
             for name, mod in extensions.extensions():
                 testedwith = getattr(mod, 'testedwith', '')
@@ -343,9 +341,9 @@ def _runcatch(req):
                 # Never blame on extensions bundled with Mercurial.
                 if testedwith == 'internal':
                     continue
 
-                tested = [tuplever(t) for t in testedwith.split()]
+                tested = [util.versiontuple(t, 2) for t in testedwith.split()]
                 if ct in tested:
                     continue
 
                 lower = [t for t in tested if t < ct]
@@ -368,26 +366,18 @@ def _runcatch(req):
                 bugtracker = _("https://mercurial-scm.org/wiki/BugTracker")
             warning = (_("** unknown exception encountered, "
                          "please report by visiting\n** ") + bugtracker + '\n')
         warning += ((_("** Python %s\n") % sys.version.replace('\n', '')) +
-                    (_("** Mercurial Distributed SCM (version %s)\n") % myver) +
+                    (_("** Mercurial Distributed SCM (version %s)\n") %
+                       util.version()) +
                     (_("** Extensions loaded: %s\n") %
                      ", ".join([x[0] for x in extensions.extensions()])))
         ui.log("commandexception", "%s\n%s\n", warning, traceback.format_exc())
         ui.warn(warning)
         raise
 
     return -1
 
-def tuplever(v):
-    try:
-        # Assertion: tuplever is only used for extension compatibility
-        # checking. Otherwise, the discarding of extra version fields is
-        # incorrect.
-        return tuple([int(i) for i in v.split('.')[0:2]])
-    except ValueError:
-        return tuple()
-
 def aliasargs(fn, givenargs):
     args = getattr(fn, 'args', [])
     if args:
         cmd = ' '.join(map(util.shellquote, args))


More information about the Mercurial-devel mailing list