Add Repository instantiation

This commit is contained in:
Matthias Beyer 2016-07-16 16:26:16 +02:00
parent e19121f43a
commit af089952c8
1 changed files with 12 additions and 0 deletions

View File

@ -2,6 +2,7 @@ use std::path::PathBuf;
use std::fmt::{Debug, Formatter, Error as FmtError}; use std::fmt::{Debug, Formatter, Error as FmtError};
use toml::Value; use toml::Value;
use git2::{Repository, Error as Git2Error};
use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreId;
use libimagstore::hook::Hook; use libimagstore::hook::Hook;
@ -9,10 +10,13 @@ use libimagstore::hook::result::HookResult;
use libimagstore::hook::position::HookPosition; use libimagstore::hook::position::HookPosition;
use libimagstore::hook::accessor::{HookDataAccessor, HookDataAccessorProvider}; use libimagstore::hook::accessor::{HookDataAccessor, HookDataAccessorProvider};
use libimagstore::hook::accessor::StoreIdAccessor; use libimagstore::hook::accessor::StoreIdAccessor;
use libimagerror::trace::trace_error;
pub struct CreateHook<'a> { pub struct CreateHook<'a> {
storepath: &'a PathBuf, storepath: &'a PathBuf,
repository: Option<Repository>,
position: HookPosition, position: HookPosition,
config: Option<Value>, config: Option<Value>,
} }
@ -20,8 +24,16 @@ pub struct CreateHook<'a> {
impl<'a> CreateHook<'a> { impl<'a> CreateHook<'a> {
pub fn new(storepath: &'a PathBuf, p: HookPosition) -> CreateHook<'a> { pub fn new(storepath: &'a PathBuf, p: HookPosition) -> CreateHook<'a> {
let r = match Repository::open(storepath) {
Ok(r) => Some(r),
Err(e) => {
trace_error(&e);
None
},
};
CreateHook { CreateHook {
storepath: storepath, storepath: storepath,
repository: r,
position: p, position: p,
config: None, config: None,
} }