From patchwork Wed Dec 10 09:48:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [1,of,3] subrepo: move git version check into a separate method From: =?utf-8?q?Mathias_De_Mar=C3=A9?= X-Patchwork-Id: 7040 Message-Id: <5a05303a5e4753fb21e9.1418204926@mathias-Latitude-E6540> To: mercurial-devel@selenic.com Date: Wed, 10 Dec 2014 10:48:46 +0100 # HG changeset patch # User Mathias De Maré # 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. 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]