commit: convert {pre-commit,prepare-commit-msg} hook to hook.h
Move these hooks hook away from run-command.h to and over to the new hook.h library. Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Acked-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Emily Shaffer committed
Dec 22, 2021 at 04:59 UTC
f443246b9f29b815f0b98a07bb2d425628ae6522
1 file changed
+8
-7
commit.c
+8
-7
@@ -21,6 +21,7 @@
21
#include "commit-reach.h"
22
#include "run-command.h"
23
#include "shallow.h"
24
+#include "hook.h"
25
26
static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
27
@@ -1702,22 +1703,22 @@ size_t ignore_non_trailer(const char *buf, size_t len)
1703
int run_commit_hook(int editor_is_used, const char *index_file,
1704
const char *name, ...)
1705
{
1705
- struct strvec hook_env = STRVEC_INIT;
1706
+ struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
1707
va_list args;
1707
- int ret;
1708
+ const char *arg;
1709
1709
- strvec_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
1710
+ strvec_pushf(&opt.env, "GIT_INDEX_FILE=%s", index_file);
1711
1712
/*
1713
* Let the hook know that no editor will be launched.
1714
*/
1715
if (!editor_is_used)
1715
- strvec_push(&hook_env, "GIT_EDITOR=:");
1716
+ strvec_push(&opt.env, "GIT_EDITOR=:");
1717
1718
va_start(args, name);
1718
- ret = run_hook_ve(hook_env.v, name, args);
1719
+ while ((arg = va_arg(args, const char *)))
1720
+ strvec_push(&opt.args, arg);
1721
va_end(args);
1720
- strvec_clear(&hook_env);
1722
1722
- return ret;
1723
+ return run_hooks_opt(name, &opt);
1724
}