mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Share git version parsing code with wrapper module
'repo' and 'git_command.py' had their own git version parsing code. This change shares that code between the modules. DRY is good. Change-Id: Ic896d2dc08353644bd4ced57e15a91284d97d54a
This commit is contained in:
parent
094cdbe090
commit
ff0a3c8f80
@ -21,6 +21,7 @@ import tempfile
|
|||||||
from signal import SIGTERM
|
from signal import SIGTERM
|
||||||
from error import GitError
|
from error import GitError
|
||||||
from trace import REPO_TRACE, IsTrace, Trace
|
from trace import REPO_TRACE, IsTrace, Trace
|
||||||
|
from wrapper import Wrapper
|
||||||
|
|
||||||
GIT = 'git'
|
GIT = 'git'
|
||||||
MIN_GIT_VERSION = (1, 5, 4)
|
MIN_GIT_VERSION = (1, 5, 4)
|
||||||
@ -84,19 +85,10 @@ class _GitCall(object):
|
|||||||
|
|
||||||
def version_tuple(self):
|
def version_tuple(self):
|
||||||
global _git_version
|
global _git_version
|
||||||
|
|
||||||
if _git_version is None:
|
if _git_version is None:
|
||||||
ver_str = git.version().decode('utf-8')
|
ver_str = git.version().decode('utf-8')
|
||||||
if ver_str.startswith('git version '):
|
_git_version = Wrapper().ParseGitVersion(ver_str)
|
||||||
num_ver_str = ver_str[len('git version '):].strip().split('-')[0]
|
if _git_version is None:
|
||||||
to_tuple = []
|
|
||||||
for num_str in num_ver_str.split('.')[:3]:
|
|
||||||
if num_str.isdigit():
|
|
||||||
to_tuple.append(int(num_str))
|
|
||||||
else:
|
|
||||||
to_tuple.append(0)
|
|
||||||
_git_version = tuple(to_tuple)
|
|
||||||
else:
|
|
||||||
print('fatal: "%s" unsupported' % ver_str, file=sys.stderr)
|
print('fatal: "%s" unsupported' % ver_str, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return _git_version
|
return _git_version
|
||||||
|
19
repo
19
repo
@ -278,6 +278,20 @@ def _Init(args):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def ParseGitVersion(ver_str):
|
||||||
|
if not ver_str.startswith('git version '):
|
||||||
|
return None
|
||||||
|
|
||||||
|
num_ver_str = ver_str[len('git version '):].strip().split('-')[0]
|
||||||
|
to_tuple = []
|
||||||
|
for num_str in num_ver_str.split('.')[:3]:
|
||||||
|
if num_str.isdigit():
|
||||||
|
to_tuple.append(int(num_str))
|
||||||
|
else:
|
||||||
|
to_tuple.append(0)
|
||||||
|
return tuple(to_tuple)
|
||||||
|
|
||||||
|
|
||||||
def _CheckGitVersion():
|
def _CheckGitVersion():
|
||||||
cmd = [GIT, '--version']
|
cmd = [GIT, '--version']
|
||||||
try:
|
try:
|
||||||
@ -295,12 +309,11 @@ def _CheckGitVersion():
|
|||||||
proc.stdout.close()
|
proc.stdout.close()
|
||||||
proc.wait()
|
proc.wait()
|
||||||
|
|
||||||
if not ver_str.startswith('git version '):
|
ver_act = ParseGitVersion(ver_str)
|
||||||
|
if ver_act is None:
|
||||||
_print('error: "%s" unsupported' % ver_str, file=sys.stderr)
|
_print('error: "%s" unsupported' % ver_str, file=sys.stderr)
|
||||||
raise CloneFailure()
|
raise CloneFailure()
|
||||||
|
|
||||||
ver_str = ver_str[len('git version '):].strip()
|
|
||||||
ver_act = tuple(map(int, ver_str.split('.')[0:3]))
|
|
||||||
if ver_act < MIN_GIT_VERSION:
|
if ver_act < MIN_GIT_VERSION:
|
||||||
need = '.'.join(map(str, MIN_GIT_VERSION))
|
need = '.'.join(map(str, MIN_GIT_VERSION))
|
||||||
_print('fatal: git %s or later required' % need, file=sys.stderr)
|
_print('fatal: git %s or later required' % need, file=sys.stderr)
|
||||||
|
Loading…
Reference in New Issue
Block a user