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>
diff --git a/project.py b/project.py
index fe55371..4c8c2ba 100644
--- a/project.py
+++ b/project.py
@@ -2440,8 +2440,10 @@
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 @@
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 @@
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 @@
# 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)
diff --git a/repo b/repo
index 0bf2121..18694c5 100755
--- a/repo
+++ b/repo
@@ -758,15 +758,17 @@
def _Fetch(url, cwd, src, quiet, verbose):
cmd = ['fetch']
- if quiet:
+ if not verbose:
cmd.append('--quiet')
+ err = None
+ if not quiet and sys.stdout.isatty():
+ cmd.append('--progress')
+ elif not verbose:
err = subprocess.PIPE
- else:
- err = None
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):