fn maybe_gc_repo(repo: &mut Repository, config: &Config) -> 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.
To try to combat this problem we attempt a git gc
here. Note, though, that
we may not even have git
installed on the system! As a result we
opportunistically try a git gc
when the pack directory looks too big, and
failing that we just blow away the repository and start over.
In theory this shouldn’t be too expensive compared to the network request we’re about to issue.