diff mbox series

[02/27] gc: use hook library for pre-auto-gc hook

Message ID patch-02.27-7209f73f28-20210617T101217Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series Base for "config-based-hooks" | expand

Commit Message

Ævar Arnfjörð Bjarmason June 17, 2021, 10:22 a.m. UTC
From: Emily Shaffer <emilyshaffer@google.com>

Using the hook.h library instead of the run-command.h library to run
pre-auto-gc means that those hooks can be set up in config files, as
well as in the hookdir. pre-auto-gc is called only from builtin/gc.c.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/gc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Emily Shaffer July 22, 2021, 9:58 p.m. UTC | #1
On Thu, Jun 17, 2021 at 12:22:36PM +0200, Ævar Arnfjörð Bjarmason wrote:
> 
> 
> Using the hook.h library instead of the run-command.h library to run
> pre-auto-gc means that those hooks can be set up in config files, as
> well as in the hookdir. pre-auto-gc is called only from builtin/gc.c.

This one is a good example of an issue Junio pointed out to me in an
earlier iteration - since the strvecs in run_hooks_opt need to be
cleared, you need to be careful with exiting without running
run_hooks_opt_clear(). need_to_gc() can exit before running the hook in
some cases.

 - Emily

> 
> Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/gc.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/builtin/gc.c b/builtin/gc.c
> index f05d2f0a1a..a12641a691 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -32,6 +32,7 @@
>  #include "remote.h"
>  #include "object-store.h"
>  #include "exec-cmd.h"
> +#include "hook.h"
>  
>  #define FAILED_RUN "failed to run %s"
>  
> @@ -348,6 +349,8 @@ static void add_repack_incremental_option(void)
>  
>  static int need_to_gc(void)
>  {
> +	struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT;
> +
>  	/*
>  	 * Setting gc.auto to 0 or negative can disable the
>  	 * automatic gc.
> @@ -394,8 +397,11 @@ static int need_to_gc(void)
>  	else
>  		return 0;
>  
> -	if (run_hook_le(NULL, "pre-auto-gc", NULL))
> +	if (run_hooks("pre-auto-gc", &hook_opt)) {
> +		run_hooks_opt_clear(&hook_opt);
>  		return 0;
> +	}
> +	run_hooks_opt_clear(&hook_opt);
>  	return 1;
>  }
>  
> -- 
> 2.32.0.576.g59759b6ca7d
>
diff mbox series

Patch

diff --git a/builtin/gc.c b/builtin/gc.c
index f05d2f0a1a..a12641a691 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -32,6 +32,7 @@ 
 #include "remote.h"
 #include "object-store.h"
 #include "exec-cmd.h"
+#include "hook.h"
 
 #define FAILED_RUN "failed to run %s"
 
@@ -348,6 +349,8 @@  static void add_repack_incremental_option(void)
 
 static int need_to_gc(void)
 {
+	struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT;
+
 	/*
 	 * Setting gc.auto to 0 or negative can disable the
 	 * automatic gc.
@@ -394,8 +397,11 @@  static int need_to_gc(void)
 	else
 		return 0;
 
-	if (run_hook_le(NULL, "pre-auto-gc", NULL))
+	if (run_hooks("pre-auto-gc", &hook_opt)) {
+		run_hooks_opt_clear(&hook_opt);
 		return 0;
+	}
+	run_hooks_opt_clear(&hook_opt);
 	return 1;
 }