From 151701e85f0beb1a7c896eb82c0d1f55ee380567 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 13 Apr 2021 15:07:21 -0400 Subject: [PATCH] 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 Tested-by: Mike Frysinger --- progress.py | 10 +++++++++- subcmds/abandon.py | 2 +- subcmds/checkout.py | 2 +- subcmds/start.py | 4 ++-- subcmds/sync.py | 6 +++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/progress.py b/progress.py index de46f538..43c7ad21 100644 --- a/progress.py +++ b/progress.py @@ -42,7 +42,8 @@ def duration_str(total): 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 @@ class Progress(object): 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 ea3f4ed0..1d22917e 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py @@ -81,7 +81,7 @@ It is equivalent to "git branch -D ". 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 cf54ced7..6b71a8fa 100644 --- a/subcmds/checkout.py +++ b/subcmds/checkout.py @@ -59,7 +59,7 @@ The command is equivalent to: 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 2593ace6..aa2f915a 100644 --- a/subcmds/start.py +++ b/subcmds/start.py @@ -106,7 +106,7 @@ revision specified in the manifest. 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 @@ revision specified in the manifest. 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 e7079879..21166af5 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -367,7 +367,7 @@ later is required to fix a server side protocol bug. 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 @@ later is required to fix a server side protocol bug. # 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 @@ later is required to fix a server side protocol bug. 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 = {}