From 43549d8d08ed206c1c5cb85bd6884d3bfd344d4c Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Wed, 30 Nov 2022 19:55:30 +0000 Subject: [PATCH] sync: cleanup output when not doing GC Do not use a progress bar when not doing GC, and restrict activity in that case to only repairing preciousObject state. This also includes additional cleanup based on review comments from previous changes. Change-Id: I48581c9d25da358bc7ae15f40e98d55bec142331 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/353514 Tested-by: LaMont Jones Reviewed-by: Mike Frysinger --- subcmds/sync.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/subcmds/sync.py b/subcmds/sync.py index 8cd1bcac..75512031 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -775,19 +775,18 @@ later is required to fix a server side protocol bug. print(f'\r{relpath}: project not found in manifest.', file=sys.stderr) return False - def _RepairPreciousObjectsState(self, project: Project, opt): + def _SetPreciousObjectsState(self, project: Project, opt): """Correct the preciousObjects state for the project. Args: - project (Project): the project to examine, and possibly correct. - opt (optparse.Values): options given to sync. + project: the project to examine, and possibly correct. + opt: options given to sync. """ expected = self._GetPreciousObjectsState(project, opt) actual = project.config.GetBoolean('extensions.preciousObjects') or False - relpath = project.RelPath(local = opt.this_manifest_only) + relpath = project.RelPath(local=opt.this_manifest_only) - if (expected != actual and - not project.config.GetBoolean('repo.preservePreciousObjects')): + if expected != actual: # If this is unexpected, log it and repair. Trace(f'{relpath} expected preciousObjects={expected}, got {actual}') if expected: @@ -816,13 +815,19 @@ later is required to fix a server side protocol bug. to potentially mark objects precious, so that `git gc` does not discard shared objects. """ - pm = Progress(f'{"" if opt.auto_gc else "NOT "}Garbage collecting', - len(projects), delay=False, quiet=opt.quiet) + if not opt.auto_gc: + # Just repair preciousObjects state, and return. + for project in projects: + self._SetPreciousObjectsState(project, opt) + return + + pm = Progress('Garbage collecting', len(projects), delay=False, + quiet=opt.quiet) pm.update(inc=0, msg='prescan') tidy_dirs = {} for project in projects: - self._RepairPreciousObjectsState(project, opt) + self._SetPreciousObjectsState(project, opt) project.config.SetString('gc.autoDetach', 'false') # Only call git gc once per objdir, but call pack-refs for the remainder. @@ -837,10 +842,6 @@ later is required to fix a server side protocol bug. project.bare_git, ) - if not opt.auto_gc: - pm.end() - return - jobs = opt.jobs if jobs < 2: