From 65af2602b58bb2470972c105aa16b30696ceeb49 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 8 Apr 2021 22:47:44 -0400 Subject: [PATCH] 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 Tested-by: Mike Frysinger --- subcmds/sync.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/subcmds/sync.py b/subcmds/sync.py index 36b1b0ac..b41b20b7 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -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: