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>
diff --git a/repo b/repo
index 114bb66..75d2769 100755
--- a/repo
+++ b/repo
@@ -383,7 +383,11 @@
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 @@
return GitVersion(*to_tuple)
-def _CheckGitVersion():
+def _GetGitVersion():
cmd = [GIT, '--version']
try:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -410,13 +414,20 @@
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()