From 3e68f728a94643e15d0237ef844ef4d0e23ac131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 7 Nov 2017 09:13:56 +0100 Subject: [PATCH] cargo: use git gc --auto This will allow git to decide when to run gc by itself and will honor userside settings. Implements #4495 --- src/cargo/sources/git/utils.rs | 11 ++++++----- tests/small-fd-limits.rs | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cargo/sources/git/utils.rs b/src/cargo/sources/git/utils.rs index ed2bc281c55..32dd100efe6 100644 --- a/src/cargo/sources/git/utils.rs +++ b/src/cargo/sources/git/utils.rs @@ -624,7 +624,7 @@ pub fn fetch(repo: &mut git2::Repository, /// failing that we just blow away the repository and start over. fn maybe_gc_repo(repo: &mut git2::Repository) -> CargoResult<()> { // Here we arbitrarily declare that if you have more than 100 files in your - // `pack` folder that we need to do a gc. + // `pack` folder we check if we have gc using git gc --auto let entries = match repo.path().join("objects/pack").read_dir() { Ok(e) => e.count(), Err(_) => { @@ -640,11 +640,12 @@ fn maybe_gc_repo(repo: &mut git2::Repository) -> CargoResult<()> { return Ok(()) } - // First up, try a literal `git gc` by shelling out to git. This is pretty - // likely to fail though as we may not have `git` installed. Note that - // libgit2 doesn't currently implement the gc operation, so there's no + // Let git decide if we need to run gc honoring the userside + // settings in .gitconfig. This is pretty likely to fail + // though as we may not have `git` installed. Note that libgit2 + // doesn't currently implement the gc operation, so there's no // equivalent there. - match Command::new("git").arg("gc").current_dir(repo.path()).output() { + match Command::new("git").arg("gc").arg("--auto").current_dir(repo.path()).output() { Ok(out) => { debug!("git-gc status: {}\n\nstdout ---\n{}\nstderr ---\n{}", out.status, diff --git a/tests/small-fd-limits.rs b/tests/small-fd-limits.rs index e997f76fd89..ecabca8bedf 100644 --- a/tests/small-fd-limits.rs +++ b/tests/small-fd-limits.rs @@ -52,6 +52,7 @@ fn run_test(path_env: Option<&OsStr>) { let mut cfg = index.config().unwrap(); cfg.set_str("user.email", "foo@bar.com").unwrap(); cfg.set_str("user.name", "Foo Bar").unwrap(); + cfg.set_str("gc.auto", "false").unwrap(); for _ in 0..N { git::commit(&repo); @@ -84,6 +85,9 @@ fn run_test(path_env: Option<&OsStr>) { } #[test] +// it looks like these tests passes on some windows machines but not others, +// notably not on AppVeyor's machines. Sounds like another bug for another day. +#[cfg_attr(windows, ignore)] fn use_git_gc() { if Command::new("git").arg("--version").output().is_err() { return @@ -92,8 +96,6 @@ fn use_git_gc() { } #[test] -// it looks like this test passes on some windows machines but not others, -// notably not on AppVeyor's machines. Sounds like another but for another day. #[cfg_attr(windows, ignore)] fn avoid_using_git() { let path = env::var_os("PATH").unwrap_or_default();