diff mbox series

[v2,11/13] read-cache: convert post-index-change to use hook.h

Message ID patch-v2-11.13-58b7689e4af-20211015T093918Z-avarab@gmail.com (mailing list archive)
State Superseded
Headers show
Series hook.[ch]: new library to run hooks + simple hook conversion | expand

Commit Message

Ævar Arnfjörð Bjarmason Oct. 15, 2021, 9:43 a.m. UTC
From: Emily Shaffer <emilyshaffer@google.com>

Move the post-index-change hook away from run-command.h to and over to
the new hook.h library.

This removes the last direct user of "run_hook_ve()" outside of
run-command.c ("run_hook_le()" still uses it). So we can make the
function static now. A subsequent commit will remove this code
entirely when "run_hook_le()" itself goes away.

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

Comments

Emily Shaffer Oct. 15, 2021, 5:17 p.m. UTC | #1
On Fri, Oct 15, 2021 at 11:43:39AM +0200, Ævar Arnfjörð Bjarmason wrote:
> 
> 
> Move the post-index-change hook away from run-command.h to and over to
> the new hook.h library.
> 
> This removes the last direct user of "run_hook_ve()" outside of
> run-command.c ("run_hook_le()" still uses it). So we can make the
> function static now. A subsequent commit will remove this code
> entirely when "run_hook_le()" itself goes away.

\o/

> 
> Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

Reviewed-by: Emily Shaffer <emilyshaffer@google.com>

> ---
>  read-cache.c  | 10 +++++++---
>  run-command.c |  2 +-
>  run-command.h |  1 -
>  3 files changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/read-cache.c b/read-cache.c
> index 9773118d078..84cc3d88196 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -3087,6 +3087,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, 0);
>  
> @@ -3115,9 +3116,12 @@ 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_oneshot("post-index-change", &hook_opt);
> +
>  	istate->updated_workdir = 0;
>  	istate->updated_skipworktree = 0;
>  
> diff --git a/run-command.c b/run-command.c
> index 7ef5cc712a9..d92e670c8ed 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -1323,7 +1323,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 49878262584..3fa7454cf8a 100644
> --- a/run-command.h
> +++ b/run-command.h
> @@ -239,7 +239,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
> -- 
> 2.33.1.1338.g20da966911a
>
diff mbox series

Patch

diff --git a/read-cache.c b/read-cache.c
index 9773118d078..84cc3d88196 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3087,6 +3087,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, 0);
 
@@ -3115,9 +3116,12 @@  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_oneshot("post-index-change", &hook_opt);
+
 	istate->updated_workdir = 0;
 	istate->updated_skipworktree = 0;
 
diff --git a/run-command.c b/run-command.c
index 7ef5cc712a9..d92e670c8ed 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1323,7 +1323,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 49878262584..3fa7454cf8a 100644
--- a/run-command.h
+++ b/run-command.h
@@ -239,7 +239,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