diff mbox series

[v2,13/30] read-cache: convert post-index-change hook to use config

Message ID patch-13.30-0300607a9b4-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:33 a.m. UTC
From: Emily Shaffer <emilyshaffer@google.com>

By using hook.h instead of run-command.h to run, post-index-change hooks
can now be specified in the config in addition to the hookdir.
post-index-change is not run anywhere besides in read-cache.c.

This removes the last direct user of run_hook_ve(), so we can make the
function static now. It'll be removed entirely soon.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 read-cache.c  | 11 ++++++++---
 run-command.c |  2 +-
 run-command.h |  1 -
 3 files changed, 9 insertions(+), 5 deletions(-)

Comments

Felipe Contreras June 25, 2021, 6:32 p.m. UTC | #1
Ævar Arnfjörð Bjarmason wrote:
> From: Emily Shaffer <emilyshaffer@google.com>
> 
> By using hook.h instead of run-command.h to run, post-index-change hooks
> can now be specified in the config in addition to the hookdir.
> post-index-change is not run anywhere besides in read-cache.c.
> 
> This removes the last direct user of run_hook_ve(), so we can make the
> function static now. It'll be removed entirely soon.

This is mixing two logically independent changes. For the same reason I
suggested to split the run_hook_le() removal I think this should be
split too.

Not a big deal though, especially since the splitted patch would be very
small.
diff mbox series

Patch

diff --git a/read-cache.c b/read-cache.c
index af5b97104cf..f801313cc95 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3063,6 +3063,7 @@  static int do_write_locked_index(struct index_state *istate, struct lock_file *l
 {
 	int ret;
 	int was_full = !istate->sparse_index;
+	struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT;
 
 	ret = convert_to_sparse(istate);
 
@@ -3091,9 +3092,13 @@  static int do_write_locked_index(struct index_state *istate, struct lock_file *l
 	else
 		ret = close_lock_file_gently(lock);
 
-	run_hook_le(NULL, "post-index-change",
-			istate->updated_workdir ? "1" : "0",
-			istate->updated_skipworktree ? "1" : "0", NULL);
+	strvec_pushl(&hook_opt.args,
+		     istate->updated_workdir ? "1" : "0",
+		     istate->updated_skipworktree ? "1" : "0",
+		     NULL);
+	run_hooks("post-index-change", &hook_opt);
+	run_hooks_opt_clear(&hook_opt);
+
 	istate->updated_workdir = 0;
 	istate->updated_skipworktree = 0;
 
diff --git a/run-command.c b/run-command.c
index 82fdf296569..eecdef5a0c8 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1321,7 +1321,7 @@  int async_with_fork(void)
 #endif
 }
 
-int run_hook_ve(const char *const *env, const char *name, va_list args)
+static int run_hook_ve(const char *const *env, const char *name, va_list args)
 {
 	struct child_process hook = CHILD_PROCESS_INIT;
 	const char *p;
diff --git a/run-command.h b/run-command.h
index b58531a7eb3..24ab5d63c4c 100644
--- a/run-command.h
+++ b/run-command.h
@@ -216,7 +216,6 @@  int run_command(struct child_process *);
  */
 LAST_ARG_MUST_BE_NULL
 int run_hook_le(const char *const *env, const char *name, ...);
-int run_hook_ve(const char *const *env, const char *name, va_list args);
 
 /*
  * Trigger an auto-gc