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 <samccone@google.com>
Tested-by: LaMont Jones <lamontjones@google.com>
This commit is contained in:
LaMont Jones 2022-11-10 00:10:44 +00:00
parent 24c6314fca
commit 5ed8c63942

View File

@ -68,9 +68,12 @@ from manifest_xml import GitcManifest
_ONE_DAY_S = 24 * 60 * 60 _ONE_DAY_S = 24 * 60 * 60
# Env var to implicitly turn off object backups. # Env var to implicitly turn off object backups.
REPO_BACKUP_OBJECTS = 'REPO_BACKUP_OBJECTS' REPO_BACKUP_OBJECTS = 'REPO_BACKUP_OBJECTS'
_BACKUP_OBJECTS = os.environ.get(REPO_BACKUP_OBJECTS) != '0' _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): class _FetchOneResult(NamedTuple):
"""_FetchOne return value. """_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)') help='delete refs that no longer exist on the remote (default)')
p.add_option('--no-prune', dest='prune', action='store_false', p.add_option('--no-prune', dest='prune', action='store_false',
help='do not delete refs that no longer exist on the remote') 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') help='run garbage collection on all synced projects')
p.add_option('--no-auto-gc', dest='auto_gc', action='store_false', p.add_option('--no-auto-gc', dest='auto_gc', action='store_false',
help='do not run garbage collection on any projects (default)') 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: if opt.prune is None:
opt.prune = True 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): def Execute(self, opt, args):
manifest = self.outer_manifest manifest = self.outer_manifest
if not opt.outer_manifest: if not opt.outer_manifest: