summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@jemstep.com>2020-03-30 11:39:49 +0200
committerJustin Worthe <justin@jemstep.com>2020-03-30 11:39:49 +0200
commit188d00388e5689315b94465d902f061073f3e095 (patch)
tree27d16251b80338f47a4412eb93327125c7d5f50a
parent0ce73c3987b8adbc210e27415f37f7c3251835f8 (diff)
Replace temp repo clone from libgit with using the Git CLI and the --shared flag
Shared sets up Git's alternative object database mechanism, letting it read objects from the original repo on demand rather than cloning everything.
-rw-r--r--src/git.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/git.rs b/src/git.rs
index 818d697..35d98a2 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -1,7 +1,7 @@
use crate::error::CapnError;
use crate::keyring::Keyring;
use git2;
-use git2::{build::RepoBuilder, ErrorClass, ErrorCode, ObjectType, Oid, Repository};
+use git2::{ErrorClass, ErrorCode, ObjectType, Oid, Repository};
use std::cell::RefCell;
use std::collections::HashMap;
use std::error::Error;
@@ -508,11 +508,26 @@ impl TempRepo {
let src_path = src_repo.path().to_str().ok_or(Box::new(CapnError::new(
"Path to the repo being verified was not valid UTF-8",
)))?;
- return Ok(TempRepo {
- repo: RepoBuilder::new()
- .bare(true)
- .clone(src_path, &tmp_repo_path)?,
- });
+
+ let result = Command::new("git")
+ .arg("clone")
+ .arg("--bare")
+ .arg("--shared")
+ .arg(src_path)
+ .arg(&tmp_repo_path)
+ .output()?;
+
+ return if result.status.success() {
+ Ok(TempRepo {
+ repo: Repository::open(tmp_repo_path)?,
+ })
+ } else {
+ debug!("Git clone Stderr: {:?}", String::from_utf8(result.stderr));
+ Err(Box::new(CapnError::new(format!(
+ "Call to git clone while creating temp repo failed with code {:?}",
+ result.status.code()
+ ))))
+ };
}
};
}