From patchwork Tue Nov 23 11:46:00 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: 12634003 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 C00D8C433F5 for ; Tue, 23 Nov 2021 11:46:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236296AbhKWLtb (ORCPT ); Tue, 23 Nov 2021 06:49:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233877AbhKWLta (ORCPT ); Tue, 23 Nov 2021 06:49:30 -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 AD73CC061574 for ; Tue, 23 Nov 2021 03:46:22 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id 137so14927875wma.1 for ; Tue, 23 Nov 2021 03:46:22 -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=Po2ZNfuMwHGqWA+G8kbTTNJxxADKBHhKX6G+BeEw6AY=; b=pPiS5Z1sBecSmMCWCuxjf+GsASA7i90ytw7IeejryZvAWXRoRtbpdBL0oFLRVhm4t1 KasYgaa+q+mgTICVd6sNLwqMyjR6Jp1v9pcHJ1P4IhoU9d1N6pnhY6e5jhJXjeHVj2fR p833Mp1ku3lGmYRrLwSgpDjHs47pKRsOXPJxWS0FlsdJFgQqvt52RatCa0W/jCCtD+2N Z/gq5iOz3h4JCR/iPLUKbkdcZJskSdz9grTFMrzRISzd3kvh3dCXqcN0CbpKAy+uo0le Vw3+eXvefpEwA/xm/1yKylcoK1GQdDQngNPCeK8kO+TfUoD3/cJhUPUc1meHhW4eCFKI e0WA== 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=Po2ZNfuMwHGqWA+G8kbTTNJxxADKBHhKX6G+BeEw6AY=; b=qiIq1k743GwgRQMjMkFhSAAOcOR0qkE1vhPD9+lwYaDeGXaz92itSdVhahfG7jNMdK NWPhvE1srrLeyx1mQBvQ5JkEJnRbfy4Dt3vb0h12bcJwSjiC4sgYpE77sqMRFdgIhWJt +pEayOpr91yCj5WtxduNFrSF1aGVDroEzZFWucA1ukTgolRpSOBx3FN6cwB29DIo4vi1 H2jEyvu9D9iUBeove52qP8/m9ghsyDjo3r8f3wnoMcsmOIYOso/askX8EQo7bOAlV3aq 5oU8CcRfBB1d0yGDebBqUlmb3QEwboIIdY1edU1g+1LhQNxUqfFgX80/Jb9/J0YXuAO7 vaDQ== X-Gm-Message-State: AOAM5331IicNN3lXgNeRN72eVfKUsoLvSK6CMldJYMXnxnN1xBj9OhK0 daPavkr4I7KOPsOV6E8dzuo70w0O/T8Uxw== X-Google-Smtp-Source: ABdhPJwo+kYv+dEFJTjemV40W86FVh3TPa3onJj9V5HQGf8Icv1WvLBxQxWQDJ22hRKh4bzF/4kgeA== X-Received: by 2002:a05:600c:2147:: with SMTP id v7mr2386388wml.36.1637667980898; Tue, 23 Nov 2021 03:46:20 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:20 -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 v5 01/17] hook: add 'run' subcommand Date: Tue, 23 Nov 2021 12:46:00 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer In order to enable hooks to be run as an external process, by a standalone Git command, or by tools which wrap Git, provide an external means to run all configured hook commands for a given hook event. Most of our hooks require more complex functionality than this, but let's start with the bare minimum required to support our simplest hooks. In terms of implementation the usage_with_options() and "goto usage" pattern here mirrors that of builtin/{commit-graph,multi-pack-index}.c. Some of the implementation here, such as a function being named run_hooks_opt() when it's tasked with running one hook, to using the run_processes_parallel_tr2() API to run with jobs=1 is somewhere between a bit odd and and an overkill for the current features of this "hook run" command and the hook.[ch] API. This code will eventually be able to run multiple hooks declared in config in parallel, by starting out with these names and APIs we reduce the later churn of renaming functions, switching from the run_command() to run_processes_parallel_tr2() API etc. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- .gitignore | 1 + Documentation/git-hook.txt | 37 +++++++++++ Documentation/githooks.txt | 4 ++ Makefile | 1 + builtin.h | 1 + builtin/hook.c | 80 +++++++++++++++++++++++ command-list.txt | 1 + git.c | 1 + hook.c | 102 +++++++++++++++++++++++++++++ hook.h | 35 ++++++++++ t/t1800-hook.sh | 129 +++++++++++++++++++++++++++++++++++++ 11 files changed, 392 insertions(+) create mode 100644 Documentation/git-hook.txt create mode 100644 builtin/hook.c create mode 100755 t/t1800-hook.sh diff --git a/.gitignore b/.gitignore index 054249b20a8..f817c509ec0 100644 --- a/.gitignore +++ b/.gitignore @@ -77,6 +77,7 @@ /git-grep /git-hash-object /git-help +/git-hook /git-http-backend /git-http-fetch /git-http-push diff --git a/Documentation/git-hook.txt b/Documentation/git-hook.txt new file mode 100644 index 00000000000..e39b1b5d069 --- /dev/null +++ b/Documentation/git-hook.txt @@ -0,0 +1,37 @@ +git-hook(1) +=========== + +NAME +---- +git-hook - Run git hooks + +SYNOPSIS +-------- +[verse] +'git hook' run [-- ] + +DESCRIPTION +----------- + +A command interface to running git hooks (see linkgit:githooks[5]), +for use by other scripted git commands. + +SUBCOMMANDS +----------- + +run:: + Run the `` hook. See linkgit:githooks[5] for + supported hook names. ++ + +Any positional arguments to the hook should be passed after a +mandatory `--` (or `--end-of-options`, see linkgit:gitcli[7]). See +linkgit:githooks[5] for arguments hooks might expect (if any). + +SEE ALSO +-------- +linkgit:githooks[5] + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index b51959ff941..a16e62bc8c8 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -698,6 +698,10 @@ and "0" meaning they were not. Only one parameter should be set to "1" when the hook runs. The hook running passing "1", "1" should not be possible. +SEE ALSO +-------- +linkgit:git-hook[1] + GIT --- Part of the linkgit:git[1] suite diff --git a/Makefile b/Makefile index 12be39ac497..6cd20534304 100644 --- a/Makefile +++ b/Makefile @@ -1107,6 +1107,7 @@ BUILTIN_OBJS += builtin/get-tar-commit-id.o BUILTIN_OBJS += builtin/grep.o BUILTIN_OBJS += builtin/hash-object.o BUILTIN_OBJS += builtin/help.o +BUILTIN_OBJS += builtin/hook.o BUILTIN_OBJS += builtin/index-pack.o BUILTIN_OBJS += builtin/init-db.o BUILTIN_OBJS += builtin/interpret-trailers.o diff --git a/builtin.h b/builtin.h index 8a58743ed63..83379f3832c 100644 --- a/builtin.h +++ b/builtin.h @@ -164,6 +164,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix); int cmd_grep(int argc, const char **argv, const char *prefix); int cmd_hash_object(int argc, const char **argv, const char *prefix); int cmd_help(int argc, const char **argv, const char *prefix); +int cmd_hook(int argc, const char **argv, const char *prefix); int cmd_index_pack(int argc, const char **argv, const char *prefix); int cmd_init_db(int argc, const char **argv, const char *prefix); int cmd_interpret_trailers(int argc, const char **argv, const char *prefix); diff --git a/builtin/hook.c b/builtin/hook.c new file mode 100644 index 00000000000..9b67ff50cef --- /dev/null +++ b/builtin/hook.c @@ -0,0 +1,80 @@ +#include "cache.h" +#include "builtin.h" +#include "config.h" +#include "hook.h" +#include "parse-options.h" +#include "strbuf.h" +#include "strvec.h" + +#define BUILTIN_HOOK_RUN_USAGE \ + N_("git hook run [-- ]") + +static const char * const builtin_hook_usage[] = { + BUILTIN_HOOK_RUN_USAGE, + NULL +}; + +static const char * const builtin_hook_run_usage[] = { + BUILTIN_HOOK_RUN_USAGE, + NULL +}; + +static int run(int argc, const char **argv, const char *prefix) +{ + int i; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + const char *hook_name; + struct option run_options[] = { + OPT_END(), + }; + int ret; + + argc = parse_options(argc, argv, prefix, run_options, + builtin_hook_run_usage, + PARSE_OPT_KEEP_DASHDASH); + + if (!argc) + goto usage; + + /* + * Having a -- for "run" when providing is + * mandatory. + */ + if (argc > 1 && strcmp(argv[1], "--") && + strcmp(argv[1], "--end-of-options")) + goto usage; + + /* Add our arguments, start after -- */ + for (i = 2 ; i < argc; i++) + strvec_push(&opt.args, argv[i]); + + /* Need to take into account core.hooksPath */ + git_config(git_default_config, NULL); + + hook_name = argv[0]; + opt.error_if_missing = 1; + ret = run_hooks_opt(hook_name, &opt); + if (ret < 0) /* error() return */ + ret = 1; + return ret; +usage: + usage_with_options(builtin_hook_run_usage, run_options); +} + +int cmd_hook(int argc, const char **argv, const char *prefix) +{ + struct option builtin_hook_options[] = { + OPT_END(), + }; + + argc = parse_options(argc, argv, NULL, builtin_hook_options, + builtin_hook_usage, PARSE_OPT_STOP_AT_NON_OPTION); + if (!argc) + goto usage; + + if (!strcmp(argv[0], "run")) + return run(argc, argv, prefix); + +usage: + usage_with_options(builtin_hook_usage, builtin_hook_options); +} diff --git a/command-list.txt b/command-list.txt index eb9cee8dee9..0c9af14bdf3 100644 --- a/command-list.txt +++ b/command-list.txt @@ -103,6 +103,7 @@ git-grep mainporcelain info git-gui mainporcelain git-hash-object plumbingmanipulators git-help ancillaryinterrogators complete +git-hook purehelpers git-http-backend synchingrepositories git-http-fetch synchelpers git-http-push synchelpers diff --git a/git.c b/git.c index 5ff21be21f3..a5be02b04b8 100644 --- a/git.c +++ b/git.c @@ -538,6 +538,7 @@ static struct cmd_struct commands[] = { { "grep", cmd_grep, RUN_SETUP_GENTLY }, { "hash-object", cmd_hash_object }, { "help", cmd_help }, + { "hook", cmd_hook, RUN_SETUP }, { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY | NO_PARSEOPT }, { "init", cmd_init_db }, { "init-db", cmd_init_db }, diff --git a/hook.c b/hook.c index 55e1145a4b7..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 Tue Nov 23 11:46:01 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: 12634007 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 4E836C433EF for ; Tue, 23 Nov 2021 11:46:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236366AbhKWLtd (ORCPT ); Tue, 23 Nov 2021 06:49:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233877AbhKWLtb (ORCPT ); Tue, 23 Nov 2021 06:49:31 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B15C2C061574 for ; Tue, 23 Nov 2021 03:46:23 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id p3-20020a05600c1d8300b003334fab53afso1960196wms.3 for ; Tue, 23 Nov 2021 03:46:23 -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=xyNb1suCSqW3g8YzXeaOzn+qvYklup8sHtg8NBE9Vok=; b=CYwpJ7PWtASjSvsejdZkzTKyq/+u6RSLc1ifDsQ33kC9Ft0lYWvKBsYHZq+keynQwq xvdr0uL/1tPji1bB+O71jkc0tGRsJIw1p5jpPzDlPl4mYvbvieAQE1UnKP2UvOfPHZJl RYS5j8MiUSu2ZrUJHyEJlx607dY8Qaox25c5taIIl6ttgEkow502wg+ghM2mf0YbaPqc P78E66JBHpAednNONq7C0p5BX0i4yZgBbai/9VW0xvG/OvAptSKYBiPQ8+bz6j4Kn0kZ oXTD5SnMDgegLoVXVfj9Zsf+019x8RykTFI6i+0/Js9G0UYiwuTEWrlreDqqjYibDtjt iR0g== 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=xyNb1suCSqW3g8YzXeaOzn+qvYklup8sHtg8NBE9Vok=; b=AaC3ptOKE/YO8A5kJxj8Jd41+Mn83zp4QNJotcQHnwsJthD8ng8w2imq7VLUJ0MiEm hxSb3tP5IMIw8J0ce7uosNStl1VmX8r235PYgeZys1m2PiktvU8OKeUwaZiW1Hg5QtZo 4o8kjzZYf6k5mRzM9fKQu3D/Hkm2qJKPeAO04tuhRHWL7tnepYeZa6b2hb8JDdh6fljo 7K98VGCLjfE8/jmTX/kjcijnHNLyu+CAmmj1DvxSltauACpsao5NjctTtUOaLSL+5aC8 550jkKFq9j4Y42r3Lt8ugqwN8mzZT3lsICEMol4l9bi7xATGLUnnVy0F2d4Vwch6HYp7 SPLw== X-Gm-Message-State: AOAM530y1TZJ5H3PN0RUDnr2DYsMOIceWYqYod5+OgKOHmVLK7Dvpq+a 3HpDaFrmyl35R1TJZk1bpX0g7jpIjPkuFg== X-Google-Smtp-Source: ABdhPJwsd21QM03La9EpZj6yZ910ByhzD2ZameSLUvKa0cUUL+bvphP+G7oxv+skoBylPgODIf5t5g== X-Received: by 2002:a7b:c744:: with SMTP id w4mr2382880wmk.50.1637667982070; Tue, 23 Nov 2021 03:46:22 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:21 -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 v5 02/17] hook API: add a run_hooks() wrapper Date: Tue, 23 Nov 2021 12:46:01 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 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 Tue Nov 23 11:46:02 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: 12634005 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 070C9C4332F for ; Tue, 23 Nov 2021 11:46:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236424AbhKWLte (ORCPT ); Tue, 23 Nov 2021 06:49:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236331AbhKWLtc (ORCPT ); Tue, 23 Nov 2021 06:49:32 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94121C061714 for ; Tue, 23 Nov 2021 03:46:24 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id c4so38412057wrd.9 for ; Tue, 23 Nov 2021 03:46:24 -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=GO0ZFMe/NSOGk9Bn4gj5ngKAwcEssKVuldI55usff28=; b=AGXKQyfUAx1P3C/GNqgHUCcZ5sNYy6XodCIEpLTfP0EF7qgd9kafa1ILa/C6jvDW43 6jURmexxaBiRBY9rcvRZAVgXvYMiYxdR/1uX8Bu9M+LnTHvIMe98u7pZSDr9j4EIriXX 8GO9qBeacu+VA6/fMSJMEgzB4qLev7rf6/VAua61mxGbfwFw7SzAk/bwBcQDv6XDjvCT oBKsvCHRLDCUo9rZK7BhfSiqsz8si0PwystR3/RYsU4KqsiSwL65OKI1zgikJ2fG/Ozs Zl2x04Inm5kwdTUMpkVBDrr0ZdMHS93MM+q9cGLo42bBLR/QU6pO6d8JYwI/xk3+KZrw xNUQ== 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=GO0ZFMe/NSOGk9Bn4gj5ngKAwcEssKVuldI55usff28=; b=078733k4BoZzf0ofjAg3N28r7olM3TlAIQG7oVF/J75xXXdrFnJsDAPzSula/TUK3e jbIyd5C+XI+zLkvF7x7mWK+lKse9TzHoJniXPkMrlelG8WIMGP6Ud5D2wwkMrl7zy+Ow 7Mm6vWrchhQiN0AxCrVH5xhdJChxyDq4iYzf1KJNac18d3/4a5d5Znn2oIeSGQ2cCvD5 PzdDCDaryE/PVBu+a8aPcUEbSUCYS+8FydpWG+84qT0k8SCHdXGVJ7jfQa6/7abOXHv8 psDlRAXnYqJ1zCfdERG2R/48mh7G2km10CRRE2dgCt32/DGZVO/UUKmQE1BxigSrrA2o u+SA== X-Gm-Message-State: AOAM531VBmZ2lPexFXOIRgdPq3MzDEaOEJjrSufAQDlZBiHI9ns6GVuH NwIRUbjiQZORy4l6MELq03Da4AyB30KQ/g== X-Google-Smtp-Source: ABdhPJx+CzeToh1HgNdAIeNZyCBwA4g89lrPt0mIY6IV3GxsmlYD0696q5tZ2ftu9JMDFkomlRiwtw== X-Received: by 2002:a5d:46cb:: with SMTP id g11mr6535078wrs.26.1637667982958; Tue, 23 Nov 2021 03:46:22 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:22 -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 v5 03/17] gc: use hook library for pre-auto-gc hook Date: Tue, 23 Nov 2021 12:46:02 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 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 Tue Nov 23 11:46:03 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: 12634011 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 25DD5C433EF for ; Tue, 23 Nov 2021 11:46:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236482AbhKWLto (ORCPT ); Tue, 23 Nov 2021 06:49:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233877AbhKWLtd (ORCPT ); Tue, 23 Nov 2021 06:49:33 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96200C061746 for ; Tue, 23 Nov 2021 03:46:25 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id r9-20020a7bc089000000b00332f4abf43fso1771779wmh.0 for ; Tue, 23 Nov 2021 03:46:25 -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=6mAVKMVNALo31TFHc0kKoUnf6Q7cV1M2z+G0+o3HaFY=; b=UAr/AoSHaDXdrC/+fXcQNEl5sTH1l2gqlHD+ADM5QFr3XdMQNG7Qn7/GmaXV6Zsq0z 1F2qfVjjK+1kzPrHgRywWSoNCZlM+gi10JgJtgfszyebK2IXkz5FQuJAidHVuk0+GrfW oTcI7/w/PYcrLqmCjiUNamMfcBuCD4oX9yqlh6CIzT/xmqQBlxESUTwlQB0WpP28Kh+n uAtlaq3gHLUrQHjnrVpsrxK/77raCBqnG/6XFxvjfSedN8dvuwOriwuKrBkhIYlQTrMg qVUxpOQOw961RrIAtMGv13GYLgi/c2ae3qKH9yBYX7wpNpe17zoSR2vAKjhNIQNEWuv9 OdmA== 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=6mAVKMVNALo31TFHc0kKoUnf6Q7cV1M2z+G0+o3HaFY=; b=GphkyYtfnoe017OE/yw5QV/HuqVwL3/BG3VTrjvunBuYh+itVuNOW/QdNa1unWGu6E cGBC+FXEO3dxNrBPmGQNQi0Sz04anHS9Nt5JT7mi4qUGGEnwpgp3APFRNYWWZxZhcRKc aBcfjFRmhT40UaDqwafU6pYEz0V9hlzrm0Ut5HIrsHqcJeobmVQ6CppQ11CqjwOeK07t qUAPjJQAwipnl4R5VPKztKaT2llVJRwwhzIMXTMkS6foeZ1s4M0hPqtG4+RtoV9nj/S9 xAQUjtwQIUjjWHbo7W7dF1wPUlu0xO/Ma+Ox1kyf5SQ6go8eQh+U2837mMeHJ0/AmwxA 5tig== X-Gm-Message-State: AOAM530ouwnfejURkQkrrP3HBEYRmblRlzkVROt6VDshjo5H9nmxG1dE SMPRarbu6I4k2amiSXPz4XAbgPrr+Jk6iA== X-Google-Smtp-Source: ABdhPJyyzGapnRsaB5py+QnJ7vJtfS9uCaYreLMEFiTKwb8kCBf79hM9QxIsSfQQR5R1ATPgJO5s9g== X-Received: by 2002:a1c:43c2:: with SMTP id q185mr2280992wma.30.1637667983774; Tue, 23 Nov 2021 03:46:23 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:23 -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 v5 04/17] am: convert {pre,post}-applypatch to use hook.h Date: Tue, 23 Nov 2021 12:46:03 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 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 Tue Nov 23 11:46:04 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: 12634013 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 0C29DC433F5 for ; Tue, 23 Nov 2021 11:46:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236427AbhKWLtn (ORCPT ); Tue, 23 Nov 2021 06:49:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236433AbhKWLtj (ORCPT ); Tue, 23 Nov 2021 06:49:39 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69808C061756 for ; Tue, 23 Nov 2021 03:46:26 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id i12so18466591wmq.4 for ; Tue, 23 Nov 2021 03:46:26 -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=OShlwfF+mae5Bcjh2nUUN9AZwGcvofZJSKoCo9MAg18=; b=oTbcEI53VCwOUIwG5LbJ5JjdI4narJwrv0EfrwxPCBCdyAwcHj0qhZ63KVWrybMtu9 OxlrdZtEIvJRgQlf69qJlb0cWIMLnRW8vFEoqiHk4HTLp7Odp2Ri9SUvW34fxpV3IG+f iMNX5ifGjUwiOlTXtQ4/tAzNNPB+gZO1yWlVbukoS2Y7DGd/RyyPXYG1BloMLVH/Cmuv /OEFDmvs/ysTu7QSQwRJWEJt5BwSeQVhZnfHkGCfXY4k5mcYWi6Io7a6V6siCHTHpT/t 9w5R7n3klT4snwAERo/Awdj3UY1goJHrbpQVuSWkQMivrnFSesC9IbEyDtmjUZ910Ddo fO4Q== 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=OShlwfF+mae5Bcjh2nUUN9AZwGcvofZJSKoCo9MAg18=; b=pL3HMGve0F2CZ1PRpU8rNZlvBvXZzJbC+2ZRLEFYMJsLXM1tpiBVQq066JDMUMYlGS FNOXtpp9m/tuCYtiWa0sszN/0UdjZVoejI8PY0tQcNqU0kBpnTM4I1BVkzWG8XJyk9d1 Rx0GerijTNDSp0nd8PvLi376wIaH5T0Y1K0i39oKvNnKWjWZmBf7JNJcqEFXiJdTbwre EjZfGkHmV8LApdPzdRNPDCoWQ3Ai14/yxhkI+R3e55+ipICYwRf38ypKWeI1hpq0TgA5 HUHma5oEtm9ytJdjX2sqG9tda38srdhm6T47fJ1nAXc+D+s9I4yoYEdmsLI0MMNbUAYX u9EA== X-Gm-Message-State: AOAM531wFDBOPQYdXtTVI++ohHk4DAPv2phmvjsQ35Jfi72fMLH6sNVn 9XojRKxizJE3l4P8vpgwTa8I8rgBk8wRiQ== X-Google-Smtp-Source: ABdhPJzngWVcQQjMPHP8/IK6YVFpKKJdXKMWDNf1hyzLufpGxWnlXHBne5EyhXbSSILjrcFMmmEcKg== X-Received: by 2002:a05:600c:350c:: with SMTP id h12mr2196826wmq.123.1637667984765; Tue, 23 Nov 2021 03:46:24 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:24 -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 v5 05/17] hook API: add a run_hooks_l() wrapper Date: Tue, 23 Nov 2021 12:46:04 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a run_hooks_l() wrapper, we'll use it in subsequent commits for the simple cases of wanting to run a single hook under a given name along with a list of arguments. Signed-off-by: Ævar Arnfjörð Bjarmason --- hook.c | 14 ++++++++++++++ hook.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/hook.c b/hook.c index 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 Tue Nov 23 11:46:05 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: 12634009 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 085BDC433EF for ; Tue, 23 Nov 2021 11:46:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236511AbhKWLtl (ORCPT ); Tue, 23 Nov 2021 06:49:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236328AbhKWLtk (ORCPT ); Tue, 23 Nov 2021 06:49:40 -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 629B0C061758 for ; Tue, 23 Nov 2021 03:46:27 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id s13so38513112wrb.3 for ; Tue, 23 Nov 2021 03:46:27 -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=N7peUV3h502g753BqcnwIVv10kL5TWPjblOYcrDNC7o=; b=eMYhbpfoblG2w70mzpd+iISzMy9cDZ2Fdg6jqC3S3O3+DWIqPUEc4ypK+PIuxUmHC+ 5sIX+e7HsXGwF6Uqibat++JyUIn/00Ef1pnvcDevxlay4VrhMiRRg4j9h5oXFp3bpKpk dat0rgto55B9etKWhd53etdDnxanmDZSD4GjcWTFgeH4t7xM18g9FLRRZ+NOov73ZdPp 4dGseg0XEMX25mUSxkJREVAkClbBRnV/3hURcG6p7UBigSa2CC80i+pX/cOa/hKZSvM4 WrlyYA8gF6SMiJqWrR8HvzNXQM0bEXiSbr9aGI5yv5CazrYYMPDeYCkJJWsVcaMazKGx JITg== 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=N7peUV3h502g753BqcnwIVv10kL5TWPjblOYcrDNC7o=; b=pYCqaqrpLnZXIkoHSl3oqbj7XlySXsrctqpU4F+JAgQDVZ6FpRiHHIzP+8UC7a1xHB hlV4uPUnb7FE/Vf7AJMt3E/myXL2ZDEl7yE0CuUNuVfsBEX3NdsCQisJRQXHY+0MAaCp Gc5Ljgc0d+UfWtgNT0gybu4K/VK/j+yshKzisT+bPb92ZUAr3VzApu99i0oHdCUkZ10d +TYUdo5jdrwBm2yIsHRHBKcVIJDiSE7+i7f/CdkRfPNBTksdtcasY7V8iZMNWfCR8hM3 gcEOJFLVw6en6l6ozYfC9XNm4c+/Tn5KKzseqfNu5cg8hlatMJfJxzyoMgiCWs2wG2De 2wZg== X-Gm-Message-State: AOAM533dFRjwSt3lztf/E8ovmsK26knginbHv/n3cPRG58v+G9gphYaN y7zHmbp9mkgXzmmFbOLx5G7avPNxZdKoGA== X-Google-Smtp-Source: ABdhPJwHwviJZyMCQr+stjvZUhj9Ju2VhhJe5P9Sf7g2gmQs9a065Co5PUkVEagpASpYes5f8GGleQ== X-Received: by 2002:adf:e5c7:: with SMTP id a7mr6332546wrn.318.1637667985758; Tue, 23 Nov 2021 03:46:25 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:25 -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 v5 06/17] rebase: convert pre-rebase to use hook.h Date: Tue, 23 Nov 2021 12:46:05 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 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 Tue Nov 23 11:46:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634017 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 17CA1C433F5 for ; Tue, 23 Nov 2021 11:46:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236514AbhKWLtr (ORCPT ); Tue, 23 Nov 2021 06:49:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236453AbhKWLtk (ORCPT ); Tue, 23 Nov 2021 06:49:40 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5799FC061761 for ; Tue, 23 Nov 2021 03:46:28 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id l16so508396wrp.11 for ; Tue, 23 Nov 2021 03:46:28 -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=r2KPCn8putcSw/APO9sbh7+Kz0gX2vznhcz7pHZj0/g=; b=L96MX+Ca/gvcO8RR3Trsw1f7fhFotjsS7za8vGG6S9STa72qH1gD/daazdySHgHd3+ KvAiFC8fXfPJOAcWagTEVk/0cTMwH7xdmlUbO/B5R9gA6R6K7qaPBn+y5RRGMg1P5ZTo k8TDW/ZgYtZGNZ2Uxlg9anT0/Ydvf/tEcmvBsrnKIjtv3d+IzOh28b4HRe0X1DiuSSl8 GNL7cLuPQsNobfSoXSME+qNCEWlKUGPIHFUBIT4U1nI2z9qCzwhpAy/pOY0Te+Hgnuh6 HYH6cVPBbqVSZlE0UTijVBLIXqpmOZSEgAkDqFotJDwYOb8z+HBnaIEuJxN5yMyBiq7c JE1g== 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=r2KPCn8putcSw/APO9sbh7+Kz0gX2vznhcz7pHZj0/g=; b=LRuTAScuWF7PHAtzDcPaEsvPbK9mKNVKiC0C2OBYz3WOpTQC0LtLyj47UoCUF1LEyk 8eFKoA1e5IqGTgSSXeA1PSOFESLZAO8sgjy4Gu3EXiMx559OTRV3FCT/4l1mR3Ylg0FM sTFoNZa5pMHkZQ+zw3WVrRxAuGkspIYhkxewWVQ4tF5AjdVt+JfzZWBOPci6zH/XUChn 2D1eV/39UdSo1d6443z8+VdOsS9O2n1ybGR8HaDX4aMA5SJA8iR/G46Uq7f9eFWcKsBU iO26nV548sXlUPDlmrEOdjKugJZrVI58uhKs9rKL7Zy0dJxHQ6P4XuoGot6X0fELfDir /kZQ== X-Gm-Message-State: AOAM531YCzEBMSepKlicuUoCiOoWbc6z0Cy/0/APfTHXkE3ahka3jU8i WJitpQI5bJw5fbVlzYRFETmCMktjhQImpw== X-Google-Smtp-Source: ABdhPJwJjty+dETupOZrI2bhkzHKB1REDrP5iA7QKS9chmhzGYOo10tdmLXEvm4qwRMea95bAYbXTw== X-Received: by 2002:a5d:4582:: with SMTP id p2mr6622004wrq.364.1637667986658; Tue, 23 Nov 2021 03:46:26 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:26 -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 v5 07/17] am: convert applypatch-msg to use hook.h Date: Tue, 23 Nov 2021 12:46:06 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 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 Tue Nov 23 11:46:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634015 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 31DEAC4332F for ; Tue, 23 Nov 2021 11:46:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236340AbhKWLtp (ORCPT ); Tue, 23 Nov 2021 06:49:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236455AbhKWLtk (ORCPT ); Tue, 23 Nov 2021 06:49:40 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26450C061763 for ; Tue, 23 Nov 2021 03:46:29 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id a9so38443550wrr.8 for ; Tue, 23 Nov 2021 03:46:29 -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=ycsl7qYc/5fSrAoXHxS9HM2S7S3ofNPq9Jqs+qOaEj4=; b=F0QrK+VF8Hnlacf3GP3HybQJzM8j9/ckEdORn6q5wIsbapcGViroL53Viz1ksB6S1w ymd3ooWHh9ZUnsZ67G/DrTLKVKpbJntPANVRMmes2YKQeMi5TfYh9VJdLprLWZqoDpnY ry6raRUHc5FPpK8jD6xBiFjlryaNbNi3WVbuVc53M7U5OWuYhaWp7VZZRJfGfw4WEh5s fIFZI1gdcInla6eoyQM+7mpgFwK0E7YSdXLcO/Ph+ApK4b4mosZ00G88uJATt3AGm5q1 1MtoBilyum064EnVrrzLEKKuYiWA7ZIXBz3BtuCQQVxi4kmao2oLolOmMd9HFachScKD zp3Q== 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=ycsl7qYc/5fSrAoXHxS9HM2S7S3ofNPq9Jqs+qOaEj4=; b=yA6qGeGBY31DfZA7GjPPbgB4Pn+J6ANzwM6EgPXN+NRP+HhbcTQPXA1SE/axbB8NeB 8VgWpipnk2hBVPJG79X3oK9k7/eEXcF525ceJQp7R4YGVdxxzi7FZIYFDe0xxjk9Aw4L dpcrP9aFuWHuw36UAVPrmLa1oRRX1DNQyHW5IhHRmvGo1/tT5Pzx/NxgjDu0H8/KbtpW 23cehUhfwNNNcEdYQPTVgLG0P6u0xr0wieoQRMfCgCqRamzacQ0SZe28OMOo38GuF9xg e455lgFafLg74zMBCvNv9u6spCCt4V+QHzKNZBXUdwf6O9D8fO+FZvszMSD4DavLmsL6 vZcQ== X-Gm-Message-State: AOAM532MrVXeOcIfFd/8DziCbYdALHaPzCKR2gilhaZhKFiqvLJA+LeB dHVb5fyz16E9v8SvgRc8uIB30NPIU3sujg== X-Google-Smtp-Source: ABdhPJw9qBim9Ol8VUs529nfutphDwwXJaUe8NXdKcPcJTGqWZTOQcCt82v6v1CN4rLfaZnCDL4gWw== X-Received: by 2002:a5d:6da9:: with SMTP id u9mr6957516wrs.237.1637667987543; Tue, 23 Nov 2021 03:46:27 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:26 -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 v5 08/17] merge: convert post-merge to use hook.h Date: Tue, 23 Nov 2021 12:46:07 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Teach post-merge to use the hook.h library instead of the run-command.h library to run hooks. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/merge.c b/builtin/merge.c index ea3112e0c0b..e6facd1c95d 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -488,7 +488,7 @@ static void finish(struct commit *head_commit, } /* Run a post-merge hook */ - run_hook_le(NULL, "post-merge", squash ? "1" : "0", NULL); + run_hooks_l("post-merge", squash ? "1" : "0", NULL); apply_autostash(git_path_merge_autostash(the_repository)); strbuf_release(&reflog_message); From patchwork Tue Nov 23 11:46:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634035 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 DE1F2C433EF for ; Tue, 23 Nov 2021 11:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236639AbhKWLuD (ORCPT ); Tue, 23 Nov 2021 06:50:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236466AbhKWLtk (ORCPT ); Tue, 23 Nov 2021 06:49:40 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07B98C0613E0 for ; Tue, 23 Nov 2021 03:46:30 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id d24so38534061wra.0 for ; Tue, 23 Nov 2021 03:46:29 -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=p+lXTBdQs+y2f8EPIlH6LT7vkrHqlHb5zjym8NAfE7w=; b=UMjHSLrqC8e4RrluZDnK1xso63uippkUuK2pVIhURIaotsYThyjpcagWeezDUFVJxT 314xn3s9c8CUxw+sMZgWRjFYI9zgEuVRaho6PMe+1y0wcxG2iLzF6UwaVC/k2VUs+oJr pMDXS7mUdpoXIRz8usEOoLiqKlGjf4UlCs750og6dlRdBQ6jvZjLwJiCQczvMWLqynkS XSDSHLvy6mbD3itneBSDi/rQwNcgY1evE7wRp9W/EVSz7uCKgD9gz+Fe45oNu1xFsVN0 WHJEvdGYQDm0CGic1jfeEr1+gGqq/anAEjBgepZWIFUjaLQ/COemFIa7rUPBlWUPAKud R7bA== 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=p+lXTBdQs+y2f8EPIlH6LT7vkrHqlHb5zjym8NAfE7w=; b=ajxxgZlW5js8DTAoBTgW96TmlITUb4PK66ljQTh544APu97/wyMRXoeqnc4vHrfKke 35P0vr5yFDlPuWQkOInoxDj2mKdkMDy/ThblemI1Wr+6k4+LS7/eRdbnkgNIfw/9vydl fjadWrpvo0e3AmbBs0guNd/w3G4KzVAXN++/63jmVHPeZ+A9e+0JnHbmc853HR4gvKa3 Qy0AW0PxPoz3/oGH7G+fBwqNg8mRKuCQAriEetILDdIwVpeYIccVdJzvpRMRX6lKlS2a bQafXT5G+H3giwr87SSchKVJ6WwPQ/TSyQr6wq4PTNB7nrqcRbZJM6i867X3gUjmgHLV wLyw== X-Gm-Message-State: AOAM5306fpixQI1UunPJaiMEunSKn6U3oPm8zJ8hSL3tI97RBKIbg+J3 WGv3yj4c3RXi29LBhO8RBXyxqKYVVunkOQ== X-Google-Smtp-Source: ABdhPJzi8pbWFvlOgSQISOygaxAaqf2a1vmoDS+LyjlCeS5LlTY6bHXivl11wYdGcwPEyj7jh8loTA== X-Received: by 2002:adf:cf05:: with SMTP id o5mr6769858wrj.325.1637667988361; Tue, 23 Nov 2021 03:46:28 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:27 -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 v5 09/17] hooks: convert non-worktree 'post-checkout' hook to hook library Date: Tue, 23 Nov 2021 12:46:08 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the running of the 'post-checkout' hook away from run-command.h to the new hook.h library, except in the case of builtin/worktree.c. That special-case will be handled in a subsequent commit. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/checkout.c | 3 ++- builtin/clone.c | 3 ++- reset.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index cbf73b8c9f6..4af17d17217 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -9,6 +9,7 @@ #include "config.h" #include "diff.h" #include "dir.h" +#include "hook.h" #include "ll-merge.h" #include "lockfile.h" #include "merge-recursive.h" @@ -106,7 +107,7 @@ struct branch_info { static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit, int changed) { - return run_hook_le(NULL, "post-checkout", + return run_hooks_l("post-checkout", oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()), oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()), changed ? "1" : "0", NULL); diff --git a/builtin/clone.c b/builtin/clone.c index fb377b27657..ee27b9f8114 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -32,6 +32,7 @@ #include "connected.h" #include "packfile.h" #include "list-objects-filter-options.h" +#include "hook.h" /* * Overall FIXMEs: @@ -705,7 +706,7 @@ static int checkout(int submodule_progress) if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) die(_("unable to write new index file")); - err |= run_hook_le(NULL, "post-checkout", oid_to_hex(null_oid()), + err |= run_hooks_l("post-checkout", oid_to_hex(null_oid()), oid_to_hex(&oid), "1", NULL); if (!err && (option_recurse_submodules.nr > 0)) { diff --git a/reset.c b/reset.c index f214df3d96c..0881e636915 100644 --- a/reset.c +++ b/reset.c @@ -7,6 +7,7 @@ #include "tree-walk.h" #include "tree.h" #include "unpack-trees.h" +#include "hook.h" int reset_head(struct repository *r, struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -127,7 +128,7 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action, reflog_head); } if (run_hook) - run_hook_le(NULL, "post-checkout", + run_hooks_l("post-checkout", oid_to_hex(orig ? orig : null_oid()), oid_to_hex(oid), "1", NULL); From patchwork Tue Nov 23 11:46:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634019 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 2C9E3C433FE for ; Tue, 23 Nov 2021 11:46:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236446AbhKWLtt (ORCPT ); Tue, 23 Nov 2021 06:49:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236480AbhKWLtk (ORCPT ); Tue, 23 Nov 2021 06:49:40 -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 0BE42C0613F4 for ; Tue, 23 Nov 2021 03:46:31 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id o19-20020a1c7513000000b0033a93202467so2325393wmc.2 for ; Tue, 23 Nov 2021 03:46:30 -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=DAsytXaxXjOs1TERHWkOTicdxYVnof0YOd+nc8NYEG4=; b=Pt9O/EN3vI5H3F5gKFfqwe6/gTxYyBBuxDJ8MqONkER+1o7494Nf31LMpfU/BwgX7Z 9avpr6pbijpta3BvbMXZfEkX+DMGewMcCSI9hQSV0kli2BxRjO8Eo8YTDxUWoTX9HYuP yXfIhOsXwhe6Wj6V8cT6oUOH0GhU13X9g98lhYmhomvRnPefVAKatznN3wS8kbu9q/1s fOADzx5Ko1VbgqLm+fIpRyuAsMSPy9WI/nar7MHv+rpvM9/Qq5lRa0yA9+VILBcnmoLN SdGZn27dLgg2Qb7B6A64/0fkmb3GIjkINL32snFKye8dNyTcA/0FNbLEXedRrWX6gSsH TUTA== 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=DAsytXaxXjOs1TERHWkOTicdxYVnof0YOd+nc8NYEG4=; b=z/pc3zteXwe1Xn8ju2Qd67HVm/sWLc5xESbFYU1AtJurJga+ZeH6YWp4qeHVHBbh4o xcBxZjNxSCYyTW6PwrECDTEx64hG2duAA+fFDA8NAo4odhcM0WKCyU3yUD31SB9ks3tJ wIGYNGlM87+8t6tKKe6crnPFEDmrG8UZxSBagZSMYKAODdga0qCRf2nPT9QiKnAUURAd fA8dKBglslAsxD6vWJEmwXb/5g7CUz452p/czGC/0TMi+9HBpjpI6cLyYB/c7Qaf0BWj EwXEydX3PYx+Ss8zeISpoR2yBHiul45SyJYuey275elsR550eqNlABUf9Fe8NFg/W6mV LdZA== X-Gm-Message-State: AOAM531BwnPWzswYdC0C+lA0ZHZqxCX7fk8vuphNxQW/c9enais9KadQ +bFG+Auzd66cV5z96FBw98ykdjB6PrtWOQ== X-Google-Smtp-Source: ABdhPJxYcrPB6uMogrroImrLk5x1JRDotnai2YdVGu0Qm6y+ozZ4Zi1shvQ5CuJYEl/qF4mMm44dxw== X-Received: by 2002:a05:600c:4ed2:: with SMTP id g18mr2367701wmq.122.1637667989322; Tue, 23 Nov 2021 03:46:29 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:28 -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 v5 10/17] hooks: convert worktree 'post-checkout' hook to hook library Date: Tue, 23 Nov 2021 12:46:09 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the running of the 'post-checkout' hook away from run-command.h to the new hook.h library in builtin/worktree.c. For this special case we need a change to the hook API to teach it to run the hook from a given directory. We cannot skip the "absolute_path" flag and just check if "dir" is specified as we'd then fail to find our hook in the new dir we'd chdir() to. We currently don't have a use-case for running a hook not in our "base" repository at a given absolute path, so let's have "dir" imply absolute_path(find_hook(hook_name)). Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/worktree.c | 27 +++++++++++---------------- hook.c | 8 ++++++++ hook.h | 6 ++++++ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/builtin/worktree.c b/builtin/worktree.c index d22ece93e1a..4d9df5ecc4c 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -382,22 +382,17 @@ static int add_worktree(const char *path, const char *refname, * is_junk is cleared, but do return appropriate code when hook fails. */ if (!ret && opts->checkout) { - const char *hook = find_hook("post-checkout"); - if (hook) { - const char *env[] = { "GIT_DIR", "GIT_WORK_TREE", NULL }; - cp.git_cmd = 0; - cp.no_stdin = 1; - cp.stdout_to_stderr = 1; - cp.dir = path; - cp.env = env; - cp.argv = NULL; - cp.trace2_hook_name = "post-checkout"; - strvec_pushl(&cp.args, absolute_path(hook), - oid_to_hex(null_oid()), - oid_to_hex(&commit->object.oid), - "1", NULL); - ret = run_command(&cp); - } + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + + strvec_pushl(&opt.env, "GIT_DIR", "GIT_WORK_TREE", NULL); + strvec_pushl(&opt.args, + oid_to_hex(null_oid()), + oid_to_hex(&commit->object.oid), + "1", + NULL); + opt.dir = path; + + ret = run_hooks_opt("post-checkout", &opt); } strvec_clear(&child_env); diff --git a/hook.c b/hook.c index 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 Tue Nov 23 11:46:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634033 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 BEABDC433FE for ; Tue, 23 Nov 2021 11:46:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236555AbhKWLuC (ORCPT ); Tue, 23 Nov 2021 06:50:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236496AbhKWLtk (ORCPT ); Tue, 23 Nov 2021 06:49:40 -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 2E583C06173E for ; Tue, 23 Nov 2021 03:46:32 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id 133so18503810wme.0 for ; Tue, 23 Nov 2021 03:46:32 -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=YdzO09LWQw2YVMbYTnsa4ZB9qjgOBMWPajyWs9V+LXc=; b=FiqIICu2sXcbAZi7GA+CG7v6+dG+1V0zlqsQxR1ptuXz/sQywotvos5YmqIjgH3Zxv 9HM04dR+/bCrpnb5nt6OeEpDRmOp5ZX3S3jDUjDsymvEVoQkYXYf8wxjuUsJXfncxgSK n5BIwandng6lgMHHWenXduUOPUapmKlITc9jaTivlaNOwDWShRrGVpuD4pXRFYnpjNdK cr8K7ytRqoW74DlIXuoSdUeCdxU2l6bwsHE5aWCZEsZDb18BudflrYJ6avXt05M+nkUo CK8gqrlSXrTWtrpNHL4ZlZrJpoItZhVkF5DJAKfckXcrgtpYe5w97pE91Ry80xvAt0qC Z2KA== 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=YdzO09LWQw2YVMbYTnsa4ZB9qjgOBMWPajyWs9V+LXc=; b=cpQ9MRyRiYqeUKpb50X87j9Mh7vozAfMigVrqNV4LYuF+N3OaWiwycCo08/BRKPF+/ XaPlawGzarS17U0J4DAFfZUxSmqQ2XGp+4iBukCQr8bRm5j5By2eXqAxYe0rhTYVMMiL jtX0V+Y8iT8Gr4NDD2f7u93VoWfYiRTqm3rendo1vWL35ZQvwqFxdLGNIY/P6lswH/dJ 8Y+nxQ6llxDeRtDpPcmyuc1ogur2T3vQcAOGZaDJ+9Tz27Y6pIdv7WklHq3c37ZTYBTs Mv+aJowxOW+ar9F5RkTaxfsDRGzA5xFlpanohrXWDZGTUggUG9bq6/+yo3O6BChRdWvC Lh5g== X-Gm-Message-State: AOAM530WyubcZNfs0LYW+bShxwNQ4b5ZJybrqj6DcpmF/okLeIJGBgm0 TxI0yUlYZwKnOdOH5kFOwx8qOq3V206Haw== X-Google-Smtp-Source: ABdhPJxxF80eb9IN4FhApj8RAYWkTFujPuLCQD9egfYY86PIOdX7/og1H6aZodvFzLw1U2FCl6BxcA== X-Received: by 2002:a7b:c10a:: with SMTP id w10mr2207106wmi.183.1637667990452; Tue, 23 Nov 2021 03:46:30 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:29 -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 v5 11/17] git hook run: add an --ignore-missing flag Date: Tue, 23 Nov 2021 12:46:10 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 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 Tue Nov 23 11:46:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634031 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 91B19C433F5 for ; Tue, 23 Nov 2021 11:46:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236670AbhKWLuB (ORCPT ); Tue, 23 Nov 2021 06:50:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236516AbhKWLtl (ORCPT ); Tue, 23 Nov 2021 06:49:41 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14A0FC061746 for ; Tue, 23 Nov 2021 03:46:33 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id 77-20020a1c0450000000b0033123de3425so2005354wme.0 for ; Tue, 23 Nov 2021 03:46:33 -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=83bR3ixLMYsp2AGkwxrbKZ/gxEE8MQxui3SCGPSvrRc=; b=f/2BHTEJp3ZqWpwz9CzwF1BRYeszxlEnA6e3m3vsseQHm5jBO+GkmeX+YAIO5ww4kn n47VR+cC95WudJ9AG1KeWIP5MPCT4F2/d86VkyMOELQyelMIQrxY1WGr5w6Rx6qAySlS OINVVkr5LU0E6Z6SiPMudVwutrOhndo+ofG8FRLzcpGrAPGr3/YcMnU1QvcHo5uwKdMT UlvrPY/fQreluG+yDEIhrjO3VWJ9d/Ut1hG5c0HoSuq9lX0/UY7BlsIJP9ZZATMtUlb4 GfOBpmxNrH1kXcxgNPWcF/FONCDX9zTfb/C13xmCcSvR6opS2eMsHokOQVvtWILqKxLl hxlw== 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=83bR3ixLMYsp2AGkwxrbKZ/gxEE8MQxui3SCGPSvrRc=; b=HVyf6fIJQbUN2UdgnggDQki/ffr7d/UtJqwVPqU1jYfwehLctRhFZPPUJShviWNAz2 frqjnnnkfBtIH8BE11YSW0IqlvLFZ3Cv2sAM86/bku9xsva+RO/h5+knBZpRWU+sQhqp ZJRU1Rr6OWSVzosR7CK/olDMs0gjr0KiBaHzGW5LQ0CrSF0wdC89Ek4+j97iCPVSp9/L EQeBWsUsULiGa9QczGltrEVjvotzqVNrv1d3Wbb53evdCz7N+Jaqvqr+eJOykfkfgfFC sRb+PCFwHlyidO7uObeT38dtZuZ13BrtWtMbmAg2MLUT0hhKzrUdvYh79S/Vyw6+Ghvh PFKw== X-Gm-Message-State: AOAM530UMowqFCbjrTpFO0gG13dCHbCH40WocVA3z3543/orgR/cET8F AtUv7D5sxNxoQ0tEo+w2OT3ff5pJ0F/b1w== X-Google-Smtp-Source: ABdhPJzSZvxL3xXdPypzInquSV8SfMjzvyz/TQagsF5s0s23bh+g+vKvJn0ys3kPBzYCeYRY2tJA+Q== X-Received: by 2002:a7b:c1c5:: with SMTP id a5mr2218501wmj.149.1637667991392; Tue, 23 Nov 2021 03:46:31 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:30 -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 v5 12/17] send-email: use 'git hook run' for 'sendemail-validate' Date: Tue, 23 Nov 2021 12:46:11 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Change the "sendmail-validate" hook to be run via the "git hook run" wrapper instead of via a direct invocation. This is the smallest possibly change to get "send-email" using "git hook run". We still check the hook itself with "-x", and set a "GIT_DIR" variable, both of which are asserted by our tests. We'll need to get rid of this special behavior if we start running N hooks, but for now let's be as close to bug-for-bug compatible as possible. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- git-send-email.perl | 22 ++++++++++++++-------- t/t9001-send-email.sh | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 5262d88ee32..4c20c0bbb79 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -195,13 +195,13 @@ sub format_2822_time { my $editor; sub system_or_msg { - my ($args, $msg) = @_; + my ($args, $msg, $cmd_name) = @_; system(@$args); my $signalled = $? & 127; my $exit_code = $? >> 8; return unless $signalled or $exit_code; - my @sprintf_args = ($args->[0], $exit_code); + my @sprintf_args = ($cmd_name ? $cmd_name : $args->[0], $exit_code); if (defined $msg) { # Quiet the 'redundant' warning category, except we # need to support down to Perl 5.8, so we can't do a @@ -2039,10 +2039,10 @@ sub validate_patch { my ($fn, $xfer_encoding) = @_; if ($repo) { + my $hook_name = 'sendemail-validate'; my $hooks_path = $repo->command_oneline('rev-parse', '--git-path', 'hooks'); require File::Spec; - my $validate_hook = File::Spec->catfile($hooks_path, - 'sendemail-validate'); + my $validate_hook = File::Spec->catfile($hooks_path, $hook_name); my $hook_error; if (-x $validate_hook) { require Cwd; @@ -2052,13 +2052,19 @@ sub validate_patch { chdir($repo->wc_path() or $repo->repo_path()) or die("chdir: $!"); local $ENV{"GIT_DIR"} = $repo->repo_path(); - $hook_error = system_or_msg([$validate_hook, $target]); + my @cmd = ("git", "hook", "run", "--ignore-missing", + $hook_name, "--"); + my @cmd_msg = (@cmd, ""); + my @cmd_run = (@cmd, $target); + $hook_error = system_or_msg(\@cmd_run, undef, "@cmd_msg"); chdir($cwd_save) or die("chdir: $!"); } if ($hook_error) { - die sprintf(__("fatal: %s: rejected by sendemail-validate hook\n" . - "%s\n" . - "warning: no patches were sent\n"), $fn, $hook_error); + $hook_error = sprintf(__("fatal: %s: rejected by %s hook\n" . + $hook_error . "\n" . + "warning: no patches were sent\n"), + $fn, $hook_name); + die $hook_error; } } diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index aa0c20499ba..84d0f40d76a 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -539,7 +539,7 @@ test_expect_success $PREREQ "--validate respects relative core.hooksPath path" ' test_path_is_file my-hooks.ran && cat >expect <<-EOF && fatal: longline.patch: rejected by sendemail-validate hook - fatal: command '"'"'my-hooks/sendemail-validate'"'"' died with exit code 1 + fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- '"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual @@ -558,7 +558,7 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" ' test_path_is_file my-hooks.ran && cat >expect <<-EOF && fatal: longline.patch: rejected by sendemail-validate hook - fatal: command '"'"'$hooks_path/sendemail-validate'"'"' died with exit code 1 + fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- '"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual From patchwork Tue Nov 23 11:46:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634023 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 54FC6C433F5 for ; Tue, 23 Nov 2021 11:46:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236575AbhKWLtx (ORCPT ); Tue, 23 Nov 2021 06:49:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236444AbhKWLtm (ORCPT ); Tue, 23 Nov 2021 06:49:42 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2C47C061756 for ; Tue, 23 Nov 2021 03:46:33 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id p18so18442064wmq.5 for ; Tue, 23 Nov 2021 03:46:33 -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=yVBi56GeAHhOM1VrDA1m5eG4tJCdLbej0iVCFsjgchM=; b=DyxYW8LNz04159VZaGlELH1ngdRpXN6xI16CmjmPA5FyatrQJjvGE7Xj+3GVNZL2gc KXZSVLEoom3w0l5//W0iZH0zampp22G4jf39MQ9GwzOku8oEQ+0gDaLvq2biAYgSwFhv pZkj/4lB3QsxRtKeQXA/FOC9scXnnEzC6YCdjLH9CI7Ql+FBGDJME2RxUXxc1CZkCsca 9inht5GExex2/HGDXBbjjamAfNuxNG5j+Jiodrw4W/BK6M3Jj4FBPGA7EkoJ28TBo2v2 azNkFt9ab+FD1k386Xhx6LoHa1YZCVgL+++vx2LYTHl3GhzFtTM4P5lchL425o3duKfm T4XQ== 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=yVBi56GeAHhOM1VrDA1m5eG4tJCdLbej0iVCFsjgchM=; b=a/O03gzqTgQni8adKJha3nFBPy1ajplJQC1fc4gFyVXLmTI2iJBnb7OILHo+FDRA03 mBXLeqhcuSKVG5JPRSRvgBhcwqV73rhKV1zW35qbfabp5qZImchbtONqIg6L3aiqVOmY zLzuJXY3f89kuyrkVARvOdIO5hrClRcMeeDiO09FEL6PMiKkZp8BUJvTOyAF/3V2KD5t gzwEyWpp0NJj3gA6p7o7URxi6SHmhDZhjcBsmMIdp5OND0z8MGdQTxx/e1/FmXCcNLbk MSyH4+Abk2+oXsTCfQ2sWE9GFJkiGSx32eWF84xgr7wzq0GQMLT3/kk0OH4w84A8oObp oEXg== X-Gm-Message-State: AOAM533SdvKyW4VkZdFZmDeyUyBx18Aju4nxbZSuvOasLTAdVYEiAsUz N973lqgos8gWb11RRkGffOIlo+cPNqH0YA== X-Google-Smtp-Source: ABdhPJxinTlUb4XkkR1yT7HAC8OeMaWn7xHar1jN8Mq46ExF6YF3ZIWs0cydmLpjP1sG48rxnQOwWg== X-Received: by 2002:a1c:9842:: with SMTP id a63mr2285755wme.102.1637667992270; Tue, 23 Nov 2021 03:46:32 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:31 -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 v5 13/17] git-p4: use 'git hook' to run hooks Date: Tue, 23 Nov 2021 12:46:12 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 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 Tue Nov 23 11:46:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634021 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 C1C95C433EF for ; Tue, 23 Nov 2021 11:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236502AbhKWLtw (ORCPT ); Tue, 23 Nov 2021 06:49:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236530AbhKWLtn (ORCPT ); Tue, 23 Nov 2021 06:49:43 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7AE5C061574 for ; Tue, 23 Nov 2021 03:46:34 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso1975218wml.1 for ; Tue, 23 Nov 2021 03:46:34 -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=frEk3qpS9FC+yX72+I6birfDNCIdPpN/tyFL8oNp9RA=; b=Bb+UskuypgcVR0A0mIrjaKv8GEG5xriNoJ9eQXaPxyOh+4cInRmOy3ZLLpfzZrSAK4 YJ7kofm44x6kB+WHLkKsbf5UaAyySjedifj5h29fBp2N/A54nsi9NLHYIHCNl7uoNVRX OKPh/Sv+sw1313ueoZIx4T4RlrKQwBhkkxV9KM4zaRELINMRotGPbRF+3CEuzOaBysiw GrKWW1fhFe9Cov+NznQrUPDO4Joj1B1+q9IKTkBcHBJ0a/Fmj0Ku8SVRFyMgRBV4GzpX ayniRgFkNe2wbruyE1uv0izNV06qrWRTG2szS8StcaoYDXbWBAvbxmGUPPQeDMlxZm43 ztBQ== 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=frEk3qpS9FC+yX72+I6birfDNCIdPpN/tyFL8oNp9RA=; b=jU33GuyYuOtlt8DHlix6yFWctmOwnQdTwGNgqNCaLTpRZ6Fz+MIwU2bay7YU42QOk1 Vs+PcJeJKsrd9XlfUEvurwrLVDR7DL0W9eR1El12dRad2y6cdnS7Aidp2jojev4y2Vb4 9qIQ4WdnCWzRPAyRjfH323NZnYPEq3Kq5pNWyetMj3w1K+QZ2ddeq+LTRhPkdmTak750 Z6IAYPztXphNHzo2gGL2xuBAM7q6a90XV3CXdrg19Mc6bmhjqSu+N60FDHKqegf++OSS ZEeirIV4u1FPJqszLEZCqSZhxrKXNFNcYHFcN4uk231hoEpf7XoRfEIyMt8hoMeJx7/F E3RQ== X-Gm-Message-State: AOAM532MhLfliiqXqSKF/hbHkf+pSypxcak5Ajl4uRHX5i5OqDRIaCrd Lhl8mFvgxKKkezH3R9UYCaNmO3eoKFCyeg== X-Google-Smtp-Source: ABdhPJwxW79SDMPlNbJuscTEyEKHr/CZFq0Hhg4Lo2kmwBkQzIS6Ff50GxUt4apaVkJZE91hNxL9wA== X-Received: by 2002:a05:600c:350c:: with SMTP id h12mr2197878wmq.123.1637667993253; Tue, 23 Nov 2021 03:46:33 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:32 -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 v5 14/17] commit: convert {pre-commit,prepare-commit-msg} hook to hook.h Date: Tue, 23 Nov 2021 12:46:13 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move these hooks hook away from run-command.h to and over to the new hook.h library. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- commit.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/commit.c b/commit.c index 551de4903c1..581d7dc216c 100644 --- a/commit.c +++ b/commit.c @@ -21,6 +21,7 @@ #include "commit-reach.h" #include "run-command.h" #include "shallow.h" +#include "hook.h" static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **); @@ -1700,22 +1701,22 @@ size_t ignore_non_trailer(const char *buf, size_t len) int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...) { - struct strvec hook_env = STRVEC_INIT; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; va_list args; - int ret; + const char *arg; - strvec_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file); + strvec_pushf(&opt.env, "GIT_INDEX_FILE=%s", index_file); /* * Let the hook know that no editor will be launched. */ if (!editor_is_used) - strvec_push(&hook_env, "GIT_EDITOR=:"); + strvec_push(&opt.env, "GIT_EDITOR=:"); va_start(args, name); - ret = run_hook_ve(hook_env.v, name, args); + while ((arg = va_arg(args, const char *))) + strvec_push(&opt.args, arg); va_end(args); - strvec_clear(&hook_env); - return ret; + return run_hooks_opt(name, &opt); } From patchwork Tue Nov 23 11:46:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634025 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 24CACC433EF for ; Tue, 23 Nov 2021 11:46:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236609AbhKWLtz (ORCPT ); Tue, 23 Nov 2021 06:49:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236449AbhKWLtn (ORCPT ); Tue, 23 Nov 2021 06:49:43 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7F93C061714 for ; Tue, 23 Nov 2021 03:46:35 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id 137so14928642wma.1 for ; Tue, 23 Nov 2021 03:46:35 -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=XClPV9UvuYLHNhiCToui77MfusE8z4zix1BfHfSjHQ4=; b=hvhovHVTPUgV9zEecE1wL4i7IYnsfy1yzeo0lzZFwxIqDT6Loz2bjsrRlP3dB+yDNw MxAmmimB5EV4iyd30RakExzJLBZnfVWQLPV2ii/uFj25QRBb88pWWPgUjt9mCwJgtx/6 MVMmovZNIJxSQQZYFuXW4jCYzFwbW1z3RRVq+te4Gb6+lqBGYlM4RLjPikaftr1PIiMW 0ht25IpJ0wn6vtAZTFGVvHwAN1LxBajBDCJvGHilo3DiwB6kfa0jwqjqFkAwn4ncZIs7 iS/Ll+Ribl0xsMNggURpldmk9DP3Dw73wpqqbjYtfl4DH85YZ6RUxKrwcPIs34vkX1qC goSA== 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=XClPV9UvuYLHNhiCToui77MfusE8z4zix1BfHfSjHQ4=; b=br6YFDDQhL1chDIiF6f/kMtHoqlbxD+J1j/LM+2W6/PqC305CPLGLG7CzbBkOY8EVb X3tyaEDeIUyLb/mQG8VgVK5x/RANHYf21tEywzQ6/CBBlIanTw5fp+tn8uaXKtWffOzq x8xKs9HDdP+kERdjATvzwWbsMb1aI4p9Rk7UljOQTCiLX9FBk+TRJdZOVkIngrfrpiKK IgF/aM09slg8cF0WjAtlOCEnqJuOeG7Wogoow9YpV3cgmVtWgNQ0nt3jj7m6ld0W3CKJ vL6t3eXXRq3Uvok0OwbAxAtUl+qXbvrRp+/8VP29lvtQBAc7Flm5hRka/Kq/WFNnh3Zr q+NA== X-Gm-Message-State: AOAM531pFL8rsWiUUFMh3qhgdhAAXS7NcrGHfjFsl4Why43Al071FTCX FDzSOPN0ZMkJLXARUfgSxrn2raKdVbSkhw== X-Google-Smtp-Source: ABdhPJwwXEF//lqWXUvRmj7thB34Zy+yxGzha03NAsFjg1vdB3oxRlke+hW9JqquJ15QnZ4z7uES7Q== X-Received: by 2002:a05:600c:1549:: with SMTP id f9mr2317661wmg.118.1637667994007; Tue, 23 Nov 2021 03:46:34 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:33 -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 v5 15/17] read-cache: convert post-index-change to use hook.h Date: Tue, 23 Nov 2021 12:46:14 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the post-index-change hook away from run-command.h to and over to the new hook.h library. This removes the last direct user of "run_hook_ve()" outside of run-command.c ("run_hook_le()" still uses it). So we can make the function static now. A subsequent commit will remove this code entirely when "run_hook_le()" itself goes away. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- read-cache.c | 3 ++- run-command.c | 2 +- run-command.h | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/read-cache.c b/read-cache.c index f3986596623..4352661549f 100644 --- a/read-cache.c +++ b/read-cache.c @@ -28,6 +28,7 @@ #include "sparse-index.h" #include "csum-file.h" #include "promisor-remote.h" +#include "hook.h" /* Mask for the name length in ce_flags in the on-disk index */ @@ -3129,7 +3130,7 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l else ret = close_lock_file_gently(lock); - run_hook_le(NULL, "post-index-change", + run_hooks_l("post-index-change", istate->updated_workdir ? "1" : "0", istate->updated_skipworktree ? "1" : "0", NULL); istate->updated_workdir = 0; diff --git a/run-command.c b/run-command.c index f40df01c772..d7d64701ede 100644 --- a/run-command.c +++ b/run-command.c @@ -1323,7 +1323,7 @@ int async_with_fork(void) #endif } -int run_hook_ve(const char *const *env, const char *name, va_list args) +static int run_hook_ve(const char *const *env, const char *name, va_list args) { struct child_process hook = CHILD_PROCESS_INIT; const char *p; diff --git a/run-command.h b/run-command.h index 49878262584..3fa7454cf8a 100644 --- a/run-command.h +++ b/run-command.h @@ -239,7 +239,6 @@ int run_command(struct child_process *); */ LAST_ARG_MUST_BE_NULL int run_hook_le(const char *const *env, const char *name, ...); -int run_hook_ve(const char *const *env, const char *name, va_list args); /* * Trigger an auto-gc From patchwork Tue Nov 23 11:46:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634027 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 54E07C433EF for ; Tue, 23 Nov 2021 11:46:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236521AbhKWLtz (ORCPT ); Tue, 23 Nov 2021 06:49:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236534AbhKWLto (ORCPT ); Tue, 23 Nov 2021 06:49:44 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 850C5C06175A for ; Tue, 23 Nov 2021 03:46:36 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id c4so38413050wrd.9 for ; Tue, 23 Nov 2021 03:46:36 -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=cgYsfXyu6U8RcbkdkCohvcCf7L5WdZbG1HX4E8qFul0=; b=ONTAWqDNX85GsUmNwiC04UPLSKCj3FcjtIekB2rForGTErewZ1vnah3ItYJbKphKQt DZQPLuvK+kX8IeRUxKSd7U4cHZgoz1ZhyvVYNiGn2cG0utNlhiM3JnpbnjxqKJkV9Ts8 0YW/4tvxfHAaLZjH7rVFYkAF6DMAK+MPyY73XYNvGFCsrUfp2VtG4xsjGbjHvpjgAwxL dKjrqp1MooBrWbc/oomFAqJDuUywkSN4rCvpwllTqoc3slbHRyZxG5HTRJQ+aWRZL/aC yoEqvpYN66eKKCYkGh0FbLOeNkHOtxOH00pm7iZQy8rP+ioceYvo3Jx7Af3XV114du1T OGRw== 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=cgYsfXyu6U8RcbkdkCohvcCf7L5WdZbG1HX4E8qFul0=; b=dJY0ZEz6Iup2Y9nz164d1NamRlCMURpgVDs1TvzIM+llQCXoi4U8hBTPealewro7nk OGdURMUF9dPTrW/et7PM5Iy1UKnsTQQSGDq7s6kZbWz0NT0my68xSc+iLiBlKyXTuimi bna2e+FP+AXaqkqrkVtOnEV+PiErrE+r+iG41quN+Rzcg4cF+D9NyX3UXnG2xdjmcMdR YNcH1nNPnbL6Bm2nZpUPc5zZeHSbp89lqX+V0qkxh8ci+lRpRb/Q6kfbTiUjvKrMXHXu HontpxzEGkwoDZJwiHXp/66bpRst5YkrspJSBRJNxcHyTLnwAbnV2hloqVPZsOEPkPH6 4hNA== X-Gm-Message-State: AOAM532SiNz7J/DFw4lZSsInvrANB6jw5tlu8c5oI03qU5UvockH8vW2 kNkgM+ZYATOZFZ8YGeB3etjFaJgDPK8ptA== X-Google-Smtp-Source: ABdhPJyvBgIOB+LmCzvWlrucZ9ceg672Il0pbTYxH2ZvF0dOkM48ALwFW5oc6/fPMG3Kb3gjFsMr5g== X-Received: by 2002:adf:ce0e:: with SMTP id p14mr6282663wrn.423.1637667994872; Tue, 23 Nov 2021 03:46:34 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:34 -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 v5 16/17] receive-pack: convert push-to-checkout hook to hook.h Date: Tue, 23 Nov 2021 12:46:15 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Move the push-to-checkout hook away from run-command.h to and over to the new hook.h library. This removes the last direct user of run_hook_le(), so we could remove that function now, but let's leave that to a follow-up cleanup commit. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/receive-pack.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 49b846d9605..5d6d8dd9a26 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1439,9 +1439,12 @@ static const char *push_to_checkout(unsigned char *hash, struct strvec *env, const char *work_tree) { + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); - if (run_hook_le(env->v, push_to_checkout_hook, - hash_to_hex(hash), NULL)) + strvec_pushv(&opt.env, env->v); + strvec_push(&opt.args, hash_to_hex(hash)); + if (run_hooks_opt(push_to_checkout_hook, &opt)) return "push-to-checkout hook declined"; else return NULL; From patchwork Tue Nov 23 11:46:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12634029 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 AE441C433EF for ; Tue, 23 Nov 2021 11:46:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236524AbhKWLt6 (ORCPT ); Tue, 23 Nov 2021 06:49:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233877AbhKWLtp (ORCPT ); Tue, 23 Nov 2021 06:49:45 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74F51C061574 for ; Tue, 23 Nov 2021 03:46:37 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id t30so38387132wra.10 for ; Tue, 23 Nov 2021 03:46:37 -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=07AFTNsSr7V9ZQdk72NB0F2afEy2FZOFwDPFdsHg+G8=; b=mKoJ4LD496Vw4gEUwx4KeAT6oAkFyv8Mr8uFrtG8tafl16vi11UnlpHEmYbWdzJWhd 44Rx0URTqhB2S8kSwMe4ay7my7V9w2P4r43FffEFrdCWMg47VYCh9P09KARCHpnO5l8W Mr8LbO0rm5J9Ps3heLoFXAA0N84HmR5QKcXATDvZEWzLKAFUFJ//mblhhiZxbLryyLmY 2Sz/hNN+dKeA3IDQqXpvPM/Mfsgu/jb1iQ6LhukhrEnnulfoQsrA/62n11wRinrEOX7W r9WJXZE2zk89vEOQJe0LDN5WBRdU2dJfZQfzZXxH/o8PwtWf2mYB95QYpWOqq1RdqPym 3JEg== 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=07AFTNsSr7V9ZQdk72NB0F2afEy2FZOFwDPFdsHg+G8=; b=p9O2y+91itnrrQiFAiNQWLpffT7vUtapGmzkMq/28qVdtTBE//7ew1f6d54N49k1jp V6xEDayYBqtEJqD5BBDv/fElZWTd0d5T9f+YtqZAScjYtyZNfOIr86BojWP5auK9D6wm ZSACzNtH98NQD+PLPD0SMBbXdC7bDggHsTvICw/aMggGBbCR9mIUaVXU9+tbAVT88PKP XleT2AX4IUrVo264ZVK6NHbGw5rOv3oFmA/Aj2NtJfkEQZilQavfwOlyRSmf+1mImlOX ogY8+ylP+8TdyfP2J3sOvWBz87n8neKYLwtXI+tKJsYT+DwjSZOhJQ0FZxARKoohMqrq HNdw== X-Gm-Message-State: AOAM533C8RPJGboJdvHLBIPrdGLUY2wP+Yrt4c807mAElAkzjQY8v0Dc 9HEA/oDReaYcFS77jDb1a4eNTyLQBrYO7g== X-Google-Smtp-Source: ABdhPJwnN628Rpu8cs+RlQsT90oJmyN6TQI3lcfqguC1j7iGGoP6SzGoA1pObgk+m+D10+czFo889g== X-Received: by 2002:a5d:4989:: with SMTP id r9mr6675258wrq.14.1637667995838; Tue, 23 Nov 2021 03:46:35 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c11sm1723145wmq.27.2021.11.23.03.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:46:35 -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 v5 17/17] run-command: remove old run_hook_{le,ve}() hook API Date: Tue, 23 Nov 2021 12:46:16 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.831.gd33babec0d1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer The new hook.h library has replaced all run-command.h hook-related functionality. So let's delete this dead code. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- run-command.c | 32 -------------------------------- run-command.h | 16 ---------------- 2 files changed, 48 deletions(-) diff --git a/run-command.c b/run-command.c index d7d64701ede..7ecff26c1dc 100644 --- a/run-command.c +++ b/run-command.c @@ -1323,38 +1323,6 @@ int async_with_fork(void) #endif } -static int run_hook_ve(const char *const *env, const char *name, va_list args) -{ - struct child_process hook = CHILD_PROCESS_INIT; - const char *p; - - p = find_hook(name); - if (!p) - return 0; - - strvec_push(&hook.args, p); - while ((p = va_arg(args, const char *))) - strvec_push(&hook.args, p); - hook.env = env; - hook.no_stdin = 1; - hook.stdout_to_stderr = 1; - hook.trace2_hook_name = name; - - return run_command(&hook); -} - -int run_hook_le(const char *const *env, const char *name, ...) -{ - va_list args; - int ret; - - va_start(args, name); - ret = run_hook_ve(env, name, args); - va_end(args); - - return ret; -} - struct io_pump { /* initialized by caller */ int fd; diff --git a/run-command.h b/run-command.h index 3fa7454cf8a..59e1fbff64c 100644 --- a/run-command.h +++ b/run-command.h @@ -224,22 +224,6 @@ int finish_command_in_signal(struct child_process *); */ int run_command(struct child_process *); -/** - * Run a hook. - * The first argument is a pathname to an index file, or NULL - * if the hook uses the default index file or no index is needed. - * The second argument is the name of the hook. - * The further arguments correspond to the hook arguments. - * The last argument has to be NULL to terminate the arguments list. - * If the hook does not exist or is not executable, the return - * value will be zero. - * If it is executable, the hook will be executed and the exit - * status of the hook is returned. - * On execution, .stdout_to_stderr and .no_stdin will be set. - */ -LAST_ARG_MUST_BE_NULL -int run_hook_le(const char *const *env, const char *name, ...); - /* * Trigger an auto-gc */