From 5ed8c639421c1669b5a945114bc169722b242697 Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Thu, 10 Nov 2022 00:10:44 +0000 Subject: [PATCH] sync: REPO_AUTO_GC=1 to restore old behavior. Add an environment variable to restore previous behavior, since the older version of repo does not support `--auto-gc`. Change-Id: I874dfb8fc3533a97b8adfd52125eb3d1d75e2f3c Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/351194 Reviewed-by: Sam Saccone Tested-by: LaMont Jones --- subcmds/sync.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/subcmds/sync.py b/subcmds/sync.py index b7542cca..862c7e2c 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -68,9 +68,12 @@ from manifest_xml import GitcManifest _ONE_DAY_S = 24 * 60 * 60 # Env var to implicitly turn off object backups. REPO_BACKUP_OBJECTS = 'REPO_BACKUP_OBJECTS' - _BACKUP_OBJECTS = os.environ.get(REPO_BACKUP_OBJECTS) != '0' +# Env var to implicitly turn auto-gc back on. +_REPO_AUTO_GC = 'REPO_AUTO_GC' +_AUTO_GC = os.environ.get(_REPO_AUTO_GC) == '1' + class _FetchOneResult(NamedTuple): """_FetchOne return value. @@ -312,7 +315,7 @@ 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', + p.add_option('--auto-gc', action='store_true', default=None, 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)') @@ -1219,6 +1222,11 @@ later is required to fix a server side protocol bug. if opt.prune is None: opt.prune = True + if opt.auto_gc is None and _AUTO_GC: + print(f"Will run `git gc --auto` because {_REPO_AUTO_GC} is set.", + file=sys.stderr) + opt.auto_gc = True + def Execute(self, opt, args): manifest = self.outer_manifest if not opt.outer_manifest: