From ba1df8bb4870fea69161d75d1c9082cd3cffd635 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Sep 2016 09:08:59 +0200 Subject: [PATCH 1/7] Remove unused config sections --- imagrc.toml | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/imagrc.toml b/imagrc.toml index de8d39ba..6e6463d4 100644 --- a/imagrc.toml +++ b/imagrc.toml @@ -38,34 +38,6 @@ mutable_hooks = false [store.hooks.stdhook_debug] aspect = "debug" -[store.hooks.stdhook_git_create] -aspect = "vcs" - -# Fail if the repository cannot be opened. If this is set to `false`, the error -# will be printed, but will not abort the store operation. `true` will print the -# error and abort the store action. -abort_on_repo_init_failure = true - -# Ensure to be on this branche before doing anything. -ensure_branch = "refs/heads/master" - -# Try to checkout the ensure_branch if it isn't checked out -try_checkout_ensure_branch = true - -[store.hooks.stdhook_git_retrieve] -aspect = "vcs" - -# Fail if the repository cannot be opened. If this is set to `false`, the error -# will be printed, but will not abort the store operation. `true` will print the -# error and abort the store action. -abort_on_repo_init_failure = true - -# Ensure to be on this branche before doing anything. -ensure_branch = "refs/heads/master" - -# Try to checkout the ensure_branch if it isn't checked out -try_checkout_ensure_branch = true - [store.hooks.stdhook_git_update] aspect = "vcs" From ece7fe061c0d030138b185a26efae34cff4d35c2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Sep 2016 09:13:19 +0200 Subject: [PATCH 2/7] Add settings for enable/disable hook --- imagrc.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/imagrc.toml b/imagrc.toml index 6e6463d4..5dbbf9fc 100644 --- a/imagrc.toml +++ b/imagrc.toml @@ -41,6 +41,9 @@ aspect = "debug" [store.hooks.stdhook_git_update] aspect = "vcs" +# set to false to disable +enabled = true + # Fail if the repository cannot be opened. If this is set to `false`, the error # will be printed, but will not abort the store operation. `true` will print the # error and abort the store action. @@ -69,6 +72,9 @@ message = "Update" [store.hooks.stdhook_git_delete] aspect = "vcs" +# set to false to disable +enabled = true + # Fail if the repository cannot be opened. If this is set to `false`, the error # will be printed, but will not abort the store operation. `true` will print the # error and abort the store action. From d115e4ca8e0aac7a6a8726e495be1ccfc3da4c72 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Sep 2016 09:13:40 +0200 Subject: [PATCH 3/7] Add config helper to check whether hook is enabled or not --- libimagstorestdhook/src/vcs/git/config.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libimagstorestdhook/src/vcs/git/config.rs b/libimagstorestdhook/src/vcs/git/config.rs index db1a4d3d..25609cea 100644 --- a/libimagstorestdhook/src/vcs/git/config.rs +++ b/libimagstorestdhook/src/vcs/git/config.rs @@ -167,3 +167,9 @@ fn get_bool_cfg(cfg: Option<&Value>, name: &str, on_fail: bool, on_unavail: bool .unwrap_or(on_unavail) } +/// Check whether the hook is enabled or not. If the config is not there, the hook is _enabled_ by +/// default. +pub fn is_enabled(cfg: &Value) -> bool { + get_bool_cfg(Some(cfg), "enabled", true, true) +} + From fbd195db25bd496633b9c7d355f0c2c0f70b6935 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Sep 2016 09:13:56 +0200 Subject: [PATCH 4/7] DeleteHook: return Ok(()) if disabled --- libimagstorestdhook/src/vcs/git/delete.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libimagstorestdhook/src/vcs/git/delete.rs b/libimagstorestdhook/src/vcs/git/delete.rs index b44bf878..b5c0e56b 100644 --- a/libimagstorestdhook/src/vcs/git/delete.rs +++ b/libimagstorestdhook/src/vcs/git/delete.rs @@ -85,11 +85,17 @@ impl StoreIdAccessor for DeleteHook { use vcs::git::error::MapIntoHookError; use vcs::git::util::fetch_index; use vcs::git::config::abort_on_repo_init_err; + use vcs::git::config::is_enabled; use git2::{ADD_DEFAULT, STATUS_WT_DELETED, IndexMatchedPath}; debug!("[GIT DELETE HOOK]: {:?}", id); let action = StoreAction::Delete; + let cfg = try!(self.runtime.config_value_or_err(&action)); + + if !is_enabled(cfg) { + return Ok(()) + } if !self.runtime.has_repository() { debug!("[GIT DELETE HOOK]: Runtime has no repository..."); @@ -108,7 +114,6 @@ impl StoreIdAccessor for DeleteHook { } let _ = try!(self.runtime.ensure_cfg_branch_is_checked_out(&action)); - let cfg = try!(self.runtime.config_value_or_err(&action)); let repo = try!(self.runtime.repository(&action)); let mut index = try!(fetch_index(repo, &action)); From da8736d003d4090700a73ef9bcab717127aec061 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Sep 2016 09:14:07 +0200 Subject: [PATCH 5/7] UpdateHook: return Ok(()) if disabled --- libimagstorestdhook/src/vcs/git/update.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libimagstorestdhook/src/vcs/git/update.rs b/libimagstorestdhook/src/vcs/git/update.rs index 25ada8a6..48fd7374 100644 --- a/libimagstorestdhook/src/vcs/git/update.rs +++ b/libimagstorestdhook/src/vcs/git/update.rs @@ -99,11 +99,17 @@ impl StoreIdAccessor for UpdateHook { use vcs::git::error::MapIntoHookError; use vcs::git::util::fetch_index; use vcs::git::config::abort_on_repo_init_err; + use vcs::git::config::is_enabled; use git2::{ADD_DEFAULT, STATUS_WT_NEW, STATUS_WT_MODIFIED, IndexMatchedPath}; debug!("[GIT UPDATE HOOK]: {:?}", id); let action = StoreAction::Update; + let cfg = try!(self.runtime.config_value_or_err(&action)); + + if !is_enabled(cfg) { + return Ok(()); + } if !self.runtime.has_repository() { debug!("[GIT UPDATE HOOK]: Runtime has no repository..."); @@ -122,7 +128,6 @@ impl StoreIdAccessor for UpdateHook { } let _ = try!(self.runtime.ensure_cfg_branch_is_checked_out(&action)); - let cfg = try!(self.runtime.config_value_or_err(&action)); let repo = try!(self.runtime.repository(&action)); let mut index = try!(fetch_index(repo, &action)); From b4fb226bb782ac62898c426f1aaf6777dc3dd1f6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Sep 2016 09:27:44 +0200 Subject: [PATCH 6/7] util: get_bool_cfg(): more debug output --- libimagstorestdhook/src/vcs/git/config.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libimagstorestdhook/src/vcs/git/config.rs b/libimagstorestdhook/src/vcs/git/config.rs index 25609cea..aca1652b 100644 --- a/libimagstorestdhook/src/vcs/git/config.rs +++ b/libimagstorestdhook/src/vcs/git/config.rs @@ -164,7 +164,10 @@ fn get_bool_cfg(cfg: Option<&Value>, name: &str, on_fail: bool, on_unavail: bool }, } }) - .unwrap_or(on_unavail) + .unwrap_or_else(|| { + debug!("No configuration to fetch {} from, assuming {}", name, on_unavail); + on_unavail + }) } /// Check whether the hook is enabled or not. If the config is not there, the hook is _enabled_ by From 52bb74da1593e0230cd6251a2a1d1b354a1b1fb4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Sep 2016 09:28:13 +0200 Subject: [PATCH 7/7] util: get_bool_cfg(): Output with warn!() instead of debug!() --- libimagstorestdhook/src/vcs/git/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/config.rs b/libimagstorestdhook/src/vcs/git/config.rs index aca1652b..f692edbb 100644 --- a/libimagstorestdhook/src/vcs/git/config.rs +++ b/libimagstorestdhook/src/vcs/git/config.rs @@ -159,13 +159,13 @@ fn get_bool_cfg(cfg: Option<&Value>, name: &str, on_fail: bool, on_unavail: bool on_fail }, None => { - debug!("No key '{}' - Assuming '{}'", name, on_unavail); + warn!("No key '{}' - Assuming '{}'", name, on_unavail); on_unavail }, } }) .unwrap_or_else(|| { - debug!("No configuration to fetch {} from, assuming {}", name, on_unavail); + warn!("No configuration to fetch {} from, assuming {}", name, on_unavail); on_unavail }) }