sync: only use --cruft when git supports it.

git gc --cruft was added in 2.37.0.

Bug: https://crbug.com/gerrit/16270
Change-Id: I71e46741e33472a92f16d6f11c51a23e1e55d869
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/346577
Reviewed-by: Emily Shaffer <emilyshaffer@google.com>
Tested-by: LaMont Jones <lamontjones@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
LaMont Jones 2022-09-22 19:05:01 +00:00
parent a39af3d432
commit acc4c857a0

View File

@ -800,7 +800,11 @@ later is required to fix a server side protocol bug.
jobs = opt.jobs jobs = opt.jobs
gc_args = ('--auto', '--cruft') gc_args = ['--auto']
backup_cruft = False
if git_require((2, 37, 0)):
gc_args.append('--cruft')
backup_cruft = True
pack_refs_args = () pack_refs_args = ()
if jobs < 2: if jobs < 2:
for (run_gc, bare_git) in tidy_dirs.values(): for (run_gc, bare_git) in tidy_dirs.values():
@ -810,6 +814,7 @@ later is required to fix a server side protocol bug.
bare_git.gc(*gc_args) bare_git.gc(*gc_args)
else: else:
bare_git.pack_refs(*pack_refs_args) bare_git.pack_refs(*pack_refs_args)
if backup_cruft:
self._backup_cruft(bare_git) self._backup_cruft(bare_git)
pm.end() pm.end()
return return
@ -834,6 +839,7 @@ later is required to fix a server side protocol bug.
err_event.set() err_event.set()
raise raise
finally: finally:
if backup_cruft:
self._backup_cruft(bare_git) self._backup_cruft(bare_git)
pm.finish(bare_git._project.name) pm.finish(bare_git._project.name)
sem.release() sem.release()