Re: [PATCH 02/27] gc: use hook library for pre-auto-gc hook
From: Emily Shaffer <hidden>
Date: 2021-07-22 21:58:14
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
quoted hunk ↗ jump to hunk
Signed-off-by: Emily Shaffer <redacted> Signed-off-by: Ævar Arnfjörð Bjarmason <redacted> --- 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