From patchwork Mon Nov 1 18:56:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5969EC433F5 for ; Mon, 1 Nov 2021 18:58:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3957C60EE9 for ; Mon, 1 Nov 2021 18:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232548AbhKATAd (ORCPT ); Mon, 1 Nov 2021 15:00:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232426AbhKAS7B (ORCPT ); Mon, 1 Nov 2021 14:59:01 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A4C3C061714 for ; Mon, 1 Nov 2021 11:56:27 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id z200so13132256wmc.1 for ; Mon, 01 Nov 2021 11:56:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vLXvaqyCHZxVwQg5wMh8hrhf9VJHxmw814odO7666Dk=; b=K0sjDUUwsE+FW1we85Fweb4Bi2n9FH7AjFIzDNP+n1VGtYV9dzKDawVaF/S2NRVjjf SbP9fB6lGcvRvEHwpIYEtwhji1pIRrAAJy1/0nZsiNIHzEoMDH9+w35GBPm3aCPqsAmN 5DfRLHo+i5MxMuKAqT3CXnejdqKAp8QvpYRQIsUz5mxzYmyHdAdus1ZnvLdm0fJnaZJ5 3eQe6xN9aRpnnhY7YQnDSsi4BhWbYDN5W4DUZrJ+m+1o/aQDcCMltpU09hOqWAR9X0Av hLEtj5kueon8sjw1UwB/2GXmj8hcxmzAJ/bgj3i4U0zPyWR6woxJjm8guMVZ5eLxHka/ AJjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vLXvaqyCHZxVwQg5wMh8hrhf9VJHxmw814odO7666Dk=; b=ilC3SmBGhVgvAQAjqeOker5jQ+wD0GAB6ePAzGn3HhZEJdwtw/IuX/RA1sPPZ6laEZ +I7Gw639bRjC+9BVO/BlnK+13cX7Ht7MHALGWuEqQXORv5jlF7fVRjJ7oR5E8KVFhNA6 bU3dpHLzdt1TCHk26A+DAlsWz7lm/4ZL+/zgUYzuUJSJ1/slnHMIdEd54hkWir1IZ+Nc QiyXlO+z+hMhL/F9o+jQBxZK5WP6hslKVS5x6Jy08u/08kyrjWPs9EHHEXZn3+jGYFlt KgpDN32n7aaUFt9wqlpPR7HyE4L0GmLG9xFbxWQaxDkuznRJ1iG3hkdnT2JS4Ud2GJ+S 1CbA== X-Gm-Message-State: AOAM532+mUi6f/Af4BGa77VdwphNl1d1sSh64fGdpZKxyN6Pc0pCb/cP EuHZrHxi9mYcDyRPtYdJPu+h50vJt87DHsw2 X-Google-Smtp-Source: ABdhPJxZ5e74tsGjsfD3mw6K84KF+2liVc7KuGesRYB1Ls488IrqmYbPd7lZMERfb93rfVn5usiCJw== X-Received: by 2002:a05:600c:4154:: with SMTP id h20mr750008wmm.189.1635792985682; Mon, 01 Nov 2021 11:56:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 01/17] hook: add 'run' subcommand Date: Mon, 1 Nov 2021 19:56:06 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer In order to enable hooks to be run as an external process, by a standalone Git command, or by tools which wrap Git, provide an external means to run all configured hook commands for a given hook event. Most of our hooks require more complex functionality than this, but let's start with the bare minimum required to support our simplest hooks. In terms of implementation the usage_with_options() and "goto usage" pattern here mirrors that of builtin/{commit-graph,multi-pack-index}.c. Some of the implementation here, such as a function being named run_hooks_opt() when it's tasked with running one hook, to using the run_processes_parallel_tr2() API to run with jobs=1 is somewhere between a bit odd and and an overkill for the current features of this "hook run" command and the hook.[ch] API. This code will eventually be able to run multiple hooks declared in config in parallel, by starting out with these names and APIs we reduce the later churn of renaming functions, switching from the run_command() to run_processes_parallel_tr2() API etc. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- .gitignore | 1 + Documentation/git-hook.txt | 37 +++++++++++ Documentation/githooks.txt | 4 ++ Makefile | 1 + builtin.h | 1 + builtin/hook.c | 80 +++++++++++++++++++++++ command-list.txt | 1 + git.c | 1 + hook.c | 102 +++++++++++++++++++++++++++++ hook.h | 35 ++++++++++ t/t1800-hook.sh | 129 +++++++++++++++++++++++++++++++++++++ 11 files changed, 392 insertions(+) create mode 100644 Documentation/git-hook.txt create mode 100644 builtin/hook.c create mode 100755 t/t1800-hook.sh diff --git a/.gitignore b/.gitignore index 054249b20a8..f817c509ec0 100644 --- a/.gitignore +++ b/.gitignore @@ -77,6 +77,7 @@ /git-grep /git-hash-object /git-help +/git-hook /git-http-backend /git-http-fetch /git-http-push diff --git a/Documentation/git-hook.txt b/Documentation/git-hook.txt new file mode 100644 index 00000000000..e39b1b5d069 --- /dev/null +++ b/Documentation/git-hook.txt @@ -0,0 +1,37 @@ +git-hook(1) +=========== + +NAME +---- +git-hook - Run git hooks + +SYNOPSIS +-------- +[verse] +'git hook' run [-- ] + +DESCRIPTION +----------- + +A command interface to running git hooks (see linkgit:githooks[5]), +for use by other scripted git commands. + +SUBCOMMANDS +----------- + +run:: + Run the `` hook. See linkgit:githooks[5] for + supported hook names. ++ + +Any positional arguments to the hook should be passed after a +mandatory `--` (or `--end-of-options`, see linkgit:gitcli[7]). See +linkgit:githooks[5] for arguments hooks might expect (if any). + +SEE ALSO +-------- +linkgit:githooks[5] + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index b51959ff941..a16e62bc8c8 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -698,6 +698,10 @@ and "0" meaning they were not. Only one parameter should be set to "1" when the hook runs. The hook running passing "1", "1" should not be possible. +SEE ALSO +-------- +linkgit:git-hook[1] + GIT --- Part of the linkgit:git[1] suite diff --git a/Makefile b/Makefile index 12be39ac497..6cd20534304 100644 --- a/Makefile +++ b/Makefile @@ -1107,6 +1107,7 @@ BUILTIN_OBJS += builtin/get-tar-commit-id.o BUILTIN_OBJS += builtin/grep.o BUILTIN_OBJS += builtin/hash-object.o BUILTIN_OBJS += builtin/help.o +BUILTIN_OBJS += builtin/hook.o BUILTIN_OBJS += builtin/index-pack.o BUILTIN_OBJS += builtin/init-db.o BUILTIN_OBJS += builtin/interpret-trailers.o diff --git a/builtin.h b/builtin.h index 8a58743ed63..83379f3832c 100644 --- a/builtin.h +++ b/builtin.h @@ -164,6 +164,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix); int cmd_grep(int argc, const char **argv, const char *prefix); int cmd_hash_object(int argc, const char **argv, const char *prefix); int cmd_help(int argc, const char **argv, const char *prefix); +int cmd_hook(int argc, const char **argv, const char *prefix); int cmd_index_pack(int argc, const char **argv, const char *prefix); int cmd_init_db(int argc, const char **argv, const char *prefix); int cmd_interpret_trailers(int argc, const char **argv, const char *prefix); diff --git a/builtin/hook.c b/builtin/hook.c new file mode 100644 index 00000000000..9b67ff50cef --- /dev/null +++ b/builtin/hook.c @@ -0,0 +1,80 @@ +#include "cache.h" +#include "builtin.h" +#include "config.h" +#include "hook.h" +#include "parse-options.h" +#include "strbuf.h" +#include "strvec.h" + +#define BUILTIN_HOOK_RUN_USAGE \ + N_("git hook run [-- ]") + +static const char * const builtin_hook_usage[] = { + BUILTIN_HOOK_RUN_USAGE, + NULL +}; + +static const char * const builtin_hook_run_usage[] = { + BUILTIN_HOOK_RUN_USAGE, + NULL +}; + +static int run(int argc, const char **argv, const char *prefix) +{ + int i; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + const char *hook_name; + struct option run_options[] = { + OPT_END(), + }; + int ret; + + argc = parse_options(argc, argv, prefix, run_options, + builtin_hook_run_usage, + PARSE_OPT_KEEP_DASHDASH); + + if (!argc) + goto usage; + + /* + * Having a -- for "run" when providing is + * mandatory. + */ + if (argc > 1 && strcmp(argv[1], "--") && + strcmp(argv[1], "--end-of-options")) + goto usage; + + /* Add our arguments, start after -- */ + for (i = 2 ; i < argc; i++) + strvec_push(&opt.args, argv[i]); + + /* Need to take into account core.hooksPath */ + git_config(git_default_config, NULL); + + hook_name = argv[0]; + opt.error_if_missing = 1; + ret = run_hooks_opt(hook_name, &opt); + if (ret < 0) /* error() return */ + ret = 1; + return ret; +usage: + usage_with_options(builtin_hook_run_usage, run_options); +} + +int cmd_hook(int argc, const char **argv, const char *prefix) +{ + struct option builtin_hook_options[] = { + OPT_END(), + }; + + argc = parse_options(argc, argv, NULL, builtin_hook_options, + builtin_hook_usage, PARSE_OPT_STOP_AT_NON_OPTION); + if (!argc) + goto usage; + + if (!strcmp(argv[0], "run")) + return run(argc, argv, prefix); + +usage: + usage_with_options(builtin_hook_usage, builtin_hook_options); +} diff --git a/command-list.txt b/command-list.txt index eb9cee8dee9..0c9af14bdf3 100644 --- a/command-list.txt +++ b/command-list.txt @@ -103,6 +103,7 @@ git-grep mainporcelain info git-gui mainporcelain git-hash-object plumbingmanipulators git-help ancillaryinterrogators complete +git-hook purehelpers git-http-backend synchingrepositories git-http-fetch synchelpers git-http-push synchelpers diff --git a/git.c b/git.c index 5ff21be21f3..a5be02b04b8 100644 --- a/git.c +++ b/git.c @@ -538,6 +538,7 @@ static struct cmd_struct commands[] = { { "grep", cmd_grep, RUN_SETUP_GENTLY }, { "hash-object", cmd_hash_object }, { "help", cmd_help }, + { "hook", cmd_hook, RUN_SETUP }, { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY | NO_PARSEOPT }, { "init", cmd_init_db }, { "init-db", cmd_init_db }, diff --git a/hook.c b/hook.c index 55e1145a4b7..64d3608e45e 100644 --- a/hook.c +++ b/hook.c @@ -1,6 +1,7 @@ #include "cache.h" #include "hook.h" #include "run-command.h" +#include "config.h" const char *find_hook(const char *name) { @@ -40,3 +41,104 @@ int hook_exists(const char *name) { return !!find_hook(name); } + +static int pick_next_hook(struct child_process *cp, + struct strbuf *out, + void *pp_cb, + void **pp_task_cb) +{ + struct hook_cb_data *hook_cb = pp_cb; + const char *hook_path = hook_cb->hook_path; + + if (!hook_path) + return 0; + + cp->no_stdin = 1; + cp->env = hook_cb->options->env.v; + cp->stdout_to_stderr = 1; + cp->trace2_hook_name = hook_cb->hook_name; + + strvec_push(&cp->args, hook_path); + strvec_pushv(&cp->args, hook_cb->options->args.v); + + /* Provide context for errors if necessary */ + *pp_task_cb = (char *)hook_path; + + /* + * This pick_next_hook() will be called again, we're only + * running one hook, so indicate that no more work will be + * done. + */ + hook_cb->hook_path = NULL; + + return 1; +} + +static int notify_start_failure(struct strbuf *out, + void *pp_cb, + void *pp_task_cp) +{ + struct hook_cb_data *hook_cb = pp_cb; + const char *hook_path = pp_task_cp; + + hook_cb->rc |= 1; + + strbuf_addf(out, _("Couldn't start hook '%s'\n"), + hook_path); + + return 1; +} + +static int notify_hook_finished(int result, + struct strbuf *out, + void *pp_cb, + void *pp_task_cb) +{ + struct hook_cb_data *hook_cb = pp_cb; + + hook_cb->rc |= result; + + return 0; +} + +static void run_hooks_opt_clear(struct run_hooks_opt *options) +{ + strvec_clear(&options->env); + strvec_clear(&options->args); +} + +int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) +{ + struct hook_cb_data cb_data = { + .rc = 0, + .hook_name = hook_name, + .options = options, + }; + const char *const hook_path = find_hook(hook_name); + int jobs = 1; + int ret = 0; + + if (!options) + BUG("a struct run_hooks_opt must be provided to run_hooks"); + + if (!hook_path && !options->error_if_missing) + goto cleanup; + + if (!hook_path) { + ret = error("cannot find a hook named %s", hook_name); + goto cleanup; + } + + cb_data.hook_path = hook_path; + run_processes_parallel_tr2(jobs, + pick_next_hook, + notify_start_failure, + notify_hook_finished, + &cb_data, + "hook", + hook_name); + ret = cb_data.rc; +cleanup: + run_hooks_opt_clear(options); + return ret; +} diff --git a/hook.h b/hook.h index 6aa36fc7ff9..782385cc235 100644 --- a/hook.h +++ b/hook.h @@ -1,5 +1,31 @@ #ifndef HOOK_H #define HOOK_H +#include "strvec.h" + +struct run_hooks_opt +{ + /* Environment vars to be set for each hook */ + struct strvec env; + + /* Args to be passed to each hook */ + struct strvec args; + + /* Emit an error if the hook is missing */ + unsigned int error_if_missing:1; +}; + +#define RUN_HOOKS_OPT_INIT { \ + .env = STRVEC_INIT, \ + .args = STRVEC_INIT, \ +} + +struct hook_cb_data { + /* rc reflects the cumulative failure state */ + int rc; + const char *hook_name; + const char *hook_path; + struct run_hooks_opt *options; +}; /* * Returns the path to the hook file, or NULL if the hook is missing @@ -13,4 +39,13 @@ const char *find_hook(const char *name); */ int hook_exists(const char *hookname); +/** + * Takes a `hook_name`, resolves it to a path with find_hook(), and + * runs the hook for you with the options specified in "struct + * run_hooks opt". Will free memory associated with the "struct run_hooks_opt". + * + * Returns the status code of the run hook, or a negative value on + * error(). + */ +int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options); #endif diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh new file mode 100755 index 00000000000..3aea1b105f0 --- /dev/null +++ b/t/t1800-hook.sh @@ -0,0 +1,129 @@ +#!/bin/sh + +test_description='git-hook command' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh + +test_expect_success 'git hook usage' ' + test_expect_code 129 git hook && + test_expect_code 129 git hook run && + test_expect_code 129 git hook run -h && + test_expect_code 129 git hook run --unknown 2>err && + grep "unknown option" err +' + +test_expect_success 'git hook run: nonexistent hook' ' + cat >stderr.expect <<-\EOF && + error: cannot find a hook named test-hook + EOF + test_expect_code 1 git hook run test-hook 2>stderr.actual && + test_cmp stderr.expect stderr.actual +' + +test_expect_success 'git hook run: basic' ' + write_script .git/hooks/test-hook <<-EOF && + echo Test hook + EOF + + cat >expect <<-\EOF && + Test hook + EOF + git hook run test-hook 2>actual && + test_cmp expect actual +' + +test_expect_success 'git hook run: stdout and stderr both write to our stderr' ' + write_script .git/hooks/test-hook <<-EOF && + echo >&1 Will end up on stderr + echo >&2 Will end up on stderr + EOF + + cat >stderr.expect <<-\EOF && + Will end up on stderr + Will end up on stderr + EOF + git hook run test-hook >stdout.actual 2>stderr.actual && + test_cmp stderr.expect stderr.actual && + test_must_be_empty stdout.actual +' + +test_expect_success 'git hook run: exit codes are passed along' ' + write_script .git/hooks/test-hook <<-EOF && + exit 1 + EOF + + test_expect_code 1 git hook run test-hook && + + write_script .git/hooks/test-hook <<-EOF && + exit 2 + EOF + + test_expect_code 2 git hook run test-hook && + + write_script .git/hooks/test-hook <<-EOF && + exit 128 + EOF + + test_expect_code 128 git hook run test-hook && + + write_script .git/hooks/test-hook <<-EOF && + exit 129 + EOF + + test_expect_code 129 git hook run test-hook +' + +test_expect_success 'git hook run arg u ments without -- is not allowed' ' + test_expect_code 129 git hook run test-hook arg u ments +' + +test_expect_success 'git hook run -- pass arguments' ' + write_script .git/hooks/test-hook <<-\EOF && + echo $1 + echo $2 + EOF + + cat >expect <<-EOF && + arg + u ments + EOF + + git hook run test-hook -- arg "u ments" 2>actual && + test_cmp expect actual +' + +test_expect_success 'git hook run -- out-of-repo runs excluded' ' + write_script .git/hooks/test-hook <<-EOF && + echo Test hook + EOF + + nongit test_must_fail git hook run test-hook +' + +test_expect_success 'git -c core.hooksPath= hook run' ' + mkdir my-hooks && + write_script my-hooks/test-hook <<-\EOF && + echo Hook ran $1 >>actual + EOF + + cat >expect <<-\EOF && + Test hook + Hook ran one + Hook ran two + Hook ran three + Hook ran four + EOF + + # Test various ways of specifying the path. See also + # t1350-config-hooks-path.sh + >actual && + git hook run test-hook -- ignored 2>>actual && + git -c core.hooksPath=my-hooks hook run test-hook -- one 2>>actual && + git -c core.hooksPath=my-hooks/ hook run test-hook -- two 2>>actual && + git -c core.hooksPath="$PWD/my-hooks" hook run test-hook -- three 2>>actual && + git -c core.hooksPath="$PWD/my-hooks/" hook run test-hook -- four 2>>actual && + test_cmp expect actual +' + +test_done From patchwork Mon Nov 1 18:56:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92719C433EF for ; Mon, 1 Nov 2021 18:58:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7022160EE9 for ; Mon, 1 Nov 2021 18:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232441AbhKATAq (ORCPT ); Mon, 1 Nov 2021 15:00:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232458AbhKAS7C (ORCPT ); Mon, 1 Nov 2021 14:59:02 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55916C061766 for ; Mon, 1 Nov 2021 11:56:28 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 77-20020a1c0450000000b0033123de3425so171219wme.0 for ; Mon, 01 Nov 2021 11:56:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2VDVE2Axqlu/cjWiNeDr8w3VB4+md4u+RP7MrPFtgws=; b=SnKI78+/GEGnesZ8zLZ1leeprjjvXthXSKIzNWAlrwwSykC7eEwdG3GUU7ovk7g2iB 9k4qolBypaXRJG/1oyEn+1aDCrFNwgFYwIjAla6Hy59uLZKKOo4l/XtMLoWNcAwHcNBl ICMQugqVMmqMT14ewtxV9Nd98irc/JzUjUDebtZWwkYOWK9rRQcC+8aHARlacowMbQ11 s8fmke0BrpxaSEId2AqdwYBMPL7sTyzr3gMG1Oefs9j52L8Y5MetUhQRQrKDy3CgEqrD nq6yYTFZzgSUxrnSo4pmKji9KxAds0uJy1wX8N9+apL/mtK6feXZFnAEtbhnnqjn8cSQ pAGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2VDVE2Axqlu/cjWiNeDr8w3VB4+md4u+RP7MrPFtgws=; b=GZ8beROlCa1Br+GV5y4l9V8sCDtGuQYX8S3r4BMwI9NsmpiFrch4PfuXm7o/rQzMRF ce7qe2UQPq872ghJaTaaaoO4vuwDSZ0pPh4kJpxbbAY8LYDAcHy5YdFOlQpYyPrkUTqS EGZeT3aCerShHBJfaR1lCbEfU8h8oNLuL9MebIB4YW1btUzLBtAnj00YOdCFPVgLKf+5 hNNSkDTimjLDidE6zSxC1SMQSWQPd+E+QjYjEDu87YANZGBiTpJuFGCnQ6ciwa09mIkW hUTAKgnP+W1AlnIrCbnoxuKrfH4UWuiIHsujO5kwQ35JjdS5eDEM1vpFmNOFNLL3lqRX yjuw== X-Gm-Message-State: AOAM533hjH4fUCBbA6XaoVyh3NzBFXxsTBoajHDEFXI6eWxTwVOLRcjC AfbcucFRpyXAAmAhzrmqdk1Iym0hKqNbe6UM X-Google-Smtp-Source: ABdhPJxenFWe8f/cjht5o/VU9csiYCyPEulDbMkAp/VXz9MIZJJ68a/SZ2VZzGzZ7VGCYBONkTcW3Q== X-Received: by 2002:a7b:cd90:: with SMTP id y16mr860449wmj.84.1635792986710; Mon, 01 Nov 2021 11:56:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 02/17] hook API: add a run_hooks() wrapper Date: Mon, 1 Nov 2021 19:56:07 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a run_hooks() wrapper, we'll use it in subsequent commits for the simple cases of wanting to run a single hook under a given name, without providing options such as "env" or "args". Signed-off-by: Ævar Arnfjörð Bjarmason --- hook.c | 7 +++++++ hook.h | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/hook.c b/hook.c index 64d3608e45e..720994bf4f6 100644 --- a/hook.c +++ b/hook.c @@ -142,3 +142,10 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) run_hooks_opt_clear(options); return ret; } + +int run_hooks(const char *hook_name) +{ + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + + return run_hooks_opt(hook_name, &opt); +} diff --git a/hook.h b/hook.h index 782385cc235..9c358789958 100644 --- a/hook.h +++ b/hook.h @@ -48,4 +48,10 @@ int hook_exists(const char *hookname); * error(). */ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options); + +/** + * A wrapper for run_hooks_opt() which provides a dummy "struct + * run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT". + */ +int run_hooks(const char *hook_name); #endif From patchwork Mon Nov 1 18:56:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B2F5C433EF for ; Mon, 1 Nov 2021 18:59:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DFED60EBB for ; Mon, 1 Nov 2021 18:59:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230004AbhKATBc (ORCPT ); Mon, 1 Nov 2021 15:01:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232468AbhKAS7D (ORCPT ); Mon, 1 Nov 2021 14:59:03 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 104D4C061714 for ; Mon, 1 Nov 2021 11:56:29 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 77-20020a1c0450000000b0033123de3425so171243wme.0 for ; Mon, 01 Nov 2021 11:56:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JGfVUS8FR8Cnu73DVRtbFOzUDo2GysTt36dRDbwV83E=; b=UqRoCmn3NUi1xIM9WbeUrN6pWJk88ByrejrJ9Q+adPyO+GTp28VBnw/yZyF8fs2swI sIUWd8N8D/gY4nhEVPGHZaGE1mbEtMv18vRsU9tMd+mZcVZK85W8A1he3s0yP4zpWylE K422ctTnf0+TW5MVSjBcr2p12alkbehEeRuA3fQz7Q5iQ+4Wz0w7Rxf7W4qVQTRv+uJP J9fcRDw1YchNcZFNfC0k7K2uEaeIlocYlvqOBKy9oMkNkpzlSgkx83JBjtj12yBnWfE9 r+PnVOZiwAyTNW+ffvdsZXknDAV/WxNsPSAUInehMpHH02ulJhHt58IA/c2Jl0UHNnA1 niwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JGfVUS8FR8Cnu73DVRtbFOzUDo2GysTt36dRDbwV83E=; b=DXDLx3l44PRnrTOXZi9IfQyREU3fyF/qkaCJ1/IwpGVlyN8TQrDp8DgrtY3NUeUIcY 9NHk4zCJKpKDlPdn78nnJYLp9UtFCkVr6Gl/uDlB3bMZahnG7CmZWxYHvS9dNJNXvfg9 J3Lc0ucX71ERXo5GVBCSYqiI+Q5rCTzIJvwagoq02sH5lsWHF9Y/Zl9T3Q+2jTq//YXz l/Rs0KlpbH3t1s3ftVY6GftQCnKZcuIcUUqJKhk7EPDONoBmOeEdstS3tyf+LU7rwTFt KX7AqS0gt5Wt6+mfEqRykurBuYD4cLDMqbVkfQexThVMnZrbZZQ9ESqcwydsu5GwRAFq vfow== X-Gm-Message-State: AOAM530mhG33jq0xwreEaqAT8NxX5JzrMuUjE6H6eEJyKPFDnFWMjIyS oFjcHuQ5O/cPpywHfKp7dO86lIZ6cUx5TjG5 X-Google-Smtp-Source: ABdhPJxTZLEgXFoEiN+M0agUbNHqJ79fF2khqAWBuNux3tu0Tk93Tt68OzHhZsYKGQeQ+LzM04HAGw== X-Received: by 2002:a1c:7413:: with SMTP id p19mr815427wmc.141.1635792987475; Mon, 01 Nov 2021 11:56:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 03/17] gc: use hook library for pre-auto-gc hook Date: Mon, 1 Nov 2021 19:56:08 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the pre-auto-gc hook away from run-command.h to and over to the new hook.h library. This uses the new run_hooks() wrapper. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/gc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/gc.c b/builtin/gc.c index 6b3de3dd514..f57cbd2d217 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -32,6 +32,7 @@ #include "remote.h" #include "object-store.h" #include "exec-cmd.h" +#include "hook.h" #define FAILED_RUN "failed to run %s" @@ -394,7 +395,7 @@ static int need_to_gc(void) else return 0; - if (run_hook_le(NULL, "pre-auto-gc", NULL)) + if (run_hooks("pre-auto-gc")) return 0; return 1; } From patchwork Mon Nov 1 18:56:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB672C433EF for ; Mon, 1 Nov 2021 18:58:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C274560EE9 for ; Mon, 1 Nov 2021 18:58:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232426AbhKATB2 (ORCPT ); Mon, 1 Nov 2021 15:01:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232479AbhKAS7D (ORCPT ); Mon, 1 Nov 2021 14:59:03 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF383C061766 for ; Mon, 1 Nov 2021 11:56:29 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id b12so25054675wrh.4 for ; Mon, 01 Nov 2021 11:56:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c0QxQO69dwzkLPhvseRHCAphU10DpsqqwD+1Q6eCgP4=; b=AhYUYb8taWDDuQnPZjMfDILJVzFeAp20m5lAOkMP6RnxqV6tOfLIBe8gsibS2utwpc TdMgL+B2s0nEctWCCYE7f5Q3lbq4qr2ZUjcNdALsZSsI8ZFsgMkR/xjCrgA+nc+gOKoh o8HTU1gC22MF8rJpWFTrLNPMO2XCjbm196sF7KZNGRYUNxqjzdCLItOaYwXzQFASyGeT uwXLlMvJznGWDiVq1Ppe8XhSzmRr7VqDAG+boI/V5G2/6Rdnf19v60Wluo5eZkRibIP9 +zd/ZoAgdAEKaAOUA9R/l5GS/Lfhcw41IimIrkKWTfUVrvkdWIboo8wPzK5GkTF4c+DZ aVtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=c0QxQO69dwzkLPhvseRHCAphU10DpsqqwD+1Q6eCgP4=; b=z651veUpeaoyXzS5L2Hja8OiKTzIXCE/MXpMS6HEaDmiwHeKg2f8iZ8rVpmHK5yb2U dn4cLTgRqTgv/vuA29o6cY4NDg83bEu02kx6QfZey1lsVLAZsG4/a+LyQLah70VWmHjD MQEHtiQdy9GETX+2AahogAdQh6+SZchgR+hKHL/VMaJDKckNQ5jaiBXA0FZN0zS5PiTx +rAcohzKarq7HxkyFT6LrGkutOw9MoKLgxthhj6XMM2dpJmCFEIedBPKOUJzOEF7Dqpp OJMl4HOIlfrUmCMvXwG33mADsE4B7drDRPXEpGZCjcA/YdyPmGkvsZSl3plrlGKlWZDR gt9w== X-Gm-Message-State: AOAM533S2pSN2MbGW0im+oyaQ/ADxRru99J9eDgamOJTerKsdJisjHkq aamx1yYJkGdKs0N+iPdrymmKcn+uxzurwth9 X-Google-Smtp-Source: ABdhPJw+k/f6AoIGweQpCqAKjUZ6x9/ZOE+I/X2ypGyrhEasam117nWh3LXgfUjCSIaM+PGxGVCh7Q== X-Received: by 2002:adf:a489:: with SMTP id g9mr26911185wrb.235.1635792988149; Mon, 01 Nov 2021 11:56:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 04/17] am: convert {pre,post}-applypatch to use hook.h Date: Mon, 1 Nov 2021 19:56:09 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Teach pre-applypatch and post-applypatch to use the hook.h library instead of the run-command.h library. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 8677ea2348a..4b334cb7b12 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1609,7 +1609,7 @@ static void do_commit(const struct am_state *state) const char *reflog_msg, *author, *committer = NULL; struct strbuf sb = STRBUF_INIT; - if (run_hook_le(NULL, "pre-applypatch", NULL)) + if (run_hooks("pre-applypatch")) exit(1); if (write_cache_as_tree(&tree, 0, NULL)) @@ -1661,7 +1661,7 @@ static void do_commit(const struct am_state *state) fclose(fp); } - run_hook_le(NULL, "post-applypatch", NULL); + run_hooks("post-applypatch"); strbuf_release(&sb); } From patchwork Mon Nov 1 18:56:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D32EC433F5 for ; Mon, 1 Nov 2021 18:58:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC4E460EBB for ; Mon, 1 Nov 2021 18:58:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230393AbhKATB1 (ORCPT ); Mon, 1 Nov 2021 15:01:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232486AbhKAS7E (ORCPT ); Mon, 1 Nov 2021 14:59:04 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99A34C061767 for ; Mon, 1 Nov 2021 11:56:30 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id k7so29409047wrd.13 for ; Mon, 01 Nov 2021 11:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GFtcvG8JjBHSuPRk0su8BXG9BUBW5rwJ/V74TzzkztE=; b=R0j6MdweHZqywZ861E6fdVRUzq9waoeTy/TMcJ9jQhm2mBFp4IOekcdnb2bKovqAUX /rNq1RMGLIlAK83lOeDNaDxZiA+mdVbaC2+i8OWdBad7tIPRZi9jsKPr8EHrv+0pDIF+ 9aznCRRV80sut1PWBmOpoSvA69ua55NvOHWHzGzRG5b63JeOUqrzgYjeIBfILn3wau2o 0UH+7JR+heqEkaeT6TK7eCKf8HxDVq3BuO3f8040PNuCr+sVDOfegPQaudwWrKnU2QPe soM588SnY6yeuXYtvz/9gW/5uzafSwMMrHSFwdix+zPIGdfcN3AuXuT763HZVMKtVTK7 ZtVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GFtcvG8JjBHSuPRk0su8BXG9BUBW5rwJ/V74TzzkztE=; b=vlTnnue4qMjt5izi14P/Yzl/VGv0E7z3htJ8B+lkjvQlgyNB0lDrkmMi5j7GbkBfgy 3nYEZhPNUpC7UEjg5Ji0uWEbcQz6XvZgzJ2/mzkD9YrsYfDeXLr2yoaiiFgdqRoR2OVJ OQC78DXjYu8jy7Agcdsenbo6sui3UFzdVGSGXfzKyb6n5ZiPI42gXZJ4dVqZw2/YlOe3 sf4V6m6QOox1539dLmtJA72uooo9pdyRWfsKYzvgRFsgg2FamUFjQQVaBeZXn0rNiKzq pOKfXJo38IhtonRjkpKdnDfnSGkyn5IE5FVrIlDCXOp/1bv498lD2Zxdw0XkDrmdGv1z RsZQ== X-Gm-Message-State: AOAM533gAjTTHluD8QOTl8ShjBrDy84D7ZxOI1OZWpu5XSIXmGpnsl/B kGriPVCFSEdiCZ8q1PLBA2bNFCNxrKzinQr5 X-Google-Smtp-Source: ABdhPJz4UjqrYkt7Ko9G8YMKbUK2zsxbnQNIfaQlGN89ic5OvcspO5LY94NPKc8z8cvIqALWfFRBFA== X-Received: by 2002:a05:6000:552:: with SMTP id b18mr40788346wrf.112.1635792989019; Mon, 01 Nov 2021 11:56:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 05/17] hook API: add a run_hooks_l() wrapper Date: Mon, 1 Nov 2021 19:56:10 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a run_hooks_l() wrapper, we'll use it in subsequent commits for the simple cases of wanting to run a single hook under a given name along with a list of arguments. Signed-off-by: Ævar Arnfjörð Bjarmason --- hook.c | 14 ++++++++++++++ hook.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/hook.c b/hook.c index 720994bf4f6..cf6d099f83a 100644 --- a/hook.c +++ b/hook.c @@ -149,3 +149,17 @@ int run_hooks(const char *hook_name) return run_hooks_opt(hook_name, &opt); } + +int run_hooks_l(const char *hook_name, ...) +{ + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + va_list ap; + const char *arg; + + va_start(ap, hook_name); + while ((arg = va_arg(ap, const char *))) + strvec_push(&opt.args, arg); + va_end(ap); + + return run_hooks_opt(hook_name, &opt); +} diff --git a/hook.h b/hook.h index 9c358789958..54528395953 100644 --- a/hook.h +++ b/hook.h @@ -54,4 +54,14 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options); * run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT". */ int run_hooks(const char *hook_name); + +/** + * Like run_hooks(), a wrapper for run_hooks_opt(). + * + * In addition to the wrapping behavior provided by run_hooks(), this + * wrapper takes a list of strings terminated by a NULL + * argument. These things will be used as positional arguments to the + * hook. This function behaves like the old run_hook_le() API. + */ +int run_hooks_l(const char *hook_name, ...); #endif From patchwork Mon Nov 1 18:56:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F5F1C433F5 for ; Mon, 1 Nov 2021 18:59:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02C5260F42 for ; Mon, 1 Nov 2021 18:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232502AbhKATBp (ORCPT ); Mon, 1 Nov 2021 15:01:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232521AbhKAS7f (ORCPT ); Mon, 1 Nov 2021 14:59:35 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6620CC0613B9 for ; Mon, 1 Nov 2021 11:56:31 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id d13so29490488wrf.11 for ; Mon, 01 Nov 2021 11:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v8b9Uh9oXQiIVYcVI9uVr+pVmRNiNOVyhLZWHNbnygA=; b=dtTMyNRqg9NEvwuLzAIMNR16AkzohIwqt3+AIxLdcLxWQxr9xatuTS0IACoQT55dXz ENgX2CdQ/UFVpJ8Y3sBF0QiCES5L1fXJQSek5rtgk88v9X4LkrYj5hMZ5YcG8OmWZi0x fpwO7X5X9VbYJr8g4CoyaXhJYORe2Mv6joS9ZRXYyhcgAetD3u8Ba9PwnfkhK87iM3xi +2cUiJmKGRLF1GJK/2Cm+Ss85fNazNXNOMtU44gVCl7g1zXX80CEPzu50JGMQWutThb4 lvZ5B7LZnvkFzNDlaoC6jqIU4ogEFCMgWJ9rOmlawINA0dF1c4cWHpKipbFXQ8ll8dd8 UAcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v8b9Uh9oXQiIVYcVI9uVr+pVmRNiNOVyhLZWHNbnygA=; b=UdLLo+h0NY3KfDoqUb0MsVLz6VwRbw1nkzey6iNn7riURG6nX5DbfJKq79YD9ck3Pf hHO6DU2BBPJ3xd+6zR6bhR1B1b1wM6pMszzspy799pkuOpKTX2w/0ILtjI7iX/e9c+LW cXryYlNjnlosPt/Yvd6msiWyYfMX6vTGD+do2dBmrs6/fo67XCbdTtOukBUJqnP2zCaW nHeJpznWhho9LJ+Cny9wWsuYwlzEazjQen5IWd3caR91TtNYRDVDjOwfpqcX7jmlRpgb oCjqqSQijZjpPy0lvFTclSpOih05+C894JtGzcaXOme37899dzsfeK4jk4CEhOrcMjBL 3Dnw== X-Gm-Message-State: AOAM531JiOQBoIPtFcxbp19Yswl1EDgCUzJlEc4fRwXJ8XeYDpHA6VLt KitcuBZhAGy6DHtu6wtUmiapRQwLxiWchsi2 X-Google-Smtp-Source: ABdhPJzxSq56wbaKkopInTfi3oWLsRQJdmDt8526uw7mnYA8Ldcsj++kJyiNnimjlcLB+r8isQTwiA== X-Received: by 2002:adf:ebd0:: with SMTP id v16mr39586474wrn.291.1635792989793; Mon, 01 Nov 2021 11:56:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 06/17] rebase: convert pre-rebase to use hook.h Date: Mon, 1 Nov 2021 19:56:11 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the pre-rebase hook away from run-command.h to and over to the new hook.h library. Since this hook needs arguments introduce a run_hooksl() wrapper, like run_hooks(), but it takes varargs. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rebase.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 34b4744e5f3..ac4120013a0 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -28,6 +28,7 @@ #include "sequencer.h" #include "rebase-interactive.h" #include "reset.h" +#include "hook.h" #define DEFAULT_REFLOG_ACTION "rebase" @@ -1712,7 +1713,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) /* If a hook exists, give it a chance to interrupt*/ if (!ok_to_skip_pre_rebase && - run_hook_le(NULL, "pre-rebase", options.upstream_arg, + run_hooks_l("pre-rebase", options.upstream_arg, argc ? argv[0] : NULL, NULL)) die(_("The pre-rebase hook refused to rebase.")); From patchwork Mon Nov 1 18:56:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42D57C433F5 for ; Mon, 1 Nov 2021 18:59:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F13060F24 for ; Mon, 1 Nov 2021 18:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232476AbhKATBd (ORCPT ); Mon, 1 Nov 2021 15:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232524AbhKAS7f (ORCPT ); Mon, 1 Nov 2021 14:59:35 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27599C061205 for ; Mon, 1 Nov 2021 11:56:32 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id a20-20020a1c7f14000000b003231d13ee3cso126518wmd.3 for ; Mon, 01 Nov 2021 11:56:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BX2Vbp10V3biCAGbAR+8Jw3LCRTeAAOD9LP8H3MoIpI=; b=M5gZOxm3+Dltu+itMR7WR9LKVPQEMUDW1jeKSLWo8g0MkedI/9faKau1p5NLW8P8tb /IolUCt5sFoLf6DTcngtf2uGeGahfhYsd0f+C6ISlw55RoH1rU+49xGAAVKHKtovIck8 mHt5zWmWdj/N4QTO+B37GxK8Sr/cKHLANy7v0hOboXxWI6xNVyAXZSEr+VmApTX8Iuxk 2kOhGtFzqjTDWXNBI/3+8XXcmiyYgA4uE1RltCU4Okx8UVDaRT2BB3caRdM5gz5T5JXT WDi5UBIEBIkpRUDj+FCNupWpYHbZXXWy+y3DpM64hwJYk/qYGTrAzqWyPl5yLXCOTfqW 8e7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BX2Vbp10V3biCAGbAR+8Jw3LCRTeAAOD9LP8H3MoIpI=; b=ZtC/CTSP7lj3C6JUHVOQwK0/e2lt7Pfx/B2cBIDKzAbWR9xq9QLDja3xDlYl8FkDCt XxIkXJ07PhVTdyjBl3MdMJfsz0tj6Qng0DDaD1tBJVhMAuekL04DZ+/N4UKpJc9MEggQ OBc37qTul6dADUVrIxfdDkAw1EVE0+oWrFDCIsmkebfqgyiL0oLK3ZBJMg0YKwvPKHQU 4NHF0djoVmh3sUc0QehTEaMS2tcA6sbYrGXdvC/aeOI5aet7afOdWn4cZY8HtuK7EZlD iqNkAgd8XRvVk8un6RMmtwN4KzNQiWwXeOAW0C4OGpp3E919NvsWiC7FCK1rHRxQvBtY 5vUA== X-Gm-Message-State: AOAM531q7//r2i0IlwP3OpVW0c9Maksyc/xolNvhVJfvGbDLDD/3ntHC qM71aZgtupl+i91Nq+jAN6B7YMsigAhyWdK7 X-Google-Smtp-Source: ABdhPJzm+dNAVxlhsWBogCtBQwRiDJNeArXzl58QFxUA+doWTn7NEV63WXKbxOFYAF0NKXVwTRGw0w== X-Received: by 2002:a7b:cbc2:: with SMTP id n2mr823494wmi.123.1635792990462; Mon, 01 Nov 2021 11:56:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 07/17] am: convert applypatch-msg to use hook.h Date: Mon, 1 Nov 2021 19:56:12 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Teach applypatch-msg to use the hook.h library instead of the run-command.h library. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/am.c b/builtin/am.c index 4b334cb7b12..ae0c484dcba 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -448,7 +448,7 @@ static int run_applypatch_msg_hook(struct am_state *state) int ret; assert(state->msg); - ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL); + ret = run_hooks_l("applypatch-msg", am_path(state, "final-commit"), NULL); if (!ret) { FREE_AND_NULL(state->msg); From patchwork Mon Nov 1 18:56:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30244C433EF for ; Mon, 1 Nov 2021 18:59:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12AC460F24 for ; Mon, 1 Nov 2021 18:59:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231910AbhKATBx (ORCPT ); Mon, 1 Nov 2021 15:01:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232454AbhKAS7f (ORCPT ); Mon, 1 Nov 2021 14:59:35 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDAF6C06120B for ; Mon, 1 Nov 2021 11:56:32 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id y84-20020a1c7d57000000b00330cb84834fso143589wmc.2 for ; Mon, 01 Nov 2021 11:56:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WhYCuOzxe+sxxCv5UAv2vnffVkwFvvfgsstQUsGX5xM=; b=TjfQPrXdnw8ZcnVeJLFt/L0JQY5+/kUVF3fWgncQIpwvLQjNk9yWDVieT8Pf6m8FDa 7U08d+iGQoQBZFp9PGYAjhVW4MNN70zU/ah3/UjRjHOAKMYNk7rXr/dE1Ul5CtTRiYD3 ltfCBFc1wbtTsw6SkAZsmrFULluTnTZa/4sW0yywSbR+EiwIaiZS9S5FTQIhEXrkYQJO UvvIbm5BQB2os38zhVzDnAHPAFnYQKejq2u9ymz7ZfEPazdBVwaC6DmfEa4cHtRn6ulT JoWZQMYNM89DNAudsCms1Blu3ydvoqdOSrid4/FdrAl0JxnWaPdcn1IH9wpOCsE/xaxN utHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WhYCuOzxe+sxxCv5UAv2vnffVkwFvvfgsstQUsGX5xM=; b=CtF9QwXDIZtDh6SvY+6KPoKM3kGxzdw7eQSAV/MhV1/PlrY5Zrnccs8dbD5iMZHHAX fwEy0tDStSXB4PUsBMEmS9M6LrzhOhNIgxzLFmtg/scmfmzsSKj1QfQEAJZBVVK0Z6zp H7qenq12I7XgOcmkeK+da3U3QZ4ZQh+W010KNwe5V4XhReYTh8uJDgme7ns64O5yv0UP 7TDBfNDEBjvazWLL02jZ696DIxfYUP8hdrAlaWoqynqgFmtYSVnrgd5nwnUQu1JpsK42 m45E7duc9lozadXCGG8lUgSECTsDwX5KigSaO5Xj1c3pXa7gkQgZ6R4f7cy38St12kNr 1eOA== X-Gm-Message-State: AOAM530teQP7/yPRaGiGYo97VVeW3gop13ty6r8vt3myNq53I219BofV cZiqFol9iwZOtHlOpKwU54DFjYL8ilvrmCqt X-Google-Smtp-Source: ABdhPJx3U5ucV+1UQTuX7CusYaxmtQKpTyFyS7Rx6nBY+YooXQ/7hUaeTUzkkE7W2KdDeZeKRogcNQ== X-Received: by 2002:a1c:7515:: with SMTP id o21mr853305wmc.99.1635792991239; Mon, 01 Nov 2021 11:56:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 08/17] merge: convert post-merge to use hook.h Date: Mon, 1 Nov 2021 19:56:13 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Teach post-merge to use the hook.h library instead of the run-command.h library to run hooks. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/merge.c b/builtin/merge.c index ea3112e0c0b..e6facd1c95d 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -488,7 +488,7 @@ static void finish(struct commit *head_commit, } /* Run a post-merge hook */ - run_hook_le(NULL, "post-merge", squash ? "1" : "0", NULL); + run_hooks_l("post-merge", squash ? "1" : "0", NULL); apply_autostash(git_path_merge_autostash(the_repository)); strbuf_release(&reflog_message); From patchwork Mon Nov 1 18:56:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8A01C433FE for ; Mon, 1 Nov 2021 18:58:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8EF9760EBB for ; Mon, 1 Nov 2021 18:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232584AbhKATAx (ORCPT ); Mon, 1 Nov 2021 15:00:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbhKATAZ (ORCPT ); Mon, 1 Nov 2021 15:00:25 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B140C06120F for ; Mon, 1 Nov 2021 11:56:34 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id c71-20020a1c9a4a000000b0032cdcc8cbafso574817wme.3 for ; Mon, 01 Nov 2021 11:56:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Any6a1LK2HXrYbq9lMDq2rjvMK57JW2CkVVXaPnmLbQ=; b=G9DQBtjfcWCYEuQ9BV+1DYHvmuiVQXHjc31Xk5bgCA0CLXNdHlf1t+OrhZlhMUcB1m jOaZQ9+b4jviBpzKKwi/6eG0rwwDCeOurufbhnV+9CKWjtmJ5mR2ncEJRxOOnkD6Ixqb h20ITi5rcmNoKcdXPl7bv7CgWRnx4rTJ2XJ5p9H4r7wMZXssztJUuTA0ba/iDbxMzYjp saobzJw1DwHTz1L41Rh40WXYrHqKQknmJbWJX7I/Q3dBFFoyA3TNfHAqLR9n/4/Mov3Z nrO8o9JOczsckgJT2noDkIqTiDpcUKtax5SJn8peixiQzSiIqObAzmdcBWKNn2QEMFb9 AOZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Any6a1LK2HXrYbq9lMDq2rjvMK57JW2CkVVXaPnmLbQ=; b=EaRXOUJn6sULVo5FUrJ7Y90FPOqPUk1RMyW1yJB6XaLwY8f9J3eyNH2JDn390kCSEn 6Pwy738vNv58fPiF2eBvGec09mnsA5LUH+5LRZQVeKrK0L2w4NkqFcBGpzu76T0GuoEh cXyMmnL+8gmnmjdOYxflPao0FJhwvdlgZsecX2rhDLn6uksKSjNiGYZKLcOryvDaiKTn mTBips0N0XoAYBvilKU3pRvSwdne70fCwI7hdhUn7iz3CSh8tDGbWR9xPQdML6UjYNLB abfnsDhjJr9vPC3FbD3Cxnp/U/bsjkg0y65WFaC9zLdkiuU6KI8wTMrQZ8NR5o82uvvG U/SQ== X-Gm-Message-State: AOAM532RZepSfPFdKnAZh0NAVAIZsZuDFtIcgv/VZXTqZDnEnuBy25qM 86mf9m5NuFsNtoXvz5Mv6upAcSrtWPY68uNv X-Google-Smtp-Source: ABdhPJwau50yxCnRnZG1NW2NOfoMMDlIVQvXwuPhgnAIyqy3BqUEoxE4WYXuayA/YaQFYclBW+2/iA== X-Received: by 2002:a7b:c007:: with SMTP id c7mr838803wmb.101.1635792991969; Mon, 01 Nov 2021 11:56:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:31 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 09/17] hooks: convert non-worktree 'post-checkout' hook to hook library Date: Mon, 1 Nov 2021 19:56:14 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the running of the 'post-checkout' hook away from run-command.h to the new hook.h library, except in the case of builtin/worktree.c. That special-case will be handled in a subsequent commit. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/checkout.c | 3 ++- builtin/clone.c | 3 ++- reset.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index cbf73b8c9f6..4af17d17217 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -9,6 +9,7 @@ #include "config.h" #include "diff.h" #include "dir.h" +#include "hook.h" #include "ll-merge.h" #include "lockfile.h" #include "merge-recursive.h" @@ -106,7 +107,7 @@ struct branch_info { static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit, int changed) { - return run_hook_le(NULL, "post-checkout", + return run_hooks_l("post-checkout", oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()), oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()), changed ? "1" : "0", NULL); diff --git a/builtin/clone.c b/builtin/clone.c index fb377b27657..ee27b9f8114 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -32,6 +32,7 @@ #include "connected.h" #include "packfile.h" #include "list-objects-filter-options.h" +#include "hook.h" /* * Overall FIXMEs: @@ -705,7 +706,7 @@ static int checkout(int submodule_progress) if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) die(_("unable to write new index file")); - err |= run_hook_le(NULL, "post-checkout", oid_to_hex(null_oid()), + err |= run_hooks_l("post-checkout", oid_to_hex(null_oid()), oid_to_hex(&oid), "1", NULL); if (!err && (option_recurse_submodules.nr > 0)) { diff --git a/reset.c b/reset.c index f214df3d96c..0881e636915 100644 --- a/reset.c +++ b/reset.c @@ -7,6 +7,7 @@ #include "tree-walk.h" #include "tree.h" #include "unpack-trees.h" +#include "hook.h" int reset_head(struct repository *r, struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -127,7 +128,7 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action, reflog_head); } if (run_hook) - run_hook_le(NULL, "post-checkout", + run_hooks_l("post-checkout", oid_to_hex(orig ? orig : null_oid()), oid_to_hex(oid), "1", NULL); From patchwork Mon Nov 1 18:56:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E932BC433F5 for ; Mon, 1 Nov 2021 18:59:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA16D60F24 for ; Mon, 1 Nov 2021 18:59:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230492AbhKATBr (ORCPT ); Mon, 1 Nov 2021 15:01:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232525AbhKATAk (ORCPT ); Mon, 1 Nov 2021 15:00:40 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68C63C061220 for ; Mon, 1 Nov 2021 11:56:34 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id y84-20020a1c7d57000000b00330cb84834fso143639wmc.2 for ; Mon, 01 Nov 2021 11:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NN0ZqfTQ5G7hfuaGyLYkRNvqVPSOuvNDbesgnKwcfqg=; b=CYGBPwSCnqFD52MZFY4zk+EfMmrdPWPo2PMzA1L6M/xzFv/9t7DgyGkMbOz10luHH2 C5vMhFfG4YnImJmMCifEYPUCrQp4r4JYcv8of25LbviGYjshPZd4UU10s3eOMp0I0lW2 W9YeFIjmPMm2H7Qb8lVaSAUfgqFt82mNTu7FyzDtezDm1GHRxb1IXFwGTgYla/uNNw9R o1PfmLK7HRIxWKxz67p7/lL2PV6Yq/XpC4Jknab3un1zv1SkBbRAuARZ3Wquk83fCS19 NlSHIEFFaTxc03bGc5rOZ5O9JIetApwAw+1g68ZSfI47eaOCntDrXxlE8iKUxFJZa387 ePBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NN0ZqfTQ5G7hfuaGyLYkRNvqVPSOuvNDbesgnKwcfqg=; b=Fn9IKzyQH2wICY1fFnK2eg7Mr0fkIDxVveXIwPZ197QCJNzi0puER41BpZddgox5pF JLwB/QWUtZsLzLs9BlfVN3UZ7vVibpE7g1dL9URI5ssLhHVQmRvGhic/PrjjlaHisxY+ FhT78oPnyCUmN9ePNWaovKY7G0GPuGRkdemjY5gHt+NERVLBLfKMIxFOUF6OiYlrRb/H NU8cOR/DM7VvrVwttCGdQe57hSluQ+Ng06BUJ8ZHz109rowjGGcNvd94npWUwMRqMfn/ FXe71HG8I959a0U+/loFBhFI6dhqJcGq9iSSkXEy0b01sURjcGh27QKPmHZlqU+TwbKM Mu9A== X-Gm-Message-State: AOAM5323/4E0VLe0diGUhguhFIFNMshJfJfuMUhmnt6A0rp66r536Aee wXbdNVhYgbtis4SpMbNTAQ1zMbMZIy0uCbmr X-Google-Smtp-Source: ABdhPJy0mk4EN4YPi7zHhLrzx61Tr4N7x/Wo1oGF5nPIuGgtgS0sn0QoIF3cqDVwW6QSBCha5hTrXA== X-Received: by 2002:a05:600c:3508:: with SMTP id h8mr880377wmq.122.1635792992707; Mon, 01 Nov 2021 11:56:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:32 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 10/17] hooks: convert worktree 'post-checkout' hook to hook library Date: Mon, 1 Nov 2021 19:56:15 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the running of the 'post-checkout' hook away from run-command.h to the new hook.h library in builtin/worktree.c. For this special case we need a change to the hook API to teach it to run the hook from a given directory. We cannot skip the "absolute_path" flag and just check if "dir" is specified as we'd then fail to find our hook in the new dir we'd chdir() to. We currently don't have a use-case for running a hook not in our "base" repository at a given absolute path, so let's have "dir" imply absolute_path(find_hook(hook_name)). Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/worktree.c | 27 +++++++++++---------------- hook.c | 8 ++++++++ hook.h | 6 ++++++ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/builtin/worktree.c b/builtin/worktree.c index d22ece93e1a..4d9df5ecc4c 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -382,22 +382,17 @@ static int add_worktree(const char *path, const char *refname, * is_junk is cleared, but do return appropriate code when hook fails. */ if (!ret && opts->checkout) { - const char *hook = find_hook("post-checkout"); - if (hook) { - const char *env[] = { "GIT_DIR", "GIT_WORK_TREE", NULL }; - cp.git_cmd = 0; - cp.no_stdin = 1; - cp.stdout_to_stderr = 1; - cp.dir = path; - cp.env = env; - cp.argv = NULL; - cp.trace2_hook_name = "post-checkout"; - strvec_pushl(&cp.args, absolute_path(hook), - oid_to_hex(null_oid()), - oid_to_hex(&commit->object.oid), - "1", NULL); - ret = run_command(&cp); - } + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + + strvec_pushl(&opt.env, "GIT_DIR", "GIT_WORK_TREE", NULL); + strvec_pushl(&opt.args, + oid_to_hex(null_oid()), + oid_to_hex(&commit->object.oid), + "1", + NULL); + opt.dir = path; + + ret = run_hooks_opt("post-checkout", &opt); } strvec_clear(&child_env); diff --git a/hook.c b/hook.c index cf6d099f83a..95f5b926354 100644 --- a/hook.c +++ b/hook.c @@ -57,6 +57,7 @@ static int pick_next_hook(struct child_process *cp, cp->env = hook_cb->options->env.v; cp->stdout_to_stderr = 1; cp->trace2_hook_name = hook_cb->hook_name; + cp->dir = hook_cb->options->dir; strvec_push(&cp->args, hook_path); strvec_pushv(&cp->args, hook_cb->options->args.v); @@ -109,6 +110,7 @@ static void run_hooks_opt_clear(struct run_hooks_opt *options) int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) { + struct strbuf abs_path = STRBUF_INIT; struct hook_cb_data cb_data = { .rc = 0, .hook_name = hook_name, @@ -130,6 +132,11 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) } cb_data.hook_path = hook_path; + if (options->dir) { + strbuf_add_absolute_path(&abs_path, hook_path); + cb_data.hook_path = abs_path.buf; + } + run_processes_parallel_tr2(jobs, pick_next_hook, notify_start_failure, @@ -139,6 +146,7 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) hook_name); ret = cb_data.rc; cleanup: + strbuf_release(&abs_path); run_hooks_opt_clear(options); return ret; } diff --git a/hook.h b/hook.h index 54528395953..18d90aedf14 100644 --- a/hook.h +++ b/hook.h @@ -12,6 +12,12 @@ struct run_hooks_opt /* Emit an error if the hook is missing */ unsigned int error_if_missing:1; + + /** + * An optional initial working directory for the hook, + * translates to "struct child_process"'s "dir" member. + */ + const char *dir; }; #define RUN_HOOKS_OPT_INIT { \ From patchwork Mon Nov 1 18:56:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CF7EC433F5 for ; Mon, 1 Nov 2021 18:59:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75D6E60EBB for ; Mon, 1 Nov 2021 18:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232583AbhKATCX (ORCPT ); Mon, 1 Nov 2021 15:02:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232527AbhKATAk (ORCPT ); Mon, 1 Nov 2021 15:00:40 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D2B7C061226 for ; Mon, 1 Nov 2021 11:56:35 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id c71-20020a1c9a4a000000b0032cdcc8cbafso574855wme.3 for ; Mon, 01 Nov 2021 11:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7p4btdGrtgBfGICmR2K2dIF+jcerZ3WaHrsukzFQpEM=; b=IqSaG9j3dbRjf5wjcNVgf0HC2luD/U7UImEhjuwmDLRsYD98yRLkmFfHo2tKyexfx6 SzH+8DB6hhADo3R95IH5sWV/XXiap59FzCCiq1InWEhO951psmt3JHfEyKrfi9t2If1B Sd1xzxwIejQLhR76ol1TUJ4Kqw+nCHBq4JDKLEXFxT9Mr2AivPCAvb5+k9UW/lLdg3i3 HJwTtWtjicKgVrwobwtzAHbpRMfWq3iLBL5WhBiCZ+TLRxuEBbFW0Gv24RBaNxxNWWVt vbuKvgWZWXB6y6MiO6jAvw8kLYVBOueCF3ZMF7CLt6ID/dUv6Pxb9HmfCJ9RBa8/2iNe G8mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7p4btdGrtgBfGICmR2K2dIF+jcerZ3WaHrsukzFQpEM=; b=27t1yvYhhY2r5kRplm/H6Tazan+Fu3w7CRD0kfNSeCWMXDcJabxWr6/jEVY9y1DbAN 6/vkBwU8Z/UIWvGD4Hdet9RCq+If2QxxjSmydJCL1W+Gyc9AfbL8+xSvZZMM536/a1df pY+iVhetfAim7PmWmI5YN5G1n63i8CC5EoU7sVWVQYynBi8lSpO+Uie242Oo59JUDsee pW2pF05fPbn2AbdyxBSr0Wi+ZLt1RS/JJYtxW5ctoYGPf9/uzmSzC2sUDqp1QuIHg0yj 4aQnW5KBLKvS6wTtvwKt28G4yWJHsYGvtNEt3cO7OjZWW2eRw0KMXlUDPOKKIcg2OAKv y7pA== X-Gm-Message-State: AOAM530f2jayjYZA0xPZ3zCwlOZkjCO5VtJWJ0rWdFdPV+i19eR2Bmbn na5+QX0j1r+oL1vnjkMlIOuGJF2EYe+e3oMo X-Google-Smtp-Source: ABdhPJwsJzdSsxSUfve3cFxNMgjTeQpomVnSBt+vWxMSc1Piodqj4OscY8Ze3JsPicAtiNCrVAgnyA== X-Received: by 2002:a1c:751a:: with SMTP id o26mr876829wmc.94.1635792993651; Mon, 01 Nov 2021 11:56:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:33 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 11/17] git hook run: add an --ignore-missing flag Date: Mon, 1 Nov 2021 19:56:16 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org For certain one-shot hooks we'd like to optimistically run them, and not complain if they don't exist. This was already supported by the underlying hook.c library, but had not been exposed via "git hook run". The command version of this will be used by send-email in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-hook.txt | 10 +++++++++- builtin/hook.c | 8 ++++++-- t/t1800-hook.sh | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Documentation/git-hook.txt b/Documentation/git-hook.txt index e39b1b5d069..77c3a8ad909 100644 --- a/Documentation/git-hook.txt +++ b/Documentation/git-hook.txt @@ -8,7 +8,7 @@ git-hook - Run git hooks SYNOPSIS -------- [verse] -'git hook' run [-- ] +'git hook' run [--ignore-missing] [-- ] DESCRIPTION ----------- @@ -28,6 +28,14 @@ Any positional arguments to the hook should be passed after a mandatory `--` (or `--end-of-options`, see linkgit:gitcli[7]). See linkgit:githooks[5] for arguments hooks might expect (if any). +OPTIONS +------- + +--ignore-missing:: + Ignore any missing hook by quietly returning zero. Used for + tools that want to do a blind one-shot run of a hook that may + or may not be present. + SEE ALSO -------- linkgit:githooks[5] diff --git a/builtin/hook.c b/builtin/hook.c index 9b67ff50cef..54e5c6ec933 100644 --- a/builtin/hook.c +++ b/builtin/hook.c @@ -7,7 +7,7 @@ #include "strvec.h" #define BUILTIN_HOOK_RUN_USAGE \ - N_("git hook run [-- ]") + N_("git hook run [--ignore-missing] [-- ]") static const char * const builtin_hook_usage[] = { BUILTIN_HOOK_RUN_USAGE, @@ -23,8 +23,11 @@ static int run(int argc, const char **argv, const char *prefix) { int i; struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + int ignore_missing = 0; const char *hook_name; struct option run_options[] = { + OPT_BOOL(0, "ignore-missing", &ignore_missing, + N_("silently ignore missing requested ")), OPT_END(), }; int ret; @@ -52,7 +55,8 @@ static int run(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); hook_name = argv[0]; - opt.error_if_missing = 1; + if (!ignore_missing) + opt.error_if_missing = 1; ret = run_hooks_opt(hook_name, &opt); if (ret < 0) /* error() return */ ret = 1; diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 3aea1b105f0..29718aa9913 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -21,6 +21,11 @@ test_expect_success 'git hook run: nonexistent hook' ' test_cmp stderr.expect stderr.actual ' +test_expect_success 'git hook run: nonexistent hook with --ignore-missing' ' + git hook run --ignore-missing does-not-exist 2>stderr.actual && + test_must_be_empty stderr.actual +' + test_expect_success 'git hook run: basic' ' write_script .git/hooks/test-hook <<-EOF && echo Test hook From patchwork Mon Nov 1 18:56:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 223EFC433EF for ; Mon, 1 Nov 2021 18:59:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0323060EE9 for ; Mon, 1 Nov 2021 18:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232486AbhKATCT (ORCPT ); Mon, 1 Nov 2021 15:02:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232556AbhKATAl (ORCPT ); Mon, 1 Nov 2021 15:00:41 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D415C061229 for ; Mon, 1 Nov 2021 11:56:36 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id r9-20020a7bc089000000b00332f4abf43fso480695wmh.0 for ; Mon, 01 Nov 2021 11:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JfY+bFqCONWSOECkngNmAvGoK4qO2SA8wAsKCpzqfDE=; b=RGxGbUZqhbHtHXWEXt7LBLFc604irGwgt7xyZZSSFoZ/0da0vOOBR7FeJRr6pS3Bn8 jq4Z4Nduar/1kekKmFr34ytxUQHxJU2/IsWPAKV0wmmsxEnw1GqonWZUO9hmMwjcIdTV 2YkWE/p/eR3vgRBDY7xE3K2E1JxmgkZYde45iDV2Iqr3vEe61EsCrqws43Xwa1JzL09Q +UWVmrpgMQKDMMgnN9E8360v11Z6Xt+zpXsWlgFxdKndhUv6U+RJGazFmmrO9uCO5zhA IolIGkYXveuyGy6sxRwMM14ZVwi+xxPB7zGjANT9m+7DgpNonWZbkYRRIFi4la5TQslO y04g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JfY+bFqCONWSOECkngNmAvGoK4qO2SA8wAsKCpzqfDE=; b=bdYMZS+PYAZbqf5bF9Lpq07Zw844Jd7dwTYt5ZTATniD4lQ2BWgvEGNYVPRJIQKjaW uFjJ9zlkZjXQwuKIvsvobo7jdtOvmazdpuAZKtdaJlTXIdVDz3jVCvXmoCQL4O0g00G8 IUttxW/qmBqRXpXn1gqOV0FIYKYdkMkVwiZz2IQOoALJ7rCHhqnZpWLefQwLf8gauuQb Lm5XEkl/C1H2Tgv3UXFJ0u+i1nOzWu782aPtQDPgAbQBZgxY2jpCkZK3lYqo2f/XKQ7g NfATcyz2N2qZG1KiJTxXSZN9iIBmvchCTOIwAEdXu0NfSKUGfsamaO6I8HwRexQksgMj qxvQ== X-Gm-Message-State: AOAM533JRfH10B7SPEpfVrGupcdzct6r0XlnczIqlfUnOhS5i/Zk7baq ccc47oJCRMR/yuMyqmGITSvtEnML0PgKBNRZ X-Google-Smtp-Source: ABdhPJysWDo8tsyMBCIilj3nmQ3JlAlrVqWqOYZYg8r7oqTRnPkjVJt7C+tKIBBMiGnu3RG2qvXmsQ== X-Received: by 2002:a7b:cb82:: with SMTP id m2mr830223wmi.11.1635792994401; Mon, 01 Nov 2021 11:56:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:33 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 12/17] send-email: use 'git hook run' for 'sendemail-validate' Date: Mon, 1 Nov 2021 19:56:17 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Change the "sendmail-validate" hook to be run via the "git hook run" wrapper instead of via a direct invocation. This is the smallest possibly change to get "send-email" using "git hook run". We still check the hook itself with "-x", and set a "GIT_DIR" variable, both of which are asserted by our tests. We'll need to get rid of this special behavior if we start running N hooks, but for now let's be as close to bug-for-bug compatible as possible. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 22 ++++++++++++++-------- t/t9001-send-email.sh | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 5262d88ee32..4c20c0bbb79 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -195,13 +195,13 @@ sub format_2822_time { my $editor; sub system_or_msg { - my ($args, $msg) = @_; + my ($args, $msg, $cmd_name) = @_; system(@$args); my $signalled = $? & 127; my $exit_code = $? >> 8; return unless $signalled or $exit_code; - my @sprintf_args = ($args->[0], $exit_code); + my @sprintf_args = ($cmd_name ? $cmd_name : $args->[0], $exit_code); if (defined $msg) { # Quiet the 'redundant' warning category, except we # need to support down to Perl 5.8, so we can't do a @@ -2039,10 +2039,10 @@ sub validate_patch { my ($fn, $xfer_encoding) = @_; if ($repo) { + my $hook_name = 'sendemail-validate'; my $hooks_path = $repo->command_oneline('rev-parse', '--git-path', 'hooks'); require File::Spec; - my $validate_hook = File::Spec->catfile($hooks_path, - 'sendemail-validate'); + my $validate_hook = File::Spec->catfile($hooks_path, $hook_name); my $hook_error; if (-x $validate_hook) { require Cwd; @@ -2052,13 +2052,19 @@ sub validate_patch { chdir($repo->wc_path() or $repo->repo_path()) or die("chdir: $!"); local $ENV{"GIT_DIR"} = $repo->repo_path(); - $hook_error = system_or_msg([$validate_hook, $target]); + my @cmd = ("git", "hook", "run", "--ignore-missing", + $hook_name, "--"); + my @cmd_msg = (@cmd, ""); + my @cmd_run = (@cmd, $target); + $hook_error = system_or_msg(\@cmd_run, undef, "@cmd_msg"); chdir($cwd_save) or die("chdir: $!"); } if ($hook_error) { - die sprintf(__("fatal: %s: rejected by sendemail-validate hook\n" . - "%s\n" . - "warning: no patches were sent\n"), $fn, $hook_error); + $hook_error = sprintf(__("fatal: %s: rejected by %s hook\n" . + $hook_error . "\n" . + "warning: no patches were sent\n"), + $fn, $hook_name); + die $hook_error; } } diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index aa0c20499ba..84d0f40d76a 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -539,7 +539,7 @@ test_expect_success $PREREQ "--validate respects relative core.hooksPath path" ' test_path_is_file my-hooks.ran && cat >expect <<-EOF && fatal: longline.patch: rejected by sendemail-validate hook - fatal: command '"'"'my-hooks/sendemail-validate'"'"' died with exit code 1 + fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- '"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual @@ -558,7 +558,7 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" ' test_path_is_file my-hooks.ran && cat >expect <<-EOF && fatal: longline.patch: rejected by sendemail-validate hook - fatal: command '"'"'$hooks_path/sendemail-validate'"'"' died with exit code 1 + fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- '"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual From patchwork Mon Nov 1 18:56:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BDE4C433FE for ; Mon, 1 Nov 2021 18:59:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4424760EE9 for ; Mon, 1 Nov 2021 18:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232509AbhKATCK (ORCPT ); Mon, 1 Nov 2021 15:02:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232563AbhKATAl (ORCPT ); Mon, 1 Nov 2021 15:00:41 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46484C06122C for ; Mon, 1 Nov 2021 11:56:37 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id a20-20020a1c7f14000000b003231d13ee3cso126675wmd.3 for ; Mon, 01 Nov 2021 11:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OrcMSbNZOdGM8XjKFkufhxbElu+IgzWMf07xkaqMzsQ=; b=A/tYSacEJxnaK22Zh33kgso8rMX5KP5poT/8xZ4Sik0c6OJyw7+QlAensU6X7h1yza 5ObHzw5LWo2O2fwUbu+rTp/9YiW+d5h3Qok4nn2F8fwWdIU3zx6oRH0m1EGpGmVoNc1V 7qDcZXzEgyuZVV1Kdl6Xxq+tRzJ2wYXhu7NY9qt1qsmh+WKxdKgaECo7HvaMv52e33fZ e4CSCahpBM+eJbofya5Em9zGrayTixvK/SypPG8cuFI/mJ49pwQGVTDvkFz9nsk38zwh IXSoOKdYgYdyKStlUdxgnPDcBPfFX4uJgsCzvYURJfCvDUqdrYWLEJ4jVclAzaaQ0rFT 4pXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OrcMSbNZOdGM8XjKFkufhxbElu+IgzWMf07xkaqMzsQ=; b=twF/nkI3u/c5cAyVdVAl6AOCjC+YIEcoFgYTy74hPHwfUZYH1liefXRpWFuqu+iCqX VTKeErd8J/lK8NyknPhCOwV8OqeoSJhnzFCjxVKHPGYt6LRkPhZn6z3PenwwwYVe6WZP Bsl8ls3IMnYs95bnF5lXE/IJsfgKPJGwuXUgWhIi0vODVHFs7qIUDXBat5IkMD7Ztg8x o3bPM/+hOHFYJq9GqY/wtk7mGhmebeWq/OWE217R+6wY3duKFAd1PLq8WEGbkEG0BxSh Fkx9O+8QpDXxKK+GedSY3K2S5gthObAFGS96jWUnxvw2BsRysF+QKGCsN6RcKxBb6vgq 3Jww== X-Gm-Message-State: AOAM530DJ/Os3YuZP21NCpM1vvHK1YvReNDeXYRr8M4iN2Zjyxv9g90T /FGfthRIIQ+wcMfu6acKvfP2T9KZKRNvivj2 X-Google-Smtp-Source: ABdhPJw5NZGa7QFfpUpb9MXCvOpp4i6KjZ0RxiXD+JYbjDBllfafPnQrJWEzNTu/LR5y23k70B7cbQ== X-Received: by 2002:a05:600c:511c:: with SMTP id o28mr892993wms.96.1635792995300; Mon, 01 Nov 2021 11:56:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:34 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 13/17] git-p4: use 'git hook' to run hooks Date: Mon, 1 Nov 2021 19:56:18 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Instead of duplicating the behavior of run-command.h:run_hook_le() in Python, we can directly call 'git hook run'. We emulate the existence check with the --ignore-missing flag. We're dropping the "verbose" handling added in 9f59ca4d6af (git-p4: create new function run_git_hook, 2020-02-11), those who want diagnostic output about how hooks are run are now able to get that via e.g. the trace2 facility and GIT_TRACE=1. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- git-p4.py | 70 +++++-------------------------------------------------- 1 file changed, 6 insertions(+), 64 deletions(-) diff --git a/git-p4.py b/git-p4.py index 2b4500226aa..3b54168eb4a 100755 --- a/git-p4.py +++ b/git-p4.py @@ -208,70 +208,12 @@ def decode_path(path): def run_git_hook(cmd, param=[]): """Execute a hook if the hook exists.""" - if verbose: - sys.stderr.write("Looking for hook: %s\n" % cmd) - sys.stderr.flush() - - hooks_path = gitConfig("core.hooksPath") - if len(hooks_path) <= 0: - hooks_path = os.path.join(os.environ["GIT_DIR"], "hooks") - - if not isinstance(param, list): - param=[param] - - # resolve hook file name, OS depdenent - hook_file = os.path.join(hooks_path, cmd) - if platform.system() == 'Windows': - if not os.path.isfile(hook_file): - # look for the file with an extension - files = glob.glob(hook_file + ".*") - if not files: - return True - files.sort() - hook_file = files.pop() - while hook_file.upper().endswith(".SAMPLE"): - # The file is a sample hook. We don't want it - if len(files) > 0: - hook_file = files.pop() - else: - return True - - if not os.path.isfile(hook_file) or not os.access(hook_file, os.X_OK): - return True - - return run_hook_command(hook_file, param) == 0 - -def run_hook_command(cmd, param): - """Executes a git hook command - cmd = the command line file to be executed. This can be - a file that is run by OS association. - - param = a list of parameters to pass to the cmd command - - On windows, the extension is checked to see if it should - be run with the Git for Windows Bash shell. If there - is no file extension, the file is deemed a bash shell - and will be handed off to sh.exe. Otherwise, Windows - will be called with the shell to handle the file assocation. - - For non Windows operating systems, the file is called - as an executable. - """ - cli = [cmd] + param - use_shell = False - if platform.system() == 'Windows': - (root,ext) = os.path.splitext(cmd) - if ext == "": - exe_path = os.environ.get("EXEPATH") - if exe_path is None: - exe_path = "" - else: - exe_path = os.path.join(exe_path, "bin") - cli = [os.path.join(exe_path, "SH.EXE")] + cli - else: - use_shell = True - return subprocess.call(cli, shell=use_shell) - + args = ['git', 'hook', 'run', '--ignore-missing', cmd] + if param: + args.append("--") + for p in param: + args.append(p) + return subprocess.call(args) == 0 def write_pipe(c, stdin): if verbose: From patchwork Mon Nov 1 18:56:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39EDEC433F5 for ; Mon, 1 Nov 2021 18:59:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1722560EBB for ; Mon, 1 Nov 2021 18:59:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232237AbhKATB5 (ORCPT ); Mon, 1 Nov 2021 15:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232568AbhKATAl (ORCPT ); Mon, 1 Nov 2021 15:00:41 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5119AC06122E for ; Mon, 1 Nov 2021 11:56:38 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id r8so16665802wra.7 for ; Mon, 01 Nov 2021 11:56:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kyC7uo4XjFURyMdmVff+ksQZo5Xgh04teTh0uKohKB0=; b=bW5RXe3j3ZEJ629e2nYdy5WnUNhS+ZXD9H3iwWyTiuvgTY7Rs5cADMRQOMNTuSahP6 U8+NRbmBR0e9VTcUi8tJ56bJea6KtThNoMRy3ny6zDNvoWEXIH36cTak+QLzrFENZJ7g rnV9sMXKrbzRU6TDdGUTk3DeSfdkJexog/cM/N1nqrE8ghXwIWVLod5f0B8uoL0Qxalj AJ7PxYmtA7cPUHo9kgLE+dxAzgV5MA272t24bgG0QOuYN6gHOdDFCQYHUCKQXzMYhHeu my7fdkQhlfnZ6OaXdUHlbLjsPpTQ7T7nOfHnMBJhXkq+Mq6QbDxXwEl7iPeu6BqV6dhe tvJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kyC7uo4XjFURyMdmVff+ksQZo5Xgh04teTh0uKohKB0=; b=B/lImZJfug8EU7dwOTFFKp4nu96zNtTgz6DtiqwiTgoqbR25HlhqRDtKRI3rsYi7b8 uE4wud3/LjXEBQdkk8JEmM8NAT7j1Jppd4rvabvGwFnbwp+7/CRXrQPR6Ly/aFn2WCei 0HHPuZMaYVqU5sJPmQzJi8n9HcEaeSr6x2iHBE8xUxAWtpP4n3yoNM6Usrv5+3Y3TlsX /oXt03bMQB3RSGQPMw6t5NKmDYzLzbBEGCKYuJi9O8jkuacfN0uLFlsrqqgBEFzrAkiL 0ererAdpy5KiiX7V5/IcQtWWaXrkdfNUM5kWKVYZBx9mhYuJ0DFMjMPM/DhucYQQO9HT upMw== X-Gm-Message-State: AOAM533NW6Y56kbxyx6Aq8QsVmQV9YofxN2uuUxA05NxdK0qJ0a/vKG7 4w6WAIlELETHdf5t51VOkfcSeYTKJ62kIC4b X-Google-Smtp-Source: ABdhPJyGB9fxM2DGRRnVGL6PtMpDCsKZ+kgJaCXsW/fkrGRLfrGX1WH99gpW5CDDK3y8LlqmPltAbg== X-Received: by 2002:a5d:54c5:: with SMTP id x5mr13136047wrv.61.1635792997045; Mon, 01 Nov 2021 11:56:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:35 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 14/17] commit: convert {pre-commit,prepare-commit-msg} hook to hook.h Date: Mon, 1 Nov 2021 19:56:19 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move these hooks hook away from run-command.h to and over to the new hook.h library. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- commit.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/commit.c b/commit.c index 551de4903c1..581d7dc216c 100644 --- a/commit.c +++ b/commit.c @@ -21,6 +21,7 @@ #include "commit-reach.h" #include "run-command.h" #include "shallow.h" +#include "hook.h" static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **); @@ -1700,22 +1701,22 @@ size_t ignore_non_trailer(const char *buf, size_t len) int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...) { - struct strvec hook_env = STRVEC_INIT; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; va_list args; - int ret; + const char *arg; - strvec_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file); + strvec_pushf(&opt.env, "GIT_INDEX_FILE=%s", index_file); /* * Let the hook know that no editor will be launched. */ if (!editor_is_used) - strvec_push(&hook_env, "GIT_EDITOR=:"); + strvec_push(&opt.env, "GIT_EDITOR=:"); va_start(args, name); - ret = run_hook_ve(hook_env.v, name, args); + while ((arg = va_arg(args, const char *))) + strvec_push(&opt.args, arg); va_end(args); - strvec_clear(&hook_env); - return ret; + return run_hooks_opt(name, &opt); } From patchwork Mon Nov 1 18:56:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80857C433EF for ; Mon, 1 Nov 2021 18:59:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DE9360EE9 for ; Mon, 1 Nov 2021 18:59:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232519AbhKATCN (ORCPT ); Mon, 1 Nov 2021 15:02:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232562AbhKATAl (ORCPT ); Mon, 1 Nov 2021 15:00:41 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D55FC06122B for ; Mon, 1 Nov 2021 11:56:39 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id y84-20020a1c7d57000000b00330cb84834fso143808wmc.2 for ; Mon, 01 Nov 2021 11:56:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rprVQrjHJK1jSwtSWPENwFVJJnWQHlIG3ZKVaLRqZLw=; b=E2JFLrVhK/ejESV4D/BoATI7vNAEz4U4JGdqrTFBaq7JUnNDF7x44tzkstUdTCRG06 9ZovbrfWibyqxE2G21sQ5WWwslxf9czrbPeaMoVF1WrCng8Gya3ENJv6cpMDtMonb9xZ gwoKWCsm6A9eo7ZwCNU0vbllvheRl9TdE0wqg1lYpFvVG7V0ua6AF/XytdDg63EQQSAc /OqtccAALC5WZNAlWqrFmvBfM0TygXGxYOeCEAnjasQrTCG0DoM3L9DDqmNRpdSWW09b TejE/+I0ZcGBNRCdkkYvaVxmpVIyqG7YCnNkwVva/2fOqaXZBVb/NztBGg7HnUvXpmCa 1v8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rprVQrjHJK1jSwtSWPENwFVJJnWQHlIG3ZKVaLRqZLw=; b=UOBUE0q6oP4q4n4OaoVqFsHwsPh5no4HIq0Xh2XAJpfMmHZMobuxWWJFA85HSxubH/ 6+dJggDvMT/szN4/CviKENeKpWUJunkMif7T2GMs6LFAlzKC4CcldfBH6jy/L2E8rcYj ccopV2KhTQHN1QGr4zO10Ng4KFyczvBRNQzyOXKnRh31v4wtdw/GamivpgXu7GEACPYO fIanQbU0v97IBvu28COJEOxZwDu0M2qc0GyUhFvPU0E9Atufa8Qd5A/dFTNDS1sa9yiR 9q+TSJ2hqRaccktWnTOVm7/FLuGMDat+RzcDVspyLkk/OZlq6jXt707pRjWwT8oIoRBB 1fYA== X-Gm-Message-State: AOAM533GezCORGLAexzgNuhs+fmSDwn/CVd7T+rf3ANjnJeqQgL1umRK wETnR3//PMdejl2X/gxVBdduf3WHDhaPwD6s X-Google-Smtp-Source: ABdhPJxBAZbhpNiRo6K3Uj0Eh5ciLV6aCgo9NuJb2C1/MmH1pYdHEpwJrqpxwwaMIDdmW8f6z1nyYg== X-Received: by 2002:a7b:cd90:: with SMTP id y16mr861588wmj.84.1635792997774; Mon, 01 Nov 2021 11:56:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:37 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 15/17] read-cache: convert post-index-change to use hook.h Date: Mon, 1 Nov 2021 19:56:20 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer 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 Signed-off-by: Ævar Arnfjörð Bjarmason --- read-cache.c | 3 ++- run-command.c | 2 +- run-command.h | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/read-cache.c b/read-cache.c index f3986596623..4352661549f 100644 --- a/read-cache.c +++ b/read-cache.c @@ -28,6 +28,7 @@ #include "sparse-index.h" #include "csum-file.h" #include "promisor-remote.h" +#include "hook.h" /* Mask for the name length in ce_flags in the on-disk index */ @@ -3129,7 +3130,7 @@ 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", + run_hooks_l("post-index-change", istate->updated_workdir ? "1" : "0", istate->updated_skipworktree ? "1" : "0", NULL); istate->updated_workdir = 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 From patchwork Mon Nov 1 18:56:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4271FC433F5 for ; Mon, 1 Nov 2021 18:59:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A31660EBB for ; Mon, 1 Nov 2021 18:59:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232526AbhKATCO (ORCPT ); Mon, 1 Nov 2021 15:02:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232560AbhKATAl (ORCPT ); Mon, 1 Nov 2021 15:00:41 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D493C06122A for ; Mon, 1 Nov 2021 11:56:40 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id y196so4785359wmc.3 for ; Mon, 01 Nov 2021 11:56:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Inn+7q8q7ks0a2q7JFUno+lhpnHTJwP6ewE5lg0TxtI=; b=FJxBSH27ddwzlJR1UykXe/244OTjYymBC35Q/dlR8dkfGQLo+ihYdkH8mh098FJLxg gqsas8nO3hmB+uYBcPG7dq7yoUdM0O2w6C+gVrtYehqzQ3hdhL1Q20AbqE7Zle1tOCwd h3cj8Z/o6HfOozi2MtOiE+x/Vdlx2pMxD/GHIIEo7LRxS6yfKDPXuZsTqmcgruF4YmRq Lid/behqBU1fLTWcihP88xD5vKeT8sq/TR4qKigqb0mEDdtjxro4PiiGw7vYJQR4Dru+ jgMnYJbVYQ8dh4SG9y9FFpSI9yPcvgrGbShxZ+VCULBgIetb9N6IUQ/MkcXSdfPDN57E nxhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Inn+7q8q7ks0a2q7JFUno+lhpnHTJwP6ewE5lg0TxtI=; b=q+MPOkhp1FfJtIKwql4lb7Aj0WmRXIu/zAaotLA4NPsSLqB52ju6PLtCJaefwjQLck 0bLeGZ3QFwAegjx6NrsEhk1LhsvhkMJkcZ3HUPPu7GEQRz0SlUjs+OiKNN4VkGRRr6fb +devum1sJ9acBl81IRzhmFpG137ptge61KtYPfp5aUxzzgoo7kLVXdCDAGr7jOJ1H64n iQ5m6aBZYZqLkZEf1sTczHMg/dPStfSQ761juvja2T9GwpiW9dxele6cFDYxuLRZSzXR JAybRFCU6gACBdyM1K3ijezHTXsTat+gyiOwv1VCrH50DjX3zlNPC98llwNz1GnXjgMF Agww== X-Gm-Message-State: AOAM533637sf92dx722pPOm9M+n9O0T41ANy7g/EfUgedN30kGTkJ40r FWINoiMuYOziDkziOoWtONjlxcsocR2vSVJm X-Google-Smtp-Source: ABdhPJyTiQr0ifxn117gyhD/RHVDhvpJ4b9CfregFnjtYQGwAUbIAGmPaFq+lNcnTTD3NjbCfHeVnw== X-Received: by 2002:a7b:c30c:: with SMTP id k12mr920461wmj.38.1635792998565; Mon, 01 Nov 2021 11:56:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 16/17] receive-pack: convert push-to-checkout hook to hook.h Date: Mon, 1 Nov 2021 19:56:21 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the push-to-checkout hook away from run-command.h to and over to the new hook.h library. This removes the last direct user of run_hook_le(), so we could remove that function now, but let's leave that to a follow-up cleanup commit. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/receive-pack.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 49b846d9605..5d6d8dd9a26 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1439,9 +1439,12 @@ static const char *push_to_checkout(unsigned char *hash, struct strvec *env, const char *work_tree) { + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); - if (run_hook_le(env->v, push_to_checkout_hook, - hash_to_hex(hash), NULL)) + strvec_pushv(&opt.env, env->v); + strvec_push(&opt.args, hash_to_hex(hash)); + if (run_hooks_opt(push_to_checkout_hook, &opt)) return "push-to-checkout hook declined"; else return NULL; From patchwork Mon Nov 1 18:56:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12597047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7AD1C433EF for ; Mon, 1 Nov 2021 18:59:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC91B60EBB for ; Mon, 1 Nov 2021 18:59:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232428AbhKATCJ (ORCPT ); Mon, 1 Nov 2021 15:02:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232565AbhKATAl (ORCPT ); Mon, 1 Nov 2021 15:00:41 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B91BC06122D for ; Mon, 1 Nov 2021 11:56:41 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id a20-20020a1c7f14000000b003231d13ee3cso126803wmd.3 for ; Mon, 01 Nov 2021 11:56:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QNL/Bo613nEHIkrJAY2T19zCcFNTguABxLUWg1g5Ktc=; b=TgKPcckwMLwGSmHxRHS8xgSUDGb+mgG3gq3LaDFhmh+hv/R09HFQ/SafOeYdt9lMJH bvyTw2VjNHRlWLcSOSYbhfwzeMoTDnwxgx9pmq3jqTXwGtZOCZav0wJCfiL3bxTsb15x vKldoW5dAuITAo1cMWlXUsY2cH5r6QCTEb71YIEZc/ZWTQDc/YnNM6O67RbbjF277qWi i/tD5rN5kcu8iVUeCmqk8BKGirnsWgUKe3zMaAkxBaZtScIV265JsyJu2W9/D+a2saqN bI/8W9pKRtH+hn5J6UprMsqmwG0ZhkTQNxJteVLQD5HeKmrj0zclmIoVQPa/BqVOjbb1 bLIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QNL/Bo613nEHIkrJAY2T19zCcFNTguABxLUWg1g5Ktc=; b=46X46+1md2Kqi9CDrYBD3WsuRopUTvTsbcd+EaTqUSJB/V3ADIs0h4n9jLnVQ3LBwX PBRG2srjE6RzkE5pteBaCZLymf8ihR6OtHjkFeJGfdFlZkwHqFyU5o97TT1RsJcHLhyj cXzkJ5p5ByKOzJHAlYlQ1vWndKHZWbSVauPRwfPIwNMPLGPT0pR42S3Q3B54usA0s+28 bDSTKmbCksxlu0NCY9NcchtU7dPHN0uKBbTON2LhK7fUX6y2JT6kScmdbTzKQRp03UEr DqYReoNSoIb7mOhwrWQBmVyjvG6ipjlNIDnH5FcU1d4rd99X8orovHPyQuSJf47+m886 6Gbg== X-Gm-Message-State: AOAM531x6oUyHaxaS92VnpIplkGWdTEEbUOh/sG7fwrNC3YDvhDMwuFS v3t3QsJTTyr0YLyskp0zY3vKAGlbTOB0dZH+ X-Google-Smtp-Source: ABdhPJyZ5pnfRlBEj3EPWHyFrxgw+RCY1jtjfnbKBR3VYF+2uidPK51ciQywzPVmBguZCoimtXMz8w== X-Received: by 2002:a1c:43c2:: with SMTP id q185mr910122wma.30.1635792999369; Mon, 01 Nov 2021 11:56:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q14sm314185wmq.4.2021.11.01.11.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:56:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v4 17/17] run-command: remove old run_hook_{le,ve}() hook API Date: Mon, 1 Nov 2021 19:56:22 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer The new hook.h library has replaced all run-command.h hook-related functionality. So let's delete this dead code. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- run-command.c | 32 -------------------------------- run-command.h | 16 ---------------- 2 files changed, 48 deletions(-) diff --git a/run-command.c b/run-command.c index d92e670c8ed..8a21ff525f3 100644 --- a/run-command.c +++ b/run-command.c @@ -1323,38 +1323,6 @@ int async_with_fork(void) #endif } -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; - - p = find_hook(name); - if (!p) - return 0; - - strvec_push(&hook.args, p); - while ((p = va_arg(args, const char *))) - strvec_push(&hook.args, p); - hook.env = env; - hook.no_stdin = 1; - hook.stdout_to_stderr = 1; - hook.trace2_hook_name = name; - - return run_command(&hook); -} - -int run_hook_le(const char *const *env, const char *name, ...) -{ - va_list args; - int ret; - - va_start(args, name); - ret = run_hook_ve(env, name, args); - va_end(args); - - return ret; -} - struct io_pump { /* initialized by caller */ int fd; diff --git a/run-command.h b/run-command.h index 3fa7454cf8a..59e1fbff64c 100644 --- a/run-command.h +++ b/run-command.h @@ -224,22 +224,6 @@ int finish_command_in_signal(struct child_process *); */ int run_command(struct child_process *); -/** - * Run a hook. - * The first argument is a pathname to an index file, or NULL - * if the hook uses the default index file or no index is needed. - * The second argument is the name of the hook. - * The further arguments correspond to the hook arguments. - * The last argument has to be NULL to terminate the arguments list. - * If the hook does not exist or is not executable, the return - * value will be zero. - * If it is executable, the hook will be executed and the exit - * status of the hook is returned. - * On execution, .stdout_to_stderr and .no_stdin will be set. - */ -LAST_ARG_MUST_BE_NULL -int run_hook_le(const char *const *env, const char *name, ...); - /* * Trigger an auto-gc */