diff options
author | Phillip Wood <phillip.wood@dunelm.org.uk> | 2019-10-15 12:25:31 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-10-16 03:30:51 +0200 |
commit | 49697cb72122cf84b44111124821c9a4bcba3ab6 (patch) | |
tree | ff996f05507c53a17a63510919a986d22ba528e0 /sequencer.c | |
parent | sequencer.h fix placement of #endif (diff) | |
download | git-49697cb72122cf84b44111124821c9a4bcba3ab6.tar.xz git-49697cb72122cf84b44111124821c9a4bcba3ab6.zip |
move run_commit_hook() to libgit and use it there
This function was declared in commit.h but was implemented in
builtin/commit.c so was not part of libgit. Move it to libgit so we can
use it in the sequencer. This simplifies the implementation of
run_prepare_commit_msg_hook() and will be used in the next commit.
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r-- | sequencer.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/sequencer.c b/sequencer.c index 2adcf5a639..cdc0d1dfba 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1127,25 +1127,22 @@ static int run_prepare_commit_msg_hook(struct repository *r, struct strbuf *msg, const char *commit) { - struct argv_array hook_env = ARGV_ARRAY_INIT; - int ret; - const char *name; + int ret = 0; + const char *name, *arg1 = NULL, *arg2 = NULL; name = git_path_commit_editmsg(); if (write_message(msg->buf, msg->len, name, 0)) return -1; - argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", r->index_file); - argv_array_push(&hook_env, "GIT_EDITOR=:"); - if (commit) - ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name, - "commit", commit, NULL); - else - ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name, - "message", NULL); - if (ret) + if (commit) { + arg1 = "commit"; + arg2 = commit; + } else { + arg1 = "message"; + } + if (run_commit_hook(0, r->index_file, "prepare-commit-msg", name, + arg1, arg2, NULL)) ret = error(_("'prepare-commit-msg' hook failed")); - argv_array_clear(&hook_env); return ret; } |