From f23004a8ec96a1bbcedc7703a3418e39b9970d8c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 29 Jul 2016 10:01:02 +0200 Subject: [PATCH] Make git-hook-registration not only when debugging --- libimagrt/src/runtime.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index df4ba3b9..67d9950b 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -123,11 +123,6 @@ impl<'a> Runtime<'a> { (Box::new(DebugHook::new(HP::PostUpdate)) , "debug", HP::PostUpdate), (Box::new(DebugHook::new(HP::PreDelete)) , "debug", HP::PreDelete), (Box::new(DebugHook::new(HP::PostDelete)) , "debug", HP::PostDelete), - - (Box::new(GitCreateHook::new(&storepath, HP::PostCreate)) , "vcs", HP::PostCreate), - (Box::new(GitDeleteHook::new(&storepath, HP::PreDelete)) , "vcs", HP::PreDelete), - (Box::new(GitRetrieveHook::new(&storepath, HP::PostRetrieve)), "vcs", HP::PostRetrieve), - (Box::new(GitUpdateHook::new(&storepath, HP::PostUpdate)) , "vcs", HP::PostUpdate), ]; // If hook registration fails, trace the error and warn, but continue. @@ -143,6 +138,26 @@ impl<'a> Runtime<'a> { } } + let sp = storepath; + + let hooks : Vec<(Box, &str, HP)> = vec![ + (Box::new(GitCreateHook::new(sp.clone(), HP::PostCreate)) , "vcs", HP::PostCreate), + (Box::new(GitDeleteHook::new(sp.clone(), HP::PreDelete)) , "vcs", HP::PreDelete), + (Box::new(GitRetrieveHook::new(sp.clone(), HP::PostRetrieve)), "vcs", HP::PostRetrieve), + (Box::new(GitUpdateHook::new(sp, HP::PostUpdate)) , "vcs", HP::PostUpdate), + ]; + + for (hook, aspectname, position) in hooks { + if let Err(e) = store.register_hook(position, &String::from(aspectname), hook) { + if e.err_type() == StoreErrorKind::HookRegisterError { + trace_error_dbg(&e); + warn!("Registering debug hook with store failed"); + } else { + trace_error(&e); + }; + } + } + Runtime { cli_matches: matches, configuration: cfg,