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>
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 8cd1bca..7551203 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -775,19 +775,18 @@
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 @@
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 @@
project.bare_git,
)
- if not opt.auto_gc:
- pm.end()
- return
-
jobs = opt.jobs
if jobs < 2: