summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
authorAllen Webb <allenwebb@google.com>2021-10-07 10:42:38 -0500
committerAllen Webb <allenwebb@google.com>2021-10-14 12:27:12 +0000
commit4ee4a45d03075c3576afcc08b654a057decaf6be (patch)
tree059850615eaf66eb369c328d36b48db0b94165a9 /subcmds/sync.py
parent0f6f16ed1784049a11be5be364879affe35ff921 (diff)
downloadgit-repo-4ee4a45d03075c3576afcc08b654a057decaf6be.tar.gz
subcmds/sync: Use pack-refs instead of gc for redundant gitdirs.
Previously `git gc` was being run on every gitdir even when they shared the same objects. Instead only call it once and use pack-refs for the gitdirs that were not gc'ed. Bug: https://crbug.com/gerrit/15113 Test: repo sync -j # and check that git pack-refs is called Change-Id: Icff37ab3ec78cfb44391d8cc7f2d875991532320 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/320275 Tested-by: Allen Webb <allenwebb@google.com> Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 83d6ca13..7318516c 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -605,7 +605,7 @@ later is required to fix a server side protocol bug.
605 pm = Progress('Garbage collecting', len(projects), delay=False, quiet=opt.quiet) 605 pm = Progress('Garbage collecting', len(projects), delay=False, quiet=opt.quiet)
606 pm.update(inc=0, msg='prescan') 606 pm.update(inc=0, msg='prescan')
607 607
608 gc_gitdirs = {} 608 tidy_dirs = {}
609 for project in projects: 609 for project in projects:
610 # Make sure pruning never kicks in with shared projects. 610 # Make sure pruning never kicks in with shared projects.
611 if (not project.use_git_worktrees and 611 if (not project.use_git_worktrees and
@@ -623,17 +623,28 @@ later is required to fix a server side protocol bug.
623 file=sys.stderr) 623 file=sys.stderr)
624 project.config.SetString('gc.pruneExpire', 'never') 624 project.config.SetString('gc.pruneExpire', 'never')
625 project.config.SetString('gc.autoDetach', 'false') 625 project.config.SetString('gc.autoDetach', 'false')
626 gc_gitdirs[project.gitdir] = project.bare_git 626 # Only call git gc once per objdir, but call pack-refs for the remainder.
627 627 if project.objdir not in tidy_dirs:
628 pm.update(inc=len(projects) - len(gc_gitdirs), msg='warming up') 628 tidy_dirs[project.objdir] = (
629 True, # Run a full gc.
630 project.bare_git,
631 )
632 elif project.gitdir not in tidy_dirs:
633 tidy_dirs[project.gitdir] = (
634 False, # Do not run a full gc; just run pack-refs.
635 project.bare_git,
636 )
629 637
630 cpu_count = os.cpu_count() 638 cpu_count = os.cpu_count()
631 jobs = min(self.jobs, cpu_count) 639 jobs = min(self.jobs, cpu_count)
632 640
633 if jobs < 2: 641 if jobs < 2:
634 for bare_git in gc_gitdirs.values(): 642 for (run_gc, bare_git) in tidy_dirs.values():
635 pm.update(msg=bare_git._project.name) 643 pm.update(msg=bare_git._project.name)
636 bare_git.gc('--auto') 644 if run_gc:
645 bare_git.gc('--auto')
646 else:
647 bare_git.pack_refs()
637 pm.end() 648 pm.end()
638 return 649 return
639 650
@@ -642,11 +653,14 @@ later is required to fix a server side protocol bug.
642 threads = set() 653 threads = set()
643 sem = _threading.Semaphore(jobs) 654 sem = _threading.Semaphore(jobs)
644 655
645 def GC(bare_git): 656 def tidy_up(run_gc, bare_git):
646 pm.start(bare_git._project.name) 657 pm.start(bare_git._project.name)
647 try: 658 try:
648 try: 659 try:
649 bare_git.gc('--auto', config=config) 660 if run_gc:
661 bare_git.gc('--auto', config=config)
662 else:
663 bare_git.pack_refs(config=config)
650 except GitError: 664 except GitError:
651 err_event.set() 665 err_event.set()
652 except Exception: 666 except Exception:
@@ -656,11 +670,11 @@ later is required to fix a server side protocol bug.
656 pm.finish(bare_git._project.name) 670 pm.finish(bare_git._project.name)
657 sem.release() 671 sem.release()
658 672
659 for bare_git in gc_gitdirs.values(): 673 for (run_gc, bare_git) in tidy_dirs.values():
660 if err_event.is_set() and opt.fail_fast: 674 if err_event.is_set() and opt.fail_fast:
661 break 675 break
662 sem.acquire() 676 sem.acquire()
663 t = _threading.Thread(target=GC, args=(bare_git,)) 677 t = _threading.Thread(target=tidy_up, args=(run_gc, bare_git,))
664 t.daemon = True 678 t.daemon = True
665 threads.add(t) 679 threads.add(t)
666 t.start() 680 t.start()