Refactor Index fetching into helper function
This commit is contained in:
parent
032110e6d8
commit
4e2a980599
3 changed files with 18 additions and 23 deletions
|
@ -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);
|
||||
|
||||
|
@ -113,16 +113,9 @@ impl StoreIdAccessor for CreateHook {
|
|||
try!(self.runtime.ensure_cfg_branch_is_checked_out());
|
||||
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 action = StoreAction::Create;
|
||||
let repo = try!(fetch_repo(&self.runtime, &action));
|
||||
let mut index = try!(fetch_index(repo, &action));
|
||||
|
||||
let file_status = try!(
|
||||
repo
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -97,16 +97,9 @@ impl StoreIdAccessor for UpdateHook {
|
|||
.map_dbg_err_str("[GIT UPDATE HOOK]: Couldn't get Value object from config")
|
||||
);
|
||||
|
||||
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 action = StoreAction::Update;
|
||||
let repo = try!(fetch_repo(&self.runtime, &action));
|
||||
let mut index = try!(fetch_index(repo, &action));
|
||||
|
||||
let tree_id = try!(
|
||||
index.write_tree()
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue