From patchwork Wed Dec 22 03:59:27 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: 12690987 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2F0AC433EF for ; Wed, 22 Dec 2021 03:59:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235870AbhLVD7v (ORCPT ); Tue, 21 Dec 2021 22:59:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232444AbhLVD7t (ORCPT ); Tue, 21 Dec 2021 22:59:49 -0500 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 B132EC061574 for ; Tue, 21 Dec 2021 19:59:48 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id v11so2019627wrw.10 for ; Tue, 21 Dec 2021 19:59:48 -0800 (PST) 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=jMmF9fUdedGgO4FOG3wSI6SFr0fNxZC/yGyg3KgC/GE=; b=PMIq45x+LQ9XG2gxH4iRoieGu6hsUyJAdmUM3VjPXX7eXFex/2rn8BJA1/lP9h3SFr IxO0vs53RTdh7iWlk0RDkSd/1zL+gH23BNB+841mnkMCRpg69OH8d4+857fUnC49ZEad 6v8JzdVQMWdaNjn87lCKQuliZjqu6n6mZbP0r3KNI+445vVRBkVB9BjWG3O0hQ74mC2B I0JbAb6BVRWTS3+7JtaWDmC8qVSLGrX+os4zlbsd8SSbBwza5ZH371CAOtSyw1VOgtsu yjYoPUG41imG0MUJV0IMvNarF63AEXIMIY7rdY31D8Qe5qPBRzHoqbqak1k84yOiPjJW sUQQ== 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=jMmF9fUdedGgO4FOG3wSI6SFr0fNxZC/yGyg3KgC/GE=; b=UYKVoYUQK1EGCTU5K9JCu88HWm5zN49g1zRfqc+yjxoq6e2qI2Uzc+hTDTFnpCtkhF x1J9qKJCUFpcEDXJ2+dhaxPohcwWzTz3tBZePVCbPg4Pb796pxlVND6unwyR2c+CJz2O 7mMQUn0RhLx3rLR3nNWnvee43B3WJ2t5q6ghVJR9IG+V2X/ES3qVSGqNUTuMRPByPaNP k0Qz9X26E/nsRUmsOA8e2+X+r8BF3+Hk4bfOKGByoe3cWbG6ubINP3TY4Yi9FRv9f5jF P4G4lujvSebuoPrZBIJ4V3nHCALP48cl/IL9cAbN4dfTmBNJl+ZaHalnqJF0orACksWx z4Ag== X-Gm-Message-State: AOAM530O0stU1oKRayH9oy2amHTWzfRGIeZWrzFb2eAbMXF/LaJhsOev ukrnr0UdXTj5sLf76dXLQYBptULnwu12wg== X-Google-Smtp-Source: ABdhPJy8RtmztE1Q6H/M9fnercyyuZ1cOduhd9xIkiebExHmGDupMcS9ygaSgGLI8/lwx/PwwN4KOA== X-Received: by 2002:adf:ec8b:: with SMTP id z11mr727646wrn.378.1640145586958; Tue, 21 Dec 2021 19:59:46 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:46 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 01/17] hook: add 'run' subcommand Date: Wed, 22 Dec 2021 04:59:27 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 75ed168adbc..9a3cbc8c414 100644 --- a/Makefile +++ b/Makefile @@ -1109,6 +1109,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 675c28f0bd0..9bd6f3c48f4 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 7edafd8ecff..7030f1180b3 100644 --- a/git.c +++ b/git.c @@ -541,6 +541,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..a0917cf877c 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; + strvec_pushv(&cp->env_array, 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 Wed Dec 22 03:59:28 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: 12690997 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AC7DC433F5 for ; Wed, 22 Dec 2021 04:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238766AbhLVD7x (ORCPT ); Tue, 21 Dec 2021 22:59:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235774AbhLVD7u (ORCPT ); Tue, 21 Dec 2021 22:59:50 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B18CEC061574 for ; Tue, 21 Dec 2021 19:59:49 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id a9so2028514wrr.8 for ; Tue, 21 Dec 2021 19:59:49 -0800 (PST) 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=OGgLsGRpc1c3jVcgobwtH1OCfHphbUiZ+J37GIu1g9Y=; b=TuGwoD/0ZPMKx/CA/Nh/ukghP4TUr5AYw/xrf28/TjeKA89bV8dW6/9bF847Dkd04T Y4wpqPhdEyz+FNjMacBX713nSmljSm7JfcK24gJgd/Vg6bkS2hB4gwV8D/SbkUV3l4YH tgBY01M4CM5UdcJOEnjIe/tyHq4uayGV7JSlaKMrN5K/Vyp3o34hwvZYWSDlc1oHUfly aHS9lCQmMpxrtGhnScS7S7aJOrENouaqM/0R+3FPx9Oh9JslHMlxBJjbgXjUoOhip+61 FEuZmznreuEFCHQ8k83UVLZm42hg+Uw5OTXCaWl2k3u7qAYY/kn7dp4IK4EuTdGX4RV9 TZ7w== 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=OGgLsGRpc1c3jVcgobwtH1OCfHphbUiZ+J37GIu1g9Y=; b=o68Ck5OEzDaQ5S6vPV+E73Vk5hBgOdhtAdGe75xSn2c5A6/M5DzYZ6asOEWDDnxXQT NEVqgLQ3dAvso4hAC/ULLSuh3QMX5wFZGd3RJGBzyybZD6y0Gmxy0jXmeXBSmPMpYmto d+MC0vIo1+a4bjUQidouLqkIlLEKQpmKewHWUWWVqwQC9fJoGjqyWtdbQLgx9pX1U1km fvaIKlMVUO6hX+8VBsAYYzFSMR0yBXC5TR75jZG2Ut6xGFNthwbimusV2Yshg8fDQGFy isv138Qe3CyI2PU/tlSvj3xBs6DhfHXRncr0KKmsKzJxpb0lII50/BwLbvEDJl5O44oM zjrg== X-Gm-Message-State: AOAM531JZ2RwxGTud6tYiGJ21tC886YqvJo+SYS/IbocJ3ODkD8wEZJd Pn6dEXs9HQwBtxzxd+SgimdK0Bt6GCA8WQ== X-Google-Smtp-Source: ABdhPJwQPG+dNs6Ml6Bd4fn7a4UnJOAC6NO8NjGMNbeIlDrxBJEoQiNT0mux4D205edx1IHqDRjfkA== X-Received: by 2002:a5d:4810:: with SMTP id l16mr702720wrq.672.1640145588106; Tue, 21 Dec 2021 19:59:48 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:47 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 02/17] hook API: add a run_hooks() wrapper Date: Wed, 22 Dec 2021 04:59:28 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 a0917cf877c..d67a114e62d 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 Wed Dec 22 03:59:29 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: 12690989 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9B49C433FE for ; Wed, 22 Dec 2021 04:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237040AbhLVD7y (ORCPT ); Tue, 21 Dec 2021 22:59:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235819AbhLVD7v (ORCPT ); Tue, 21 Dec 2021 22:59:51 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3CE1C061401 for ; Tue, 21 Dec 2021 19:59:50 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id d9so2159995wrb.0 for ; Tue, 21 Dec 2021 19:59:50 -0800 (PST) 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=8e8skhwx5TBhXXvs47KPPydWQNEhj5T/BSaFUM+zPwA=; b=jp1bGL/fR0lPeSvQSix7ZH9mBrm0/jawXd7HUPVlV8IgWzGFc+TEPxczAsDxarrlCC bQocURxQMJIaFNJtBPiJbYGEqGv/7uj3wn1OhTgRRYOrC7U/BEcF5aw9UyH+88KYcPmM VAinwX3bDfN+wZr30LO2S0kh0FZeBhzh6UtD8AFrO+jFNwPrHSY07iViNMpn5VzoyOzD 9rX5nOr+0dvb/ONCqXVPKEIA7iZYv0Z4xmXmtE3f7k28EY69qYjgW6Nd3iii3jEuOBNb OWf/69F/ilyx5UoOdAeZIfbsRccsFcmMSTGvTUzWd4Z3/nzDqtz6E2GiHJbSewxbG/XD VhAQ== 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=8e8skhwx5TBhXXvs47KPPydWQNEhj5T/BSaFUM+zPwA=; b=KSMwKQTu6g7PrTml/dntqyEEW0e3bI/CRuYlAxREfEbeMwu+mjQlHA1qrx5xPHKrZm c+KxBNhT5/g/7CpvJPhnxcr3aW2hy16WRtirRieHsdypq6CS1t4YmF45tET2K9kgjgVh CrFX5/EY/SIg0yPT3RYk77Kb9Z54RoYstoejGQKX1DXRPs1cMuTo7CclMHBq9inPkRSg MwVg1W9DdUaAJOoHzzFxVxHOIUcSE3wagELvLRFb9KOEc+sJ/EIyFjh8+GXjDBBhOpnq zrkB5KhndBWKonwHHQrToxFSUE2QTt/o5cqESz0tI0JP5BrzL8bnRikAqTeKNNzCYar9 JScw== X-Gm-Message-State: AOAM531zpyVA7Z3IVMXw2m011ZRux/KLDsEN4ZpGmB5Tc8/UmC/EU2Ry Y37bbq/6xewJ5KfMvW0sUUf6H6eGrFKfgQ== X-Google-Smtp-Source: ABdhPJyEGogebxEykRPSNwVB4YOALTQzA5yLCqzlOENhj8SXckC2FVuESvv7AlOcnHXHaw/2M3pxMg== X-Received: by 2002:a5d:408c:: with SMTP id o12mr679294wrp.691.1640145589271; Tue, 21 Dec 2021 19:59:49 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:48 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 03/17] gc: use hook library for pre-auto-gc hook Date: Wed, 22 Dec 2021 04:59:29 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 bcef6a4c8da..4bbc58aae5b 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 Wed Dec 22 03:59:30 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: 12690991 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA9A0C433EF for ; Wed, 22 Dec 2021 04:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238842AbhLVD74 (ORCPT ); Tue, 21 Dec 2021 22:59:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235956AbhLVD7w (ORCPT ); Tue, 21 Dec 2021 22:59:52 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A11EEC061747 for ; Tue, 21 Dec 2021 19:59:51 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id t26so2065320wrb.4 for ; Tue, 21 Dec 2021 19:59:51 -0800 (PST) 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=KbjkKWMfaGacuSQjas0jvZkMj0+eXrixHCO+wIuSVc0=; b=hjjhzwaWvW4XJWg5bRuKCQk9VYgAEYPV8EBUovAeZ92u+bdq6/UopA4dFOIJh092BK 5LAqUzh5Ejsn4wvxBu3KTXcC5xrVSHVcToifRMdhESLGgmeZ4x5O2Pb4D04udHGdyrPO /CJ45a6PqLQ9lNrArCRYA8iI3tzEH4SQIMmAcmTn5U4EB803Iy3zg/VLCh/8NQXeMREU 32Itm3a8WH8+PtSAIsiATQGnWamcf4tnnVCx6R2tZotkvTZZ3h6++bvHY70S6bXOIayB Yjx0nASfGxgMbjng2fzleOG06lS8oZvewndH6eE1Kxq8KfuQqQchS+09A3u5smjF2lRU SifA== 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=KbjkKWMfaGacuSQjas0jvZkMj0+eXrixHCO+wIuSVc0=; b=D2b+y50oa6rrc3x/ziGMWZfgVLxEJRMf7PZLonx7l6+zOlR/dlCRYfCDrvfn1098jx FvnSWVeBabbLUGGt7aqjFn4YOIq5U3I+xQRonJgnVTf24FMm+KSyZpxUg7JMb1Hd+KRo rnN+7Voode7UjNaPOw3yZNJgx3BGadCNNz5qqRZtBUD2VzcJbro1mNQ3cxBI0/ET4HHi FzQlh556RCY6mkVgb8Jh3n8FAon+kl8z9rkZqrGxf+fwfuEXESf8yr98REZfeq3KwsqG AKQd4rwe7dJspW8dTdt4TxPSUIv4WCZ60k+XvCqiQrsVQbERMr4KODI1f8w/oFl37hgp EhtQ== X-Gm-Message-State: AOAM5339Nj3FChhrAbl+W04szSTbLYFMI4PAPLStgI0zlFs1cZwiRzgh hXHcQQW8DXrfFiq/Zi9+llONidySRiExKw== X-Google-Smtp-Source: ABdhPJyZxAuHuzZJK5GZIop4ZJbWDFpM11RtpY1dPsos0b61zB+3DJtFvz1j3Xxlqe6u9TPixzCECA== X-Received: by 2002:a5d:4acb:: with SMTP id y11mr732957wrs.64.1640145590012; Tue, 21 Dec 2021 19:59:50 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:49 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 04/17] am: convert {pre,post}-applypatch to use hook.h Date: Wed, 22 Dec 2021 04:59:30 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 Wed Dec 22 03:59:31 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: 12690995 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9A12C43217 for ; Wed, 22 Dec 2021 04:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238860AbhLVD75 (ORCPT ); Tue, 21 Dec 2021 22:59:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235960AbhLVD7w (ORCPT ); Tue, 21 Dec 2021 22:59:52 -0500 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 79713C061574 for ; Tue, 21 Dec 2021 19:59:52 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id v7so1990887wrv.12 for ; Tue, 21 Dec 2021 19:59:52 -0800 (PST) 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=2sUftsF+Vt2B9b7tO2kQbmd0BoTEf9vxJh1ljVQUvns=; b=OEAV9JwCUE8QcOdvpAvgwvgYaaOVQs63NV4WApwu9pbKy0WVoqXOxoBQWMafn101G+ SaejS/tsJWBV3XurGZGR6J+OIEXB4fP0/48OcEwUQLVA0IOdCLlK/1NIxZm6yOY8RPjJ yT02WFCWVya3LgwLncRDxBm93Fzhbm7Tr/tNXfzKRmdbCWXxdNf0n9L6ZmahRtQgfc+h g35lQbj/Cv/TfjW7kFoGqqAkyshaIdY/KJ/khBgYgl7Td08J2dIziNAfEdogBtatIX1a rxuu5dH3ICGdzzFHTbyGOQsUfC/uTt9VpnBbA5llPrl2YsuvITNTc7tPTDyWxpp1GZie NkUw== 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=2sUftsF+Vt2B9b7tO2kQbmd0BoTEf9vxJh1ljVQUvns=; b=q3vze9H30a3e9qhatF+oLqEP1uu4W3YJRCM+Po8OK/3+b9WsHbPwk0tOdCkiy7Lj19 WRgyjEreMWLYJSAMUG89UIMpdJgnHfav85w5FJ1uw2pRzUGEAdfgJvEP6yr03xEFPrsW wiAHxub93vi6jyBtsnthstzuEWQ6DiHEC1tD63jyK73v1IqQtWARitQP/hUYCf97kcBK UENWFGOX4YxDGkhqhWsCd5Ix5p59t5FRbnFySzL7bw9/8M2Im9Odv3JDMhaZBw3xiFbf ptO6pZ/PxCiKywvsmVUUp6t5cAs9W2iIk0j6RPhlVA2H685u3QZLBb8rYLnY31z+IadH Wfpw== X-Gm-Message-State: AOAM531VDkKXZFYnh2bJYvVeZo83SfHSWyefscApWJ1Eex9WCJpTeWQy VpHi8mcxZ71iw1FsULE+Qzt6Jb6q0mAeYQ== X-Google-Smtp-Source: ABdhPJymKac8XsgJrvfl1snnN1x6FV4LzccZrYeSZAqEAdw/a4Q3RATdzCL7J2x2u3meguK2bRsEbQ== X-Received: by 2002:adf:bc89:: with SMTP id g9mr689285wrh.578.1640145590845; Tue, 21 Dec 2021 19:59:50 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:50 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 05/17] hook API: add a run_hooks_l() wrapper Date: Wed, 22 Dec 2021 04:59:31 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 Reviewed-by: Emily Shaffer --- hook.c | 14 ++++++++++++++ hook.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/hook.c b/hook.c index d67a114e62d..1ad123422b2 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 Wed Dec 22 03:59:32 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: 12690993 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8828C4332F for ; Wed, 22 Dec 2021 04:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238948AbhLVD76 (ORCPT ); Tue, 21 Dec 2021 22:59:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235775AbhLVD7x (ORCPT ); Tue, 21 Dec 2021 22:59:53 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43D88C061574 for ; Tue, 21 Dec 2021 19:59:53 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id i22so1984329wrb.13 for ; Tue, 21 Dec 2021 19:59:53 -0800 (PST) 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=yWXFkykf3ve1z11gwEEAzo/g2vz8vkH7h4Z37DlxoVY=; b=RDioV+iiOyMXk+wYNBMwCppx+R0m5SP+ZIGWmN4oEHn9PTd74FrobAJMsfVIIq/mD5 4vxvLVeCXpP6l+5+xs8/wHVQqnjqYtk8/pThV8CjO7iqMCYPsfFa7aygGC6GStez5hy8 BpWybnqRkLbFcBRRoxVRy6xhfKKOTr1Hz8l0P0lZ2lqRoKfB4jEScWRcsSYrHfvOqk9z feROiM4VidiFHknUslC+HSHWXDW/vev9P/sZ7zMh0U6FzmuAPTONJegTxB36g1L3YH+M dUrE2cEmWjftu1KD0/ZCvCJvSokKgHpHfp96eCI1nixjjJ2fc+mvdrop3d2Ql3SKF//C Dc5g== 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=yWXFkykf3ve1z11gwEEAzo/g2vz8vkH7h4Z37DlxoVY=; b=Ew2ChqpSsF2JZIOWnY2ofSCB+tu95fZ4+74wegJDeWgu0Cqv8R0c/mnbvejsAbiwJp Okzip6rSSjdg1R+YCYsxOF1DHf5bg0p7OnhbZ2V5ygFY2IjYEcaHDwT7DOjjuDv1MQ9Z fpPrMfkMnmgEmuAynt/9Oz6345y5qKhP/ndSg/ylUVScxPZTiK4Tdqrk1vRaQDvTStVa xxaYtL7SgpBDjbdkUYWBLUMzKXdUPpV7JI2GwtUIG8O8qYTth8IY38nAA1JtYh9nGxyi zaKWgnOKtlmdDKFsjMAOSRoFqexDw0O6oonXhweWETAGD0FYQ5IjP3K/Ro6uCqXfGsyz M8Hw== X-Gm-Message-State: AOAM532uQtk6meuKzbvr0dFxZqleVNSKy2FIzVTiBYD1wFTLMOi41Sxk mA+i9pEXp0tYpfHYFVCwmBEVzxoUfbmnag== X-Google-Smtp-Source: ABdhPJy9dorINm1wL7D2lzHuDBqxyP+F+hrFjHdG42u6tkK94P4buTloi1r7LFoSpX48L3jwix2/Vg== X-Received: by 2002:a05:6000:cd:: with SMTP id q13mr720766wrx.302.1640145591688; Tue, 21 Dec 2021 19:59:51 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:51 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 06/17] rebase: convert pre-rebase to use hook.h Date: Wed, 22 Dec 2021 04:59:32 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 Wed Dec 22 03:59:33 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: 12690999 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C26F7C433F5 for ; Wed, 22 Dec 2021 04:00:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238861AbhLVD77 (ORCPT ); Tue, 21 Dec 2021 22:59:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238781AbhLVD7y (ORCPT ); Tue, 21 Dec 2021 22:59:54 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10FFCC06173F for ; Tue, 21 Dec 2021 19:59:54 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id q16so2045481wrg.7 for ; Tue, 21 Dec 2021 19:59:53 -0800 (PST) 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=JNiXDWMrDZB2xAvAJhT6o2OGXyA2gfFIOenjoHoWt/Q=; b=lKFAwwHX83Bw12bd7a2TxAZSzypfwuzX7JiG2tX9N4vtPDSvcK5JdZscntqtuth42n VeVfXNtI2GdXrGhPT1BRxXfuY6SSGmlkg8YKwvfUtNMA+W9OanX2UWHAnuDaXRSKYKTE k1KIPQvS3mDWCMcZ++6KVwDG0olL+PpDxwIFpWMkd6asUtYllRltZsobRafrgdGDGzcz 7haW8yk6MuZ2lLAUpd7wYwrb5cLMJYFaTqBieRYVeDe9tWT6vc0KHF+SLfDsB92y7VMq zi9inJsb10fMEuGs+cW5icMrztbeHepGBKdTWKPo5QkedkB1amZyui+6iT6x3uu2/TNP SUTQ== 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=JNiXDWMrDZB2xAvAJhT6o2OGXyA2gfFIOenjoHoWt/Q=; b=DKHrVjtHUb8onSG7IEuRn6CCo28F5fohrNKIL7o7xf0gZLpKh/75uCk4+0kxmfSA9s w9WB0v+MCS7+GdSSUiqZehqXtzMtj53ilSpZXal9UTYPj1VqK0jmYvcjCUBfTi/5s6fp TW8UUeRjqkR85jFnCg8AZ56q5oYjIY+IL8jDLqRzgdUjOLjhDxG6SyzME7PayWpgmxfZ GmpbUSccfiTeKMWPAhjEXkF7V/NBBO8tYoTAsmFM3k2hh7NmpO6PX8Bn2KTJJS+NUl5c HtgC5329Wa4qkVPdy2kj5zmlmwsJt0jdanY0Zr0OGjkbY6MnOI6e+2uRd7oZmoMpwSAJ F0zw== X-Gm-Message-State: AOAM533G4YPyDLYEIis21C7DNbfn0hUtebmzCCxXRu/suGl9iUvOoJge DAF/SucPbuWW5N28AcXAeLyAWtzrg9e5Lw== X-Google-Smtp-Source: ABdhPJyDCYNPcbtgVjkKS6n7dX6IZjMNT5jFfMfqgYSqcibIlBiNdPE1p/zfxRAhQQM4F/lDFluJbA== X-Received: by 2002:a05:6000:2cc:: with SMTP id o12mr734386wry.285.1640145592523; Tue, 21 Dec 2021 19:59:52 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:52 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 07/17] am: convert applypatch-msg to use hook.h Date: Wed, 22 Dec 2021 04:59:33 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 Wed Dec 22 03:59:34 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: 12691003 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FD08C4332F for ; Wed, 22 Dec 2021 04:00:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238982AbhLVEAD (ORCPT ); Tue, 21 Dec 2021 23:00:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238795AbhLVD7z (ORCPT ); Tue, 21 Dec 2021 22:59:55 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5925C061746 for ; Tue, 21 Dec 2021 19:59:54 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id f134-20020a1c1f8c000000b00345c05bc12dso696325wmf.3 for ; Tue, 21 Dec 2021 19:59:54 -0800 (PST) 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=DRcDz5mRrLFJg1Chi59B2VkbtbvV25HAmi3ZWGu9OWQ=; b=HRx/jbIMkk8Q2IEpFaMxKyM0vPWzb/QpYLmosAq1z7kvIaUqRYF9bxWw4UWEeQlr2w 7CdiUlwCHLB4uXf8lffK5CG8HFjSYaHL2Cm2FLAa1AXG55dBXCXhjWHf/jDFHuIfh78T kc2gFZ15/CNH/MXMW7qxHEOviYCefb6tvLtNGcMzpYcw4Aqgb4Sg6aXj5xIczc6R6EhO V0G+BiSdmYQLaZUjN4qKGltSp/oFHECImn0eNXHpYXrTkEm6RNzl/m9MW8vOMxcYhqJV FMYrY1IJhmqPPfu81SvcRVR7TqnLZMfP9zSYtQz+lraDG4NuxIry3F0iA0Y2wf7kUDmN eJJA== 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=DRcDz5mRrLFJg1Chi59B2VkbtbvV25HAmi3ZWGu9OWQ=; b=LnWHyL/HjDDuIslRTajBjDxjwmfu8ruaHmxwZDP5M8BJe8qqcKeb06ObShgXP5Fmki /t/5GJuN0WnP9y3SX/ESB+6YMot+zTzUbvdw60miVDV6oEz7FJ4HFqgKAyxtwNeUynOo elM4NUseIa1lo35Wthj8u8EC4aaPq30sYqxsYyXq9caxOtsy6umDKog6Bk2pRHEHt9Ua k9G1P2bxv5citcuNriIeVEwSjE31eMYTeZ0J/VfkCzt5SczMqzrsXAvD3WHCsTc1G/rr +WvbTUiGwykGGRaN97O14ziiX5qr99Y7chKJD+gPq+fhFSlP5DtArJroFYj1+W/3XxpB 4Jxw== X-Gm-Message-State: AOAM533KMN5A6uyHOmDEe99lO/oH1yyzJf6wcWXcrjlqSFDrYIQMxmFk moJ42Ik74H2kIXUU36aMQE2ts3JkIMfUdw== X-Google-Smtp-Source: ABdhPJyawPP7JdG7klC3xQVtWrxREnsV5Yy36bMtIWv37u6jOUxraBr2mk4GPwD4e8ztHA8Si0eRsg== X-Received: by 2002:a05:600c:5025:: with SMTP id n37mr958142wmr.18.1640145593163; Tue, 21 Dec 2021 19:59:53 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:52 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 08/17] merge: convert post-merge to use hook.h Date: Wed, 22 Dec 2021 04:59:34 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 5f0476b0b76..5be3009c2a2 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -487,7 +487,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 Wed Dec 22 03:59:35 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: 12691005 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE63DC433FE for ; Wed, 22 Dec 2021 04:00:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238919AbhLVEAC (ORCPT ); Tue, 21 Dec 2021 23:00:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238870AbhLVD76 (ORCPT ); Tue, 21 Dec 2021 22:59:58 -0500 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 96D92C061756 for ; Tue, 21 Dec 2021 19:59:55 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id g7-20020a7bc4c7000000b00345c4bb365aso282165wmk.4 for ; Tue, 21 Dec 2021 19:59:55 -0800 (PST) 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=UnKtuPBXICpvJKAEmfLfcOUU4owo0ELp8kOt+Hr6O7A=; b=EOoPBRiHrnABe3lw+/HED917tRkZEQA9yQ0bEYrvWEicaPQXDQE8r5S0Pcz2pEGrkp nAfQtIuuVsIKwJcp6krGa7OFn4qisfZobTXQnJtCQguiJVqNJKpGnAu0pF2O1R97p7lN KOCP9d2INNCVbgpmmxkSN3/9LbeqfknLJZcpLwjMmsSQIHf4GAOFY9UUiYvDtfVXo/yH sCcZnHlJb69D2m+0VYjNGH4lBb6/WtUiUqjAfT6ohXVLG4SV8Qd5d++IdGRLj98+gg/f hcpQHtdziU6ltV4QGNZfc0ZSkqPVHZCpVolk8GDrNxG3GhyrucWk24ZLw2yLVADFrytZ bEwA== 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=UnKtuPBXICpvJKAEmfLfcOUU4owo0ELp8kOt+Hr6O7A=; b=ZOcbW0dxt72/Hdfb8WumVRH1dW6hmlz2V96jBecdPdr002R79niG7vzWj5UN/rqHP8 xn8cSUtijSMYX5gp50ZVilIgUtFOhWxnlxV+5h4xAlsaisI1JfUvzKoS1z1s1wiVYlPm zjyp2rKdxZD5x2thXAQe002MUcLQM7LSZo15dOfHVaHSlnm+RBwPIkQURF+SaMOZd5oe 9JRfe/mP91wJ88b7ashBaCcwmuwnas3r/vOLudM9Q0F5yJ64KTvS2g9+/9VXe+1NCy/8 WU+1w5AwYn0dVNCSbKdLJkg4gI7SlqaAj1+2ASl+qzFq26sNnKpGOlTz3G1xmcOdOk4w MUgg== X-Gm-Message-State: AOAM530LQyKGchxCOTbTPpRUTvCY3wpAbyFKJOjnBybxZhVSSQqHSDLv B9xzH4uNVf9aIFLt2AVzwr/MC65455+Lpw== X-Google-Smtp-Source: ABdhPJwc2D3WTmgD91HowB7ONlchko9SDK+zckp6hSejqBLb41ataTRX0PXFJg/Z4jqcNBc/HeXypQ== X-Received: by 2002:a1c:a98f:: with SMTP id s137mr767271wme.5.1640145594024; Tue, 21 Dec 2021 19:59:54 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:53 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 09/17] hooks: convert non-worktree 'post-checkout' hook to hook library Date: Wed, 22 Dec 2021 04:59:35 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 72beeb49aa9..e2e95445407 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" @@ -114,7 +115,7 @@ static void branch_info_release(struct branch_info *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 Wed Dec 22 03:59:36 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: 12691001 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D89C4C433EF for ; Wed, 22 Dec 2021 04:00:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238834AbhLVEAB (ORCPT ); Tue, 21 Dec 2021 23:00:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238871AbhLVD76 (ORCPT ); Tue, 21 Dec 2021 22:59:58 -0500 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 436DDC061757 for ; Tue, 21 Dec 2021 19:59:56 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id n10-20020a7bc5ca000000b00345c520d38eso247000wmk.1 for ; Tue, 21 Dec 2021 19:59:56 -0800 (PST) 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=GYrrxyO7GpzNpIu9CAymevWAL9XN0Ai/pEcH2dxzW14=; b=Lg2i4GzIzGRvKkIISKqElpOvgJd0ZX5F/hECGg5AZYPlvQoDgdq5E+pa8mpsV95TQJ jT1wOzXtUUw6uim9igBYaKgtqYhv6dvh4Nw+EGMCxcAVfjo+mnI13x8y9Nx/B10yL9I/ DZ3BbUplpszdVpfjad7LLklqAM0L4TkrmiecQVTYdbDIvzC+RCWqlWAb+WNlosK0Gy5f T9Z+LD+JZVj/1Mf9cHxIlX+EhxpkKWM+5aEpI0jSetTd+1PQ0U+2udjgQVk7nKWPA2LL rntp/mRtO01vf36M33/ZyXnwzyrSMm6dHWR0f/Pz4mhf0KjaOboqU0jvpRoYLe8azWHQ Pdbw== 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=GYrrxyO7GpzNpIu9CAymevWAL9XN0Ai/pEcH2dxzW14=; b=xIlxOM6YdDFb5trdmJFLsx21zPHVo7oJfd+5oaQ9gPPvZtNDfwC9FZ+2UIG4iPNQg1 jPqBvh4f7Yb2hi7DmX7TES1Gik3hrx3Hl6jCV9Z9uL687rDRnADSyLGOFvvFSct+qGsN IlaqyAY+RVBST3AmFmIgD36FAhnsQFc+7RbY1duptBhsorUnHXGtsscFEaASv/OFwBz5 watApaCzOL6Pb3PLt89uD2RIe/WN+NpohDR7f2sVQAL4P54PSZqMhvWmncBL3UDEjUck muWQD08plj56jwz2RqJw42/E1PgfRjQ+PvvmJIByXqHqe2SIAVBCQxCXQL1HL+Kkzr1w h+NA== X-Gm-Message-State: AOAM532VCqodr8t6YeIP/MQv5cm7WJNwKfeOypvYOyRIhYBmJk3YLcXu TjQofgw5fX0jtItMxZqcrR8NR4anlHXZpg== X-Google-Smtp-Source: ABdhPJxPSxP/CI5kAHwPOy2dte/5pP9IyuWaAjbaEM+9fAKbmYSwAa7owVn6X5Q7y7JLaqQmki8zig== X-Received: by 2002:a05:600c:1d1c:: with SMTP id l28mr730642wms.69.1640145594631; Tue, 21 Dec 2021 19:59:54 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:54 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 10/17] hooks: convert worktree 'post-checkout' hook to hook library Date: Wed, 22 Dec 2021 04:59:36 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 | 26 +++++++++++--------------- hook.c | 8 ++++++++ hook.h | 6 ++++++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/builtin/worktree.c b/builtin/worktree.c index a396cfdc64e..6f03afad974 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -382,21 +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 }; - struct child_process cp = CHILD_PROCESS_INIT; - cp.no_stdin = 1; - cp.stdout_to_stderr = 1; - cp.dir = path; - strvec_pushv(&cp.env_array, env); - 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 1ad123422b2..69a215b2c3c 100644 --- a/hook.c +++ b/hook.c @@ -57,6 +57,7 @@ static int pick_next_hook(struct child_process *cp, strvec_pushv(&cp->env_array, 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 Wed Dec 22 03:59:37 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: 12691007 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF211C43217 for ; Wed, 22 Dec 2021 04:00:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238904AbhLVEAF (ORCPT ); Tue, 21 Dec 2021 23:00:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238892AbhLVD76 (ORCPT ); Tue, 21 Dec 2021 22:59:58 -0500 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 E1882C06175B for ; Tue, 21 Dec 2021 19:59:56 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id i12so692589wmq.4 for ; Tue, 21 Dec 2021 19:59:56 -0800 (PST) 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=+UOX0WuCe4CPTST0DJGyLS9XOBqaNw51sDUWCeNrbWE=; b=pkDAQ03a1xq9Sl5Dwnpi1R+E5Xl36eGkQekXtVj7Oj8R0ewG+/FCUkt2Ecq+bPE2WE yZZzjB8WN3p6STaMpr76jHi1UnwYFdgO9KDqvPa+B+9EhiodhIFHdHENSL6skvIRq2uV 5ha+g8i2+z94lnS4QSeGTFAl9NmzH9PUppDdp45xVs30adzOVPEtC3HrFcqBhFW8Hs7l j9FdZ+NMy3aAqpV8a/wQ7ObSOaNhWMvS0/dk5O2QDZekfAWNIJs0aH8UzVqL1pejo2PI MKFcg6PU1TJy0Vbayfz1YsxETOF9YBibUpqckfHPYm+8CfALcEE9ER4n0Hhh8YTwvGQp YvKg== 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=+UOX0WuCe4CPTST0DJGyLS9XOBqaNw51sDUWCeNrbWE=; b=GKMdx0l6e6yLKkVbZC9Ygov+QI8w5AM18YvT5F+EwzmueL0mC30p37qu+HvbzWUzTT WOrY01Zc8TlPs6gKvk7VH9kY1hqhrExqOqrwEI5FLUZ5hziOKOWXBJJ8WBJmxeDVsun8 ri2cmmjB9s1xtWlZCrqQxEMaxuGyDgatomm3Wh/RtOLv2n+QG8M5RvOujuaLRZPN88PG wuy0f+PjMVF7HFkMvug+FT74oe9ce8hC5Yp83c4IrRnag3E1AuhqV3LgW1dMIGuV0FC/ wNXDUV3O7W8v4NpA695VJmB1gSco7hOj89zffSbCjK/5MTob0uZ+x4mfyw0XBmSdGN9N zepw== X-Gm-Message-State: AOAM533nYOWyz3eo/oLs6oFQQGs6fCMT3j4px1mX64RlNoKAEE8h4xUQ 6O+FNSsKOV4Fbeh80j0ViJ7G3xQkOE5Uiw== X-Google-Smtp-Source: ABdhPJyVmU/OxqorfFiVS+mmDByOH61743Byr0WsZ59NNF1gY5XquXCl3PtvCTNC55sKRBBVtIEkhg== X-Received: by 2002:a05:600c:3acd:: with SMTP id d13mr941730wms.37.1640145595328; Tue, 21 Dec 2021 19:59:55 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:54 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 11/17] git hook run: add an --ignore-missing flag Date: Wed, 22 Dec 2021 04:59:37 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 Wed Dec 22 03:59:38 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: 12691009 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45973C433F5 for ; Wed, 22 Dec 2021 04:00:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239076AbhLVEAG (ORCPT ); Tue, 21 Dec 2021 23:00:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238931AbhLVD76 (ORCPT ); Tue, 21 Dec 2021 22:59:58 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7589C061763 for ; Tue, 21 Dec 2021 19:59:57 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id a83-20020a1c9856000000b00344731e044bso710681wme.1 for ; Tue, 21 Dec 2021 19:59:57 -0800 (PST) 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=LMflRAJWFPo2LUUHCj/aRw+wr8spaxRcfqdnSadEjYA=; b=BX8DUjmpNUibhNeqgF2LmPBWxZiDPRs5pcWvEEYQTa0sirteK6n3gGEOcbOcFW7h2x KQRBIq4A23FRs67y9gecJ+K4gAIejydYqygoYHLSLEpnI0eOSy8UdIYsgJicFlpwrp1a o9rLapUVjPSdfNf4tXRTqZ/443yHT7rGUt1hniUBNNLCvnplh+amnPO+ySiP3pyCJ2wU Yh420UkXhiod9vztRM153e5K/6CFbredND3G8aL+wokfi3ie6MEfrWHrISrVjYOuiErl BTBdCWcJBD1dBGa+934BA8mb4aFS6CurBI1VGfX+SH884tGY82RJEXSdT3D+xZPL0ZPv 8f/g== 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=LMflRAJWFPo2LUUHCj/aRw+wr8spaxRcfqdnSadEjYA=; b=lkhiQfKz9QVxqzArMI1+glaEp27vTJsAtfg51h2cecSHckm24KIvzLHf4kJ8mCXGOM AZ9UU4y/gLvIvRV4TxLswHS2PeiCfgqg+SP2HHus7j/w4WQLfbVSs4TshVqcggh4zfpW vCDZLAVyntV6QpY1jb6kaQeM98XPdCE69afHvc2VRvC1mykBJLokUS0fTMYnnEqt4Uw7 xCsvnDYoV44TyiRTxi3R6phvY5Wy7gjZChhaG3smYpzGNrDBGafJQpPZOrUfxWwdFUp3 u0asVhHknHpzq0fZS9q8j+INww2/jnDb9bP7CWbIOzeNj0EGq6vSGxdRCFbdpeUcUNYI 1dDQ== X-Gm-Message-State: AOAM532jrDW4VKUxo0JWWlVnBb6xkaADGVs/rYEodZt0IJrxOxfqGhDU i4Qac5u74eFCeMeGfGi6ajdVsO6ajfNVuw== X-Google-Smtp-Source: ABdhPJxS2uhA7hvEqdPIzKJdYVg9KUT5m7YI/1MLu/RzgQxswLhsJ39LI4/TSMjAGjZahV5nogp60Q== X-Received: by 2002:a05:600c:4e8d:: with SMTP id f13mr902771wmq.7.1640145596178; Tue, 21 Dec 2021 19:59:56 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:55 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 12/17] send-email: use 'git hook run' for 'sendemail-validate' Date: Wed, 22 Dec 2021 04:59:38 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 04087221aa7..a98460bdb96 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -225,13 +225,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 @@ -2075,10 +2075,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; @@ -2088,13 +2088,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 Wed Dec 22 03:59:39 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: 12691011 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEC47C4332F for ; Wed, 22 Dec 2021 04:00:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242193AbhLVEAH (ORCPT ); Tue, 21 Dec 2021 23:00:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238970AbhLVD77 (ORCPT ); Tue, 21 Dec 2021 22:59:59 -0500 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 AEB08C061574 for ; Tue, 21 Dec 2021 19:59:58 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id p1-20020a1c7401000000b00345c2d068bdso494827wmc.3 for ; Tue, 21 Dec 2021 19:59:58 -0800 (PST) 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=QYzwCnq2igDg55TYenVdAFCneRzYTszgqPq9NLVZsAw=; b=I4zoYGRPFS1BaTJBJLz8zvQwaLurte5egN/iCF9IOqgA8G0Ag8PZe50740GJ4Q6PKN UqjZJP+6yEzK7f426bLns6dX93wJiyN1yVoqWI2IG8vJ0MhNZHm2EI9fS9c08tHndH7R DyvYZd4v3SuvkJ/s9ae3Rq36pXJ7hnC14/BhoEZNtzDDcJfjL9D9KBi8xw60B0FN9GI1 2ahqjKlR2+198+u8vOE/iZOtjXPOw3z1vEf82YkJgDojH4AGllBs4YRPqn/CYGCwzz+/ jr2nu/dG7G9RMJSEOXdDnI3P7aHdwhtvCePdVEQuzlv/jnlxBR0dyKBbFOZVva7tKjFB YrmQ== 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=QYzwCnq2igDg55TYenVdAFCneRzYTszgqPq9NLVZsAw=; b=chF6bXmoF3AxcNgLAg7uwMAtEgrCUCa336ZTmciI0TM1ghdzLDZPuGzyCi9Tk2H5ei ux09IEAnD0Vjkm0WUj7sh0zTbRcSKVs52tBgetFmg1cgdx5EqlXKccznw52Qtc6BNgdN +JGrWA+CKzAwUowE+12bUCsGX5RZqE7yXp01frwM/Pes+6D1DXBYFhNEDzgoXssgLD+W 7nCyLBH0WTygE2dvQ/7NUrbatBHOuPCdaOTUGHxaxpPUqh7C/5nRpT3FY3go61IbV/4X rYKTkaqsc+8EIyMkL5IjQ7Oy3qMCo0SnL74g3jgZghQcEhahoYlzhl9jSZXropdTe3Qj 1V2w== X-Gm-Message-State: AOAM531iRF4ew+5LOFU7fmCCtGqeHqNSlUm18soCzKuIkWUWsrJBVVNL pFqb+aZFsYxcTZAaA9smF2RfDW+c2MJhQw== X-Google-Smtp-Source: ABdhPJxFGIrLeLbospIe1tlEgll/QdlOHML/H4Ybt7iaLUkp/oxuhdJ75Awu2Sa5NKIqr7a3TbYUUw== X-Received: by 2002:a1c:20c2:: with SMTP id g185mr914028wmg.115.1640145597100; Tue, 21 Dec 2021 19:59:57 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:56 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 13/17] git-p4: use 'git hook' to run hooks Date: Wed, 22 Dec 2021 04:59:39 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 Wed Dec 22 03:59:40 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: 12691013 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50A77C433F5 for ; Wed, 22 Dec 2021 04:00:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242231AbhLVEAI (ORCPT ); Tue, 21 Dec 2021 23:00:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238872AbhLVD77 (ORCPT ); Tue, 21 Dec 2021 22:59:59 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A808C061748 for ; Tue, 21 Dec 2021 19:59:59 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id e5so294420wmq.1 for ; Tue, 21 Dec 2021 19:59:59 -0800 (PST) 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=R9Vh4J5qDL1WzbfDPhI8hUBr71+QffQ8cyPXhjCK6l4=; b=lif8a4mHvpEYzKjFJbpUztXeK8ecBAUJg9BPUAYd2Qk5RnlLuH+OOhF7/inRJQFX9H 8aM/sw98gl6kiUDLvft/DNpHMsd2h6Rn8FE7F2O5nZcRV5JqEDmL9CmFQ4OwkSsgjC57 4TqxYmEf5LMgtWGLMY35qe647d9VR8m4WoBi8ixIGUFI4oopNowqUfmaKEUue5kCoAF3 pBICWhgVKmEbA5qv7+zK43PXBjGwJwlRyvTCKVtyth90Se2Q5FhWs6xtSWc2p+9O3AwI 1t90XV+328zHpGgBm/9ma5jC5XYUt1C9N+LyWYT+doMxZcy5qZ7IcuinDM9NrnIsPWXx cKUw== 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=R9Vh4J5qDL1WzbfDPhI8hUBr71+QffQ8cyPXhjCK6l4=; b=7tK0xYl6XK2jPYXnMtSPQs1Bz4N7Q9s31zR1ERDKIMPVzLlEPrBfwiK/L1KIBV37C7 F591PGOd8X5pubrV7o+ZeT0f4YMaXVBNmeCeEa0PwfcgWwXeH3MIihSzgy9QptduSeol GbF0o67Dkpax1WIy0XuyZ9528biXrSzd7hte6TTEdV6CWUq+T3rPgZfl9HlqxqWHtwRr VVrhNArNRYquC2t3GcS4xqXOL6Zq8FV4+AhTgGPL0sH8ACGDx0cnXq1MSqXsA5ihhVBM oRF4HIxMK0Irza7BZvZ4LthrhW0d/z9wgL8/08hjX6g88hZBFJa2LsNYItqxLI0F/G+W Op5A== X-Gm-Message-State: AOAM530v8WCshTbFNgcD8d9tj23R9kFDRx+kt1LyqXDsOvGznT7gmNDQ mUp6XwZbCe9iTgghrx0xZ4/fnvEAv4egRQ== X-Google-Smtp-Source: ABdhPJzwcfJ2D/CLM5TFQ51pedgAy0S8O6FTaiDJPOC1Z5hoiZmQeYT6U+CrxDMp1DVIxCGp3tXbsA== X-Received: by 2002:a05:600c:3c85:: with SMTP id bg5mr764849wmb.58.1640145597734; Tue, 21 Dec 2021 19:59:57 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:57 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 14/17] commit: convert {pre-commit,prepare-commit-msg} hook to hook.h Date: Wed, 22 Dec 2021 04:59:40 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 a348f085b2b..931f65d56d6 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 **); @@ -1702,22 +1703,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 Wed Dec 22 03:59:41 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: 12691015 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31C64C433F5 for ; Wed, 22 Dec 2021 04:00:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242248AbhLVEAL (ORCPT ); Tue, 21 Dec 2021 23:00:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238930AbhLVEAC (ORCPT ); Tue, 21 Dec 2021 23:00:02 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51A18C061751 for ; Tue, 21 Dec 2021 20:00:00 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id e5so2059126wrc.5 for ; Tue, 21 Dec 2021 20:00:00 -0800 (PST) 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=fNxjASHtk7FYsm8QZXDSWsHyExGJQmszv61J0Vq/jSI=; b=iqBQ8kd2Qmr+dfRXxJfkk5MtjvjQBY6culQs2ZGqnpvhWVSVmllO9G4JrMkenYrzy+ tiUSak4FM1fnDiy/UPpuFNrc7J63q9b5El/PzRCQNqZ2lP7WeUgJNIstrtS1fKhmLVhf R10yUVRW2Jz5epTDG5XKz6tPKlCIQ9xHP1N+wQIF8u43XKpw9VMbiN+KYVAnW3JvJzYk cSdDHEGiEOpq8twnHnRsnwX6kL8lVlW2opTT+hwTsk84mHXHDrynOXnykFDn8ElUSVXA LWVAUzZ/LfdD/wEtJMx4P+V4yMEDrpDz9zmKNftFLXfvYhOvm2TnyBezrPeb0zugqT7Y bvfw== 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=fNxjASHtk7FYsm8QZXDSWsHyExGJQmszv61J0Vq/jSI=; b=atldTa0CDXU+b+zkRp2aYuS79R2LhzmqRKwm6jqtB2T1Qqe5vL0YxfoT+3OZDymDUy mEAer2vmQo/zeiMvrdZEYclmI7VZWeS+KwzrBYCJ6RUGnTcnHODlOcAH1sO97r4Bz5Jl hN4dVX3BZ2jmV7KzYjr7xe0ZQcCl/fCas1sjDe9iWcXu4xpn2EERCmx9Np+bTc559yvR Iwx8a/FwSYUl4qZlHary3KP+Qi9gkrM3om5zKmEURE2CKgMvbZiDC7SKXpEdIpgdJDgq MPddFcnviDp+Wfzs9RDNjRrqK7466FWh7/1CfFVVjIMpcqpHIbYpfyaxrcn6tsEq3ipJ CPNg== X-Gm-Message-State: AOAM530HZ3NUw2EK6IYq1dmAZR73E5h4EB5j/q7ELUWx/3g278vg/j00 6SjQse9/XHVZPJ+5R4tSbk+sDNglKWhpFw== X-Google-Smtp-Source: ABdhPJwWS1onCRFtKjTBOXKyJvSSlMd18yHgI2RNP7UaZWM1YOfiqa7GsgdybBJBCEnGlgiKTLgdeQ== X-Received: by 2002:adf:e10e:: with SMTP id t14mr733610wrz.272.1640145598665; Tue, 21 Dec 2021 19:59:58 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:58 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 15/17] read-cache: convert post-index-change to use hook.h Date: Wed, 22 Dec 2021 04:59:41 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 cbe73f14e5e..a7fbf144fec 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 */ @@ -3150,7 +3151,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 3ea2c2fc101..ea09de040a7 100644 --- a/run-command.c +++ b/run-command.c @@ -1313,7 +1313,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 2be5f5d6422..88a398c300a 100644 --- a/run-command.h +++ b/run-command.h @@ -235,7 +235,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 Wed Dec 22 03:59:42 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: 12691017 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A959C433EF for ; Wed, 22 Dec 2021 04:00:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242261AbhLVEAN (ORCPT ); Tue, 21 Dec 2021 23:00:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238870AbhLVEAC (ORCPT ); Tue, 21 Dec 2021 23:00:02 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AF0EC061757 for ; Tue, 21 Dec 2021 20:00:01 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id c66so689327wma.5 for ; Tue, 21 Dec 2021 20:00:01 -0800 (PST) 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=ab1uxr9U2iog4UxufO1MxpAOKZi1TGVFChdPYp1iPB8=; b=ct50dJ1YjJbiyWAvhw8pb0eVinivBkrD/3eVMP36t4cFQ8zsIYGYspIM9gk1xn4kFQ 6wNQlnTGjqVdVj3mQq2fkPjJ8CkT5IydKgNlC47qZa6ysY7SodqDIRA4mXTOtCwogCjA bIRbvCSLZW/xu1DqYGSoKDVDE05bYXhsxuWVPzLTgJQ1sXt+Jv/DddeBVHnL98eDlfV7 Twlm4MBjRgoyrhfU7wD8CbiA/Nr2DJSeytk8opME1Ot5B3R6sc44P1oGg0ZSVXwKOxSH gyVqiCaZa0iTyvyv0/Qg7eJeg+2NUvX7zyF2w17nLGdhr+f41bF1YdMIhcYdd9Otf2ET GY1w== 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=ab1uxr9U2iog4UxufO1MxpAOKZi1TGVFChdPYp1iPB8=; b=z6j8byXR8O7SJjr5ksxIOIYNkK+v61oM4xSnkHUL0WZG0r8Vf/DuSHiC4hjKZOJWyA XEfeeP76uQLu+aMssrgSshl7hYKupVwk3RmFKLddfOUCk73d9WmMtoxY6lq3AnC0dW2Z 3DBMatoabrnDxUlI+q8snxxlHsetJNgrRCdJInqqFkLnGOMH2ZdTKa+F7oOtNhyoMk0C 5CkxtPJDwwg7mbYmb9zrEujKbvNMslFdrfQfelxQBN77AkCLbYMGu2JsrRx6b1VRH2eG VzbXNoJaaWqEhjVWYME5hLmm3ebbkmRH0Rr2kDC3MT4ZvPtbhGQ/ZbfBODI0gaYWIOUn +Npw== X-Gm-Message-State: AOAM5337rjFYPa/4MP52ftBLQLq/f6OPg/bVvJavn1KIJx3VKIFxNfED tMePsuEbgfOb6oaYsz2ffnbz5idcirn+1g== X-Google-Smtp-Source: ABdhPJyh2B7MWEbQxVSkjn3sdyypcLLoVE4gQG4yqHJOmGXhx0Hc75Fy8RTFIeXEai1V0kWOGHtBfA== X-Received: by 2002:a05:600c:5010:: with SMTP id n16mr746521wmr.139.1640145599480; Tue, 21 Dec 2021 19:59:59 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:58 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 16/17] receive-pack: convert push-to-checkout hook to hook.h Date: Wed, 22 Dec 2021 04:59:42 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 4f92e6f059d..e99b1ecd103 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1424,9 +1424,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 Wed Dec 22 03:59:43 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: 12691019 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20F20C433FE for ; Wed, 22 Dec 2021 04:00:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242301AbhLVEAO (ORCPT ); Tue, 21 Dec 2021 23:00:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238973AbhLVEAD (ORCPT ); Tue, 21 Dec 2021 23:00:03 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3A46C06175B for ; Tue, 21 Dec 2021 20:00:01 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id e5so2059200wrc.5 for ; Tue, 21 Dec 2021 20:00:01 -0800 (PST) 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=FREPKRs4ZWNCdjOP6rplEQxzOfMcjra5hssbyxqAsho=; b=EQ9vK8Vnxw8P2ykkNCZ0O/n1Xo0MAFQZGac2uR616OoEOwfwDxMfYw0YtbKRkx6Psn 0e0BdeMf8/Rge50NNcKg9vBMzmDgSyUi9ngWyFYKoYWN4c2nTRGoyOYpgPMf02ZzG/oG OVaA9QZhrCKB33xU7wsCxBI/YDKVuYzr+fchYtVFacIJJvvPA7tzDiOTyUdAhWLcfLAO rar6wnquw0VDQarc7LxvaULQO5g36iFT+fhifA2TQHQzptdJtG9YUGK51QGes3yhHWcD pGR5N9XSQJEN0hzcxRcT8A49MgXy4sC2xPwTK0/dKIBvUBSJgwPLKZyb3XwW23tNsT7m zowA== 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=FREPKRs4ZWNCdjOP6rplEQxzOfMcjra5hssbyxqAsho=; b=aVEwM+kk7bBUk51kt7jv8X6cvQglOe2JqCeMyaC4N7Z+DpTxeQO8u8a5M73eE2/Zup mRargBfJICUdtuNverdXpSCDE/9EWFlRJ3z9auzWF5S3lABor2xwAwmXIw5q3/NIcUkV I+gZG2Qp18EPM85yj+2Nx+3mqW0FNrH5a/o+dwPpeK/4Es+8rUi65SD5OSOCLs9Xho7R kf+xFHOetnG7BJNIIWjiWKUCVAyB5hYY5Qrd1u0Tc4tn39LcsJIq+d04HJX6zKnxO2pa TfaTmqH1pM70JWbs117y3HKNwvc/Imfq+5JS/5lFhK8qXkvhZsiLwzhE66qxxo4WCRe5 d6tg== X-Gm-Message-State: AOAM530aJJhfrBCFnLILulVfZgpEuu+2S8Uz2cXSACCjw0pQCOCSdQ6X ytFkpdLthIdbi9BgP00rGqAVNbSJAPVgxQ== X-Google-Smtp-Source: ABdhPJzkhOWlxVA85w5fx+cgHWndVATjMZrYJ1hnjeeYCr88TrNTVNTUbEB8vQr2d5+1s0u7Xs5OxQ== X-Received: by 2002:a5d:47cb:: with SMTP id o11mr701964wrc.686.1640145600242; Tue, 21 Dec 2021 20:00:00 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s8sm867300wra.9.2021.12.21.19.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 19:59:59 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Bagas Sanjaya , Emily Shaffer , =?utf-8?q?Ren=C3=A9_Scharfe?= , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v6 17/17] run-command: remove old run_hook_{le,ve}() hook API Date: Wed, 22 Dec 2021 04:59:43 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 | 33 --------------------------------- run-command.h | 16 ---------------- 2 files changed, 49 deletions(-) diff --git a/run-command.c b/run-command.c index ea09de040a7..f32e4fe1326 100644 --- a/run-command.c +++ b/run-command.c @@ -1313,39 +1313,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); - if (env) - strvec_pushv(&hook.env_array, (const char **)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 88a398c300a..07bed6c31b4 100644 --- a/run-command.h +++ b/run-command.h @@ -220,22 +220,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 */