From f88b2fe5699ed224ad693e22a4c26fb76b8befc8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 10 Jul 2019 15:37:43 -0400 Subject: [PATCH] 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 Reviewed-by: David Pursehouse --- repo | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/repo b/repo index 114bb662..75d27692 100755 --- a/repo +++ b/repo @@ -383,7 +383,11 @@ def _Init(args, gitc_init=False): GitVersion = collections.namedtuple( '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 '): return None @@ -399,7 +403,7 @@ def ParseGitVersion(ver_str): return GitVersion(*to_tuple) -def _CheckGitVersion(): +def _GetGitVersion(): cmd = [GIT, '--version'] try: proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) @@ -410,13 +414,20 @@ def _CheckGitVersion(): print(file=sys.stderr) print('Please make sure %s is installed and in your path.' % GIT, file=sys.stderr) - raise CloneFailure() + raise ver_str = proc.stdout.read().strip() proc.stdout.close() 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: print('error: "%s" unsupported' % ver_str, file=sys.stderr) raise CloneFailure()