diff options
| author | Mike Frysinger <vapier@google.com> | 2021-04-13 15:07:21 -0400 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2021-04-13 22:25:26 +0000 |
| commit | 151701e85f0beb1a7c896eb82c0d1f55ee380567 (patch) | |
| tree | 7e86c0ff2835050abf73b62bac69390dfb67b8a6 | |
| parent | 9180a07b8fb33d5ba0b82facf987b51ca7b15dc4 (diff) | |
| download | git-repo-151701e85f0beb1a7c896eb82c0d1f55ee380567.tar.gz | |
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>
| -rw-r--r-- | progress.py | 10 | ||||
| -rw-r--r-- | subcmds/abandon.py | 2 | ||||
| -rw-r--r-- | subcmds/checkout.py | 2 | ||||
| -rw-r--r-- | subcmds/start.py | 4 | ||||
| -rw-r--r-- | 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): | |||
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | class Progress(object): | 44 | class Progress(object): |
| 45 | def __init__(self, title, total=0, units='', print_newline=False, delay=True): | 45 | def __init__(self, title, total=0, units='', print_newline=False, delay=True, |
| 46 | quiet=False): | ||
| 46 | self._title = title | 47 | self._title = title |
| 47 | self._total = total | 48 | self._total = total |
| 48 | self._done = 0 | 49 | self._done = 0 |
| @@ -54,6 +55,13 @@ class Progress(object): | |||
| 54 | self._show_jobs = False | 55 | self._show_jobs = False |
| 55 | self._active = 0 | 56 | self._active = 0 |
| 56 | 57 | ||
| 58 | # When quiet, never show any output. It's a bit hacky, but reusing the | ||
| 59 | # existing logic that delays initial output keeps the rest of the class | ||
| 60 | # clean. Basically we set the start time to years in the future. | ||
| 61 | if quiet: | ||
| 62 | self._show = False | ||
| 63 | self._start += 2**32 | ||
| 64 | |||
| 57 | def start(self, name): | 65 | def start(self, name): |
| 58 | self._active += 1 | 66 | self._active += 1 |
| 59 | if not self._show_jobs: | 67 | 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 <branchname>". | |||
| 81 | err[branch].append(project) | 81 | err[branch].append(project) |
| 82 | pm.update() | 82 | pm.update() |
| 83 | 83 | ||
| 84 | pm = Progress('Abandon %s' % nb, len(all_projects)) | 84 | pm = Progress('Abandon %s' % nb, len(all_projects), quiet=opt.quiet) |
| 85 | # NB: Multiprocessing is heavy, so don't spin it up for one job. | 85 | # NB: Multiprocessing is heavy, so don't spin it up for one job. |
| 86 | if len(all_projects) == 1 or opt.jobs == 1: | 86 | if len(all_projects) == 1 or opt.jobs == 1: |
| 87 | _ProcessResults(self._ExecuteOne(opt, nb, x) for x in all_projects) | 87 | _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: | |||
| 59 | err.append(project) | 59 | err.append(project) |
| 60 | pm.update() | 60 | pm.update() |
| 61 | 61 | ||
| 62 | pm = Progress('Checkout %s' % nb, len(all_projects)) | 62 | pm = Progress('Checkout %s' % nb, len(all_projects), quiet=opt.quiet) |
| 63 | # NB: Multiprocessing is heavy, so don't spin it up for one job. | 63 | # NB: Multiprocessing is heavy, so don't spin it up for one job. |
| 64 | if len(all_projects) == 1 or opt.jobs == 1: | 64 | if len(all_projects) == 1 or opt.jobs == 1: |
| 65 | _ProcessResults(self._ExecuteOne(nb, x) for x in all_projects) | 65 | _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. | |||
| 106 | if not os.path.exists(os.getcwd()): | 106 | if not os.path.exists(os.getcwd()): |
| 107 | os.chdir(self.manifest.topdir) | 107 | os.chdir(self.manifest.topdir) |
| 108 | 108 | ||
| 109 | pm = Progress('Syncing %s' % nb, len(all_projects)) | 109 | pm = Progress('Syncing %s' % nb, len(all_projects), quiet=opt.quiet) |
| 110 | for project in all_projects: | 110 | for project in all_projects: |
| 111 | gitc_project = self.gitc_manifest.paths[project.relpath] | 111 | gitc_project = self.gitc_manifest.paths[project.relpath] |
| 112 | # Sync projects that have not been opened. | 112 | # Sync projects that have not been opened. |
| @@ -129,7 +129,7 @@ revision specified in the manifest. | |||
| 129 | err.append(project) | 129 | err.append(project) |
| 130 | pm.update() | 130 | pm.update() |
| 131 | 131 | ||
| 132 | pm = Progress('Starting %s' % nb, len(all_projects)) | 132 | pm = Progress('Starting %s' % nb, len(all_projects), quiet=opt.quiet) |
| 133 | # NB: Multiprocessing is heavy, so don't spin it up for one job. | 133 | # NB: Multiprocessing is heavy, so don't spin it up for one job. |
| 134 | if len(all_projects) == 1 or opt.jobs == 1: | 134 | if len(all_projects) == 1 or opt.jobs == 1: |
| 135 | _ProcessResults(self._ExecuteOne(opt, nb, x) for x in all_projects) | 135 | _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. | |||
| 367 | 367 | ||
| 368 | jobs = opt.jobs_network if opt.jobs_network else self.jobs | 368 | jobs = opt.jobs_network if opt.jobs_network else self.jobs |
| 369 | fetched = set() | 369 | fetched = set() |
| 370 | pm = Progress('Fetching', len(projects), delay=False) | 370 | pm = Progress('Fetching', len(projects), delay=False, quiet=opt.quiet) |
| 371 | 371 | ||
| 372 | objdir_project_map = dict() | 372 | objdir_project_map = dict() |
| 373 | for project in projects: | 373 | for project in projects: |
| @@ -470,7 +470,7 @@ later is required to fix a server side protocol bug. | |||
| 470 | # Only checkout projects with worktrees. | 470 | # Only checkout projects with worktrees. |
| 471 | all_projects = [x for x in all_projects if x.worktree] | 471 | all_projects = [x for x in all_projects if x.worktree] |
| 472 | 472 | ||
| 473 | pm = Progress('Checking out', len(all_projects)) | 473 | pm = Progress('Checking out', len(all_projects), quiet=opt.quiet) |
| 474 | 474 | ||
| 475 | def _ProcessResults(results): | 475 | def _ProcessResults(results): |
| 476 | for (success, project, start, finish) in results: | 476 | for (success, project, start, finish) in results: |
| @@ -504,7 +504,7 @@ later is required to fix a server side protocol bug. | |||
| 504 | return ret and not err_results | 504 | return ret and not err_results |
| 505 | 505 | ||
| 506 | def _GCProjects(self, projects, opt, err_event): | 506 | def _GCProjects(self, projects, opt, err_event): |
| 507 | pm = Progress('Garbage collecting', len(projects), delay=False) | 507 | pm = Progress('Garbage collecting', len(projects), delay=False, quiet=opt.quiet) |
| 508 | pm.update(inc=0, msg='prescan') | 508 | pm.update(inc=0, msg='prescan') |
| 509 | 509 | ||
| 510 | gc_gitdirs = {} | 510 | gc_gitdirs = {} |
