sync: add progress bar to garbage collection phase

This can take a few seconds, if not a lot more, so add a progress bar
so users understand what's going on.

Change-Id: I5b4b54c1bbb9ec18728f979521310f7087afaa5c
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/302802
Reviewed-by: Raman Tenneti <rtenneti@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2021-04-08 22:47:44 -04:00
parent 347f9ed393
commit 65af2602b5

View File

@ -501,34 +501,39 @@ later is required to fix a server side protocol bug.
return ret and not err_results
def _GCProjects(self, projects, opt, err_event):
pm = Progress('Garbage collecting', len(projects), delay=False)
pm.update(inc=0, msg='prescan')
gc_gitdirs = {}
for project in projects:
# Make sure pruning never kicks in with shared projects.
if (not project.use_git_worktrees and
len(project.manifest.GetProjectsWithName(project.name)) > 1):
if not opt.quiet:
print('%s: Shared project %s found, disabling pruning.' %
#pm.update(inc=0, msg='Shared project found')
print('\r%s: Shared project %s found, disabling pruning.' %
(project.relpath, project.name))
if git_require((2, 7, 0)):
project.EnableRepositoryExtension('preciousObjects')
else:
# This isn't perfect, but it's the best we can do with old git.
print('%s: WARNING: shared projects are unreliable when using old '
print('\r%s: WARNING: shared projects are unreliable when using old '
'versions of git; please upgrade to git-2.7.0+.'
% (project.relpath,),
file=sys.stderr)
project.config.SetString('gc.pruneExpire', 'never')
gc_gitdirs[project.gitdir] = project.bare_git
if multiprocessing:
cpu_count = multiprocessing.cpu_count()
else:
cpu_count = 1
pm.update(inc=len(projects) - len(gc_gitdirs), msg='warming up')
cpu_count = os.cpu_count()
jobs = min(self.jobs, cpu_count)
if jobs < 2:
for bare_git in gc_gitdirs.values():
pm.update(msg=bare_git._project.name)
bare_git.gc('--auto')
pm.end()
return
config = {'pack.threads': cpu_count // jobs if cpu_count > jobs else 1}
@ -537,6 +542,7 @@ later is required to fix a server side protocol bug.
sem = _threading.Semaphore(jobs)
def GC(bare_git):
pm.start(bare_git._project.name)
try:
try:
bare_git.gc('--auto', config=config)
@ -546,6 +552,7 @@ later is required to fix a server side protocol bug.
err_event.set()
raise
finally:
pm.finish(bare_git._project.name)
sem.release()
for bare_git in gc_gitdirs.values():
@ -559,6 +566,7 @@ later is required to fix a server side protocol bug.
for t in threads:
t.join()
pm.end()
def _ReloadManifest(self, manifest_name=None):
if manifest_name: