Add basic module setup

This commit is contained in:
Matthias Beyer 2016-05-15 00:21:26 +02:00
parent e385927316
commit 07a3a32265
11 changed files with 108 additions and 0 deletions

View file

@ -26,4 +26,5 @@ extern crate libimagentrylink;
pub mod debug;
pub mod flock;
pub mod linkverify;
pub mod vcs;

View file

@ -0,0 +1,80 @@
use std::error::Error;
use std::fmt::Error as FmtError;
use std::clone::Clone;
use std::fmt::{Display, Formatter};
/**
* Kind of error
*/
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum GitHookErrorKind {
}
fn githook_error_type_as_str(e: &GitHookErrorKind) -> &'static str {
match *e {
_ => "",
}
}
impl Display for GitHookErrorKind {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "{}", githook_error_type_as_str(self)));
Ok(())
}
}
/**
* Store error type
*/
#[derive(Debug)]
pub struct GitHookError {
err_type: GitHookErrorKind,
cause: Option<Box<Error>>,
}
impl GitHookError {
/**
* Build a new GitHookError from an GitHookErrorKind, optionally with cause
*/
pub fn new(errtype: GitHookErrorKind, cause: Option<Box<Error>>)
-> GitHookError
{
GitHookError {
err_type: errtype,
cause: cause,
}
}
/**
* Get the error type of this GitHookError
*/
pub fn err_type(&self) -> GitHookErrorKind {
self.err_type.clone()
}
}
impl Display for GitHookError {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
try!(write!(fmt, "[{}]", githook_error_type_as_str(&self.err_type.clone())));
Ok(())
}
}
impl Error for GitHookError {
fn description(&self) -> &str {
githook_error_type_as_str(&self.err_type.clone())
}
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|e| &**e)
}
}

View file

@ -0,0 +1,9 @@
mod config;
pub mod create;
pub mod delete;
mod error;
mod result;
pub mod retrieve;
pub mod update;
pub mod util;

View file

@ -0,0 +1,5 @@
use std::result::Result as RResult;
use vcs::git::error::GitHookError;
pub type Result<T> = RResult<T, GitHookError>;

View file

@ -0,0 +1,12 @@
//! Utility functionality for integrating git hooks in the store
//!
//! Contains primitives to create a repository within the store path
pub fn mkrepo(store: &Store) -> Result<()> {
unimplemented!()
}
pub fn hasrepo(store: &Store) -> bool {
Repository::open(store.path()).is_ok()
}

View file

@ -0,0 +1 @@
pub mod git;