From 741ebff2da3c115e76ab7e732564628152b72de5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Sep 2016 21:32:11 +0200 Subject: Outsource repository fetching into helper fn --- libimagstorestdhook/src/vcs/git/create.rs | 13 +++++-------- libimagstorestdhook/src/vcs/git/update.rs | 13 +++++-------- libimagstorestdhook/src/vcs/git/util.rs | 19 +++++++++++++++---- 3 files changed, 25 insertions(+), 20 deletions(-) (limited to 'libimagstorestdhook') 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() +} -- cgit v1.2.3