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 <lamontjones@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
LaMont Jones 2022-11-30 19:55:30 +00:00
parent 55b7125d6a
commit 43549d8d08

View File

@ -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) print(f'\r{relpath}: project not found in manifest.', file=sys.stderr)
return False return False
def _RepairPreciousObjectsState(self, project: Project, opt): def _SetPreciousObjectsState(self, project: Project, opt):
"""Correct the preciousObjects state for the project. """Correct the preciousObjects state for the project.
Args: Args:
project (Project): the project to examine, and possibly correct. project: the project to examine, and possibly correct.
opt (optparse.Values): options given to sync. opt: options given to sync.
""" """
expected = self._GetPreciousObjectsState(project, opt) expected = self._GetPreciousObjectsState(project, opt)
actual = project.config.GetBoolean('extensions.preciousObjects') or False 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 if expected != actual:
not project.config.GetBoolean('repo.preservePreciousObjects')):
# If this is unexpected, log it and repair. # If this is unexpected, log it and repair.
Trace(f'{relpath} expected preciousObjects={expected}, got {actual}') Trace(f'{relpath} expected preciousObjects={expected}, got {actual}')
if expected: 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 to potentially mark objects precious, so that `git gc` does not discard
shared objects. shared objects.
""" """
pm = Progress(f'{"" if opt.auto_gc else "NOT "}Garbage collecting', if not opt.auto_gc:
len(projects), delay=False, quiet=opt.quiet) # 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') pm.update(inc=0, msg='prescan')
tidy_dirs = {} tidy_dirs = {}
for project in projects: for project in projects:
self._RepairPreciousObjectsState(project, opt) self._SetPreciousObjectsState(project, opt)
project.config.SetString('gc.autoDetach', 'false') project.config.SetString('gc.autoDetach', 'false')
# Only call git gc once per objdir, but call pack-refs for the remainder. # 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, project.bare_git,
) )
if not opt.auto_gc:
pm.end()
return
jobs = opt.jobs jobs = opt.jobs
if jobs < 2: if jobs < 2: