git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 7/8] hook.c users: use "hook_exists()" instead of "find_hook()"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 26, 2021, 19:03 UTC
Message-ID
<patch-v2-7.8-6237a1a5549-20210926T185800Z-avarab@gmail.com>
In-Reply-To
<cover-v2-0.8-00000000000-20210926T185800Z-avarab@gmail.com>

Use the new hook_exists() function instead of find_hook() where the latter was called in boolean contexts. This make subsequent changes in a series where we further refactor the hook API clearer, as we won't conflate wanting to get the path of the hook with checking for its existence.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/commit.c       | 2 +-
 builtin/merge.c        | 2 +-
 builtin/receive-pack.c | 2 +-
 sequencer.c            | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 5359d961d22..883c16256c8 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1052,7 +1052,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		return 0;
 	}
 
-	if (!no_verify && find_hook("pre-commit")) {
+	if (!no_verify && hook_exists("pre-commit")) {
 		/*
 		 * Re-read the index as pre-commit hook could have updated it,
 		 * and write it out as a tree.  We must do this before we invoke
diff --git a/builtin/merge.c b/builtin/merge.c
index fe664f6a863..956b6259f21 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -849,7 +849,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
 	 * and write it out as a tree.  We must do this before we invoke
 	 * the editor and after we invoke run_status above.
 	 */
-	if (find_hook("pre-merge-commit"))
+	if (hook_exists("pre-merge-commit"))
 		discard_cache();
 	read_cache_from(index_file);
 	strbuf_addbuf(&msg, &merge_msg);
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index e3895aec622..25cc0c907e1 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1464,7 +1464,7 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w
 
 	strvec_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir));
 
-	if (!find_hook(push_to_checkout_hook))
+	if (!hook_exists(push_to_checkout_hook))
 		retval = push_to_deploy(sha1, &env, work_tree);
 	else
 		retval = push_to_checkout(sha1, &env, work_tree);
diff --git a/sequencer.c b/sequencer.c
index 8ee6c4ac240..e501945796d 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1460,7 +1460,7 @@ static int try_to_commit(struct repository *r,
 		}
 	}
 
-	if (find_hook("prepare-commit-msg")) {
+	if (hook_exists("prepare-commit-msg")) {
 		res = run_prepare_commit_msg_hook(r, msg, hook_commit);
 		if (res)
 			goto out;
-- 
2.33.0.1291.g8857a6a91ac
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 32 of 39 in “Makefile: generate a hook-list.h, prep for config-based-hooks”
  1. 0/8 Makefile: generate a hook-list.h, prep for config-based-hooksÆvar Arnfjörð Bjarmason, Sep 23, 2021
  2. 1/8 Makefile: mark "check" target as .PHONYÆvar Arnfjörð Bjarmason, Sep 23, 2021
  3. 2/8 Makefile: stop hardcoding {command,config}-list.hÆvar Arnfjörð Bjarmason, Sep 23, 2021
  4. 3/8 Makefile: don't perform "mv $@+ $@" dance for $(GENERATED_H)Ævar Arnfjörð Bjarmason, Sep 23, 2021
  5. 4/8 Makefile: remove an out-of-date commentÆvar Arnfjörð Bjarmason, Sep 23, 2021
  6. 5/8 hook.[ch]: move find_hook() from run-command.c to hook.cÆvar Arnfjörð Bjarmason, Sep 23, 2021
  7. 6/8 hook.c: add a hook_exists() wrapper and use it in bugreport.cÆvar Arnfjörð Bjarmason, Sep 23, 2021
  8. 7/8 hook.c users: use "hook_exists()" instead of "find_hook()"Ævar Arnfjörð Bjarmason, Sep 23, 2021
  9. 8/8 hook-list.h: add a generated list of hooks, like config-list.hÆvar Arnfjörð Bjarmason, Sep 23, 2021
  10. Phillip WoodSep 24, 2021
  11. Junio C HamanoSep 24, 2021
  12. René ScharfeSep 24, 2021
  13. Ævar Arnfjörð BjarmasonSep 24, 2021
  14. René ScharfeSep 24, 2021
  15. Ævar Arnfjörð BjarmasonSep 24, 2021
  16. Phillip WoodSep 27, 2021
  17. Ævar Arnfjörð BjarmasonSep 27, 2021
  18. Mike HommeyNov 15, 2021
  19. Ævar Arnfjörð BjarmasonNov 15, 2021
  20. Mike HommeyNov 15, 2021
  21. Ævar Arnfjörð BjarmasonNov 15, 2021
  22. Mike HommeyNov 15, 2021
  23. Ævar Arnfjörð BjarmasonNov 16, 2021
  24. Junio C HamanoNov 17, 2021
  25. 0/8 Makefile: generate a hook-list.h, prep for config-based-hooksÆvar Arnfjörð Bjarmason, Sep 26, 2021
  26. 1/8 Makefile: mark "check" target as .PHONYÆvar Arnfjörð Bjarmason, Sep 26, 2021
  27. 2/8 Makefile: stop hardcoding {command,config}-list.hÆvar Arnfjörð Bjarmason, Sep 26, 2021
  28. 3/8 Makefile: don't perform "mv $@+ $@" dance for $(GENERATED_H)Ævar Arnfjörð Bjarmason, Sep 26, 2021
  29. 4/8 Makefile: remove an out-of-date commentÆvar Arnfjörð Bjarmason, Sep 26, 2021
  30. 5/8 hook.[ch]: move find_hook() from run-command.c to hook.cÆvar Arnfjörð Bjarmason, Sep 26, 2021
  31. 6/8 hook.c: add a hook_exists() wrapper and use it in bugreport.cÆvar Arnfjörð Bjarmason, Sep 26, 2021
  32. 7/8 hook.c users: use "hook_exists()" instead of "find_hook()"Ævar Arnfjörð Bjarmason, Sep 26, 2021
  33. 8/8 hook-list.h: add a generated list of hooks, like config-list.hÆvar Arnfjörð Bjarmason, Sep 26, 2021
  34. Junio C HamanoSep 27, 2021
  35. René ScharfeSep 27, 2021
  36. Junio C HamanoSep 27, 2021
  37. Phillip WoodSep 27, 2021
  38. Ævar Arnfjörð BjarmasonSep 27, 2021
  39. Phillip WoodSep 27, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.