Refactor Index fetching into helper function

This commit is contained in:
Matthias Beyer 2016-09-07 21:47:39 +02:00
parent 032110e6d8
commit 4e2a980599
3 changed files with 18 additions and 23 deletions

View file

@ -92,7 +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;
use vcs::git::util::{fetch_repo, fetch_index};
debug!("[GIT CREATE HOOK]: {:?}", id);
@ -114,15 +114,8 @@ impl StoreIdAccessor for CreateHook {
debug!("[GIT CREATE HOOK]: Branch checked out");
let action = StoreAction::Create;
let repo = try!(fetch_repo(&self.runtime, &action));
let mut index = try!(
repo
.index()
.map_err_into(GHEK::RepositoryIndexFetchingError)
.map_into_hook_error()
);
let mut index = try!(fetch_index(repo, &action));
let file_status = try!(
repo

View file

@ -87,7 +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;
use vcs::git::util::{fetch_repo, fetch_index};
debug!("[GIT UPDATE HOOK]: {:?}", id);
@ -98,15 +98,8 @@ impl StoreIdAccessor for UpdateHook {
);
let action = StoreAction::Update;
let repo = try!(fetch_repo(&self.runtime, &action));
let mut index = try!(
repo
.index()
.map_err_into(GHEK::RepositoryIndexFetchingError)
.map_into_hook_error()
);
let mut index = try!(fetch_index(repo, &action));
let tree_id = try!(
index.write_tree()

View file

@ -2,7 +2,7 @@
//!
//! Contains primitives to create a repository within the store path
use git2::Repository;
use git2::{Repository, Index};
use vcs::git::error::GitHookErrorKind as GHEK;
use vcs::git::error::MapErrInto;
@ -24,3 +24,12 @@ pub fn fetch_repo<'a>(runtime: &'a GRuntime, action: &StoreAction) -> Result<&'a
.map_into_hook_error()
}
pub fn fetch_index(repo: &Repository, action: &StoreAction) -> Result<Index, HookError> {
debug!("[GIT {} HOOK]: Getting Index", action.uppercase());
repo.index()
.map_dbg_err(|_| format!("[GIT {} HOOK]: Couldn't fetch Index", action.uppercase()))
.map_dbg(|_| format!("[GIT {} HOOK]: Index object fetched", action.uppercase()))
.map_err_into(GHEK::RepositoryIndexFetchingError)
.map_into_hook_error()
}