summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjemstep-edward <42668885+jemstep-edward@users.noreply.github.com>2020-03-30 14:53:18 +0200
committerGitHub <noreply@github.com>2020-03-30 14:53:18 +0200
commitc8a3be444887eb7b462ec6942c715818acad13f8 (patch)
tree98916baabbb3c0f5ff0cdf91a497e88ec45f9f1e
parent37cee2339857bfc8537f326ddcc99062f4393c64 (diff)
parent51ab40d1cf1c8796fdfcc8a9bafc54cb24b6f7a5 (diff)
Merge pull request #52 from jemstep/Merge-reproduction-perf-improvementsHEADmain
Merge reproduction perf improvements
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/git.rs27
-rw-r--r--src/policies.rs46
-rw-r--r--src/policies/policy_result.rs10
5 files changed, 55 insertions, 32 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 99f5796..1123eb7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -38,7 +38,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "capn"
-version = "0.5.2"
+version = "0.5.3"
dependencies = [
"chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"git2 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index f441308..b4b8f65 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "capn"
-version = "0.5.2"
+version = "0.5.3"
authors = ["Justin Wernick <justin@jemstep.com>"]
edition = "2018"
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()
+ ))))
+ };
}
};
}
diff --git a/src/policies.rs b/src/policies.rs
index 5eed65f..cc2b71e 100644
--- a/src/policies.rs
+++ b/src/policies.rs
@@ -70,37 +70,35 @@ pub fn verify_git_commits<G: Git, P: Gpg>(
)?;
if config.verify_email_addresses {
- policy_result = policy_result.and(verify_email_addresses(
- &config.author_domain,
- &config.committer_domain,
- &not_manually_verified_commits,
- ));
+ policy_result = policy_result.and_then(|| {
+ Ok(verify_email_addresses(
+ &config.author_domain,
+ &config.committer_domain,
+ &not_manually_verified_commits,
+ ))
+ })?;
}
- if config.verify_commit_signatures {
- policy_result = policy_result.and(verify_commit_signatures::<G, P>(
- git,
- &gpg,
- &not_manually_verified_commits,
- &mut keyring,
- )?);
+ if config.verify_rebased {
+ policy_result = policy_result.and_then(|| {
+ verify_rebased::<G>(&all_commits, git, &ref_update, &config.override_tag_pattern)
+ })?;
}
if config.verify_different_authors {
- policy_result = policy_result.and(verify_different_authors::<G>(
- &all_commits,
- git,
- &ref_update,
- )?);
+ policy_result = policy_result
+ .and_then(|| verify_different_authors::<G>(&all_commits, git, &ref_update))?;
}
- if config.verify_rebased {
- policy_result = policy_result.and(verify_rebased::<G>(
- &all_commits,
- git,
- &ref_update,
- &config.override_tag_pattern,
- )?);
+ if config.verify_commit_signatures {
+ policy_result = policy_result.and_then(|| {
+ verify_commit_signatures::<G, P>(
+ git,
+ &gpg,
+ &not_manually_verified_commits,
+ &mut keyring,
+ )
+ })?;
}
}
diff --git a/src/policies/policy_result.rs b/src/policies/policy_result.rs
index e12ff42..852c705 100644
--- a/src/policies/policy_result.rs
+++ b/src/policies/policy_result.rs
@@ -1,4 +1,5 @@
use git2::Oid;
+use std::error::Error;
use std::fmt;
use std::iter;
@@ -22,6 +23,15 @@ impl PolicyResult {
x => x,
}
}
+ pub fn and_then(
+ self,
+ mut next: impl FnMut() -> Result<PolicyResult, Box<dyn Error>>,
+ ) -> Result<PolicyResult, Box<dyn Error>> {
+ match self {
+ PolicyResult::Ok => next(),
+ x => Ok(x),
+ }
+ }
pub fn is_ok(&self) -> bool {
match self {
PolicyResult::Ok => true,