diff mbox series

[v2,04/30] gc: use hook library for pre-auto-gc hook

Message ID patch-04.30-da2763192ae-20210614T101920Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series Minimal restart of "config-based-hooks" | expand

Commit Message

Ævar Arnfjörð Bjarmason June 14, 2021, 10:32 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 June 14, 2021, 11:57 p.m. UTC | #1
On Mon, Jun 14, 2021 at 12:32:53PM +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.

I think all the commit messages in "convert x to hook library" commits I
wrote extol the virtues of config-based hooks. Since that's not part of
your reroll, I expect we should change the commit messages too.

 - Emily
diff mbox series

Patch

diff --git a/builtin/gc.c b/builtin/gc.c
index f05d2f0a1ac..a12641a691d 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;
 }