From 188d00388e5689315b94465d902f061073f3e095 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Mon, 30 Mar 2020 11:39:49 +0200 Subject: 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. --- src/git.rs | 27 +++++++++++++++++++++------ 1 file 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() + )))) + }; } }; } -- cgit v1.2.3