Patchwork [1,of,3] subrepo: move git version check into a separate method

login
register
mail settings
Submitter Mathias De Maré
Date Dec. 10, 2014, 9:48 a.m.
Message ID <5a05303a5e4753fb21e9.1418204926@mathias-Latitude-E6540>
Download mbox | patch
Permalink /patch/7040/
State Accepted
Commit f5de2a82b77ef9d5209b78546404795c204f0a72
Headers show

Comments

Mathias De Maré - Dec. 10, 2014, 9:48 a.m.
# HG changeset patch
# User Mathias De Maré <mathias.demare@gmail.com>
# Date 1418196783 -3600
#      Mit Dez 10 08:33:03 2014 +0100
# Node ID 5a05303a5e4753fb21e99c08635284c25dc8569f
# Parent  3575f42e1b7b174f46f1c69951526d410452abf4
subrepo: move git version check into a separate method

This allows checking the git version in other methods,
instead of only being able to check if the version is ok or not.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1130,16 +1130,24 @@  class gitsubrepo(abstractsubrepo):
         if versionstatus == 'unknown':
             self._ui.warn(_('cannot retrieve git version\n'))
         elif versionstatus == 'abort':
             raise util.Abort(_('git subrepo requires at least 1.6.0 or later'))
         elif versionstatus == 'warning':
             self._ui.warn(_('git subrepo requires at least 1.6.0 or later\n'))
 
     @staticmethod
+    def _gitversion(out):
+        m = re.search(r'^git version (\d+)\.(\d+)', out)
+        if m:
+            return (int(m.group(1)), int(m.group(2)))
+
+        return -1
+
+    @staticmethod
     def _checkversion(out):
         '''ensure git version is new enough
 
         >>> _checkversion = gitsubrepo._checkversion
         >>> _checkversion('git version 1.6.0')
         'ok'
         >>> _checkversion('git version 1.8.5')
         'ok'
@@ -1153,23 +1161,22 @@  class gitsubrepo(abstractsubrepo):
         'ok'
         >>> _checkversion('git version 1.9.0.GIT')
         'ok'
         >>> _checkversion('git version 12345')
         'unknown'
         >>> _checkversion('no')
         'unknown'
         '''
-        m = re.search(r'^git version (\d+)\.(\d+)', out)
-        if not m:
-            return 'unknown'
-        version = (int(m.group(1)), int(m.group(2)))
+        version = gitsubrepo._gitversion(out)
         # git 1.4.0 can't work at all, but 1.5.X can in at least some cases,
         # despite the docstring comment.  For now, error on 1.4.0, warn on
         # 1.5.0 but attempt to continue.
+        if version == -1:
+            return 'unknown'
         if version < (1, 5):
             return 'abort'
         elif version < (1, 6):
             return 'warning'
         return 'ok'
 
     def _gitcommand(self, commands, env=None, stream=False):
         return self._gitdir(commands, env=env, stream=stream)[0]