project: handle verbose with initial clone bundle

If we're not in --verbose mode with repo sync, then omit the
per-project clone bundle progress bar.

Bug: https://crbug.com/gerrit/11293
Change-Id: Ibdf3be86d35fcbccbf6788c192189f38c577e6e9
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255854
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
Mike Frysinger 2020-02-19 01:45:48 -05:00 committed by David Pursehouse
parent 8a98efee5c
commit e50b6a7c4f

View File

@ -1487,9 +1487,9 @@ class Project(object):
else: else:
alt_dir = None alt_dir = None
if clone_bundle \ if (clone_bundle
and alt_dir is None \ and alt_dir is None
and self._ApplyCloneBundle(initial=is_new, quiet=quiet): and self._ApplyCloneBundle(initial=is_new, quiet=quiet, verbose=verbose)):
is_new = False is_new = False
if not current_branch_only: if not current_branch_only:
@ -2415,7 +2415,7 @@ class Project(object):
return ok return ok
def _ApplyCloneBundle(self, initial=False, quiet=False): def _ApplyCloneBundle(self, initial=False, quiet=False, verbose=False):
if initial and \ if initial and \
(self.manifest.manifestProject.config.GetString('repo.depth') or (self.manifest.manifestProject.config.GetString('repo.depth') or
self.clone_depth): self.clone_depth):
@ -2439,7 +2439,8 @@ class Project(object):
return False return False
if not exist_dst: if not exist_dst:
exist_dst = self._FetchBundle(bundle_url, bundle_tmp, bundle_dst, quiet) exist_dst = self._FetchBundle(bundle_url, bundle_tmp, bundle_dst, quiet,
verbose)
if not exist_dst: if not exist_dst:
return False return False
@ -2460,13 +2461,13 @@ class Project(object):
platform_utils.remove(bundle_tmp) platform_utils.remove(bundle_tmp)
return ok return ok
def _FetchBundle(self, srcUrl, tmpPath, dstPath, quiet): def _FetchBundle(self, srcUrl, tmpPath, dstPath, quiet, verbose):
if os.path.exists(dstPath): if os.path.exists(dstPath):
platform_utils.remove(dstPath) platform_utils.remove(dstPath)
cmd = ['curl', '--fail', '--output', tmpPath, '--netrc', '--location'] cmd = ['curl', '--fail', '--output', tmpPath, '--netrc', '--location']
if quiet: if quiet:
cmd += ['--silent'] cmd += ['--silent', '--show-error']
if os.path.exists(tmpPath): if os.path.exists(tmpPath):
size = os.stat(tmpPath).st_size size = os.stat(tmpPath).st_size
if size >= 1024: if size >= 1024:
@ -2488,12 +2489,17 @@ class Project(object):
if IsTrace(): if IsTrace():
Trace('%s', ' '.join(cmd)) Trace('%s', ' '.join(cmd))
if verbose:
print('%s: Downloading bundle: %s' % (self.name, srcUrl))
stdout = None if verbose else subprocess.PIPE
stderr = None if verbose else subprocess.STDOUT
try: try:
proc = subprocess.Popen(cmd) proc = subprocess.Popen(cmd, stdout=stdout, stderr=stderr)
except OSError: except OSError:
return False return False
curlret = proc.wait() (output, _) = proc.communicate()
curlret = proc.returncode
if curlret == 22: if curlret == 22:
# From curl man page: # From curl man page:
@ -2504,6 +2510,8 @@ class Project(object):
print("Server does not provide clone.bundle; ignoring.", print("Server does not provide clone.bundle; ignoring.",
file=sys.stderr) file=sys.stderr)
return False return False
elif curlret and not verbose and output:
print('%s' % output, file=sys.stderr)
if os.path.exists(tmpPath): if os.path.exists(tmpPath):
if curlret == 0 and self._IsValidBundle(tmpPath, quiet): if curlret == 0 and self._IsValidBundle(tmpPath, quiet):