Outsource repository fetching into helper fn

This commit is contained in:
Matthias Beyer 2016-09-07 21:32:11 +02:00
parent fddd6ec4cb
commit 741ebff2da
3 changed files with 25 additions and 20 deletions

View file

@ -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

View file

@ -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

View file

@ -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()
}