summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@jemstep.com>2020-03-30 10:50:06 +0200
committerJustin Worthe <justin@jemstep.com>2020-03-30 10:50:06 +0200
commit6785bade8f9a9636fc468223e33b9c12002ac593 (patch)
treed7e532dc8c7ad72cd53238f311447f6abfbc1358
parent37cee2339857bfc8537f326ddcc99062f4393c64 (diff)
Added a lazily-executed variant of policy result chaining
-rw-r--r--src/policies.rs42
-rw-r--r--src/policies/policy_result.rs10
2 files changed, 30 insertions, 22 deletions
diff --git a/src/policies.rs b/src/policies.rs
index 5eed65f..fb10aed 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,
- )?);
+ policy_result = policy_result.and_then(|| {
+ verify_commit_signatures::<G, P>(
+ git,
+ &gpg,
+ &not_manually_verified_commits,
+ &mut keyring,
+ )
+ })?;
}
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,
- )?);
+ policy_result = policy_result.and_then(|| {
+ verify_rebased::<G>(&all_commits, git, &ref_update, &config.override_tag_pattern)
+ })?;
}
}
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,