summaryrefslogtreecommitdiffstats
path: root/libimagstorestdhook
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-09-07 21:32:11 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-09-07 22:06:07 +0200
commit741ebff2da3c115e76ab7e732564628152b72de5 (patch)
tree22d80a199494f7155b10ae5db71bde3af92ef78f /libimagstorestdhook
parentfddd6ec4cb8b36a163e955baa7214f48f34a9c25 (diff)
Outsource repository fetching into helper fn
Diffstat (limited to 'libimagstorestdhook')
-rw-r--r--libimagstorestdhook/src/vcs/git/create.rs13
-rw-r--r--libimagstorestdhook/src/vcs/git/update.rs13
-rw-r--r--libimagstorestdhook/src/vcs/git/util.rs19
3 files changed, 25 insertions, 20 deletions
diff --git a/libimagstorestdhook/src/vcs/git/create.rs b/libimagstorestdhook/src/vcs/git/create.rs
index 54845cdd..d3df670d 100644
--- a/libimagstorestdhook/src/vcs/git/create.rs
+++ b/libimagstorestdhook/src/vcs/git/create.rs
@@ -92,6 +92,7 @@ impl StoreIdAccessor for CreateHook {
use vcs::git::action::StoreAction;
use vcs::git::config::commit_message;
use vcs::git::error::MapIntoHookError;
+ use vcs::git::util::fetch_repo;
debug!("[GIT CREATE HOOK]: {:?}", id);
@@ -112,15 +113,11 @@ impl StoreIdAccessor for CreateHook {
try!(self.runtime.ensure_cfg_branch_is_checked_out());
debug!("[GIT CREATE HOOK]: Branch checked out");
- debug!("[GIT CREATE HOOK]: Getting repository");
- let repo = try!(
- self.runtime
- .repository()
- .map_dbg_err_str("[GIT CREATE HOOK]: Couldn't fetch Repository")
- .map_err_into(GHEK::RepositoryError)
- .map_into_hook_error()
+ let repo = try!(fetch_repo(&self.runtime,
+ "[GIT CREATE HOOK]: Getting repository",
+ "[GIT CREATE HOOK]: Couldn't fetch Repository",
+ "[GIT CREATE HOOK]: Repository object fetched")
);
- debug!("[GIT CREATE HOOK]: Repository object fetched");
let mut index = try!(
repo
diff --git a/libimagstorestdhook/src/vcs/git/update.rs b/libimagstorestdhook/src/vcs/git/update.rs
index b0d2d05e..e423c0de 100644
--- a/libimagstorestdhook/src/vcs/git/update.rs
+++ b/libimagstorestdhook/src/vcs/git/update.rs
@@ -87,6 +87,7 @@ impl StoreIdAccessor for UpdateHook {
use vcs::git::action::StoreAction;
use vcs::git::config::commit_message;
use vcs::git::error::MapIntoHookError;
+ use vcs::git::util::fetch_repo;
debug!("[GIT UPDATE HOOK]: {:?}", id);
@@ -96,15 +97,11 @@ impl StoreIdAccessor for UpdateHook {
.map_dbg_err_str("[GIT UPDATE HOOK]: Couldn't get Value object from config")
);
- debug!("[GIT UPDATE HOOK]: Getting repository");
- let repo = try!(
- self.runtime
- .repository()
- .map_dbg_err_str("[GIT UPDATE HOOK]: Couldn't fetch Repository")
- .map_err_into(GHEK::RepositoryError)
- .map_into_hook_error()
+ let repo = try!(fetch_repo(&self.runtime,
+ "[GIT UPDATE HOOK]: Getting repository",
+ "[GIT UPDATE HOOK]: Couldn't fetch Repository",
+ "[GIT UPDATE HOOK]: Repository object fetched")
);
- debug!("[GIT UPDATE HOOK]: Repository object fetched");
let mut index = try!(
repo
diff --git a/libimagstorestdhook/src/vcs/git/util.rs b/libimagstorestdhook/src/vcs/git/util.rs
index 0a022a9a..a87fc6dd 100644
--- a/libimagstorestdhook/src/vcs/git/util.rs
+++ b/libimagstorestdhook/src/vcs/git/util.rs
@@ -3,11 +3,22 @@
//! Contains primitives to create a repository within the store path
use git2::Repository;
-use git2::RepositoryInitOptions;
-
-use libimagstore::store::Store;
use vcs::git::error::GitHookErrorKind as GHEK;
use vcs::git::error::MapErrInto;
-use vcs::git::result::Result;
+use vcs::git::runtime::Runtime as GRuntime;
+use vcs::git::action::StoreAction;
+use vcs::git::error::MapIntoHookError;
+
+use libimagutil::debug_result::*;
+use libimagstore::hook::error::HookError;
+
+pub fn fetch_repo<'a>(runtime: &'a GRuntime, action: &StoreAction) -> Result<&'a Repository, HookError>
+{
+ runtime
+ .repository()
+ .map_dbg_err_str(on_err_str)
+ .map_err_into(GHEK::RepositoryError)
+ .map_into_hook_error()
+}