progress: hide progress bar when --quiet
We want progress bars in the default output mode, but not when the
user specifies --quiet. Add a setting to the Progress bar class so
it takes care of not displaying anything itself rather than having
to update every subcommand to conditionally setup & call the object.
Change-Id: I1134993bffc5437bc22e26be11a512125f10597f
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/303225
Reviewed-by: Raman Tenneti <rtenneti@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
diff --git a/progress.py b/progress.py
index de46f53..43c7ad2 100644
--- a/progress.py
+++ b/progress.py
@@ -42,7 +42,8 @@
class Progress(object):
- def __init__(self, title, total=0, units='', print_newline=False, delay=True):
+ def __init__(self, title, total=0, units='', print_newline=False, delay=True,
+ quiet=False):
self._title = title
self._total = total
self._done = 0
@@ -54,6 +55,13 @@
self._show_jobs = False
self._active = 0
+ # When quiet, never show any output. It's a bit hacky, but reusing the
+ # existing logic that delays initial output keeps the rest of the class
+ # clean. Basically we set the start time to years in the future.
+ if quiet:
+ self._show = False
+ self._start += 2**32
+
def start(self, name):
self._active += 1
if not self._show_jobs:
diff --git a/subcmds/abandon.py b/subcmds/abandon.py
index ea3f4ed..1d22917 100644
--- a/subcmds/abandon.py
+++ b/subcmds/abandon.py
@@ -81,7 +81,7 @@
err[branch].append(project)
pm.update()
- pm = Progress('Abandon %s' % nb, len(all_projects))
+ pm = Progress('Abandon %s' % nb, len(all_projects), quiet=opt.quiet)
# NB: Multiprocessing is heavy, so don't spin it up for one job.
if len(all_projects) == 1 or opt.jobs == 1:
_ProcessResults(self._ExecuteOne(opt, nb, x) for x in all_projects)
diff --git a/subcmds/checkout.py b/subcmds/checkout.py
index cf54ced..6b71a8f 100644
--- a/subcmds/checkout.py
+++ b/subcmds/checkout.py
@@ -59,7 +59,7 @@
err.append(project)
pm.update()
- pm = Progress('Checkout %s' % nb, len(all_projects))
+ pm = Progress('Checkout %s' % nb, len(all_projects), quiet=opt.quiet)
# NB: Multiprocessing is heavy, so don't spin it up for one job.
if len(all_projects) == 1 or opt.jobs == 1:
_ProcessResults(self._ExecuteOne(nb, x) for x in all_projects)
diff --git a/subcmds/start.py b/subcmds/start.py
index 2593ace..aa2f915 100644
--- a/subcmds/start.py
+++ b/subcmds/start.py
@@ -106,7 +106,7 @@
if not os.path.exists(os.getcwd()):
os.chdir(self.manifest.topdir)
- pm = Progress('Syncing %s' % nb, len(all_projects))
+ pm = Progress('Syncing %s' % nb, len(all_projects), quiet=opt.quiet)
for project in all_projects:
gitc_project = self.gitc_manifest.paths[project.relpath]
# Sync projects that have not been opened.
@@ -129,7 +129,7 @@
err.append(project)
pm.update()
- pm = Progress('Starting %s' % nb, len(all_projects))
+ pm = Progress('Starting %s' % nb, len(all_projects), quiet=opt.quiet)
# NB: Multiprocessing is heavy, so don't spin it up for one job.
if len(all_projects) == 1 or opt.jobs == 1:
_ProcessResults(self._ExecuteOne(opt, nb, x) for x in all_projects)
diff --git a/subcmds/sync.py b/subcmds/sync.py
index e707987..21166af 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -367,7 +367,7 @@
jobs = opt.jobs_network if opt.jobs_network else self.jobs
fetched = set()
- pm = Progress('Fetching', len(projects), delay=False)
+ pm = Progress('Fetching', len(projects), delay=False, quiet=opt.quiet)
objdir_project_map = dict()
for project in projects:
@@ -470,7 +470,7 @@
# Only checkout projects with worktrees.
all_projects = [x for x in all_projects if x.worktree]
- pm = Progress('Checking out', len(all_projects))
+ pm = Progress('Checking out', len(all_projects), quiet=opt.quiet)
def _ProcessResults(results):
for (success, project, start, finish) in results:
@@ -504,7 +504,7 @@
return ret and not err_results
def _GCProjects(self, projects, opt, err_event):
- pm = Progress('Garbage collecting', len(projects), delay=False)
+ pm = Progress('Garbage collecting', len(projects), delay=False, quiet=opt.quiet)
pm.update(inc=0, msg='prescan')
gc_gitdirs = {}