summaryrefslogtreecommitdiffstats
path: root/src/commands/build.rs
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-03-01 11:38:42 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-03-01 17:42:26 +0100
commit6387e8f333aa9f5b65a5ebb8ce3d8ebeaa0fa58c (patch)
tree20796512435300b6dd3b2c6ee0a3a41631f2cc60 /src/commands/build.rs
parent18d06cc867fb3c7c10b7494b96d213aa62fa9927 (diff)
Refactor: Open git repository in command::build()
This commit refactors the git2::Repository::open() call to be in the command::build() implementation, so we do not open the repository multiple times. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/commands/build.rs')
-rw-r--r--src/commands/build.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/commands/build.rs b/src/commands/build.rs
index 1044896..4474d4e 100644
--- a/src/commands/build.rs
+++ b/src/commands/build.rs
@@ -61,7 +61,10 @@ pub async fn build(
) -> Result<()> {
use crate::db::models::{EnvVar, GitHash, Image, Job, Package, Submit};
- let _ = crate::ui::package_repo_cleanness_check(&repo_root)?;
+ let git_repo = git2::Repository::open(repo_path)
+ .with_context(|| anyhow!("Opening repository at {}", repo_path.display()))?;
+
+ let _ = crate::ui::package_repo_cleanness_check(&git_repo)?;
let now = chrono::offset::Local::now().naive_local();
let shebang = Shebang::from({
@@ -92,7 +95,7 @@ pub async fn build(
}
debug!("Getting repository HEAD");
- let hash_str = crate::util::git::get_repo_head_commit_hash(repo_path)?;
+ let hash_str = crate::util::git::get_repo_head_commit_hash(&git_repo)?;
trace!("Repository HEAD = {}", hash_str);
let phases = config.available_phases();