From patchwork Tue Oct 12 13:30:26 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: 12552615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FABCC433F5 for ; Tue, 12 Oct 2021 13:31:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D6E160EB6 for ; Tue, 12 Oct 2021 13:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236781AbhJLNdB (ORCPT ); Tue, 12 Oct 2021 09:33:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233296AbhJLNc7 (ORCPT ); Tue, 12 Oct 2021 09:32:59 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55E3BC061570 for ; Tue, 12 Oct 2021 06:30:57 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id d3so53495495edp.3 for ; Tue, 12 Oct 2021 06:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9GLpHuGbhe2M2R8zJwcIFHRXRnV6eD2bJ2zrB69DyMs=; b=RzQApunXrdPCOZQz3mQnZvqYvsVfIyefRW5bZXl91S0LC3b8tg4rpFnAPWjm8Ole+G PM+L/u3eoUFW5F/hHSpNxD2NvkeWiztfKC2zn5e7YWbHYRz18D7FaM0tR7/TPZ5lK1Cz tI5ZDpLg3l33hWXQ97is39JYLKRbVAwOb8Sqju23r4BUU6CxFqVcK8dPGnF8gED6TLuS HxBgBNX+bhdBmt6XUlJ7o1uhAmrIDWvmeWiCw6m2kPshlJ3MrW4JWlhXyucCb0l2vz8q l6b/P+4KYhFOsMG3VfE5bOTFApN+5Zg5svxKNX+IF9KA5JuljIodedHmESjJaoAhiPt3 IJhg== 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=9GLpHuGbhe2M2R8zJwcIFHRXRnV6eD2bJ2zrB69DyMs=; b=2HNsQk854Y8uYj2GmqeKlfDhfQlt7tzOGTGWHCEtKYtnKtibvAoMLNY8tJDv7yTAjX 7x3ac1l0vtGAz/3IIi+ylqm2aB7KsRbiDkOk6IQhbO9IY8RkaeGJXBLK1aZlXiZhuxI+ fegM11Ryg9mC7DGam+6sDU2thx4HxUEpB5LhB94IX4nW0a8TAyNQZJRqMcy68xuuRxUJ GwEtuCybZbZeeYzzh9pOtIcxcDQZ2fsji09p7Axb/ea3V2EWL7pQz5WyyiOszMyMRerx xEztABFG9kE7IObBlq0VMrvsJJFd3Kh5TLmOwr42afXxDD5CEamuScc23j5epfLSl4JU NnEA== X-Gm-Message-State: AOAM531WMdK0HQLoiMTL/ANvck0Jpj1Tmyu7Sgj2cuN9FCet9E1aefbl 5Z0yADz2lg69FX/LNZlgMnrvmUsWQ7kOLw== X-Google-Smtp-Source: ABdhPJzdkcMHbWuvpAO1hccf1ItPB57mi215jSgjXzAhKBevLPdYbICCLNJ9Pz8zavhO8XRo4cOPvg== X-Received: by 2002:a17:906:5e52:: with SMTP id b18mr19867227eju.560.1634045451221; Tue, 12 Oct 2021 06:30:51 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:30:50 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 01/13] hook: add 'run' subcommand Date: Tue, 12 Oct 2021 15:30:26 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- .gitignore | 1 + Documentation/git-hook.txt | 38 +++++++++++ Documentation/githooks.txt | 4 ++ Makefile | 1 + builtin.h | 1 + builtin/hook.c | 90 ++++++++++++++++++++++++++ command-list.txt | 1 + git.c | 1 + hook.c | 101 +++++++++++++++++++++++++++++ hook.h | 39 +++++++++++ t/t1800-hook.sh | 129 +++++++++++++++++++++++++++++++++++++ 11 files changed, 406 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 6be9de41ae8..66189ca3cdc 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..660d6a992a0 --- /dev/null +++ b/Documentation/git-hook.txt @@ -0,0 +1,38 @@ +git-hook(1) +=========== + +NAME +---- +git-hook - run git hooks + +SYNOPSIS +-------- +[verse] +'git hook' run [-- ] + +DESCRIPTION +----------- + +This command is an interface to git hooks (see linkgit:githooks[5]). +Currently it only provides a convenience wrapper for running hooks for +use by git itself. In the future it might gain other functionality. + +SUBCOMMANDS +----------- + +run:: + Run the `` hook. See linkgit:githooks[5] for + the hook names we support. ++ +Any positional arguments to the hook should be passed after an +optional `--` (or `--end-of-options`, see linkgit:gitcli[7]). The +arguments (if any) differ by hook name, see linkgit:githooks[5] for +what those are. + +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 877492386ee..12b481fdabe 100644 --- a/Makefile +++ b/Makefile @@ -1108,6 +1108,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..012a2973b38 --- /dev/null +++ b/builtin/hook.c @@ -0,0 +1,90 @@ +#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; + const char *hook_path; + 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); + + /* + * We are not using a plain run_hooks() because we'd like to + * detect missing hooks. Let's find it ourselves and call + * run_hooks() instead. + */ + hook_name = argv[0]; + hook_path = find_hook(hook_name); + if (!hook_path) { + error("cannot find a hook named %s", hook_name); + return 1; + } + + ret = run_hooks(hook_name, hook_path, &opt); + run_hooks_opt_clear(&opt); + 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 a289f09ed6f..9ccd8e5aebe 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 mainporcelain git-http-backend synchingrepositories git-http-fetch synchelpers git-http-push synchelpers diff --git a/git.c b/git.c index 60c2784be45..e5891e02021 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..240270db64e 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,103 @@ int hook_exists(const char *name) { return !!find_hook(name); } + +void run_hooks_opt_clear(struct run_hooks_opt *o) +{ + strvec_clear(&o->env); + strvec_clear(&o->args); +} + +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; + struct hook *run_me = hook_cb->run_me; + + if (!run_me) + return 0; + + cp->no_stdin = 1; + cp->env = hook_cb->options->env.v; + cp->stdout_to_stderr = 1; + cp->trace2_hook_name = hook_cb->hook_name; + + /* add command */ + strvec_push(&cp->args, run_me->hook_path); + + /* + * add passed-in argv, without expanding - let the user get back + * exactly what they put in + */ + strvec_pushv(&cp->args, hook_cb->options->args.v); + + /* Provide context for errors if necessary */ + *pp_task_cb = run_me; + + /* + * 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->run_me = 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; + struct hook *attempted = pp_task_cp; + + hook_cb->rc |= 1; + + strbuf_addf(out, _("Couldn't start hook '%s'\n"), + attempted->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; +} + +int run_hooks(const char *hook_name, const char *hook_path, + struct run_hooks_opt *options) +{ + struct hook my_hook = { + .hook_path = hook_path, + }; + struct hook_cb_data cb_data = { + .rc = 0, + .hook_name = hook_name, + .options = options, + }; + int jobs = 1; + + if (!options) + BUG("a struct run_hooks_opt must be provided to run_hooks"); + + cb_data.run_me = &my_hook; + + run_processes_parallel_tr2(jobs, + pick_next_hook, + notify_start_failure, + notify_hook_finished, + &cb_data, + "hook", + hook_name); + + return cb_data.rc; +} diff --git a/hook.h b/hook.h index 6aa36fc7ff9..111c5cf9296 100644 --- a/hook.h +++ b/hook.h @@ -1,5 +1,33 @@ #ifndef HOOK_H #define HOOK_H +#include "strvec.h" + +struct hook { + /* The path to the hook */ + const char *hook_path; +}; + +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; +}; + +#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; + struct hook *run_me; + struct run_hooks_opt *options; +}; /* * Returns the path to the hook file, or NULL if the hook is missing @@ -13,4 +41,15 @@ const char *find_hook(const char *name); */ int hook_exists(const char *hookname); +/** + * Clear data from an initialized "struct run_hooks-opt". + */ +void run_hooks_opt_clear(struct run_hooks_opt *o); + +/** + * Takes an already resolved hook found via find_hook() and runs + * it. Does not call run_hooks_opt_clear() for you. + */ +int run_hooks(const char *hookname, const char *hook_path, + 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 Oct 12 13:30:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2208BC433F5 for ; Tue, 12 Oct 2021 13:31:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0477460F23 for ; Tue, 12 Oct 2021 13:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236762AbhJLNdG (ORCPT ); Tue, 12 Oct 2021 09:33:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236811AbhJLNdD (ORCPT ); Tue, 12 Oct 2021 09:33:03 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A791CC061745 for ; Tue, 12 Oct 2021 06:31:01 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id g8so81215018edt.7 for ; Tue, 12 Oct 2021 06:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=azapiTOO/bu5iHFIX+c8E6p12RQzoBrZPHSKEVG+ifg=; b=Z4UoxxqLWXhI+NfnZHnS4q+D/w1AW8mqM5nXOgGiceZ14r3kLOYF2d9jjiXyu9gLtF wJtRLyMx3bh5Tje2lX0+qrZ5p/hrdb6WSb9hrLZ03zc45ar1sX9UL/sKDJBWs/EE3Asv ju1jc/9VVXe+5HMYyYvscvjzkwEBcptQyrwYpPwlJD1maphfCC9YCCPY5iQxBvFIlO4g nYDLokd+9Ri9b5Pc3vwQUbUg429n7IU4V/ob6n+eboNYqCNP4yz8RYfierW9mRFfjXj9 Z7SA4uLlcgIAxx2y+lzxbSbLcnRQ+to/ZD3wx4yWA/OWHeDEBlbyZ1W7pMBXy0QHl6rN EAJg== 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=azapiTOO/bu5iHFIX+c8E6p12RQzoBrZPHSKEVG+ifg=; b=vaBB7+faJZVp+NRZnKOb3uLNwGAcdfnP538AO9w45Po7n/8SIwnoxxFz+qqVXq/u8W o+n/fMtkibr1YkDPFbQZZSdLgIpEieLU+O87DV49Zg1JDT7hV6zUdGYkLFc4y3zPx5LX DFx+eMlZmhwU6wp81dZ6tgCJEFWxPHnUOdxDwtryXX7E1zfEXg4uvCP9sKpfa0tFsTU/ lvCzW3ndn71pFDqPWfOa7FfgAaPQdSwT0cPQnw99XAcDF8LeDBV4JyN71ex+Fr8bPhAz Q8ffv1NWl8cPozxPAKo2RTlrdiVt8hg2opTmQVVbZv+B4o5zagtXWEc0csBEsBrQxmL1 qNSQ== X-Gm-Message-State: AOAM533AInUmcjmbOspPtqetfQyHjLxBVDOYXevgLQRO3lgSONBfydQU 6YEVCgBfBEVFovjyCTSmuF5kCXBbmjrc5Q== X-Google-Smtp-Source: ABdhPJwAiotxBvWO3veQIkUB1GWeBqEpXEcTV5WDgI9ouiazXFW/sCyG6A/XfOLBzla+vDQYBidK5w== X-Received: by 2002:a50:d84e:: with SMTP id v14mr50298879edj.85.1634045452740; Tue, 12 Oct 2021 06:30:52 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:30:51 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 02/13] gc: use hook library for pre-auto-gc hook Date: Tue, 12 Oct 2021 15:30:27 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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. To do this introduce a simple run_hooks_oneshot() wrapper, we'll be using it extensively for these simple cases of wanting to run a single hook under a given name, and having it free the memory we allocate for us. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/gc.c | 3 ++- hook.c | 20 ++++++++++++++++++++ hook.h | 13 +++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/builtin/gc.c b/builtin/gc.c index 6b3de3dd514..95939e77f53 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_oneshot("pre-auto-gc", NULL)) return 0; return 1; } diff --git a/hook.c b/hook.c index 240270db64e..bfdc79e2f1a 100644 --- a/hook.c +++ b/hook.c @@ -141,3 +141,23 @@ int run_hooks(const char *hook_name, const char *hook_path, return cb_data.rc; } + +int run_hooks_oneshot(const char *hook_name, struct run_hooks_opt *options) +{ + const char *hook_path; + struct run_hooks_opt hook_opt_scratch = RUN_HOOKS_OPT_INIT; + int ret = 0; + + if (!options) + options = &hook_opt_scratch; + + hook_path = find_hook(hook_name); + if (!hook_path) + goto cleanup; + + ret = run_hooks(hook_name, hook_path, options); +cleanup: + run_hooks_opt_clear(options); + + return ret; +} diff --git a/hook.h b/hook.h index 111c5cf9296..a2b8d4fc6bd 100644 --- a/hook.h +++ b/hook.h @@ -49,7 +49,20 @@ void run_hooks_opt_clear(struct run_hooks_opt *o); /** * Takes an already resolved hook found via find_hook() and runs * it. Does not call run_hooks_opt_clear() for you. + * + * See run_hooks_oneshot() for the simpler one-shot API. */ int run_hooks(const char *hookname, const char *hook_path, struct run_hooks_opt *options); + +/** + * Calls find_hook() on your "hook_name" and runs the hooks (if any) + * with run_hooks(). + * + * If "options" is provided calls run_hooks_opt_clear() on it for + * you. If "options" is NULL the default options from + * RUN_HOOKS_OPT_INIT will be used. + */ +int run_hooks_oneshot(const char *hook_name, struct run_hooks_opt *options); + #endif From patchwork Tue Oct 12 13:30:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B7DEC433FE for ; Tue, 12 Oct 2021 13:31:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E63E560F23 for ; Tue, 12 Oct 2021 13:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236835AbhJLNdH (ORCPT ); Tue, 12 Oct 2021 09:33:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236821AbhJLNdE (ORCPT ); Tue, 12 Oct 2021 09:33:04 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F2AAC06174E for ; Tue, 12 Oct 2021 06:31:02 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id g10so80377999edj.1 for ; Tue, 12 Oct 2021 06:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hk7VAKpCJ9kv56DGsimnorPjq9Gc1UHu3Y22jaTXlI4=; b=Gu0lkqCxvpXY7gfLidVmi8XjmbCgWRlT8rmDFYBYzEJmCnGKnDgYAiuTekaAEf1HYo dqU7EVMC1LbNoZ7q1Iix6Jdo+8flQUas4L7y9SvgGD3+RwEWXXGR0C72T4q36/U+19HN Oweq+PbOFQBB3frKVy+SmCZmymb71laXxc7QsP4jUFnLC8TLtPJgSG9yTnMHWkP+3+Hn 6k6dTvs1cnbmSygMSmLV/SOG95iS0hAIdkigJ2zawYVCnnq0pxUuqUHvQe0UpeKjl+Ax ZUnZs5ww9EOFMC4RIRCVgAFpZ6JlHoj6W7VAdiKcrvp6sO0uuyQ32QixLpiPpaXR6zWl G/2g== 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=Hk7VAKpCJ9kv56DGsimnorPjq9Gc1UHu3Y22jaTXlI4=; b=xeC1FjURidQpX+VfD+XbGvEyVP7uK7MoTju73q/i2IA1fkAr4iRuKFjF/HzaF42kca NsSFz237I3sBoQgYTdiVlgkEla+qZj785uagBs1IpY0zZck//AfFqRJi4KLOFF2WuSEc hSgAw2eUBtSFtzEG7vD6z4pgJv0YWLzU8suQTp3k7nPhwbJ/f2aobtGnZp1+srgUAuk6 tMa2sitY5TCuPa9pSdq7El/JtMtM1LGCFjHJzZdJDGUau6+VH0w538rERca0Sfh8Qm9k QOL+Gz8XcDISmbhkpXp2rcr969ONz75CDLXghAv8KqFD4CCEG1jfUfC32EKS/tVvrcm3 BAew== X-Gm-Message-State: AOAM530Ssdgd6A2GeyUl0EDSGU6fAHTdo30qEl3BHVYYqCduYeJpyOKa nXjsby17q2M8lGlzSE/FaTGwdO0GUdQ47w== X-Google-Smtp-Source: ABdhPJw/YGaW6TxmX77wDLw3CpZOfe+ct+fMO5/rrPPYpHIkZ7K4yh/YN55A4CMwbCgyfRENCo7hcg== X-Received: by 2002:a05:6402:1d55:: with SMTP id dz21mr39085307edb.164.1634045458377; Tue, 12 Oct 2021 06:30:58 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:30:56 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 03/13] rebase: convert pre-rebase to use hook.h Date: Tue, 12 Oct 2021 15:30:28 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rebase.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 8c6393f6d78..9a44939d662 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" @@ -1305,6 +1306,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) char *squash_onto_name = NULL; int reschedule_failed_exec = -1; int allow_preemptive_ff = 1; + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT; struct option builtin_rebase_options[] = { OPT_STRING(0, "onto", &options.onto_name, N_("revision"), @@ -2021,9 +2023,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } /* If a hook exists, give it a chance to interrupt*/ + strvec_push(&hook_opt.args, options.upstream_arg); + if (argc) + strvec_push(&hook_opt.args, argv[0]); if (!ok_to_skip_pre_rebase && - run_hook_le(NULL, "pre-rebase", options.upstream_arg, - argc ? argv[0] : NULL, NULL)) + run_hooks_oneshot("pre-rebase", &hook_opt)) die(_("The pre-rebase hook refused to rebase.")); if (options.flags & REBASE_DIFFSTAT) { From patchwork Tue Oct 12 13:30:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21CA5C433F5 for ; Tue, 12 Oct 2021 13:31:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08EFB61076 for ; Tue, 12 Oct 2021 13:31:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236863AbhJLNdI (ORCPT ); Tue, 12 Oct 2021 09:33:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236819AbhJLNdD (ORCPT ); Tue, 12 Oct 2021 09:33:03 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0375BC061749 for ; Tue, 12 Oct 2021 06:31:02 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id y12so68335893eda.4 for ; Tue, 12 Oct 2021 06:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rftZ8iNXSu0rSO57W0MaTcUuPpmjP12H7zzslixwEVA=; b=bHm9h4RqwMkm98FYLD9GmhI3xCxf0+iQEI8MZX+5Fmxgbg0SZuIpTgEDchkSTseKoT hUG1qbPJAQUHfEdTBkmlbgYrBoWxh6PwmWHqmfuTu5LBmIm0gOo6t6B8nsfQ8xaoOMSF qi3Bn2LIp2ioWuYZiTCFkmNSjaZ7GbF5a0dPGPbNpcYOpR6ew351ZtpZjKy8uRbuy8cC EGVar7k/mVTTL9++Uc9Ocgnnafw26lq9X443zmmp6UauWln1tg+hORzMZlNY2AwIdmJr 3KgkYf4V8teC2EM8yDimTFLUWqxBxKJ731ACvznGyPZ28NTL/9rfNMtyV0DLzBTyHvjj M++A== 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=rftZ8iNXSu0rSO57W0MaTcUuPpmjP12H7zzslixwEVA=; b=x78a5yJQoG5ONFs/IPXPBUoKsKxBmMEdgCCMXpuMoKkzA/NNJbJFry1jL6fTJbBjxR H5ibKW0ND4ut/SyGA4ob5JnkAirbeGyreuvcpIGCkQ3W6iZjuG1Vazdr+swZJvzEUmQ5 xkM7GHUTz4UsIBdKsVwVALM9+cJBn21GwYdTyxmab6ZTNlOdvJK7O4gTvg4L42Oz6pLr 0b+CVixe2x9Lc8k1+UEMrrwdLq6rSPBmgpcVy+A60O4jxGrtf/SX2TqK433RLuDDcdMB O3XK9HS1kmfL6sO2fKyW5TTlzeqvGzc3z/Motc+cORBIV7PBHNYNnuXLFIX6ndQr+ieI Pf+w== X-Gm-Message-State: AOAM5316o0RTjwpmUpdJCXtd/iym2YePmQgQtltaRsVzMKoVyS5X6hh+ K6iKT2r7oLwSmz+AstByu/RmO3PkBjXlGg== X-Google-Smtp-Source: ABdhPJyDY1pZE2E86AwzuiQ6rdSc9FRYk3+QH7tnFqYLAOOziHDHSYT5pM3KnlqsyCC4InRRsVzyNQ== X-Received: by 2002:a50:be82:: with SMTP id b2mr49856735edk.56.1634045459703; Tue, 12 Oct 2021 06:30:59 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:30:58 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 04/13] am: convert applypatch to use hook.h Date: Tue, 12 Oct 2021 15:30:29 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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, post-applypatch, and 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 3527945a467..2cfe6451b6f 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -446,9 +446,11 @@ static void am_destroy(const struct am_state *state) static int run_applypatch_msg_hook(struct am_state *state) { int ret; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; assert(state->msg); - ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL); + strvec_push(&opt.args, am_path(state, "final-commit")); + ret = run_hooks_oneshot("applypatch-msg", &opt); if (!ret) { FREE_AND_NULL(state->msg); @@ -1609,7 +1611,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_oneshot("pre-applypatch", NULL)) exit(1); if (write_cache_as_tree(&tree, 0, NULL)) @@ -1661,7 +1663,7 @@ static void do_commit(const struct am_state *state) fclose(fp); } - run_hook_le(NULL, "post-applypatch", NULL); + run_hooks_oneshot("post-applypatch", NULL); strbuf_release(&sb); } From patchwork Tue Oct 12 13:30:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07C1BC433F5 for ; Tue, 12 Oct 2021 13:31:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE0646101D for ; Tue, 12 Oct 2021 13:31:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236912AbhJLNdK (ORCPT ); Tue, 12 Oct 2021 09:33:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236879AbhJLNdI (ORCPT ); Tue, 12 Oct 2021 09:33:08 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACB7CC06174E for ; Tue, 12 Oct 2021 06:31:06 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id a25so65268208edx.8 for ; Tue, 12 Oct 2021 06:31:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UmOzkmvYJAHGeV9locM1gpM9LYZf5E8OArUGc1uLP68=; b=T4Wos4v767gXxILYAwkoMbgWqP6jvjXA8ShXb6Md3nDpKpG6Yvl0EXTSC2WrySjznw y2O59zwpjO0wOdkfjLYc6Kn3LgZl5OKIlO3ymF+Bv0HwyN/8lJbBaGSqZW5BW96E1dul u6qGJqVCD+IjQlixMPpH8RAPOJltUeYBesOjbSAdz1OSZayyo1hrtay2N2kCxrGZ91bH 3sjuz27rPz6KPO9tXJNDujTdQg39Skol4mwjeW0CqHB+74siKGy9y0jOnTz1B+EdfNYn 1Z9UDtJlKObyCjBrxCTtF/iBraEnh6Zqid0ydq9nrURZmAqItO4IKNBCYCAfLAj2lLRO 9yrQ== 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=UmOzkmvYJAHGeV9locM1gpM9LYZf5E8OArUGc1uLP68=; b=wN0AF41pqSMIgEBRu6Ri6XNeB44rBz9PQN3PLQ92jO8Tm5SOKjlW8wF2NSOLcv26e3 e69dAdnNNYYtFbO3IvPQRwWBSkKCuUnIg2VNIS8TJa+4rJAmeXvIU9gyRYoTk+SFUxaN P86gPUKtPy7hDKtyWnCupjlmCURngIgsi4Zx9LpdCMbRuv5O1v/o1+0eD15SXWDzjyVW ccsXRupXE5j3GFSHZ8unkS/i248yy7+B+ryM4QffwMlthM2udmP5Zb1mt4KOcVINhYVJ h0cbmEp3rdUNxq8sm7XiPOXHar6S6xTrBBQAhFjmy98jbItIDgZNrIFvRP2aUUNpznAi JyPQ== X-Gm-Message-State: AOAM531Cduxboj1gKLF+Hwy0I42OPm63s+pVtzaYUE9fWPzCjpql3VJ3 xjLubEa/3VFhFGwk7F1Dqw6qZSfCqdSEmg== X-Google-Smtp-Source: ABdhPJwArKTXjxId9BWRR163vnXUTe78/qhNN0OVHdArPKvkgkU1kV8PlxKyMWv1Ra4TOi5mtBOJEw== X-Received: by 2002:aa7:c945:: with SMTP id h5mr51092643edt.350.1634045461621; Tue, 12 Oct 2021 06:31:01 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:31:00 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 05/13] hooks: convert 'post-checkout' hook to hook library Date: Tue, 12 Oct 2021 15:30:30 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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. For "worktree" this requires a change to it to run the hooks from a given directory. We could strictly speaking skip the "absolute_path" flag and just check if "dir" is specified, but let's split them up for clarity, as well as for any future user who'd like to set "dir" but not implicitly change the argument to an absolute path. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/checkout.c | 14 +++++++++----- builtin/clone.c | 7 +++++-- builtin/worktree.c | 28 ++++++++++++---------------- hook.c | 9 +++++++++ hook.h | 9 +++++++++ read-cache.c | 1 + reset.c | 14 ++++++++++---- 7 files changed, 55 insertions(+), 27 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 8c69dcdf72a..555119cc322 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,13 +107,16 @@ 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", - 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); + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + /* "new_commit" can be NULL when checking out from the index before a commit exists. */ - + strvec_pushl(&opt.args, + 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); + return run_hooks_oneshot("post-checkout", &opt); } static int update_some(const struct object_id *oid, struct strbuf *base, diff --git a/builtin/clone.c b/builtin/clone.c index c9d4ca26640..4b356770739 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: @@ -659,6 +660,7 @@ static int checkout(int submodule_progress) struct tree *tree; struct tree_desc t; int err = 0; + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT; if (option_no_checkout) return 0; @@ -704,8 +706,9 @@ 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()), - oid_to_hex(&oid), "1", NULL); + strvec_pushl(&hook_opt.args, oid_to_hex(null_oid()), oid_to_hex(&oid), + "1", NULL); + err |= run_hooks_oneshot("post-checkout", &hook_opt); if (!err && (option_recurse_submodules.nr > 0)) { struct strvec args = STRVEC_INIT; diff --git a/builtin/worktree.c b/builtin/worktree.c index d22ece93e1a..330867c19bf 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -382,22 +382,18 @@ 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; + opt.absolute_path = 1; + + ret = run_hooks_oneshot("post-checkout", &opt); } strvec_clear(&child_env); diff --git a/hook.c b/hook.c index bfdc79e2f1a..186c249bbec 100644 --- a/hook.c +++ b/hook.c @@ -63,6 +63,7 @@ static int pick_next_hook(struct child_process *cp, cp->env = hook_cb->options->env.v; cp->stdout_to_stderr = 1; cp->trace2_hook_name = hook_cb->hook_name; + cp->dir = hook_cb->options->dir; /* add command */ strvec_push(&cp->args, run_me->hook_path); @@ -116,6 +117,7 @@ static int notify_hook_finished(int result, int run_hooks(const char *hook_name, const char *hook_path, struct run_hooks_opt *options) { + struct strbuf abs_path = STRBUF_INIT; struct hook my_hook = { .hook_path = hook_path, }; @@ -129,6 +131,10 @@ int run_hooks(const char *hook_name, const char *hook_path, if (!options) BUG("a struct run_hooks_opt must be provided to run_hooks"); + if (options->absolute_path) { + strbuf_add_absolute_path(&abs_path, hook_path); + my_hook.hook_path = abs_path.buf; + } cb_data.run_me = &my_hook; run_processes_parallel_tr2(jobs, @@ -139,6 +145,9 @@ int run_hooks(const char *hook_name, const char *hook_path, "hook", hook_name); + if (options->absolute_path) + strbuf_release(&abs_path); + return cb_data.rc; } diff --git a/hook.h b/hook.h index a2b8d4fc6bd..7a858a6beed 100644 --- a/hook.h +++ b/hook.h @@ -14,6 +14,15 @@ struct run_hooks_opt /* Args to be passed to each hook */ struct strvec args; + + /* + * Resolve and run the "absolute_path(hook)" instead of + * "hook". Used for "git worktree" hooks + */ + int absolute_path; + + /* Path to initial working directory for subprocess */ + const char *dir; }; #define RUN_HOOKS_OPT_INIT { \ diff --git a/read-cache.c b/read-cache.c index a78b88a41bf..9773118d078 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 */ diff --git a/reset.c b/reset.c index 79310ae071b..1237ced8a58 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, @@ -125,10 +126,15 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action, ret = create_symref("HEAD", switch_to_branch, reflog_head); } - if (run_hook) - run_hook_le(NULL, "post-checkout", - oid_to_hex(orig ? orig : null_oid()), - oid_to_hex(oid), "1", NULL); + if (run_hook) { + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + strvec_pushl(&opt.args, + oid_to_hex(orig ? orig : null_oid()), + oid_to_hex(oid), + "1", + NULL); + run_hooks_oneshot("post-checkout", &opt); + } leave_reset_head: strbuf_release(&msg); From patchwork Tue Oct 12 13:30:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA7A6C433EF for ; Tue, 12 Oct 2021 13:31:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B056E6101D for ; Tue, 12 Oct 2021 13:31:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236773AbhJLNdV (ORCPT ); Tue, 12 Oct 2021 09:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236853AbhJLNdJ (ORCPT ); Tue, 12 Oct 2021 09:33:09 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABF30C061570 for ; Tue, 12 Oct 2021 06:31:07 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id a25so65268421edx.8 for ; Tue, 12 Oct 2021 06:31:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FwydAA9+XG/fWb2WQeKawbthbsDNY7R6cy2eA5hH3PE=; b=aw8k8cjlQEbsQJkU0GcLffqUOUMEcQm61rYIH9IQoqJDQtlazArj/9KAlFZ+KLHuV6 lSWrnSxE1BxEDRBWl8v1GhuRA7uO8jMqtB+9fQJl51vSu5IIrRe4hflzaisjoLQO7uVY k7U6ASgWmhM2VpnUy1ywZCB+mavNQx1hWSxM4AJVozUbuixJ72pjmXXESP9OGziovz4F aGyBG5/O4RH3wD30zX2fWpMzWJZuzuuCziBZmVnJGqt6HoR1Yxg03S0VTCTkBPeKdaMn vNRMeYwkPVdJGKUP1BczWke6SRKKW4a6hRV29Yw+ZzhH6VixpD4kswDXOCNkh/6cYqnh qk+A== 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=FwydAA9+XG/fWb2WQeKawbthbsDNY7R6cy2eA5hH3PE=; b=ocOPg5mE8RN2ZgAZUg6m2wu6A53oKZ0IIMc7jD77Jk86NB4bbG6FI0WnHA3QBzCsMf 3MDSVItaFrN+7HuQVEvAPx773FwMO7HYD35CxdiDuiYaZdQPokNe00TBJAnbcvJtZGrh 1724NMsMBeKkyx6jlGUbH0UZQ1DprkU+yvN7ROAuwfglaSqC1FlhtI8L6cK087mSk7Tf 2W6I7Ca8iWfR6uTI1kdQ1kJ+ePwh/v94f/mczTY6Z1kOHLJTCMCyzG8TXFnBm4dJ3pFv m46lvDbdf+cer44XfVkBsVs1v1kPjXsD8FFc6PROJl8qgcdKXepuL/i2+YdEQAIs5YrE sYSA== X-Gm-Message-State: AOAM531x6hwtM6xSEMDfcIsF6xgTxIqoszc/ZYK0ZhCugoJBXz2SQyoz Ibwd0nTrCq5pvLy397zMqq/ItoIwy11Kzg== X-Google-Smtp-Source: ABdhPJzD7qtu1vXg7qIfSfuBUEihzLe3lagu9cAwtPsEiayU7TK5qWdBUEg+IQ+Uic4fRt5TbDTPKA== X-Received: by 2002:a05:6402:520b:: with SMTP id s11mr31921490edd.123.1634045462748; Tue, 12 Oct 2021 06:31:02 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:31:01 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 06/13] merge: convert post-merge to use hook.h Date: Tue, 12 Oct 2021 15:30:31 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/merge.c b/builtin/merge.c index 956b6259f21..167d13bd737 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -448,6 +448,7 @@ static void finish(struct commit *head_commit, const struct object_id *new_head, const char *msg) { struct strbuf reflog_message = STRBUF_INIT; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; const struct object_id *head = &head_commit->object.oid; if (!msg) @@ -488,7 +489,8 @@ static void finish(struct commit *head_commit, } /* Run a post-merge hook */ - run_hook_le(NULL, "post-merge", squash ? "1" : "0", NULL); + strvec_push(&opt.args, squash ? "1" : "0"); + run_hooks_oneshot("post-merge", &opt); apply_autostash(git_path_merge_autostash(the_repository)); strbuf_release(&reflog_message); From patchwork Tue Oct 12 13:30:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C00FC433F5 for ; Tue, 12 Oct 2021 13:31:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72DFF60F23 for ; Tue, 12 Oct 2021 13:31:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236903AbhJLNdX (ORCPT ); Tue, 12 Oct 2021 09:33:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236889AbhJLNdK (ORCPT ); Tue, 12 Oct 2021 09:33:10 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 434F7C061745 for ; Tue, 12 Oct 2021 06:31:08 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id d9so57232636edh.5 for ; Tue, 12 Oct 2021 06:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jGqs/XUnJ5Y7+xSjOqY9uHIYqZbTxjYJ79DPSRzb69c=; b=hmOrGlsmZ5pu4/rXMNhal1kXCwi3kLKC8OgrgPYZa2ltdLDClmsbi/JuhRDm/7lyS+ i9A8FWgFt1vzipuv5EgpjRD2eaGsObfdpslJiHwjW9Y5fru/qJfeU2in86UI5NqD8BD5 zJMvLGSOuNNbiqADVeQDz1xtHMb+ZI2EbezfZj6Ye80n/JnDPRhLMBM1XtV8HdgTF9eu rQT8W6hT/smrz6kW9gKotBvTVGp1IC9wylzNR0k1lNkLZ4ZZ40h/yc7LVFDTv/e/VBf9 kLSS23AWxx9H3cFH+dpzcGgU5z3z2d2Upryqgy+FKiTmzW4uB1/eSG/HuBDO8zIRXSzh LoCQ== 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=jGqs/XUnJ5Y7+xSjOqY9uHIYqZbTxjYJ79DPSRzb69c=; b=sdDnIqeb+CopQdIFYtBFyJC0rjjsfRZEaXOmlgJDU1YF5vUW6cMdMW9sHf6KaJrdQz TJ9UXEi4D7kMrdfp1ASLPSVXwSm8Dh0rGsYUE9yfjqZm9OEDZnQEXJKfCS2Z6eJlcYyh G15M5An17gmihu4Oz5eymfezWBQpvVoXqv/86ZwHY3eCbI7RPAjuggrO4PRlN4U+RNlV q68i2NZltYRvRPzRS00I9cSui2yyOXAJdV+ZbpMC4HjhpJepp8CO+kNbjILTFuVhodkA hDJHWBqhqBDRwCJCINffvd/7nl4AbUuTrgOQYlUMtCwzeK8q0vqnB4ErHOGu7MTPVvDQ d5BA== X-Gm-Message-State: AOAM530Yn5whA2oiJrjSQl5WA6HP0ZbF6/kvmY1ZAOVIiR+cs5ZZ4+uD w06QHncAi4ke4hNBGyvY8NCZFaMu99dF8g== X-Google-Smtp-Source: ABdhPJyNQWqZC9zEMJFRAF0uML8jD4/FdVl7TPUaX9LbupLY2qtTdH8+cLBIxP3qH5u/NLxWY4yxhw== X-Received: by 2002:a17:906:5ac8:: with SMTP id x8mr33166591ejs.132.1634045463986; Tue, 12 Oct 2021 06:31:03 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:31:03 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 07/13] git hook run: add an --ignore-missing flag Date: Tue, 12 Oct 2021 15:30:32 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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 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 | 10 ++++++++-- t/t1800-hook.sh | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Documentation/git-hook.txt b/Documentation/git-hook.txt index 660d6a992a0..097fb9de63b 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 ----------- @@ -29,6 +29,14 @@ optional `--` (or `--end-of-options`, see linkgit:gitcli[7]). The arguments (if any) differ by hook name, see linkgit:githooks[5] for what those are. +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 012a2973b38..e6b01a7f5c6 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,9 +23,12 @@ 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; const char *hook_path; struct option run_options[] = { + OPT_BOOL(0, "ignore-missing", &ignore_missing, + N_("silently ignore missing requested ")), OPT_END(), }; int ret; @@ -55,9 +58,12 @@ static int run(int argc, const char **argv, const char *prefix) /* * We are not using a plain run_hooks() because we'd like to * detect missing hooks. Let's find it ourselves and call - * run_hooks() instead. + * run_hooks() instead... */ hook_name = argv[0]; + if (ignore_missing) + /* ... act like a plain run_hooks() under --ignore-missing */ + return run_hooks_oneshot(hook_name, &opt); hook_path = find_hook(hook_name); if (!hook_path) { error("cannot find a hook named %s", hook_name); 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 Oct 12 13:30:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81414C433EF for ; Tue, 12 Oct 2021 13:33:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6218F61050 for ; Tue, 12 Oct 2021 13:33:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236912AbhJLNfM (ORCPT ); Tue, 12 Oct 2021 09:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236920AbhJLNdP (ORCPT ); Tue, 12 Oct 2021 09:33:15 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 642C2C061767 for ; Tue, 12 Oct 2021 06:31:10 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id i20so64599759edj.10 for ; Tue, 12 Oct 2021 06:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4BFFKJStaje5Bteau/87786ZGo86FiscjRMM7Bq9g68=; b=YvE9fuPYXQZVxbUMVqmXM4M6a6/c2h1hDWz8Y65iUdOo/IR6rKh0++hWjHJFJWtmwR Va5zqu62G5nDfhtWwRkOEgImz4zjIZb8aCW6jl5inSepU4Y2nDF99BaulpEjAR8OpTN5 JyDsHYVVHCDzKvfG/Z+IAVN5Gxh3PmDx3JSteLfjN1I75sdmJYuK7miRLANRL5+lRbbh zHP3QIPq0ewdggOR4Bh3wM0sv/K0a3feyWcwetZ8Mv0MZjyRPLX2HQ0eRU/yeNzqNlvc R9vBizPRx/BqnWB7RzhId7iS6V6THb6GbrFuS9U9vuNhlGt6u/hC1oVroy9DdLxV3cEP u3wQ== 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=4BFFKJStaje5Bteau/87786ZGo86FiscjRMM7Bq9g68=; b=Gn/F/467QGUMqcw6DEoI8UMeags7tpyGPyXVlFz51QBplmAJDe6wHmmN8fp7q3lIcy OTUjEFZaQxSf7+r/BIdWs1sFuBon0SLJVh4LE3NDEt2GE15RZyGi0WjazHqHo0dsKfpD asS+yD1WzlbAp6iAQGt31Rh71+1vqDlCBrBOrAWhcEOk7xH75B3ae5b4slXLvbXagiYm MYWrt5j/ivwz0DgH8z/iS3i/J8wMbJnVAixzjgGEY4fXbOT4V7Fsq1c/QSqEosmvbLos /dF1MA1MoEoQbj8X/PF1E7QESKXplEALPlwJlwZ13xZdtPCvjpfbTk5pKPkeH/GjAHeI 7w+w== X-Gm-Message-State: AOAM5303paMAljTtP44d+nfC0ZPDozq8YHn9qToMyAQLN5ZvRbEbMLvI 911xe6Akb3TbaPxzhwdi1ahPwkA3CuUCqg== X-Google-Smtp-Source: ABdhPJwo6miv0M5QMDErY8SfYCxdmexZJTPkOOyttRWrqsRZkO0KB0v7CWDtGwp6dIm4hoI3n7Y8Vg== X-Received: by 2002:a17:906:fc7:: with SMTP id c7mr32830806ejk.333.1634045465174; Tue, 12 Oct 2021 06:31:05 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:31:04 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 08/13] send-email: use 'git hook run' for 'sendemail-validate' Date: Tue, 12 Oct 2021 15:30:33 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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 Oct 12 13:30:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61FACC433FE for ; Tue, 12 Oct 2021 13:31:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C26E6101D for ; Tue, 12 Oct 2021 13:31:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236878AbhJLNdW (ORCPT ); Tue, 12 Oct 2021 09:33:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236890AbhJLNdK (ORCPT ); Tue, 12 Oct 2021 09:33:10 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58A47C061753 for ; Tue, 12 Oct 2021 06:31:08 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id y12so68337190eda.4 for ; Tue, 12 Oct 2021 06:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WhloPMShTRx9Cpe0BYA8PAVBrJ36V9soI0h3m8gb3wU=; b=QwfTamP9SN3RsFdskrfQHzsGP2M6FPljDffSZYVyETWF+ot0ZuEQimKFHPbdJlx9cw TMr6VLvH7DWgRVKHe8iC6DXirMTYmvAz31PrgfaoLAG4BgmiYOQJr1DQCWmKM3zw6lcj 003nCnGwxsoifI47BVDk/vUGM0ENvkyj1ZdDIQTncmzYqcamT0E4g9123QATubRdBgzK itka3As+wxqWjA2ml5eh3j/he5UPWw9um7OnUcWNUehRl13wHymXgVnmEVah3QJG1Mie mteyS6ZLds+nYqRfMVXBDAK357lkZmo+ITShU2gR2JYehXZRJ6pDvaYa74Kv0q3hTX+Q gFcA== 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=WhloPMShTRx9Cpe0BYA8PAVBrJ36V9soI0h3m8gb3wU=; b=cRXuMoLY1htx7Lkvhug6P24olZdsSwUKcMRXXzpSz1qNwRVTHW7OGc/HbWhYD1uPC2 bsB2/QMHxeIDNws7MY3a8sDRXFCW5hwi80mZz186sQyr0ve7zHctqUVkzV3H7st+SRvD IRed50zIJiYBWGkLjBCDl0Wj15Gtmo42Fa/oTIg+amXQkPaqb/F8y85IBomjjSqAKAOU EWO8Ac1s2WosqepVoQDdzW0pl1xmYNxUKSdEEp8qVRZPz/Tvnmp1phabbIOsgj9rd6Yg MhviaijEICHWm9LM0R6NJLcyyEsow4kQOcYvNL3YH8gh2/V9US+dEJit6hMB/dZi7fSt rzPg== X-Gm-Message-State: AOAM532Sxm6ckFOj5QAjd+pGL+i1fF4oeRi+HxqIHufw0B+jv1dJOI05 mjTyzCg/CfjyKto1SFQseeHEafAb/uJLGA== X-Google-Smtp-Source: ABdhPJzHLOxmZdySF/cXrmrFReEZXwdDSrLsh3tq5PbJo3P1DhHR8m1QmLlply0bGSl1AMD/adMAhw== X-Received: by 2002:a17:906:7716:: with SMTP id q22mr34367090ejm.457.1634045466518; Tue, 12 Oct 2021 06:31:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:31:05 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 09/13] git-p4: use 'git hook' to run hooks Date: Tue, 12 Oct 2021 15:30:34 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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. As this is the last hook execution in git.git to not go through "git hook run" or the hook.[ch] library we can now be absolutely sure that our assertion in hook.c that only hooks known by the generated (from githooks(5)) hook-list.h are permitted. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- git-p4.py | 72 ++++++------------------------------------------------- 1 file changed, 7 insertions(+), 65 deletions(-) diff --git a/git-p4.py b/git-p4.py index 2b4500226aa..1f24cbf0bca 100755 --- a/git-p4.py +++ b/git-p4.py @@ -207,71 +207,13 @@ def decode_path(path): return 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 are specified with -a -a -a """ + 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 Oct 12 13:30:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F6E1C433EF for ; Tue, 12 Oct 2021 13:31:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0827961040 for ; Tue, 12 Oct 2021 13:31:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236924AbhJLNdY (ORCPT ); Tue, 12 Oct 2021 09:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237000AbhJLNdT (ORCPT ); Tue, 12 Oct 2021 09:33:19 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2011AC061570 for ; Tue, 12 Oct 2021 06:31:18 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id g10so80381164edj.1 for ; Tue, 12 Oct 2021 06:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aS07F5XXW2YQcc52JWFDy8Wv0Sv3g8l6JlGjWc0BNhs=; b=qPpOdJeOKLPETu/N0GafwKZpDBI4w1TReRrLT6A0PLTHeND9ziPOVLQFkPLh5Tg9PG TPtqJ/Zrh7ucJBnG7iyt5KBsNbwoPASt8czW8q9yKNe9QhNXL8kbAIZWNjztqwi7w15a A51GAh1spSVWBs0ZnT2j0wFxp5zakHfQcS+bF7hFfLsbGXKQasXsQ1SiVgP4eCjrJq/W 4G1nhbyJHs+HiwxqlBJkQ8tEXgzPqPw/RAh1CBVTQ2rBJEzjGETyP0MajX+ntASO8bvF IGENW/T1Gx6S3TCPX1JS+UaDO5xTv12hK6Il/7OL+3d4vevUN5RJ/pzB1aNjtgGTve88 aM5Q== 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=aS07F5XXW2YQcc52JWFDy8Wv0Sv3g8l6JlGjWc0BNhs=; b=g5JqDpllXG8pwkxpTmQ78CIBjHdBouL53wg/UTiIcN+hTfKCwxBdYk7kvXRlFWCHZv xL4eNmXtohgYXak3n6vBtJq3b5ajCDzQXesFoaNb1MdoGmr/odvo2bfaJl3dz4Gi3KSH of93wJlzCtKovYkkg+4XqNZ6FC98n/CJwmtKxUaqbmo4HDA2vfB3PgCDsZIZx2Krd3d1 xhacmDat3qKBc1FI9DouCGRjRpmTPph0In1A1vqxCIQN3mTXWJhESy5OVPCwzXobCcWV K6ozZTFd97Q3gYofEQPLeV/bL1uquj8zOKlRj1CxWFHXZHAArM9+y9K1hkDOpyDeqlOL 16EQ== X-Gm-Message-State: AOAM5320bd8K4hIybA9ssJ8A7HKatsVSxFTEYtwLRyoeoI9bPM3hT4+H YC8iG+9aIsN3LA9aFmZzWxMVx2uORxOLYw== X-Google-Smtp-Source: ABdhPJxrhLQruwY3tQY4eZUN2ZA5ywLoCYL3n4LL64LNv999CDknqStkI8NI5NgAiwKrb1gYtQXJHQ== X-Received: by 2002:a50:c006:: with SMTP id r6mr51978692edb.289.1634045467749; Tue, 12 Oct 2021 06:31:07 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:31:06 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 10/13] commit: convert {pre-commit,prepare-commit-msg} hook to hook.h Date: Tue, 12 Oct 2021 15:30:35 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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..4e7cbd7585d 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_oneshot(name, &opt); } From patchwork Tue Oct 12 13:30:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45314C433EF for ; Tue, 12 Oct 2021 13:31:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AF3860F23 for ; Tue, 12 Oct 2021 13:31:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236917AbhJLNd1 (ORCPT ); Tue, 12 Oct 2021 09:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236861AbhJLNdW (ORCPT ); Tue, 12 Oct 2021 09:33:22 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79789C061570 for ; Tue, 12 Oct 2021 06:31:20 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id z20so81083207edc.13 for ; Tue, 12 Oct 2021 06:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lKDeerjw7gH8UCoPGHuOtep1D7ZSA4jINp4kuhDSpd0=; b=BKvp2lYft+Nh7klqd2w31dSp5fIH+pCQsInGODtQaU1ULvCyLeCQCO41Ud2W37s90A dfCkN4MSlLovOfjCZM0k0NWdyesX6lLd5+cvXxLUBRdOCKGFVCw44PVl0ZkhSwVn4SaJ WKRwFiBmT+EmwEa32YgInu6tVadZQy4mrBLIH5JvxYLNA3DyqlshIfxEW+uALI87dBDh C1YGuiENhV+4K+fHZ4TCd4Wd1Aq0h40vN15ZwYC6q+9GGTkZR+wKC+xLt0hXPpsE/Yo+ Gm94UNE63F3hv+Xs7u8ciFUsBesunxE8hp2eRA0Cc6KsuYYFIxH3zP3orU6woVVKASyg STsw== 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=lKDeerjw7gH8UCoPGHuOtep1D7ZSA4jINp4kuhDSpd0=; b=8HQKPJE9X1g2LEUCv8zqRxvGUzh/Qtw22a10qOY7g3SsiIP8IF2Oa0lSTsyKbtbFeh NWu4DRdSNQpuBMioW5FNWDQZ2IaClP2m2DaxCMHOidGiqKBDJfZzAIJVPSzHrKO//azJ 5nQ5Lrp0ymN7fiQHLJuaLDsCvcDYVLWW7qEeU2LzU80uqtgf+UQkyiZyzobfyVP6XntW zfxTDmuKy1zGEOz5arBRek0hih3lszXDqMwQls3vVzsYzrB+1vN1p3P1crdd+HeF+DQR uS/HPtpTqSpLhrCpX+NzmI1/gg8S4a1KLO8qpd+fW5uKt8pp8pyA6G5vIF5iPc04k+ER q6kQ== X-Gm-Message-State: AOAM533POyeAxXs6i8LqQZtMhzAq9IkNNSX1gWNy69IkMIWbTWYYuDHd G8Ca2RIMx2dLmVPYSaMHYmTn7bPyDT9M+w== X-Google-Smtp-Source: ABdhPJw2Q9RE6ME2uAOIjZMqiBA7HhyfIai1F5w4C+Ib8U71++aBfrMAVKXuucoqztp/Oa+xuJuOug== X-Received: by 2002:a50:be82:: with SMTP id b2mr49858576edk.56.1634045475778; Tue, 12 Oct 2021 06:31:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:31:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 11/13] read-cache: convert post-index-change to use hook.h Date: Tue, 12 Oct 2021 15:30:36 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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 | 10 +++++++--- run-command.c | 2 +- run-command.h | 1 - 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/read-cache.c b/read-cache.c index 9773118d078..84cc3d88196 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3087,6 +3087,7 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l { int ret; int was_full = !istate->sparse_index; + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT; ret = convert_to_sparse(istate, 0); @@ -3115,9 +3116,12 @@ 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", - istate->updated_workdir ? "1" : "0", - istate->updated_skipworktree ? "1" : "0", NULL); + strvec_pushl(&hook_opt.args, + istate->updated_workdir ? "1" : "0", + istate->updated_skipworktree ? "1" : "0", + NULL); + run_hooks_oneshot("post-index-change", &hook_opt); + istate->updated_workdir = 0; istate->updated_skipworktree = 0; diff --git a/run-command.c b/run-command.c index e4862b8f46d..7a05aa73e3d 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 5e544acf4bc..f06b39c50ee 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 Oct 12 13:30:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B83D7C433FE for ; Tue, 12 Oct 2021 13:31:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F12161040 for ; Tue, 12 Oct 2021 13:31:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236926AbhJLNdZ (ORCPT ); Tue, 12 Oct 2021 09:33:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233296AbhJLNdV (ORCPT ); Tue, 12 Oct 2021 09:33:21 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48601C061749 for ; Tue, 12 Oct 2021 06:31:20 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id t16so59351101eds.9 for ; Tue, 12 Oct 2021 06:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iBDjdgd/Hpdiz9QOa9PGjBGbg5jmNn+Lkf/ybTrFUsM=; b=qscKEnY3v655tvC8qwOLR4jzGILUipE9wYP9Z+4qPTrXk632l3Q6NhFA+cQLnXEMtU t3eciYFDrC24gjIcJDfLG4yZXDu/d6NiiC7jTFjWmaKbJS3SplRz5vqEyC8xNvZzJgmX WCsRXira6Eo+0/XlHbM4oW4K3E8l4n5qR1HloqR6BhSUkzBO2zwAwb0R6gMXUUh4e7/g bBcmg6v3k+Z+VN7YoVAQ+PJZMinrDW2qt0B/GnzdjfNRyXfNKTnrfgU708nap8aSGmL8 OnvnG8CeBN3fvneU4geEjufvOdGQax6Z91KqxrJnNvx4o8iGisauSSsGqNNRhx2EWJWq Q42w== 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=iBDjdgd/Hpdiz9QOa9PGjBGbg5jmNn+Lkf/ybTrFUsM=; b=3BU8/uImUEnI0dXAk7EF+vQ8LsIvSQoSluUxQ62Jn+WgYbsZ48YT8C01Iaf1RyBSig ODed+2Oa6q1jsKnIcDb9bgTtN89YBmtI9SE2wc+m9+B9adFqyWRYMjf0TCcmegPYC6KI EtdGpYaRwdA5AwSybycocKS/R7aoGdvYToi0keN1vV50Jo3dHuOkfGzJKnsxcAvPtVuz 51DDxn2fUA3NtL0HSBQ0LnEmg0GNbgW0k19TsaUka+GUTVJoGg3+ijjY57Qn/2LFWVrR Yud31f0jdAJVbmaxLoc8OQkOPB7VOz2qnYlL9Zps6YguNbvJWpRh9bYVpov/RBaCGwYp ZkKQ== X-Gm-Message-State: AOAM530xvdzq1NYoTXPgiB1q0YLDubAQ0ENKLQm3JI0Uzu/8wxYY7J9l Vl7j68FnkGLoZ+rYl+P87jDii2Svq1Nlew== X-Google-Smtp-Source: ABdhPJwYzjmC8K4Xqowy+Aiz4lEZz/x7FnEnn8XikUsWSBck3uso0VlL/Q6NX8fg9TyqRlttFS8jjA== X-Received: by 2002:a17:907:6283:: with SMTP id nd3mr32368677ejc.362.1634045476680; Tue, 12 Oct 2021 06:31:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:31:16 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 12/13] receive-pack: convert push-to-checkout hook to hook.h Date: Tue, 12 Oct 2021 15:30:37 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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 25cc0c907e1..22e7a431728 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1435,9 +1435,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_oneshot(push_to_checkout_hook, &opt)) return "push-to-checkout hook declined"; else return NULL; From patchwork Tue Oct 12 13:30:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12552637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA513C433F5 for ; Tue, 12 Oct 2021 13:31:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B76BE60EB6 for ; Tue, 12 Oct 2021 13:31:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236941AbhJLNda (ORCPT ); Tue, 12 Oct 2021 09:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236896AbhJLNdX (ORCPT ); Tue, 12 Oct 2021 09:33:23 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0565BC061745 for ; Tue, 12 Oct 2021 06:31:22 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id g8so81218708edt.7 for ; Tue, 12 Oct 2021 06:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=etAb3RTVGQOQ1l0KO7fd+/AN9YDkbZqth6qtUGTjzqs=; b=Jo9ynXedetBULxbbWo/bBX7bJJkcsGkQljjLfk4cZRaQHMaBY4y/WhNvt91rGA4ymZ a1z72yWw4mXzZJb8aFQqNHGRBr1Vy29/AYFuyfaFTtG4l3XZ74dXWnXYwSrIRNXi8EkE I20q8QkXYACxC4xPYtX2po7bcztA5SDuYxv7VAh93C13MU7vw6avdD1V1gl4xMA1imMh YOxh6AXovoGxc+MfSzepu/kzwBEfHiUlw0PorxzEDVUBsLUg0CgIXcxBiUQHYDAyuFQN gVIos5iQgkSWEXhDlVIU4YPXIfgSViuIpaGbeMcdt0cskJEon9twzLXdizUqml7q9tLr tpiQ== 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=etAb3RTVGQOQ1l0KO7fd+/AN9YDkbZqth6qtUGTjzqs=; b=eMuWojeMwnFzkwObXIHnmaVSkLG3uFiHaigZyLxCCVpoP38ctzfUK3X4OnLDgvrqT7 RIp2d7qWHqB+cMPmkv/mriWEQgWJ/5Lrs+0vc2tLPcl1XFQvsSQr8mWse8gWR6alXhNl E1ssUxo3faYMylBoDFk8lrl9eXJUeUDuoDOVkmvmrVP5XZJKn43Z8sWtJf0MmSOj6xeS 9kc9FBYhSD6qbt98mI9bjPyOR1q7/4RnkOX6jwC5YvDMoIpR5rzwfzoKY9LaaNC3Riww n3h6zabnG4w9sEF4NKzE0BYvUOpk/T2I1yuW+WqlCrQdo3zYs8dcuB3TU1jY0++ph090 gr4A== X-Gm-Message-State: AOAM532amx72zEPpzFZ45JYFgck+Xm5lV+I9YJJo2LrXompjHwU1WewK YTqIj2XD9e+ddYqlxRu26j0FdInpyQzVHw== X-Google-Smtp-Source: ABdhPJyu3SVMwQUdLXTGUowTot1/GXyxX9QszyuvUeqZRrHxLbWEKbxTdpTVFunZRlIDNSLckzWlmQ== X-Received: by 2002:a17:906:912:: with SMTP id i18mr32483159ejd.131.1634045477566; Tue, 12 Oct 2021 06:31:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id bi23sm2016405ejb.122.2021.10.12.06.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:31:16 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Joachim Kuebart , Daniel Levin , Luke Diamand , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 13/13] run-command: remove old run_hook_{le,ve}() hook API Date: Tue, 12 Oct 2021 15:30:38 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1567.g7b23ce7ed9e 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 7a05aa73e3d..e39ce17d009 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 f06b39c50ee..6d6c50fe0a9 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 */