From 7efab539f0fc78aa759000a922c30ac45e84530b Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Thu, 1 Sep 2022 15:41:12 +0000 Subject: sync: no garbage collection by default Adds --auto-gc and --no-auto-gc (default) options to control sync's behavior around calling `git gc`. Bug: b/184882274 Change-Id: I4d6ca3b233d79566f27e876ab2d79f238ebc12a9 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/344535 Reviewed-by: Xin Li Tested-by: LaMont Jones --- subcmds/sync.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'subcmds/sync.py') diff --git a/subcmds/sync.py b/subcmds/sync.py index 83c9ad36..b7542cca 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -200,6 +200,9 @@ exist locally. The --prune option can be used to remove any refs that no longer exist on the remote. +The --auto-gc option can be used to trigger garbage collection on all +projects. By default, repo does not run garbage collection. + # SSH Connections If at least one project remote URL uses an SSH connection (ssh://, @@ -309,6 +312,10 @@ later is required to fix a server side protocol bug. help='delete refs that no longer exist on the remote (default)') p.add_option('--no-prune', dest='prune', action='store_false', help='do not delete refs that no longer exist on the remote') + p.add_option('--auto-gc', action='store_true', + help='run garbage collection on all synced projects') + p.add_option('--no-auto-gc', dest='auto_gc', action='store_false', + help='do not run garbage collection on any projects (default)') if show_smart: p.add_option('-s', '--smart-sync', dest='smart_sync', action='store_true', @@ -829,7 +836,14 @@ later is required to fix a server side protocol bug. project.config.SetString('gc.pruneExpire', None) def _GCProjects(self, projects, opt, err_event): - pm = Progress('Garbage collecting', len(projects), delay=False, quiet=opt.quiet) + """Perform garbage collection. + + If We are skipping garbage collection (opt.auto_gc not set), we still want + 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) pm.update(inc=0, msg='prescan') tidy_dirs = {} @@ -849,6 +863,10 @@ later is required to fix a server side protocol bug. project.bare_git, ) + if not opt.auto_gc: + pm.end() + return + jobs = opt.jobs gc_args = ['--auto'] -- cgit v1.2.3-54-g00ecf