fn maybe_gc_repo(repo: &mut Repository, gctx: &GlobalContext) -> CargoResult<()>Expand description
Attempts to git gc a repository.
Cargo has a bunch of long-lived git repositories in its global cache and some, like the index, are updated very frequently. Right now each update creates a new “pack file” inside the git database, and over time this can cause bad performance and bad current behavior in libgit2.
One pathological use case today is where libgit2 opens hundreds of file descriptors, getting us dangerously close to blowing out the OS limits of how many fds we can have open. This is detailed in #4403.
Instead of trying to be clever about when gc is needed, we just run
git gc --auto and let git figure it out. It checks its own thresholds
(gc.auto, gc.autoPackLimit) and either does the work or exits quickly.
If git isn’t installed, no worries - we skip it.