repo/init/sync: rework default git download output

When we download git sources, we get a progress bar (good) and we get
a dump of all the refs we downloaded (bad) as it can easily be 100+ if
not 1000+ depending on the project (for each git repo!).  Lets rework
the output behavior so that:
* quiet: Only errors.
* default: Progress bars (if on a tty).
* verbose: Full output (progress bars & downloaded refs).

Bug: https://crbug.com/gerrit/11293
Change-Id: I87a380075e79de6805f91095876dd1b37d32873a
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/256456
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Michael Mortensen <mmortensen@google.com>
This commit is contained in:
Mike Frysinger 2020-02-22 00:07:35 -05:00
parent bb8ee7f54a
commit 4847e05743
2 changed files with 15 additions and 10 deletions

View File

@ -2440,8 +2440,10 @@ class Project(object):
if os.path.exists(os.path.join(self.gitdir, 'shallow')):
cmd.append('--depth=2147483647')
if quiet:
if not verbose:
cmd.append('--quiet')
if not quiet and sys.stdout.isatty():
cmd.append('--progress')
if not self.worktree:
cmd.append('--update-head-ok')
cmd.append(name)
@ -2498,7 +2500,7 @@ class Project(object):
ok = False
for _i in range(2):
gitcmd = GitCommand(self, cmd, bare=True, ssh_proxy=ssh_proxy,
merge_output=True, capture_stdout=not verbose)
merge_output=True, capture_stdout=quiet)
ret = gitcmd.Wait()
if ret == 0:
ok = True
@ -2578,8 +2580,10 @@ class Project(object):
return False
cmd = ['fetch']
if quiet:
if not verbose:
cmd.append('--quiet')
if not quiet and sys.stdout.isatty():
cmd.append('--progress')
if not self.worktree:
cmd.append('--update-head-ok')
cmd.append(bundle_dst)
@ -2639,9 +2643,8 @@ class Project(object):
# 22: HTTP page not retrieved. The requested url was not found or
# returned another error with the HTTP error code being 400 or above.
# This return code only appears if -f, --fail is used.
if not quiet:
print("Server does not provide clone.bundle; ignoring.",
file=sys.stderr)
if verbose:
print('Server does not provide clone.bundle; ignoring.')
return False
elif curlret and not verbose and output:
print('%s' % output, file=sys.stderr)

10
repo
View File

@ -758,15 +758,17 @@ def _InitHttp():
def _Fetch(url, cwd, src, quiet, verbose):
cmd = ['fetch']
if quiet:
if not verbose:
cmd.append('--quiet')
err = subprocess.PIPE
else:
err = None
if not quiet and sys.stdout.isatty():
cmd.append('--progress')
elif not verbose:
err = subprocess.PIPE
cmd.append(src)
cmd.append('+refs/heads/*:refs/remotes/origin/*')
cmd.append('+refs/tags/*:refs/tags/*')
run_git(*cmd, stderr=err, cwd=cwd)
run_git(*cmd, stderr=err, capture_output=False, cwd=cwd)
def _DownloadBundle(url, cwd, quiet, verbose):