mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
repo: all ParseGitVersion to load git version info itself
All code that calls ParseGitVersion needs to run `git --version` itself and parse the output before passing it in. To avoid that duplication, allow ParseGitVersion to run `git --version` itself if ver_str=None. Bug: https://crbug.com/gerrit/11144 Change-Id: Ie07793ca57a40c0231af808df04a576118d5eea3 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/231054 Tested-by: Mike Frysinger <vapier@google.com> Reviewed-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
parent
6db1b9e282
commit
f88b2fe569
19
repo
19
repo
@ -383,7 +383,11 @@ def _Init(args, gitc_init=False):
|
|||||||
GitVersion = collections.namedtuple(
|
GitVersion = collections.namedtuple(
|
||||||
'GitVersion', ('major', 'minor', 'micro', 'full'))
|
'GitVersion', ('major', 'minor', 'micro', 'full'))
|
||||||
|
|
||||||
def ParseGitVersion(ver_str):
|
def ParseGitVersion(ver_str=None):
|
||||||
|
if ver_str is None:
|
||||||
|
# Load the version ourselves.
|
||||||
|
ver_str = _GetGitVersion()
|
||||||
|
|
||||||
if not ver_str.startswith('git version '):
|
if not ver_str.startswith('git version '):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -399,7 +403,7 @@ def ParseGitVersion(ver_str):
|
|||||||
return GitVersion(*to_tuple)
|
return GitVersion(*to_tuple)
|
||||||
|
|
||||||
|
|
||||||
def _CheckGitVersion():
|
def _GetGitVersion():
|
||||||
cmd = [GIT, '--version']
|
cmd = [GIT, '--version']
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||||
@ -410,13 +414,20 @@ def _CheckGitVersion():
|
|||||||
print(file=sys.stderr)
|
print(file=sys.stderr)
|
||||||
print('Please make sure %s is installed and in your path.' % GIT,
|
print('Please make sure %s is installed and in your path.' % GIT,
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
raise CloneFailure()
|
raise
|
||||||
|
|
||||||
ver_str = proc.stdout.read().strip()
|
ver_str = proc.stdout.read().strip()
|
||||||
proc.stdout.close()
|
proc.stdout.close()
|
||||||
proc.wait()
|
proc.wait()
|
||||||
|
return ver_str.decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
|
def _CheckGitVersion():
|
||||||
|
try:
|
||||||
|
ver_act = ParseGitVersion()
|
||||||
|
except OSError:
|
||||||
|
raise CloneFailure()
|
||||||
|
|
||||||
ver_act = ParseGitVersion(ver_str)
|
|
||||||
if ver_act is None:
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user