From patchwork Tue Dec 22 00:04:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985457 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5992BC433E0 for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F34222B2D for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726567AbgLVAF6 (ORCPT ); Mon, 21 Dec 2020 19:05:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726296AbgLVAF5 (ORCPT ); Mon, 21 Dec 2020 19:05:57 -0500 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F31EC0613D6 for ; Mon, 21 Dec 2020 16:04:45 -0800 (PST) Received: by mail-qv1-xf49.google.com with SMTP id eb4so9335666qvb.21 for ; Mon, 21 Dec 2020 16:04:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=DKmsIxc4f89WV+IsjEfUFNY3Ih4tONMREdtf+PB9Zak=; b=YIjK/KiGbJ4rxfawWEne0Rm6+qxvEQe9Jdv8UqOjoo5wNp11QbRObMcIuLHct5OaCI kuxfcPFjuaXNbFYxo+rzAWQZorsJuI3j4TdEYvBumvwyntJBcnXHLtISuCPKIWxoEhZI muttuHsLt+efTv48gQUi0XcTaE9omZ7FO+a0SXMmviJ6n3LMqcRmQjnXAsewq1x5cHem dBn7Ri3zZtEyUGTv/L3XTcN57qykdXY0LiQc5Ki/SG/sF+aKqy4yW367ez7C3k/V+RdC YBoBOaJMfFO4RNWwWQm/ZvSqYtBtYXEtr2e85oFRBvXpoEPuWgXv6KzkPfHE7o4l+TiD WDMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DKmsIxc4f89WV+IsjEfUFNY3Ih4tONMREdtf+PB9Zak=; b=nNxzRBSebUy4xzRUz51BMsEuPKIYuKvqcGfby6SGt79EdMTBjdZIBIgsZf5p8liK2N cu2ikuuOU2OCa8uVF0Ato7+s4pcfCdF4tvGjXIy01I+0vUKXb8Ji3Kf02JjB/Zj46QZC rRlBsmWy5D74UPsrrAk4+wo+mS7T6aXI1XWINzP48icetIN5QXROdyzcqrIjJxVRdwLu z/Yj+V8hvfOHOswHLoI2sA8XnSC+AqPWutgi3aQHsT9jh2K9z/gctGqoIxegLMZPKPZ7 C6zjb2hhNMvzQi5kgQ1kY1kwFnPkkeT/frDi6gbBc/7i7g5L9uqNdPFHPA8Hbvr23Un6 RNiw== X-Gm-Message-State: AOAM531DaphPEequO2X+fUWrgQ/CNFqregJ1G2OO+KVNUpQcXuxZw/5f +weuFl48O5QxCrfIExNAM0G7cchP3zHipaVQU82C3y66Izr0zAG+V5CLXewvd4OTA3QQqPysybO aubSOb6Lr8riwcXXX0Izv7HpRlurZ4JKCvLMb3E68gi1xmkV5M0nv2dRqncV1nPKKhl2UPm40Ow == X-Google-Smtp-Source: ABdhPJzGdelXVshnN7jyKP2KNq0osbQcelbGqAylfvq7XQcOkg63FsmYJWoiZ9oqmSUfjPyMS0sCK/nDjat/veCgBR0= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:ad4:4e4d:: with SMTP id eb13mr19292228qvb.6.1608595484765; Mon, 21 Dec 2020 16:04:44 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:19 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 01/17] commit: use config-based hooks From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As part of the adoption of config-based hooks, teach run_commit_hook() to call hook.h instead of run-command.h. This covers 'pre-commit', 'commit-msg', and 'prepare-commit-msg'. Additionally, ask the hook library - not run-command - whether any hooks will be run, as it's possible hooks may exist in the config but not the hookdir. Because all but 'post-commit' hooks are expected to make some state change, force all but 'post-commit' hook to run in series. 'post-commit' "is meant primarily for notification, and cannot affect the outcome of `git commit`," so it is fine to run in parallel. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 10 ++++++++++ builtin/commit.c | 11 +++++----- builtin/merge.c | 9 +++++---- commit.c | 20 +++++++++++++------ commit.h | 3 ++- sequencer.c | 7 ++++--- ...3-pre-commit-and-pre-merge-commit-hooks.sh | 17 ++++++++++++++-- 7 files changed, 56 insertions(+), 21 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index ffccfc7760..8b352be43f 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -103,6 +103,8 @@ The default 'pre-commit' hook, when enabled--and with the `hooks.allownonascii` config option unset or set to false--prevents the use of non-ASCII filenames. +Hooks executed during 'pre-commit' will not be parallelized. + pre-merge-commit ~~~~~~~~~~~~~~~~ @@ -125,6 +127,8 @@ need to be resolved and the result committed separately (see linkgit:git-merge[1]). At that point, this hook will not be executed, but the 'pre-commit' hook will, if it is enabled. +Hooks executed during 'pre-merge-commit' will not be parallelized. + prepare-commit-msg ~~~~~~~~~~~~~~~~~~ @@ -150,6 +154,8 @@ be used as replacement for pre-commit hook. The sample `prepare-commit-msg` hook that comes with Git removes the help message found in the commented portion of the commit template. +Hooks executed during 'prepare-commit-msg' will not be parallelized. + commit-msg ~~~~~~~~~~ @@ -166,6 +172,8 @@ file. The default 'commit-msg' hook, when enabled, detects duplicate `Signed-off-by` trailers, and aborts the commit if one is found. +Hooks executed during 'commit-msg' will not be parallelized. + post-commit ~~~~~~~~~~~ @@ -175,6 +183,8 @@ invoked after a commit is made. This hook is meant primarily for notification, and cannot affect the outcome of `git commit`. +Hooks executed during 'post-commit' will run in parallel by default. + pre-rebase ~~~~~~~~~~ diff --git a/builtin/commit.c b/builtin/commit.c index 505fe60956..f4dea2b510 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -36,6 +36,7 @@ #include "help.h" #include "commit-reach.h" #include "commit-graph.h" +#include "hook.h" static const char * const builtin_commit_usage[] = { N_("git commit [] [--] ..."), @@ -699,7 +700,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, /* This checks and barfs if author is badly specified */ determine_author_info(author_ident); - if (!no_verify && run_commit_hook(use_editor, index_file, "pre-commit", NULL)) + if (!no_verify && run_commit_hook(use_editor, 0, index_file, "pre-commit", NULL)) return 0; if (squash_message) { @@ -983,7 +984,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, return 0; } - if (!no_verify && find_hook("pre-commit")) { + if (!no_verify && hook_exists("pre-commit", configured_hookdir_opt())) { /* * Re-read the index as pre-commit hook could have updated it, * and write it out as a tree. We must do this before we invoke @@ -998,7 +999,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, return 0; } - if (run_commit_hook(use_editor, index_file, "prepare-commit-msg", + if (run_commit_hook(use_editor, 0, index_file, "prepare-commit-msg", git_path_commit_editmsg(), hook_arg1, hook_arg2, NULL)) return 0; @@ -1015,7 +1016,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, } if (!no_verify && - run_commit_hook(use_editor, index_file, "commit-msg", git_path_commit_editmsg(), NULL)) { + run_commit_hook(use_editor, 0, index_file, "commit-msg", git_path_commit_editmsg(), NULL)) { return 0; } @@ -1701,7 +1702,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) repo_rerere(the_repository, 0); run_auto_maintenance(quiet); - run_commit_hook(use_editor, get_index_file(), "post-commit", NULL); + run_commit_hook(use_editor, 1, get_index_file(), "post-commit", NULL); if (amend && !no_post_rewrite) { commit_post_rewrite(the_repository, current_head, &oid); } diff --git a/builtin/merge.c b/builtin/merge.c index 1cff730715..d654b6923c 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -42,6 +42,7 @@ #include "commit-reach.h" #include "wt-status.h" #include "commit-graph.h" +#include "hook.h" #define DEFAULT_TWOHEAD (1<<0) #define DEFAULT_OCTOPUS (1<<1) @@ -836,14 +837,14 @@ static void prepare_to_commit(struct commit_list *remoteheads) struct strbuf msg = STRBUF_INIT; const char *index_file = get_index_file(); - if (!no_verify && run_commit_hook(0 < option_edit, index_file, "pre-merge-commit", NULL)) + if (!no_verify && run_commit_hook(0 < option_edit, 0, index_file, "pre-merge-commit", NULL)) abort_commit(remoteheads, NULL); /* * Re-read the index as pre-merge-commit hook could have updated it, * and write it out as a tree. We must do this before we invoke * the editor and after we invoke run_status above. */ - if (find_hook("pre-merge-commit")) + if (hook_exists("pre-merge-commit", configured_hookdir_opt())) discard_cache(); read_cache_from(index_file); strbuf_addbuf(&msg, &merge_msg); @@ -864,7 +865,7 @@ static void prepare_to_commit(struct commit_list *remoteheads) append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0); write_merge_heads(remoteheads); write_file_buf(git_path_merge_msg(the_repository), msg.buf, msg.len); - if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg", + if (run_commit_hook(0 < option_edit, 0, get_index_file(), "prepare-commit-msg", git_path_merge_msg(the_repository), "merge", NULL)) abort_commit(remoteheads, NULL); if (0 < option_edit) { @@ -872,7 +873,7 @@ static void prepare_to_commit(struct commit_list *remoteheads) abort_commit(remoteheads, NULL); } - if (!no_verify && run_commit_hook(0 < option_edit, get_index_file(), + if (!no_verify && run_commit_hook(0 < option_edit, 0, get_index_file(), "commit-msg", git_path_merge_msg(the_repository), NULL)) abort_commit(remoteheads, NULL); diff --git a/commit.c b/commit.c index fe1fa3dc41..1bad721a20 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 **); @@ -1630,25 +1631,32 @@ size_t ignore_non_trailer(const char *buf, size_t len) return boc ? len - boc : len - cutoff; } -int run_commit_hook(int editor_is_used, const char *index_file, +int run_commit_hook(int editor_is_used, int parallelize, const char *index_file, const char *name, ...) { - struct strvec hook_env = STRVEC_INIT; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_SYNC; va_list args; + const char *arg; int ret; - strvec_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file); + if (parallelize) + opt.jobs = configured_hook_jobs(); + + 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); + + ret = run_hooks(name, &opt); + run_hooks_opt_clear(&opt); return ret; } diff --git a/commit.h b/commit.h index 5467786c7b..dd33ead8e0 100644 --- a/commit.h +++ b/commit.h @@ -352,6 +352,7 @@ int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused) int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused); LAST_ARG_MUST_BE_NULL -int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...); +int run_commit_hook(int editor_is_used, int parallelize, const char *index_file, + const char *name, ...); #endif /* COMMIT_H */ diff --git a/sequencer.c b/sequencer.c index 8909a46770..5a98fd2fbc 100644 --- a/sequencer.c +++ b/sequencer.c @@ -34,6 +34,7 @@ #include "commit-reach.h" #include "rebase-interactive.h" #include "reset.h" +#include "hook.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" @@ -1203,7 +1204,7 @@ static int run_prepare_commit_msg_hook(struct repository *r, } else { arg1 = "message"; } - if (run_commit_hook(0, r->index_file, "prepare-commit-msg", name, + if (run_commit_hook(0, 0, r->index_file, "prepare-commit-msg", name, arg1, arg2, NULL)) ret = error(_("'prepare-commit-msg' hook failed")); @@ -1438,7 +1439,7 @@ static int try_to_commit(struct repository *r, } } - if (find_hook("prepare-commit-msg")) { + if (hook_exists("prepare-commit-msg", configured_hookdir_opt())) { res = run_prepare_commit_msg_hook(r, msg, hook_commit); if (res) goto out; @@ -1528,7 +1529,7 @@ static int try_to_commit(struct repository *r, goto out; } - run_commit_hook(0, r->index_file, "post-commit", NULL); + run_commit_hook(0, 1, r->index_file, "post-commit", NULL); if (flags & AMEND_MSG) commit_post_rewrite(r, current_head, oid); diff --git a/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh b/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh index b3485450a2..fc93bc3d23 100755 --- a/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh +++ b/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh @@ -5,8 +5,8 @@ test_description='pre-commit and pre-merge-commit hooks' . ./test-lib.sh HOOKDIR="$(git rev-parse --git-dir)/hooks" -PRECOMMIT="$HOOKDIR/pre-commit" -PREMERGE="$HOOKDIR/pre-merge-commit" +PRECOMMIT="$(pwd)/$HOOKDIR/pre-commit" +PREMERGE="$(pwd)/$HOOKDIR/pre-merge-commit" # Prepare sample scripts that write their $0 to actual_hooks test_expect_success 'sample script setup' ' @@ -103,6 +103,19 @@ test_expect_success 'with succeeding hook' ' test_cmp expected_hooks actual_hooks ' +# NEEDSWORK: when 'git hook add' and 'git hook remove' have been added, use that +# instead +test_expect_success 'with succeeding hook (config-based)' ' + test_when_finished "git config --unset hook.pre-commit.command success.sample" && + test_when_finished "rm -f expected_hooks actual_hooks" && + git config hook.pre-commit.command "$HOOKDIR/success.sample" && + echo "$HOOKDIR/success.sample" >expected_hooks && + echo "more" >>file && + git add file && + git commit -m "more" && + test_cmp expected_hooks actual_hooks +' + test_expect_success 'with succeeding hook (merge)' ' test_when_finished "rm -f \"$PREMERGE\" expected_hooks actual_hooks" && cp "$HOOKDIR/success.sample" "$PREMERGE" && From patchwork Tue Dec 22 00:04:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70151C433E6 for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3ADBC22512 for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbgLVAF5 (ORCPT ); Mon, 21 Dec 2020 19:05:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726282AbgLVAF5 (ORCPT ); Mon, 21 Dec 2020 19:05:57 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 416F8C061793 for ; Mon, 21 Dec 2020 16:04:47 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id n16so7482825pgk.12 for ; Mon, 21 Dec 2020 16:04:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=QuFgqQ38kuuOuGbPFEj0v9gRTsM5mCpbZ9OoGbpfPIY=; b=tB4Av8cYa+WUcZAiZcD3neiJiMs59Wm1e4Ya5qfyJ7Pqzvk70szflo/7l3YJg6ljm1 mpWbSM7XZwLoAfeU+aOrKDfL8TbIDl5OlPkkO5CJrXUWYUxNnNzwdfuZaP8Ek7DreBpU iz429QJsgRyBNCixgxtTTto/DxBgxRLSrkoeGtHtSZl0fLSUcK5KyAyOmWxXKaSNCOpv +uViw52zoAiknjOcengRiJHzAJa5ZoHVSKPxbLmBVp5I244ieRJ1NYiRDNOo8urVFaMz Nei6IVQDAVJE1LYIXoIMhNgsIQSdd5WkXcsMGUxK7HJFZFN5wFA2PHFOPgqE2QGhgic9 WgEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QuFgqQ38kuuOuGbPFEj0v9gRTsM5mCpbZ9OoGbpfPIY=; b=B1QNA9DH/MxPHl2PXrUgRrocWx43qQ7mK5VomxGT3MFm5Znyt+R//sXcwmly3C/B9g SpHAqtjo6ydTcGBMhX4rogVPnPSsEo/pdkZenzO0CKih/PZXrxcvb3jO80MbTE80lZMU 9QB7+fH7uyjeWfDBLIwVdKIVS6iEWZ/W3zKoUsClqsMGB0QQu7cm/h0Zaf5FjpGBQYc1 Fz11depR0tDLb66wLae+QgGTqNqXm5Ogfe/zQchFq9jLnEhx5TV+wVgrgxYKcaihpn6G JEjhV8QgVnuRfcVQkya37+wKUd9ASnbno9OcIUtmkKutq5bgpFqZ89MYq+pjRh9BsLqb YhxA== X-Gm-Message-State: AOAM531cNNTJUCQL0m9E+tlucwnme84b9iG5RgEGPvX6BvMKcm8bVDrT fQvbsZLB/4XY4azoSdqohfq3ZbOhu3FlFGW87F180ClPRSzke0OgRj2lLt6DsgTRyRM2wUwnhA0 HRmehfVB9MWqbl6hL/Dfl88zIgGs65SJfz3LsctAaC08zkQDUJeFYlJMDUNYurwWSXb1dr4qk8g == X-Google-Smtp-Source: ABdhPJzKQB9v1gloZ5PikvFhRhlJo8f6fNzn4NT/Ss5fkN0zTURdEXmB7Vps5GQu7oAS9MCtbMzu+f2NVz5JZjp6Haw= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a17:902:6b0a:b029:dc:31af:8dc3 with SMTP id o10-20020a1709026b0ab02900dc31af8dc3mr15219646plk.41.1608595486721; Mon, 21 Dec 2020 16:04:46 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:20 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 02/17] am: convert applypatch hooks to use config From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach pre-applypatch, post-applypatch, and applypatch-msg to use the hook.h library instead of the run-command.h library. This enables use of hooks specified in the config, in addition to those in the hookdir. These three hooks are called only by builtin/am.c. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 6 ++++++ builtin/am.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 8b352be43f..0842cd812c 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -58,6 +58,8 @@ the message file. The default 'applypatch-msg' hook, when enabled, runs the 'commit-msg' hook, if the latter is enabled. +Hooks run during 'applypatch-msg' will not be parallelized. + pre-applypatch ~~~~~~~~~~~~~~ @@ -73,6 +75,8 @@ make a commit if it does not pass certain test. The default 'pre-applypatch' hook, when enabled, runs the 'pre-commit' hook, if the latter is enabled. +Hooks run during 'pre-applypatch' will be run in parallel by default. + post-applypatch ~~~~~~~~~~~~~~~ @@ -82,6 +86,8 @@ and is invoked after the patch is applied and a commit is made. This hook is meant primarily for notification, and cannot affect the outcome of `git am`. +Hooks run during 'post-applypatch' will be run in parallel by default. + pre-commit ~~~~~~~~~~ diff --git a/builtin/am.c b/builtin/am.c index f22c73a05b..22d147bc19 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -33,6 +33,7 @@ #include "string-list.h" #include "packfile.h" #include "repository.h" +#include "hook.h" /** * Returns the length of the first line of msg. @@ -426,9 +427,12 @@ 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_SYNC; 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("applypatch-msg", &opt); + run_hooks_opt_clear(&opt); if (!ret) { FREE_AND_NULL(state->msg); @@ -1558,8 +1562,9 @@ static void do_commit(const struct am_state *state) struct commit_list *parents = NULL; const char *reflog_msg, *author, *committer = NULL; struct strbuf sb = STRBUF_INIT; + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT_ASYNC; - if (run_hook_le(NULL, "pre-applypatch", NULL)) + if (run_hooks("pre-applypatch", &hook_opt)) exit(1); if (write_cache_as_tree(&tree, 0, NULL)) @@ -1611,8 +1616,9 @@ static void do_commit(const struct am_state *state) fclose(fp); } - run_hook_le(NULL, "post-applypatch", NULL); + run_hooks("post-applypatch", &hook_opt); + run_hooks_opt_clear(&hook_opt); strbuf_release(&sb); } From patchwork Tue Dec 22 00:04:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985459 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81A0BC433E9 for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AB2A22B51 for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726472AbgLVAF5 (ORCPT ); Mon, 21 Dec 2020 19:05:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726095AbgLVAF5 (ORCPT ); Mon, 21 Dec 2020 19:05:57 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59083C061282 for ; Mon, 21 Dec 2020 16:04:49 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id l8so15808504ybj.16 for ; Mon, 21 Dec 2020 16:04:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=JBKVjRnbzqESSv9JqchxvmDRnDuoKg97DbxCNoBxVeU=; b=jo7HPMX9/haT7U5c7l30Hi5oT3X29kRasLgEbvpDMhN6D2xPnMK4Vcd1lgdlJzgi6G M7ArJD76GsfIESfOmY77rI8/cOfcOUYelGEvcEpNvgKzcZRCQIGakq3N6NB5GdQHfKVV 3UteO7w4aYzH4TC3+7P649MD4z9fr4FrAyg0rSwYvpQgmJXxG8MO2uRbCf+2//TS4IXO H2UJ79GpWiLPOVPqWlE1HMg0SW5bps2bSqGNjEz+Tk95jmH/EiPWc9PzMaJJZbR0DyZE TARmp6bERjSdVUhuAw3mglBl7KqJHZ15CvBjbw6AzY+vXvGsxCXQYsegzESdaocAnpgy r4Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=JBKVjRnbzqESSv9JqchxvmDRnDuoKg97DbxCNoBxVeU=; b=FnR9y/qgINeS8bF5OXDpjR6vNBwF8LBnuyFS+yeZqNAv45JMnuQTIzz00rUBe6TZIb B6dohn6DRtCxmOFj5t5xd59ejnB5BbCtiybNGhTbqxIsZIsAGzd2MsePvmfX49FbP0sk qoONNGJjyNEhST0Ndnz1WXNPLWtwdy6PGlwQiha7x+D9ccs+y8FWKY+TwdSjpnxqIMZm L9ixjufWCrx2zSWOMRabrM5EwvokQrQpXP3SJOXLZqZZx6G2jd5rCB+oKzoqk9nt7CHl POQ0NLp7AXce+7CDYC1xwG+gZlUGeBkKLQRE8XjRVszPJILzQ2YS1JW68aIx824hA4Cc BIaQ== X-Gm-Message-State: AOAM533XB3/860pqFbSrVfXrbWxd6lBiyNQEDCEMgN/m5nJfa08Nos0C H9MITs8+LqbhP0FMqjZtJ9H4CGEB64nv2aUSWUcyzthOWSjR/cBQKj18bfA7sxrDMVAhnu9toAX MKs/AYcgBmgLI6vHyE1abcCS/HdKtDAq3BFjBxZmpoo4I3Fv7Y1+TRXnhReA9hNQ5bNUxBqT2uw == X-Google-Smtp-Source: ABdhPJwGJ/KYXLzttTkSyVYRh88TEeVKplzXloMWuufDEALKagtbd7Wo4ea9e2D5gPAv0AtYWToCBkIVfrsV8udajKE= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a25:ab30:: with SMTP id u45mr25601483ybi.516.1608595488527; Mon, 21 Dec 2020 16:04:48 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:21 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 03/17] merge: use config-based hooks for post-merge hook From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach post-merge to use the hook.h library instead of the run-command.h library to run hooks. This means that post-merge hooks can come from the config as well as from the hookdir. post-merge is invoked only from builtin/merge.c. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 2 ++ builtin/merge.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 0842cd812c..f6ddf1aa22 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -236,6 +236,8 @@ save and restore any form of metadata associated with the working tree (e.g.: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl for an example of how to do this. +Hooks executed during 'post-merge' will run in parallel by default. + pre-push ~~~~~~~~ diff --git a/builtin/merge.c b/builtin/merge.c index d654b6923c..717fbaa019 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -443,6 +443,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_ASYNC; const struct object_id *head = &head_commit->object.oid; if (!msg) @@ -484,7 +485,9 @@ 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("post-merge", &opt); + run_hooks_opt_clear(&opt); apply_autostash(git_path_merge_autostash(the_repository)); strbuf_release(&reflog_message); From patchwork Tue Dec 22 00:04:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CE68C433DB for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA2C522512 for ; Tue, 22 Dec 2020 00:06:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726579AbgLVAF6 (ORCPT ); Mon, 21 Dec 2020 19:05:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726167AbgLVAF5 (ORCPT ); Mon, 21 Dec 2020 19:05:57 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AC08C061285 for ; Mon, 21 Dec 2020 16:04:51 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id i13so9113870qtp.10 for ; Mon, 21 Dec 2020 16:04:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=szzTHJd6sqRvu0qG5IShlxbRdUP7g1k3ZqXUc4Z/QWk=; b=AxIyqaytIPJHKxvI76D3hsCXrK9ohOnipMqnBbBawwgJ5E4uCAMlWMsp2Ge3fDeVFP bp5hQEAFZQLTH/dzEeXE1wW9rawP0Qrhi5Qylk2UpSXzIRrZ+YiiRIdxx/nFZmlcDp3L zZEhN2IKnJwb8wwvjM6H2nnH4p1yMroufFkbJ0FfZLyIVU25iQWwAswy89zPQQRR0NDX 76RJwK/QajojFTn8eOddElzoEUqHGo05MlWhxF9dQp8TSToPqUo4qhT9FEim+ESW/37T Aewhn7q+KXA1GKtrmWcfYghEs7izvcvHOYkavVlPx4WZCLnOL32zfcn8PF3w7m61LFC/ 4klA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=szzTHJd6sqRvu0qG5IShlxbRdUP7g1k3ZqXUc4Z/QWk=; b=ZqDdbrBgkCwbROjT9zVvXE/gOF57ViHQkiEULBllExvo4tgVfaC9vRVB4Eb8x+ER7H 84+qd6ZEKBmdbPJ8nE7vUa8BICanTGaY+3shCnQL4kAwKf0MNwVzscdNn3vR6rq+gpbd gRqpOqMuh0KixX7jsDLL75KLAzwPaJDIPBtFosVfNpNchrIlF88+xNFV3qG6nj8O4UWO 06s+DOfMowYXiDNSMFktdWj4/g61Udi+4Kys8O/+h0ohBG7Z8eAfu7stnQRzQHQea67M kQkVF4qJm+cglIBYySicIeF1Ku87FjpTLPbi/2Rl2HeklLQkF4Wt3hrxtYpEqH0Kwu5K wJRw== X-Gm-Message-State: AOAM532vs8L/QDOznQh+aGCIyz2tIXZF0e7ohcZUVHKCt90zL21eqxzc SNouUKm6+HhKBmi2s6+XODT9cdu2+B5inr62iH1o3+2iq3IARcj2NNyONSC1/bxzRDIJI4HzP/K DjkqIk6/QW0qqYGk6d3hggu9/5s+6v5u6I9bUuex45B3wrbBIvIiNVz0ZOIIe/c0aHcyHxFxslQ == X-Google-Smtp-Source: ABdhPJwJkx0NLueH7AVdVA53FhCFPyo6gp6arsOvuY9HpoN/hivesYIcKI8PvwKbIPpv5jiDDvM6jTDyb5OPVB1OOag= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a0c:b59e:: with SMTP id g30mr19864459qve.30.1608595490098; Mon, 21 Dec 2020 16:04:50 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:22 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 04/17] gc: use hook library for pre-auto-gc hook From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Using the hook.h library instead of the run-command.h library to run pre-auto-gc means that those hooks can be set up in config files, as well as in the hookdir. pre-auto-gc is called only from builtin/gc.c. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 2 ++ builtin/gc.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index f6ddf1aa22..d74308dc20 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -553,6 +553,8 @@ This hook is invoked by `git gc --auto` (see linkgit:git-gc[1]). It takes no parameter, and exiting with non-zero status from this script causes the `git gc --auto` to abort. +Hooks run during 'pre-auto-gc' will be run in parallel by default. + post-rewrite ~~~~~~~~~~~~ diff --git a/builtin/gc.c b/builtin/gc.c index b57fda4924..edcc873c70 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" @@ -340,6 +341,7 @@ static void add_repack_incremental_option(void) static int need_to_gc(void) { + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT_ASYNC; /* * Setting gc.auto to 0 or negative can disable the * automatic gc. @@ -386,7 +388,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", &hook_opt)) return 0; return 1; } From patchwork Tue Dec 22 00:04:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E082DC4332D for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC18822B51 for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726611AbgLVAGD (ORCPT ); Mon, 21 Dec 2020 19:06:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726167AbgLVAF7 (ORCPT ); Mon, 21 Dec 2020 19:05:59 -0500 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE4AC061248 for ; Mon, 21 Dec 2020 16:04:52 -0800 (PST) Received: by mail-qv1-xf49.google.com with SMTP id l7so9293783qvp.15 for ; Mon, 21 Dec 2020 16:04:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=luXBwOtpikkdNrYnfdM9JMdzWElhhuE/WuLI+XXCgms=; b=AwMi2bMbHHzN9V7mEjc9snf05SLJ6Bkv/NNWNB5kzr/VZKC1uarnuR4K7cqUuF/ODh 0pYM/by/0q00okypTsMrNuLMJI9k/wWoZ7mZmBtswpxJeVElgu90ZOHS+RnwercIzcGj GflhARQxJ7HAG7B9We/LhZS35rQ5k7h3Dy7p4QuUbwxRM++dQYAVu7olmMTBrvhjyE06 dMvGoiiubgX2BCHhK0C6EZjF88Ig6PEdpL6OiTEymU2yjsixcHlEZfAROJM2oacMGDUS iDYUTMON+VoiYbGyjRrafTJcA5IyA8yHFczQd90zgUUe9EEJj7DaIz+NpyJP5aYEOIUb 4QcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=luXBwOtpikkdNrYnfdM9JMdzWElhhuE/WuLI+XXCgms=; b=qRb5M4qK17Bhg6YC3bpeOtWvu6jfY/rHdJaK/TcG6bSLqzYU5/kQudsjBNVZrQTe8p ymZwtWIWGYkf6pvcBAl3u97lze0X8+C1d3+pMVemIlnEeCjr3R+DHiJ9jpkZnffGfeB4 Eq38/kiL3cxuusfg+0E7egTqh8M3+cmithwserxhahVzUlt71IICCk8t7X2lTSRd1/wK 14ZpkZ6XlNMJDfYO1cThzouAx97EFvyF4aQhJEWlrZsa9dnf5ZWP+r5+KE1XdXvCXoeb t4Saq7YpMGNBMjJHoA09jKDhi7Nm7UjcrSm8KuQvpcVISQqAc2sEVlCuboAao6QFz4su J8Uw== X-Gm-Message-State: AOAM533EN7E42QwfQD3H+34G4QogGjS83usjgjCgkKUJBLnWnf5knmja iIQaJnZAVQl96e6tXLPMW+ouXeR/ShrGwmAF6VgejXzPo/192j13zSufVv6dTpr5tItkYASsEXN 1HzjVIlU0RT8dmbZKD6yKt+In/0oQ6146ocKk0yx1AI+EMyjTClta3yBL9luOpAsUrSaijQfRCA == X-Google-Smtp-Source: ABdhPJxNBsR3ydFKq8TJQSZgbXmB38eWUc5IQUVwn+/WNwpDYh+xcy0gbmwl+38Jyfoo6Br/3DUeGUJyfmHOIVyy0gk= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a0c:c583:: with SMTP id a3mr19334590qvj.15.1608595491884; Mon, 21 Dec 2020 16:04:51 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:23 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 05/17] rebase: teach pre-rebase to use hook.h From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By using hook.h instead of run-command.h to run hooks, pre-rebase hooks can now be specified in the config as well as in the hookdir. pre-rebase is not called anywhere besides builtin/rebase.c. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 2 ++ builtin/rebase.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index d74308dc20..5dc0690607 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -200,6 +200,8 @@ two parameters. The first parameter is the upstream from which the series was forked. The second parameter is the branch being rebased, and is not set when rebasing the current branch. +Hooks executed during 'pre-rebase' will run in parallel by default. + post-checkout ~~~~~~~~~~~~~ diff --git a/builtin/rebase.c b/builtin/rebase.c index 19c7b377aa..f61ca3e5af 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" @@ -1312,6 +1313,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_ASYNC; struct option builtin_rebase_options[] = { OPT_STRING(0, "onto", &options.onto_name, N_("revision"), @@ -2024,9 +2026,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } /* If a hook exists, give it a chance to interrupt*/ + strvec_pushl(&hook_opt.args, options.upstream_arg, argc ? argv[0] : NULL, NULL); if (!ok_to_skip_pre_rebase && - run_hook_le(NULL, "pre-rebase", options.upstream_arg, - argc ? argv[0] : NULL, NULL)) + run_hooks("pre-rebase", &hook_opt)) die(_("The pre-rebase hook refused to rebase.")); if (options.flags & REBASE_DIFFSTAT) { @@ -2106,6 +2108,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) ret = !!run_specific_rebase(&options, action); cleanup: + run_hooks_opt_clear(&hook_opt); strbuf_release(&buf); strbuf_release(&revisions); free(options.head_name); From patchwork Tue Dec 22 00:04:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96726C43381 for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 729FB22AED for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726600AbgLVAGC (ORCPT ); Mon, 21 Dec 2020 19:06:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbgLVAF7 (ORCPT ); Mon, 21 Dec 2020 19:05:59 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FB09C061257 for ; Mon, 21 Dec 2020 16:04:54 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id v5so4582101pgq.15 for ; Mon, 21 Dec 2020 16:04:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=Dfa0Az4U4Jg19K2ZkjvnVLjkTUIAgpE93RN//ozv9BM=; b=MrXcfLfqYpOOKB9k69605ChvptZyOTdnJx0MkZA7a1r6aZQw5wtZXIZSQn3jmIv32O SktBYEj/5V/N6IoIJ9f0uFp59YDKYZpKhIwqyjGFzlmZiy66itOQU726EKIg7bs188dL /q9jCPFzrONSgvDDg7A115HxWzLYLyVd6uxjJgzJp4gynQPcg2Gvxdio4UtYgjTWwy40 jfVCS3GU8e+B5Pj4nIPUfLu7JmkD/+VpCSNGywur8IrCdpUJmIyiD8J3Imya/00jxs/t Y4OZJbCi7D/aYNTOtizlH+Ly+a8WaHyo6wjlfpoLNnGH7xwDTBhmNcl2DOyB1X/CSqOI iIyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Dfa0Az4U4Jg19K2ZkjvnVLjkTUIAgpE93RN//ozv9BM=; b=rMV68izSsmwZg41Sg06DDbON6CJjqnqzaslatTFB+iWsmRg9NjqXWSoum8yXCJtb2p qjwa3H/DPn2p0eUNmWjef5LFvYVtJZGeSuDyJz3kcKXaoaHgjBn3r0F84Njjy+1Z8C0j 0vRaPPx/8P8GCqnTIMCBw/jqWrBboA3HuAwCnzEK12VSDvomtHZmXqxx0n4bR/8mKJGz Vc6EpkJmeKtTGPyEFnE2KW/77cTjBeolJJDgktrU9BBXIwrK1lz95QZPpu/fqdwVoQYt HdHL9mpsN+P2MjHdFCIccoqrhBMja+MS24YAQ0WvtrPy/ja/NUHXtcO8TImBnvW+dsQh GgGQ== X-Gm-Message-State: AOAM531YkSkm4R7RQ2q1DucyCkBxByC8mS31wymFlrEHoMCEmfvwoZnx vR4CJD37V+hr2ec6REr9D2FPBqMmMA4luVa0o3Bp4yrV5sihnqLeqYwWIB9adSQoYr3V1G+/P08 ypeVpvIhsm05mhqYNrGXGBO9hDDHn0hhmOK8GrohLRrdMZAXmcIYTOAni3rIN55gRetaysbrD6Q == X-Google-Smtp-Source: ABdhPJwHrBIxuYKjbbzATOJ485znTuxBJ8/r8ah3XnOgRPj5MdRcQ7k6KDhDPSnmqxTq8FqBamGeHKyN1ALie0b31Lk= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a17:902:7144:b029:da:7268:d730 with SMTP id u4-20020a1709027144b02900da7268d730mr18262946plm.20.1608595493796; Mon, 21 Dec 2020 16:04:53 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:24 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-7-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 06/17] read-cache: convert post-index-change hook to use config From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By using hook.h instead of run-command.h to run, post-index-change hooks can now be specified in the config in addition to the hookdir. post-index-change is not run anywhere besides in read-cache.c. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 2 ++ read-cache.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 5dc0690607..8249ecec5f 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -711,6 +711,8 @@ 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. +Hooks run during 'post-index-change' will be run in parallel by default. + GIT --- Part of the linkgit:git[1] suite diff --git a/read-cache.c b/read-cache.c index ecf6f68994..dcfc080aaa 100644 --- a/read-cache.c +++ b/read-cache.c @@ -25,6 +25,7 @@ #include "fsmonitor.h" #include "thread-utils.h" #include "progress.h" +#include "hook.h" /* Mask for the name length in ce_flags in the on-disk index */ @@ -3052,6 +3053,7 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l unsigned flags) { int ret; + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT_ASYNC; /* * TODO trace2: replace "the_repository" with the actual repo instance @@ -3070,9 +3072,13 @@ 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("post-index-change", &hook_opt); + run_hooks_opt_clear(&hook_opt); + istate->updated_workdir = 0; istate->updated_skipworktree = 0; From patchwork Tue Dec 22 00:04:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985469 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4AFDC4332B for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8848022512 for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726632AbgLVAGD (ORCPT ); Mon, 21 Dec 2020 19:06:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726586AbgLVAF7 (ORCPT ); Mon, 21 Dec 2020 19:05:59 -0500 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CD00C0611C5 for ; Mon, 21 Dec 2020 16:04:56 -0800 (PST) Received: by mail-qv1-xf4a.google.com with SMTP id i20so9230986qvk.18 for ; Mon, 21 Dec 2020 16:04:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=yNSL21HxP5RNNCKYE8EwhTeFGbdFXT4FMmuUI4tLRiA=; b=GqhR9TqrIl7wkSYs5g75h/LFJ031s7xBXP+W353m48JkXZ+1KKKTa9A7ASCfKVj9AY 6n4gjpO5UseVCV9q/Ve3+rggxM8ZcYYPBAfeiqLA0h2wsSXG5E/YC2gb0ZGv14oxsHyM a6xcVel5C0ltEChwTHQbBQm7C0QS+1/wj1JLkz+s3cPv3vfsYAOwPjtRc7/cC8l5wzB6 sJJBScxMIL6PbNDLw3SDuzkiFxNQfzl72iW97t/ySjNjfS+TK5Spc8oPe/P7BEdzqYaE NRy3Tc8x2mJofjB63eveI4mfu8b0u3+Je1YJLB+UQ36humKvGiq/OAREuwykH9bL6AFC 0kzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=yNSL21HxP5RNNCKYE8EwhTeFGbdFXT4FMmuUI4tLRiA=; b=tU5nD3WTMRGc7m4wImSRaGEYUpfwQzlmdyohBfGbzfEPl7M0zo66RRmKqX0LBu5jUF /v5XT2McAtpZaW/2pe66ebFjlVmgi9iZgzNU3n3MY8QZ3eCt5JbKYv1TYKt2LTUhzTAw lbpAF4DIlyv9D4YlBv8b9d+tdj8ssxtY2xlt/pSMqOxE3LmTniEL2Oe9QgoEvZAVfomB 16QXIRKwgtchRzPhtpBgaKvY1VObIAmm4MtKXdGZibrGnuJkamZsb3fr6oYmQC7gIBdu Z4a3slT2czB1W0LSGPBF8WMBQqoYw00OzOYFH11hoOzTMpy8SOC3BfUUFj9VkaF9954Z +OnA== X-Gm-Message-State: AOAM533SFZXdFXB2Q5yL9CSyX7IemzVkTomZD+U8GiwuYQZFuuz6DebD jfl/ql7bEx8/ceHsvnLJo8MI3QLbNE/deOFAmt4kobdL+hYWWcrAnzHa07Hn4ORUlfmyXgC1Pvn +UVGsIp/JRivfPxTm1da/tcNWOXVPDV8hBzJ+wZGz3xn/UDB653XCYI8hJwOzeZA7gSl0pPOm0g == X-Google-Smtp-Source: ABdhPJyEky+977ZKH5ZrNZD3n4BA6B+0Wrfg6Uhk3LQos43h3YH2dvVNxmwqf8RRTZ4aw2s1GkSryhFJo0HBNLDqWh0= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a05:6214:302:: with SMTP id i2mr19908079qvu.14.1608595495624; Mon, 21 Dec 2020 16:04:55 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:25 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-8-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 07/17] receive-pack: convert push-to-checkout hook to hook.h From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By using hook.h instead of run-command.h to invoke push-to-checkout, hooks can now be specified in the config as well as in the hookdir. push-to-checkout is not called anywhere but in builtin/receive-pack.c. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 1 + builtin/receive-pack.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 8249ecec5f..8de512ee5d 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -547,6 +547,7 @@ that switches branches while keeping the local changes in the working tree that do not interfere with the difference between the branches. +Hooks executed during 'push-to-checkout' will not be parallelized. pre-auto-gc ~~~~~~~~~~~ diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d49d050e6e..1c0bad0448 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -29,6 +29,7 @@ #include "commit-reach.h" #include "worktree.h" #include "shallow.h" +#include "hook.h" static const char * const receive_pack_usage[] = { N_("git receive-pack "), @@ -1435,12 +1436,18 @@ 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_SYNC; + 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(push_to_checkout_hook, &opt)) { + run_hooks_opt_clear(&opt); return "push-to-checkout hook declined"; - else + } else { + run_hooks_opt_clear(&opt); return NULL; + } } static const char *update_worktree(unsigned char *sha1, const struct worktree *worktree) @@ -1464,7 +1471,7 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w strvec_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir)); - if (!find_hook(push_to_checkout_hook)) + if (!hook_exists(push_to_checkout_hook, configured_hookdir_opt())) retval = push_to_deploy(sha1, &env, work_tree); else retval = push_to_checkout(sha1, &env, work_tree); From patchwork Tue Dec 22 00:04:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985467 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D057C43332 for ; Tue, 22 Dec 2020 00:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC08F22B43 for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726427AbgLVAGC (ORCPT ); Mon, 21 Dec 2020 19:06:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726594AbgLVAF7 (ORCPT ); Mon, 21 Dec 2020 19:05:59 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BF45C0611CA for ; Mon, 21 Dec 2020 16:04:58 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id a206so15781586ybg.0 for ; Mon, 21 Dec 2020 16:04:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=L4RilQ5LCEZEBzhRS+wHs2R686j6A/MWoLRo01wQIRA=; b=r92Uh608WETvd0mauBeRCjYj/PU0Crxo4Z58Ni86xml1aoTGwCXfo892iMnollHkIl q+vG9vU5Fb8F5dSrkJaS3Zjkr0AayEIzFUZ3Dbg1RRUP03AgfrCNADMkRAJCNe2AthHv ssbLtRqhqsB+iCmwMG6GGZxrPurt1h6lY6fZNULeVRC6zUGXKSziqXbhK9eEAOs72A3n dJRM3kd480ZT7vnqvasoE9d6c9+QbMwDKXZZrd9UbfQaySAsAGINQI3MaqonCT2NQYsF HjyQu/J8XvZqNs9bSJR4JD1PtFaaMXvdL47V+eTVTUvOeZm1p1hb/G+dYKxhfJsCbWDl 2+BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=L4RilQ5LCEZEBzhRS+wHs2R686j6A/MWoLRo01wQIRA=; b=QdSWUr3da8e+qLtJhh+zFVRJ5eRofqKKiKO6BiK05tv1JA/GGgQhUbHcLe8sf3Wg8a hLwiR+CJ24B5KKQQg/49yS/R6TCWzJxMPtX7DiQxCHOLyP1PfKyMX5ECaQ+MVwK+z+Pu gt35q5qKsBfBiqukSw/fC38aFjO/pD6ZxIeA3kkAX5szxZGQEXRguPNjBmpx5RP5C8ZU J40qHrNTbRVRbUHbPPqz+slaS0Y8tFMcGPEZEugDxV5UqF1vLJwJsMRaP6HJmy6U02v2 HYiclMnA6AnfjHeJn+oMpdF1f57bJkSXvwAEsmMhU23cXX8ZFRsqzwwZVcpCb61IroI3 yfHg== X-Gm-Message-State: AOAM533roJb+xyCFB6xI/fFWfcstnkmE8uaGyhygGhpe23lfWlBlJQlK h571NtL8xH8WFyTE07by/DBV9SarvoKP4Sb1Xcu43UFLjZ08q7zqNuxQRrDlwZg8CCTv9blxElQ vLUP3OlFrgGwY5KLh6f9XhlqsCp0LgpWifOtc3sDHfCjWpzHPc9NpB1amtB6G0G3l72nd+g21MA == X-Google-Smtp-Source: ABdhPJxLqB5QN7rfFnpecdDx+S5H9CZF0qfrNkpsb4zcC1dguaCNezxKJIkkstvEdXptVJ3sO4rIqFZ+YcTx7agVes8= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a25:b5c6:: with SMTP id d6mr24921983ybg.421.1608595497421; Mon, 21 Dec 2020 16:04:57 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:26 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-9-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 08/17] git-p4: use 'git hook' to run hooks From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Instead of duplicating the behavior of run-command.h:run_hook_le() in Python, we can directly call 'git hook run'. As a bonus, this means git-p4 learns how to find hook specifications from the Git config as well as from the hookdir. Signed-off-by: Emily Shaffer --- Notes: Maybe there is a better way to do this - I had a hard time getting this to run locally, and Python is not my forte, so if anybody has a better approach I'd love to just take that patch instead :) Since v6, removed the developer debug print statements.... :X Maybe there is a better way to do this - I had a hard time getting this to run locally, and Python is not my forte, so if anybody has a better approach I'd love to just take that patch instead :) git-p4.py | 67 +++++-------------------------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-) diff --git a/git-p4.py b/git-p4.py index 6ae5bbfe99..6e23e2ad1a 100755 --- a/git-p4.py +++ b/git-p4.py @@ -208,70 +208,15 @@ 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): + if not cmd: 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'] + + ["-a" + arg for arg in param] + + [cmd]) + return subprocess.call(args) == 0 def write_pipe(c, stdin): if verbose: From patchwork Tue Dec 22 00:04:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1868C4332E for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC13822B3B for ; Tue, 22 Dec 2020 00:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726651AbgLVAGF (ORCPT ); Mon, 21 Dec 2020 19:06:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbgLVAGE (ORCPT ); Mon, 21 Dec 2020 19:06:04 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E56D0C0611CB for ; Mon, 21 Dec 2020 16:04:59 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id l7so9113808qth.15 for ; Mon, 21 Dec 2020 16:04:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=LUxw/hFdF9lowPah09S7Zj467fY7yAG7wcNTSHnpxaE=; b=pRsHALvO3OybA+4+vuCn/zpiQ5GxTueiRQqDWAXi2N01rZv5/c/FTOPqXIDoAzt5c1 qSUVZj8HCdudtb0Ub43Xx+MUeORJTuwv95Xm/LS0cCRjHWjDdOUDoy7ILbrIX7idxXAG IDL1TlFedfyEBJJg6KFr2z4zpgtY+k/f0okBKXSc0Md3bS5TRd+q0GcV4eg3oprRFDaO Y27rSL2M5XOwZ8YWgRgcpjNpn8+UXYC16Qgdv68hygOcDn4B7yIvIVsdBlvj9JVWAk9n 7BTTLHwHz8nQe6zli3KIGYuUNP2Wl8FMjlIRehDDiSyg25t71Qazr2t8mNeuOSc3xvxX BW0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LUxw/hFdF9lowPah09S7Zj467fY7yAG7wcNTSHnpxaE=; b=cmWi1XYGP5eYqnq2spbeISvBNo1Ts9g+GpVFzDOmDp86X4SxVVZ8ALpIjNvb0gE6qz 9LQav59P0T+ijGy6PkmlK4lgDGAAmqA3LEigmAaCLItWVeWZgQg2ZKFxWVxOtxjfpRRj ceG4cD2wO9EjrL9UWqzGqY3trWx+ZQOmUOIEAiNb7UAFfN3WXhQVcO1Q/i0byUdBZT8u HZ/AhtwGR4Gm6jCmqzK7kdzHFhI6uyJNt5oGbSXRBwxDbbNPgDVJHEqtCWuaNu0Qa8Rk 4dT1XPC55i5SJMmG7sAtT2zVWLpFR2n326qyv3WjKSIGoIIobv6UnlbA1yPe4KRLk/MF yoYA== X-Gm-Message-State: AOAM530kEetIOyr4kZUuuYto1OKBlXXx5EuBJdjL7VRpiLFd7bFKjmUn RCfNndd+x2LW3Z2UNXZrFQJlRQ0k9RrsdDSsq70u2LK6ok5BMFxqbIBkpfw3QqZGC3CHvTQUHIg Iv6/Ezt8EUZyv44olAAqcDvWWitmHkLHLN5SV2kdElMC014skZV8/ioLXSR9/MLUzgSKrA1+bgA == X-Google-Smtp-Source: ABdhPJz0uPhwxJX4GOY0vRaX3NEIoQmfi6Vqk27+CoCo9sKZwIr8gDhQ7hPm6miLGTOtcscNhg0Vr6nxJzDbGbjhk0k= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a0c:8642:: with SMTP id p60mr17002905qva.6.1608595499088; Mon, 21 Dec 2020 16:04:59 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:27 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-10-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 09/17] hooks: convert 'post-checkout' hook to hook library From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By using the 'hook.h' library, 'post-checkout' hooks can now be specified in the config as well as in the hook directory. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 2 ++ builtin/checkout.c | 16 +++++++++++----- builtin/clone.c | 7 +++++-- builtin/worktree.c | 30 ++++++++++++++---------------- reset.c | 15 +++++++++++---- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 8de512ee5d..14035ef725 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -224,6 +224,8 @@ This hook can be used to perform repository validity checks, auto-display differences from the previous HEAD if different, or set working dir metadata properties. +Hooks executed during 'post-checkout' will not be parallelized. + post-merge ~~~~~~~~~~ diff --git a/builtin/checkout.c b/builtin/checkout.c index 9b82119129..20966452b8 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" @@ -104,13 +105,18 @@ 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_SYNC; + int rc; /* "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); + rc = run_hooks("post-checkout", &opt); + run_hooks_opt_clear(&opt); + return rc; } static int update_some(const struct object_id *oid, struct strbuf *base, diff --git a/builtin/clone.c b/builtin/clone.c index a0841923cf..307336e576 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: @@ -771,6 +772,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_SYNC; if (option_no_checkout) return 0; @@ -816,8 +818,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("post-checkout", &hook_opt); + run_hooks_opt_clear(&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 197fd24a55..9a87c4c120 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -12,6 +12,7 @@ #include "submodule.h" #include "utf8.h" #include "worktree.h" +#include "hook.h" static const char * const worktree_usage[] = { N_("git worktree add [] []"), @@ -455,22 +456,19 @@ 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_SYNC; + + 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("post-checkout", &opt); + + run_hooks_opt_clear(&opt); } strvec_clear(&child_env); diff --git a/reset.c b/reset.c index 2f4fbd07c5..e6bfaf67e1 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, @@ -126,10 +127,16 @@ 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_SYNC; + strvec_pushl(&opt.args, + oid_to_hex(orig ? orig : &null_oid), + oid_to_hex(oid), + "1", + NULL); + run_hooks("post-checkout", &opt); + run_hooks_opt_clear(&opt); + } leave_reset_head: strbuf_release(&msg); From patchwork Tue Dec 22 00:04:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 384CFC43331 for ; Tue, 22 Dec 2020 00:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11DD022B3B for ; Tue, 22 Dec 2020 00:06:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726586AbgLVAGH (ORCPT ); Mon, 21 Dec 2020 19:06:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726637AbgLVAGE (ORCPT ); Mon, 21 Dec 2020 19:06:04 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2B9DC0611CC for ; Mon, 21 Dec 2020 16:05:01 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id kb15so298597pjb.4 for ; Mon, 21 Dec 2020 16:05:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=cffkahU1lSzSwVG5AbrWY7gx1XvLJa7VTE+r84Lr7GM=; b=RJY18XhodH+l3Gn6k/48vqJIt8c/xhQdogZKJh0NiK6IEsHmGrsLwVgddVPoYdBkhh 6HFEZ0eBo9pgwrVZfzdeH8TT4npbZFam/l+unXR36IzDDyZ7tVwVRNMlhpA8k69ahh7m 1HyvQ+L4KKykCDscmE7RmyXohB9Pu++tE6tmHmfbCNcANeHkPdcZV0CqFV+jM+Kvuuvp M1HSBblQQXgm7FxYdEakd6fLp1HPmp4m4YwM7fIpl/lxbqWJ7P0kZzZD0nwIB0SDJrk2 U01a5OTnOMOOQ76zzDvKwthjFcvGrPYLCLFefkCG0D3pcCV08zGl/Y+s3Xhy5f1nGPUX X04Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=cffkahU1lSzSwVG5AbrWY7gx1XvLJa7VTE+r84Lr7GM=; b=K4FE2y01YsGnAiShZy+nBrzziiQj6k6y5bphteYR9siQSAGBzYM9KyZasU4HrW0gCu bM5MD+rawlcrHHPfnQVpfnxSF3bpSbVW1WlIs9C1XzBDtmQS2cNxOSM7l9fyXPcTrKxn Eed6fiM6DTb8K2xSI0ggCGhavT/UYZ8zkymp21RAOTdaJ5wY0pmIej4zPcTo1bIYABYS THfomHOu/09UNFVC99mrjxQUxBM/gIWgusNAiLRc2XebS68pCxVQGRMfSDb8D7yuyktE 0Az2RFC6ouv3G0b/V8VwGBpnWLVPpiAtNSyWXekkc3a2+kI1kbak9NVWRVoG6pLSoXtC 1Oew== X-Gm-Message-State: AOAM531bwfuPdKiWTljVuRa6iLyLXeLt/lAP4BG8dNUyEbDQzv4Skt5U PbJ8JJloBytYHgSmRA02RmORvpQpYKrAEsnOTctnadbjwoomnPuNktFeiYjdVDQc2aTsdo9rndS uDIE2J/nTvejQrMyAtCFH1UFM6Rrt13HMBY3rzQWYbTqOwIGmC0PKnPCuLk34WFXv8QexnnwnVg == X-Google-Smtp-Source: ABdhPJzdGUcDpbG67AcAKSKPU5B6dzMfj7Cdp8gdpxjCejcAtOIKZZ0N4zhlosg6WGw+E45D/qcZ055OqqbV6qVrwjQ= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a17:902:a9cb:b029:d8:fae5:9e9a with SMTP id b11-20020a170902a9cbb02900d8fae59e9amr18523416plr.32.1608595501146; Mon, 21 Dec 2020 16:05:01 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:28 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-11-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 10/17] hook: convert 'post-rewrite' hook to config From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By using 'hook.h' for 'post-rewrite', we simplify hook invocations by not needing to put together our own 'struct child_process' and we also learn to run hooks specified in the config as well as the hook dir. The signal handling that's being removed by this commit now takes place in run-command.h:run_processes_parallel(), so it is OK to remove them here. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 2 + builtin/am.c | 18 +++------ sequencer.c | 76 +++++++++++++++----------------------- 3 files changed, 36 insertions(+), 60 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 14035ef725..db290984f6 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -585,6 +585,8 @@ The hook always runs after the automatic note copying (see "notes.rewrite." in linkgit:git-config[1]) has happened, and thus has access to these notes. +Hooks run during 'post-rewrite' will be run in parallel by default. + The following command-specific comments apply: rebase:: diff --git a/builtin/am.c b/builtin/am.c index 22d147bc19..c7cad2cb32 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -449,23 +449,15 @@ static int run_applypatch_msg_hook(struct am_state *state) */ static int run_post_rewrite_hook(const struct am_state *state) { - struct child_process cp = CHILD_PROCESS_INIT; - const char *hook = find_hook("post-rewrite"); + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_ASYNC; int ret; - if (!hook) - return 0; - - strvec_push(&cp.args, hook); - strvec_push(&cp.args, "rebase"); + strvec_push(&opt.args, "rebase"); + opt.path_to_stdin = am_path(state, "rewritten"); - cp.in = xopen(am_path(state, "rewritten"), O_RDONLY); - cp.stdout_to_stderr = 1; - cp.trace2_hook_name = "post-rewrite"; + ret = run_hooks("post-rewrite", &opt); - ret = run_command(&cp); - - close(cp.in); + run_hooks_opt_clear(&opt); return ret; } diff --git a/sequencer.c b/sequencer.c index 5a98fd2fbc..4befd862ff 100644 --- a/sequencer.c +++ b/sequencer.c @@ -35,6 +35,7 @@ #include "rebase-interactive.h" #include "reset.h" #include "hook.h" +#include "string-list.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" @@ -1143,33 +1144,23 @@ int update_head_with_reflog(const struct commit *old_head, static int run_rewrite_hook(const struct object_id *oldoid, const struct object_id *newoid) { - struct child_process proc = CHILD_PROCESS_INIT; - const char *argv[3]; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_ASYNC; + struct strbuf tmp = STRBUF_INIT; int code; - struct strbuf sb = STRBUF_INIT; - argv[0] = find_hook("post-rewrite"); - if (!argv[0]) - return 0; + strvec_push(&opt.args, "amend"); - argv[1] = "amend"; - argv[2] = NULL; - - proc.argv = argv; - proc.in = -1; - proc.stdout_to_stderr = 1; - proc.trace2_hook_name = "post-rewrite"; - - code = start_command(&proc); - if (code) - return code; - strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid)); - sigchain_push(SIGPIPE, SIG_IGN); - write_in_full(proc.in, sb.buf, sb.len); - close(proc.in); - strbuf_release(&sb); - sigchain_pop(SIGPIPE); - return finish_command(&proc); + strbuf_addf(&tmp, + "%s %s", + oid_to_hex(oldoid), + oid_to_hex(newoid)); + string_list_append(&opt.str_stdin, tmp.buf); + + code = run_hooks("post-rewrite", &opt); + + run_hooks_opt_clear(&opt); + strbuf_release(&tmp); + return code; } void commit_post_rewrite(struct repository *r, @@ -4317,30 +4308,21 @@ static int pick_commits(struct repository *r, flush_rewritten_pending(); if (!stat(rebase_path_rewritten_list(), &st) && st.st_size > 0) { - struct child_process child = CHILD_PROCESS_INIT; - const char *post_rewrite_hook = - find_hook("post-rewrite"); - - child.in = open(rebase_path_rewritten_list(), O_RDONLY); - child.git_cmd = 1; - strvec_push(&child.args, "notes"); - strvec_push(&child.args, "copy"); - strvec_push(&child.args, "--for-rewrite=rebase"); + struct child_process notes_cp = CHILD_PROCESS_INIT; + struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT_ASYNC; + + notes_cp.in = open(rebase_path_rewritten_list(), O_RDONLY); + notes_cp.git_cmd = 1; + strvec_push(¬es_cp.args, "notes"); + strvec_push(¬es_cp.args, "copy"); + strvec_push(¬es_cp.args, "--for-rewrite=rebase"); /* we don't care if this copying failed */ - run_command(&child); - - if (post_rewrite_hook) { - struct child_process hook = CHILD_PROCESS_INIT; - - hook.in = open(rebase_path_rewritten_list(), - O_RDONLY); - hook.stdout_to_stderr = 1; - hook.trace2_hook_name = "post-rewrite"; - strvec_push(&hook.args, post_rewrite_hook); - strvec_push(&hook.args, "rebase"); - /* we don't care if this hook failed */ - run_command(&hook); - } + run_command(¬es_cp); + + hook_opt.path_to_stdin = rebase_path_rewritten_list(); + strvec_push(&hook_opt.args, "rebase"); + run_hooks("post-rewrite", &hook_opt); + run_hooks_opt_clear(&hook_opt); } apply_autostash(rebase_path_autostash()); From patchwork Tue Dec 22 00:04:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9463C433E9 for ; Tue, 22 Dec 2020 00:06:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A73F622AED for ; Tue, 22 Dec 2020 00:06:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726230AbgLVAGi (ORCPT ); Mon, 21 Dec 2020 19:06:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725780AbgLVAGh (ORCPT ); Mon, 21 Dec 2020 19:06:37 -0500 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1D16C0611CD for ; Mon, 21 Dec 2020 16:05:03 -0800 (PST) Received: by mail-qv1-xf49.google.com with SMTP id t16so9293595qvk.13 for ; Mon, 21 Dec 2020 16:05:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=CVbnpWOwK+ivPuNaZHaYPy5vxV5u/BNDRDW9Ol7Q52s=; b=qNlfx5p6Nh2uHYdR+c9wiMQAj7kTH1h2mlE52opYmthPfeW6wRqMkWO9DQ4LchX05Q 0RoDNTa7+daLuoEQbcmLbsZTuRbgME1UbedbmGZY6glrsVL1gSetbwBGEX2ebp9yd2O/ Z19UlN14E7vZJy7WdLZ9+bZlciLSXjAVI+ocYa+KsgNnGkdoUIiMIacyI/N5uqvYrKRx IoHxnK6s2Mti/SNGHwPo5EtI4473O9wEjE76U4aaejMoixCO+PEL/IcduD7gcMbPSbZ2 OwcO6EO7r+IPUBDnYPhpU/6QxwDuFraDjMq8J/TK+t3DMTGxdKL4aZxzIs6bjV3CLG4N yXeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=CVbnpWOwK+ivPuNaZHaYPy5vxV5u/BNDRDW9Ol7Q52s=; b=CqnGu+LR70BJiGv3U8oxNLSGmM6bl8CQi+5jTp/HkWc0b8b2zx7lDda7H1iENXB+4A vi68HZWVtH2fgP6Qzea72fou5jo6DNc4aqFuXypGTMD3IIsmz7cTR/012rmppGo613wO C9/o+QBdKswZxs744io9svhQLYz30HqBKcF93vfICYCsJUF/Bn7NjfF6ktth+be0YOzn Osu3lW9Z/0Yc5nXQvKlsbXDygkkjmxTLBh/rRq4pYAtehJezkvk8xHrxKY+X4jySlkwN Zdy1oanJ1yWW8nWnT68eARpxJzDQP/pSrfUlJbYfJdjIV76l/pnOCowYxMtgqawWYvUS xdLw== X-Gm-Message-State: AOAM530be079buVbTAQVeo0BeMiKvwz/WgyzY7vEa2jc17K+DySEYA92 jvc9/18r0twv6xbCw4Mp0T3R5ia1kRiu0T8qIBwva2JuLcn6qghJc0XY3NWfngu7/MAozjJ3ZHe ZRqNXlFUEVnFXIg4Nv4bj3s5PXq/lyOFe2DOAdxbbVxAIIyfy5DY6n+0nxFBwktZ4HAP4bI9Yig == X-Google-Smtp-Source: ABdhPJyo2G0eFKolNZQCahm25P53lJ83aVw74CabZtMPsn16xlVHNURsPieAaXf334DoXDKsF0rZ0QjHDHBllW5ZJ3c= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a05:6214:d4a:: with SMTP id 10mr19507745qvr.62.1608595502933; Mon, 21 Dec 2020 16:05:02 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:29 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-12-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 11/17] transport: convert pre-push hook to use config From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By using the hook.h:run_hooks API, pre-push hooks can be specified in the config as well as in the hookdir. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 2 ++ transport.c | 55 +++++++++----------------------------- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index db290984f6..8f5524055b 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -271,6 +271,8 @@ If this hook exits with a non-zero status, `git push` will abort without pushing anything. Information about why the push is rejected may be sent to the user by writing to standard error. +Hooks executed during 'pre-push' will run in parallel by default. + [[pre-receive]] pre-receive ~~~~~~~~~~~ diff --git a/transport.c b/transport.c index 679a35e7c1..58fee65815 100644 --- a/transport.c +++ b/transport.c @@ -22,6 +22,7 @@ #include "protocol.h" #include "object-store.h" #include "color.h" +#include "hook.h" static int transport_use_color = -1; static char transport_colors[][COLOR_MAXLEN] = { @@ -1172,31 +1173,13 @@ static void die_with_unpushed_submodules(struct string_list *needs_pushing) static int run_pre_push_hook(struct transport *transport, struct ref *remote_refs) { - int ret = 0, x; + int ret = 0; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_ASYNC; + struct strbuf tmp = STRBUF_INIT; struct ref *r; - struct child_process proc = CHILD_PROCESS_INIT; - struct strbuf buf; - const char *argv[4]; - - if (!(argv[0] = find_hook("pre-push"))) - return 0; - - argv[1] = transport->remote->name; - argv[2] = transport->url; - argv[3] = NULL; - - proc.argv = argv; - proc.in = -1; - proc.trace2_hook_name = "pre-push"; - - if (start_command(&proc)) { - finish_command(&proc); - return -1; - } - sigchain_push(SIGPIPE, SIG_IGN); - - strbuf_init(&buf, 256); + strvec_push(&opt.args, transport->remote->name); + strvec_push(&opt.args, transport->url); for (r = remote_refs; r; r = r->next) { if (!r->peer_ref) continue; @@ -1205,30 +1188,16 @@ static int run_pre_push_hook(struct transport *transport, if (r->status == REF_STATUS_REJECT_REMOTE_UPDATED) continue; if (r->status == REF_STATUS_UPTODATE) continue; - strbuf_reset(&buf); - strbuf_addf( &buf, "%s %s %s %s\n", + strbuf_reset(&tmp); + strbuf_addf(&tmp, "%s %s %s %s", r->peer_ref->name, oid_to_hex(&r->new_oid), r->name, oid_to_hex(&r->old_oid)); - - if (write_in_full(proc.in, buf.buf, buf.len) < 0) { - /* We do not mind if a hook does not read all refs. */ - if (errno != EPIPE) - ret = -1; - break; - } + string_list_append(&opt.str_stdin, tmp.buf); } - strbuf_release(&buf); - - x = close(proc.in); - if (!ret) - ret = x; - - sigchain_pop(SIGPIPE); - - x = finish_command(&proc); - if (!ret) - ret = x; + ret = run_hooks("pre-push", &opt); + run_hooks_opt_clear(&opt); + strbuf_release(&tmp); return ret; } From patchwork Tue Dec 22 00:04:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDF3BC43219 for ; Tue, 22 Dec 2020 00:06:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BF2722AED for ; Tue, 22 Dec 2020 00:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726667AbgLVAGM (ORCPT ); Mon, 21 Dec 2020 19:06:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726596AbgLVAGM (ORCPT ); Mon, 21 Dec 2020 19:06:12 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8242CC0611CE for ; Mon, 21 Dec 2020 16:05:05 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id y2so5844975pfr.12 for ; Mon, 21 Dec 2020 16:05:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=mgaJUEyE3U2GM/t3u/ymLmxNso4EbETblhtJPcndBjI=; b=tNfH1/T9qs68wLH3IKVyo/RvR9pM8uSeCL/R93TUA69hrgj26cTLWSAvvDMD4q9NZ7 6E6t+6XuNtsQSexdi40kDJr1htKdMKnxBqGiky+xOSgKPlIXsVQ23vdvR1wDBw0RqNSw AnNN+9mwcyA2SfZ2GeCGQRJlqrjSMHNX8gOiRaRLV46p4co06J1KpdcPhgb5cppePAmQ 6ZUpAR92Be71dE0msPbM6x9v7DG4hZJVCYOzrzcXAb9JHuz79IM9uJPsh/y6Om2+HQ0/ gWkR1FhADos1NBWWHVHHxDUudfFJ0kOp/VEI266PSFM8zG6M26wDN6Oy9QQcMIlKNq50 3BkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mgaJUEyE3U2GM/t3u/ymLmxNso4EbETblhtJPcndBjI=; b=CjDJYgdmagA0s65FwxZ/QKusklmPjjG8MSjba5YnFrLqIb+wSmB9P9K2xONmXC+Vhy xCoD5Oi1brMB/C8u2hBpwK5BkT955hu/5GbptwzE2NmUkgFjxFbSae9wLl2T8eb1De9x jRLmYkKmFhF5PtP8x9v6ipNleqS3BqARwpqOfhbZU2vY4AO6gW6Dd3A3h5Oh6tKrjYio hvZkFZTQ0ZbgfYVfFEPhE42+3HHdpEa+nyDmoT8c9dNWs8Vl3Hw/xmRvAlCodrLNPIO7 oEXGsNXa1GRr/yU1br3pJUMj4xStY0emRZ00MjdL785OictF5JQocMaIACrIyWwYcbbv JyaQ== X-Gm-Message-State: AOAM532vsbiY1jRmAgWkXnReS0gNV/DPOz6Uy9e399kCgYiXLs2+bjNX NMKjRPy4nidiFH+A2UmJs6QigbdmA/7OKJZXVTon1IG17PnhiP/99kJ88V7R4YjZjnupBYQ+a+A WRB7GymoqNoEFCV2S/teoXehUkvuGhP6vCypeKpV+V8KwW87MY01xuPKWXxj5WbcNt1TNBTk9Hg == X-Google-Smtp-Source: ABdhPJyMkLC2JzxAcu5gvM/ZW5YMEAlgVXqGfeD5DiBcKH3VdQeK7bnSBqWAM6aZr3fzqGSQ0CkWTQqHuC1OEtwpgXo= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a17:902:bcc6:b029:dc:44a5:c363 with SMTP id o6-20020a170902bcc6b02900dc44a5c363mr1973563pls.5.1608595504939; Mon, 21 Dec 2020 16:05:04 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:30 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-13-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 12/17] reference-transaction: look for hooks in config From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By using the hook.h library, reference-transaction hooks can be specified in the config instead. The expected output of the test is not fully updated to reflect the absolute path of the hook called because the 'update' hook has not yet been converted to use hook.h. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 2 ++ refs.c | 38 +++++++++----------------------- t/t1416-ref-transaction-hooks.sh | 8 +++---- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 8f5524055b..3a35500132 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -521,6 +521,8 @@ The exit status of the hook is ignored for any state except for the cause the transaction to be aborted. The hook will not be called with "aborted" state in that case. +Hooks run during 'reference-transaction' will be run in parallel by default. + push-to-checkout ~~~~~~~~~~~~~~~~ diff --git a/refs.c b/refs.c index 392f0bbf68..b025dc4140 100644 --- a/refs.c +++ b/refs.c @@ -18,6 +18,7 @@ #include "strvec.h" #include "repository.h" #include "sigchain.h" +#include "hook.h" /* * List of all available backends @@ -1957,47 +1958,30 @@ int ref_update_reject_duplicates(struct string_list *refnames, static int run_transaction_hook(struct ref_transaction *transaction, const char *state) { - struct child_process proc = CHILD_PROCESS_INIT; struct strbuf buf = STRBUF_INIT; - const char *hook; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_ASYNC; int ret = 0, i; + char o[GIT_MAX_HEXSZ + 1], n[GIT_MAX_HEXSZ + 1]; - hook = find_hook("reference-transaction"); - if (!hook) + if (!hook_exists("reference-transaction", configured_hookdir_opt())) return ret; - strvec_pushl(&proc.args, hook, state, NULL); - proc.in = -1; - proc.stdout_to_stderr = 1; - proc.trace2_hook_name = "reference-transaction"; - - ret = start_command(&proc); - if (ret) - return ret; - - sigchain_push(SIGPIPE, SIG_IGN); + strvec_push(&opt.args, state); for (i = 0; i < transaction->nr; i++) { struct ref_update *update = transaction->updates[i]; + oid_to_hex_r(o, &update->old_oid); + oid_to_hex_r(n, &update->new_oid); strbuf_reset(&buf); - strbuf_addf(&buf, "%s %s %s\n", - oid_to_hex(&update->old_oid), - oid_to_hex(&update->new_oid), - update->refname); - - if (write_in_full(proc.in, buf.buf, buf.len) < 0) { - if (errno != EPIPE) - ret = -1; - break; - } + strbuf_addf(&buf, "%s %s %s", o, n, update->refname); + string_list_append(&opt.str_stdin, buf.buf); } - close(proc.in); - sigchain_pop(SIGPIPE); + ret = run_hooks("reference-transaction", &opt); + run_hooks_opt_clear(&opt); strbuf_release(&buf); - ret |= finish_command(&proc); return ret; } diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index f6e741c6c0..17f11f5cb0 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -122,11 +122,11 @@ test_expect_success 'interleaving hook calls succeed' ' cat >expect <<-EOF && hooks/update refs/tags/PRE $ZERO_OID $PRE_OID - hooks/reference-transaction prepared - hooks/reference-transaction committed + $(pwd)/target-repo.git/hooks/reference-transaction prepared + $(pwd)/target-repo.git/hooks/reference-transaction committed hooks/update refs/tags/POST $ZERO_OID $POST_OID - hooks/reference-transaction prepared - hooks/reference-transaction committed + $(pwd)/target-repo.git/hooks/reference-transaction prepared + $(pwd)/target-repo.git/hooks/reference-transaction committed EOF git push ./target-repo.git PRE POST && From patchwork Tue Dec 22 00:04:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 436E7C43333 for ; Tue, 22 Dec 2020 00:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 295B822B43 for ; Tue, 22 Dec 2020 00:06:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726680AbgLVAGN (ORCPT ); Mon, 21 Dec 2020 19:06:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726597AbgLVAGM (ORCPT ); Mon, 21 Dec 2020 19:06:12 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0815C0611CF for ; Mon, 21 Dec 2020 16:05:07 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id b11so9162697qtj.11 for ; Mon, 21 Dec 2020 16:05:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=iDqJWsAPBG3G1J20vMEo0a/NxzvZWVs472i9yb8IPXA=; b=IbCUee66QH6JP09LlerCOebl26j9eTk+FPxlsSqgJ5FwobCx3xWXQWl9zc32DuF3Ah 6HdWY/UmQL1w86wp/s+CnP6E8mzXcdbydGAQcrwm+2xeMS/ZdTa2c4xyZYBDevoLldMI KnJlsmzaGKUwv+me7heEBrBBH1fkUc5Lk6d39R24f+Q3eEEEilOojpf7xTS0iZ16ZSoj Dy4FlmukD8k9VT7Sx+EUX19gihv5YAGaDZzilj0ySM3LmSCEU5ND86JsVCXRJSMYovFb JwfS2R6fbkQRnaaNO2ImuqmRElR3NktLYQkkDSZEDIcK8/wdyyswiKYUaPbqyusF+KQi fwOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=iDqJWsAPBG3G1J20vMEo0a/NxzvZWVs472i9yb8IPXA=; b=UliQwwCIjwToQ6NajVmyJXUOIMcujce8W1eIDUhC//boCpqqFvCJDB53arwhBQx/Tn +FTMx71zzKL7QEKbsbHt6J7I9E6/BVfy/e08o0uf3S4HV3Ggj4RQjWz2b9t1JaBaCUKr M6GmhL7Z8tMLFDfoJl5d8JuU1cyryNfW8JmODwMYmX0W9t4SmfoEKl7GS+lX+crn/sPP ILPaCgcUh1leR9eXEL1fKgo9dBujID93qfWF7FwImh1kKE5EDEx5AU6dZiTOHTlDTNiX Owu2YWikpPO7XB2ItPvZNUkT7j0GhwnkYZfhMWN9kIWUqpa7mymN6reak+nj+u67lxFN 1SEw== X-Gm-Message-State: AOAM5312TNw3Duh0rw93rW/Pj6MoAzNuIekIi1S05Jo4iWWVoKXJ3Bsh wn4lefam28Q7vbbaEWLgY1QzMVDhymgjyW9bf/9JtqbAr5tpmVe0SD9X7JeLFprpxq8ooKB+P+8 WOo+mauC0Wq6ZjopK/lZFtSsXUZ1P5CToBByiBM3gNMOxL4WkEZriBzjXglbfkj9/7RlIZwIJWg == X-Google-Smtp-Source: ABdhPJzaHIaD4Ut5WPEUPRHThmYsK5zdhZxLtuTY2mX3WqlLtgnzsIJn6eYK3wNiE00S4gf8gnH6FuKzkDhphob60O8= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a05:6214:124d:: with SMTP id q13mr19673177qvv.52.1608595506839; Mon, 21 Dec 2020 16:05:06 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:31 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-14-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 13/17] receive-pack: convert 'update' hook to hook.h From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By using hook.h to invoke the 'update' hook, now hooks can be specified in the config in addition to the hookdir. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 2 + builtin/receive-pack.c | 65 +++++++++++++++++++++----------- t/t1416-ref-transaction-hooks.sh | 4 +- 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 3a35500132..2b3a74f249 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -359,6 +359,8 @@ The default 'update' hook, when enabled--and with `hooks.allowunannotated` config option unset or set to false--prevents unannotated tags to be pushed. +Hooks executed during 'update' are run in parallel by default. + [[proc-receive]] proc-receive ~~~~~~~~~~~~ diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 1c0bad0448..57f3bb979c 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -938,33 +938,56 @@ static int run_receive_hook(struct command *commands, return status; } -static int run_update_hook(struct command *cmd) +static void hook_output_to_sideband(struct strbuf *output, void *cb_data) { - const char *argv[5]; - struct child_process proc = CHILD_PROCESS_INIT; - int code; + int keepalive_active = 0; - argv[0] = find_hook("update"); - if (!argv[0]) - return 0; + if (keepalive_in_sec <= 0) + use_keepalive = KEEPALIVE_NEVER; + if (use_keepalive == KEEPALIVE_ALWAYS) + keepalive_active = 1; - argv[1] = cmd->ref_name; - argv[2] = oid_to_hex(&cmd->old_oid); - argv[3] = oid_to_hex(&cmd->new_oid); - argv[4] = NULL; + /* send a keepalive if there is no data to write */ + if (keepalive_active && !output->len) { + static const char buf[] = "0005\1"; + write_or_die(1, buf, sizeof(buf) - 1); + return; + } - proc.no_stdin = 1; - proc.stdout_to_stderr = 1; - proc.err = use_sideband ? -1 : 0; - proc.argv = argv; - proc.trace2_hook_name = "update"; + if (use_keepalive == KEEPALIVE_AFTER_NUL && !keepalive_active) { + const char *first_null = memchr(output->buf, '\0', output->len); + if (first_null) { + /* The null bit is excluded. */ + size_t before_null = first_null - output->buf; + size_t after_null = output->len - (before_null + 1); + keepalive_active = 1; + send_sideband(1, 2, output->buf, before_null, use_sideband); + send_sideband(1, 2, first_null + 1, after_null, use_sideband); + + return; + } + } + + send_sideband(1, 2, output->buf, output->len, use_sideband); +} + +static int run_update_hook(struct command *cmd) +{ + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_ASYNC; + int code; + + strvec_pushl(&opt.args, + cmd->ref_name, + oid_to_hex(&cmd->old_oid), + oid_to_hex(&cmd->new_oid), + NULL); - code = start_command(&proc); - if (code) - return code; if (use_sideband) - copy_to_sideband(proc.err, -1, NULL); - return finish_command(&proc); + opt.consume_sideband = hook_output_to_sideband; + + code = run_hooks("update", &opt); + run_hooks_opt_clear(&opt); + return code; } static struct command *find_command_by_refname(struct command *list, diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index 17f11f5cb0..28359f6099 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -121,10 +121,10 @@ test_expect_success 'interleaving hook calls succeed' ' EOF cat >expect <<-EOF && - hooks/update refs/tags/PRE $ZERO_OID $PRE_OID + $(pwd)/target-repo.git/hooks/update refs/tags/PRE $ZERO_OID $PRE_OID $(pwd)/target-repo.git/hooks/reference-transaction prepared $(pwd)/target-repo.git/hooks/reference-transaction committed - hooks/update refs/tags/POST $ZERO_OID $POST_OID + $(pwd)/target-repo.git/hooks/update refs/tags/POST $ZERO_OID $POST_OID $(pwd)/target-repo.git/hooks/reference-transaction prepared $(pwd)/target-repo.git/hooks/reference-transaction committed EOF From patchwork Tue Dec 22 00:04:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69A9DC43217 for ; Tue, 22 Dec 2020 00:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DB3422512 for ; Tue, 22 Dec 2020 00:06:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726688AbgLVAGN (ORCPT ); Mon, 21 Dec 2020 19:06:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbgLVAGM (ORCPT ); Mon, 21 Dec 2020 19:06:12 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 713C3C0611D0 for ; Mon, 21 Dec 2020 16:05:09 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id v9so9140324qtw.12 for ; Mon, 21 Dec 2020 16:05:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=1o0hPV2s7/JsQZRvHI51CDqnvS/73mfzcDdKUyyGEcY=; b=qGsx9izsvvNl7Ks4esWK1KZjaFMaxay4rRBSMaJxDDvYnDMQNfhQQIoFd8dESp2qvA 1RC+RpjWOU3qwNprNvDtzmJm2Y5alsq/rbXzv7LUT/oJsSx5t22WwCI6SiSCB94WOTkx YW7smMsrlhRQREkiHVw0gq7qws1L1rA4QJg2OMF7qiW6t3gfaH+dql8Ui0LbgmD4MILv ahYUpbv+h8Vn82h/87hAJXpw6naPfsToHeu0qDIY4sacPryIPCs4on+DT4e7R2uSUgqX cJzISFcbpmQbu+lF7l5sIXEPPlL4yCnA7F470VZCU3JRJ/9Jq/JDA/nrwFhAUYgNAPSH YYNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1o0hPV2s7/JsQZRvHI51CDqnvS/73mfzcDdKUyyGEcY=; b=WRAs5yGqZA1rgMmPF6jAyAUKW2X0R1t+HvfLHYDwxOX2bRsO7AZC4Fsb0ldX8C3aQO 8UWVySeoSs0fDRNylppYCwertUZbKrh3c/Bed9D8VIQgpulAp3MYzAJvNiRad1QotZ5j WMhnH7J4YA+O+XY7gHq/3H1DTSJBb48C9TayCNr84YwGt/1exwF+CLQqPjmKt1xnHDAy 09DCRq9g2hR5UfZrovFFv9hAqrlE0NAVg/PNVVu39ofc3LbY5XWJuN5XJnwn9/Yt8nMJ H1MtID8EpFiFJ/Whvjf5qg71iyOWdse1LWy78dnfVirheb7u3erHJmG/MiGqt9dCwTQO s25g== X-Gm-Message-State: AOAM531Nj9M9uu30trRtqcS+BzZGZpbTk8qtyPNaS1bFYMHRjV9I+H4e 1GJxvJrzAfyhV+arwpLzyx4shVhJKbb/NDCO+N+RBJK4uYIEflv9Tj+IzgUonOwQ/tHUhe+jNt0 ozKg/jIKMLAwM55p2Y61tr4B7LHIwyP1K3hsMOIg+WKnZ95kVBXakUip7g5XfsGNZWBAv/+Qxkw == X-Google-Smtp-Source: ABdhPJw54b42kUJmLEVSQBU2Lg/HMcaYddwix34OuB2MvuQhUEbeOxuF6l4Q9Bl9WSNYDIfaPYvoMqBbIsNbRSYT2jg= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:ad4:55f2:: with SMTP id bu18mr2337226qvb.27.1608595508600; Mon, 21 Dec 2020 16:05:08 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:32 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-15-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 14/17] proc-receive: acquire hook list from hook.h From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The proc-receive hook differs from most other hooks Git invokes because the hook and the parent Git process engage in bidirectional communication via stdin/stdout. This bidirectional communication is unsuitable for multiple hooks, whether they are in series or in parallel, and is incompatible with run-command.h:run_processes_parallel: - The proc-receive hook is intended to modify the state of the Git repo. From 'git help githooks': This [proc-receive] hook is responsible for updating the relevant references and reporting the results back to 'receive-pack'. This prevents parallelization and implies, at least, specific ordering of hook execution. - The proc-receive hook can reject a push by aborting early with an error code. If a former hook ran through the entire push contents successfully but a later hook rejects some of the push, the repo may be left in a partially-updated (and corrupt) state. - The callback model of the run_processes_parallel() API is unsuited to the current implementation of proc-receive, which loops through "send-receive-consider" with the child process. proc-receive today relies on stateful communication with the child process, which would be unwieldy to implement with callbacks and saved state. - Additionally, run_processes_parallel() is designed to collate the output of many child processes into a single output (stderr or callback), and would require significant work to tell the caller which process sent the output, and indeed to collect any output before the child process has exited. So, rather than using hook.h:run_hooks() to invoke the proc-receive hook, receive-pack.c can learn to ask hook.h:hook_list() for the location of a hook to run. This allows users to configure their proc-receive in a global config for all repos if they want, or a local config if they just don't want to use the hookdir. Because running more than one proc-receive hook doesn't make sense from a repo state perspective, we can explicitly ban configuring more than one proc-receive hook at a time. If a user wants to globally configure one proc-receive hook for most of their repos, but override that hook in a single repo, they should use 'skip' to manually remove the global hook in their special repo: ~/.gitconfig: [hook.proc-receive] command = /usr/bin/usual-proc-receive ~/special-repo/.git/config: [hookcmd./usr/bin/usual-proc-receive] skip = true [hook.proc-receive] command = /usr/bin/special-proc-receive Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 4 ++ builtin/receive-pack.c | 33 +++++++++++++++- t/t5411/test-0015-too-many-hooks-error.sh | 47 +++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 t/t5411/test-0015-too-many-hooks-error.sh diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 2b3a74f249..2c59c537f9 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -423,6 +423,10 @@ the input. The exit status of the 'proc-receive' hook only determines the success or failure of the group of commands sent to it, unless atomic push is in use. +It is forbidden to specify more than one hook for 'proc-receive'. If a +globally-configured 'proc-receive' must be overridden, use +'hookcmd..skip = true' to ignore it. + [[post-receive]] post-receive ~~~~~~~~~~~~ diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 57f3bb979c..4a6ad27404 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1145,11 +1145,40 @@ static int run_proc_receive_hook(struct command *commands, int version = 0; int code; - argv[0] = find_hook("proc-receive"); - if (!argv[0]) { + struct strbuf hookname = STRBUF_INIT; + struct hook *proc_receive = NULL; + struct list_head *pos, *hooks; + + strbuf_addstr(&hookname, "proc-receive"); + hooks = hook_list(&hookname); + + list_for_each(pos, hooks) { + if (proc_receive) { + rp_error("only one 'proc-receive' hook can be specified"); + return -1; + } + proc_receive = list_entry(pos, struct hook, list); + /* check if the hookdir hook should be ignored */ + if (proc_receive->from_hookdir) { + switch (configured_hookdir_opt()) { + case HOOKDIR_INTERACTIVE: + case HOOKDIR_NO: + proc_receive = NULL; + break; + default: + break; + } + } + + } + + if (!proc_receive) { rp_error("cannot find hook 'proc-receive'"); return -1; } + + + argv[0] = proc_receive->command.buf; argv[1] = NULL; proc.argv = argv; diff --git a/t/t5411/test-0015-too-many-hooks-error.sh b/t/t5411/test-0015-too-many-hooks-error.sh new file mode 100644 index 0000000000..2d64534510 --- /dev/null +++ b/t/t5411/test-0015-too-many-hooks-error.sh @@ -0,0 +1,47 @@ +test_expect_success "setup too many proc-receive hooks (ok, $PROTOCOL)" ' + write_script "proc-receive" <<-EOF && + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/main/topic" + EOF + + git -C "$upstream" config --add "hook.proc-receive.command" proc-receive && + cp proc-receive "$upstream/hooks/proc-receive" +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : next(A) refs/for/main/topic(A) +test_expect_success "proc-receive: reject more than one configured hook" ' + test_must_fail git -C workbench push origin \ + HEAD:next \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< refs/heads/next + remote: pre-receive< refs/for/main/topic + remote: error: only one "proc-receive" hook can be specified + remote: # post-receive hook + remote: post-receive< refs/heads/next + To + * [new branch] HEAD -> next + ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output actual && + cat >expect <<-EOF && + refs/heads/main + refs/heads/next + EOF + test_cmp expect actual +' + +# Refs of upstream : main(A) next(A) +# Refs of workbench: main(A) tags/v123 +test_expect_success "cleanup ($PROTOCOL)" ' + git -C "$upstream" config --unset "hook.proc-receive.command" "proc-receive" && + git -C "$upstream" update-ref -d refs/heads/next +' From patchwork Tue Dec 22 00:04:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C23AC433DB for ; Tue, 22 Dec 2020 00:06:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6826122AED for ; Tue, 22 Dec 2020 00:06:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726429AbgLVAGi (ORCPT ); Mon, 21 Dec 2020 19:06:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726048AbgLVAGh (ORCPT ); Mon, 21 Dec 2020 19:06:37 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17BE6C0611E4 for ; Mon, 21 Dec 2020 16:05:11 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id c21so312307pjr.8 for ; Mon, 21 Dec 2020 16:05:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=95WssQGkSGjhfagG6g7ltjwqaKVtmBM5EOhXY6N4OsU=; b=GqbLcAxteGCqKS5gtMrqZBhFYHWyNNmIadqjeZBxasr+jT0R+OETaLieEK0T+/sBmK Ik4Tr/ClxCQW2rEyMS9beIae4qIfKQ8nLd82UbtXWrKjxGst0S3/pVQhjF54whLN+QZl hYDdqcWd2FK8G4WfN0ZF1+JIqeCyL36ciOR3oRrwvGtO1g23W91lqxg5lDjkDOw6vWq5 JJN67P6oBnpVEUZGYOnICdS3ChrtjGeyB+UeX3yphJCMV98UmwmyAnrO2TAtRxeGDgS5 RGu/8z4W5o4zLDniRiEy3NvepzStQrLZc1ar1LVVhOBpdAC88YSyoPN6TuHB2JiNuLFr 0kCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=95WssQGkSGjhfagG6g7ltjwqaKVtmBM5EOhXY6N4OsU=; b=FPjmbTY1FWULM1GRtPqwHH0FwbU4Zf6tiyc8Qvv6rPz1KEo/3rfdQb2MOCuhDD4Rcd DEb1PUgX9Ql0ynkUwivo+pg0f07h9Ie5kGl24jQ36S2jDeoyEbU1fQ0D+INHGbkpnn2r raBA+xI9aUa6/0l3cYC6IvFayBKBxBFAAHdoEPtwldXZF4gITa0La/c3xbJ8gmVBGmwG srIIXoxhvE96AIs/scWcCLv5D26ogliofxWBr98Gt5T32GaOU2Zro6/kFiBn3E4wjXTQ PaMnFuvn64D+4ZVNWSVTKF12SuC+Am8D/XHphgiueaugCdMvw99+/HfaynJSHtBjR17S msHQ== X-Gm-Message-State: AOAM5319/f/UUk3Au5CU1YwjzeRQzzLyyewJkbtF4QtHQTClcJ2vvXhi dP9CZlyyIx31mjzZCgjdyjIYXKNaVdkle91AvPuLpwnhh49+zAY836XTlhtH553pp3PMZvEnRlG DYECkC829aOQ9mNHGRAP9dpHek5MNkfxAdgua7BrYtpyurXrAQcPUlnc283QUoSJUIKDnXOumxQ == X-Google-Smtp-Source: ABdhPJyNcTYN5Omu4FPnBHXdlsoFAAFgwfts4h3RThiCVGtZgBefq0f5ihJHDi71C8YqyQ2+vn68vsQYRGGJ1C2TjvI= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a63:d846:: with SMTP id k6mr17297051pgj.167.1608595510444; Mon, 21 Dec 2020 16:05:10 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:33 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-16-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 15/17] post-update: use hook.h library From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By using run_hooks() instead of run_hook_le(), 'post-update' hooks can be specified in the config as well as the hookdir. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 2 ++ builtin/receive-pack.c | 26 +++++++------------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 2c59c537f9..1412cd5846 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -498,6 +498,8 @@ Both standard output and standard error output are forwarded to `git send-pack` on the other end, so you can simply `echo` messages for the user. +Hooks run during 'post-update' will be run in parallel by default. + reference-transaction ~~~~~~~~~~~~~~~~~~~~~ diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 4a6ad27404..5c23d5ed86 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1686,33 +1686,21 @@ static const char *update(struct command *cmd, struct shallow_info *si) static void run_update_post_hook(struct command *commands) { struct command *cmd; - struct child_process proc = CHILD_PROCESS_INIT; - const char *hook; - - hook = find_hook("post-update"); - if (!hook) - return; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_ASYNC; for (cmd = commands; cmd; cmd = cmd->next) { if (cmd->error_string || cmd->did_not_exist) continue; - if (!proc.args.nr) - strvec_push(&proc.args, hook); - strvec_push(&proc.args, cmd->ref_name); + strvec_push(&opt.args, cmd->ref_name); } - if (!proc.args.nr) + if (!opt.args.nr) return; - proc.no_stdin = 1; - proc.stdout_to_stderr = 1; - proc.err = use_sideband ? -1 : 0; - proc.trace2_hook_name = "post-update"; + if (use_sideband) + opt.consume_sideband = hook_output_to_sideband; - if (!start_command(&proc)) { - if (use_sideband) - copy_to_sideband(proc.err, -1, NULL); - finish_command(&proc); - } + run_hooks("post-update", &opt); + run_hooks_opt_clear(&opt); } static void check_aliased_update_internal(struct command *cmd, From patchwork Tue Dec 22 00:04:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81133C432C3 for ; Tue, 22 Dec 2020 00:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5249F22B43 for ; Tue, 22 Dec 2020 00:06:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726690AbgLVAGN (ORCPT ); Mon, 21 Dec 2020 19:06:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726637AbgLVAGM (ORCPT ); Mon, 21 Dec 2020 19:06:12 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3858BC0611BB for ; Mon, 21 Dec 2020 16:05:13 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id n12so9215708qta.9 for ; Mon, 21 Dec 2020 16:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=u9/hXbeix7Y1mawzrALxseBhGQVFK8WA3OIjXSsgTA8=; b=GUHwy6OMRVDlpOYS1kn6GuIvyh/s0+UwP/V80Vde2+fqloCY3EErc/oagTBuQzYA+V Ji3WJFigjFkVTcy0Nfq1dIu8skaWPcXiYmZ0jhg8j8mmsMWqdH50QOy5L9ugkgGwT07T 3z6qV3rF4lcwd1D7mKacNZKkxWfl/VyVYCQ0GhNHNZQFWST28iPmZr3O/+t+DH1rYhAf EBGWLaqaHGKOo6u9VUQIrFN1PfRroWWUVpiak0yQxO1zx5IQ0cQyMk60cPis25+auOyo fjzxejEImk8JFIk67qgmggVpqBy9JXkAhhocrbNT10t4x44MNSTG9e4FugHuDYHwPN0/ xI3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=u9/hXbeix7Y1mawzrALxseBhGQVFK8WA3OIjXSsgTA8=; b=Md41wQwnW9Tyr1r7NbXzO5eaNgbXC7VaeRKi3wFaz8XmuxDzhWQFyR2V5nZNGjVS5X ZdOYd2wuXBQw+bl0XqQ9nX7csfAXrDh8LY9H8vjmafwEfWGE9/sCOJJHGPci0kz4EuX2 0vUb5yXFnV2AVpRxBTBBQWwohS324wlmOBNw063ApQAMFEt7XIeYft4mMhpXN0JWQKNj Y8aekj/JViHCXM00VEo1AtsXpiWc8N6NTYOGqAHF7MJcuFUOzEQKucLkfTepgbphycYw 8a+EDOA080VklXGeoZ22a17Qky71ZFozXEA5sOtBr+LUGRqW0HeYEv524r2yDkDRjvS6 B4jg== X-Gm-Message-State: AOAM533i2RD4l23OosIGtVeWBxF6tMmZWQnxGDqBo9H+6iI5rDqdcQ+P +097MEFEHQ+bVuIYnXGKaHrd49ZkcSWEQJYLE6e3tc/Xgxh0rSVKI/FbxlWHyzyZsaIt2cy1UZY 2ZkqyDnaEgrKEkR9lfPVbgdLWuU58pY0+52u+dv+ufIV5Jb8jBlzmA6Tqf6u3bl70Gu3DkleKvA == X-Google-Smtp-Source: ABdhPJwrKG2SX2xJEbQqmt4M25DCpkTvad5BYX408+IJCvQGajfGU87p6CHLkoLY6LvzteCv4ValeWWpo2n/WPGCoUw= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a0c:f0d3:: with SMTP id d19mr19582886qvl.55.1608595512295; Mon, 21 Dec 2020 16:05:12 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:34 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-17-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 16/17] receive-pack: convert receive hooks to hook.h From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By using the hook.h library to run receive hooks, they can be specified in the config as well as in the hookdir. Signed-off-by: Emily Shaffer --- Documentation/githooks.txt | 4 + builtin/receive-pack.c | 197 +++++++++++++++++-------------------- 2 files changed, 94 insertions(+), 107 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 1412cd5846..c450f7a27e 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -314,6 +314,8 @@ will be set to zero, `GIT_PUSH_OPTION_COUNT=0`. See the section on "Quarantine Environment" in linkgit:git-receive-pack[1] for some caveats. +Hooks executed during 'pre-receive' will not be parallelized. + [[update]] update ~~~~~~ @@ -466,6 +468,8 @@ environment variables will not be set. If the client selects to use push options, but doesn't transmit any, the count variable will be set to zero, `GIT_PUSH_OPTION_COUNT=0`. +Hooks executed during 'post-receive' are run in parallel by default. + [[post-update]] post-update ~~~~~~~~~~~ diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 5c23d5ed86..348d5b0a9b 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -748,7 +748,7 @@ static int check_cert_push_options(const struct string_list *push_options) return retval; } -static void prepare_push_cert_sha1(struct child_process *proc) +static void prepare_push_cert_sha1(struct run_hooks_opt *opt) { static int already_done; @@ -772,110 +772,42 @@ static void prepare_push_cert_sha1(struct child_process *proc) nonce_status = check_nonce(push_cert.buf, bogs); } if (!is_null_oid(&push_cert_oid)) { - strvec_pushf(&proc->env_array, "GIT_PUSH_CERT=%s", + strvec_pushf(&opt->env, "GIT_PUSH_CERT=%s", oid_to_hex(&push_cert_oid)); - strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s", + strvec_pushf(&opt->env, "GIT_PUSH_CERT_SIGNER=%s", sigcheck.signer ? sigcheck.signer : ""); - strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s", + strvec_pushf(&opt->env, "GIT_PUSH_CERT_KEY=%s", sigcheck.key ? sigcheck.key : ""); - strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_STATUS=%c", + strvec_pushf(&opt->env, "GIT_PUSH_CERT_STATUS=%c", sigcheck.result); if (push_cert_nonce) { - strvec_pushf(&proc->env_array, + strvec_pushf(&opt->env, "GIT_PUSH_CERT_NONCE=%s", push_cert_nonce); - strvec_pushf(&proc->env_array, + strvec_pushf(&opt->env, "GIT_PUSH_CERT_NONCE_STATUS=%s", nonce_status); if (nonce_status == NONCE_SLOP) - strvec_pushf(&proc->env_array, + strvec_pushf(&opt->env, "GIT_PUSH_CERT_NONCE_SLOP=%ld", nonce_stamp_slop); } } } +struct receive_hook_feed_context { + struct command *cmd; + int skip_broken; +}; + struct receive_hook_feed_state { struct command *cmd; struct ref_push_report *report; int skip_broken; struct strbuf buf; - const struct string_list *push_options; }; -typedef int (*feed_fn)(void *, const char **, size_t *); -static int run_and_feed_hook(const char *hook_name, feed_fn feed, - struct receive_hook_feed_state *feed_state) -{ - struct child_process proc = CHILD_PROCESS_INIT; - struct async muxer; - const char *argv[2]; - int code; - - argv[0] = find_hook(hook_name); - if (!argv[0]) - return 0; - - argv[1] = NULL; - - proc.argv = argv; - proc.in = -1; - proc.stdout_to_stderr = 1; - proc.trace2_hook_name = hook_name; - - if (feed_state->push_options) { - int i; - for (i = 0; i < feed_state->push_options->nr; i++) - strvec_pushf(&proc.env_array, - "GIT_PUSH_OPTION_%d=%s", i, - feed_state->push_options->items[i].string); - strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT=%d", - feed_state->push_options->nr); - } else - strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT"); - - if (tmp_objdir) - strvec_pushv(&proc.env_array, tmp_objdir_env(tmp_objdir)); - - if (use_sideband) { - memset(&muxer, 0, sizeof(muxer)); - muxer.proc = copy_to_sideband; - muxer.in = -1; - code = start_async(&muxer); - if (code) - return code; - proc.err = muxer.in; - } - - prepare_push_cert_sha1(&proc); - - code = start_command(&proc); - if (code) { - if (use_sideband) - finish_async(&muxer); - return code; - } - - sigchain_push(SIGPIPE, SIG_IGN); - - while (1) { - const char *buf; - size_t n; - if (feed(feed_state, &buf, &n)) - break; - if (write_in_full(proc.in, buf, n) < 0) - break; - } - close(proc.in); - if (use_sideband) - finish_async(&muxer); - - sigchain_pop(SIGPIPE); - - return finish_command(&proc); -} - -static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep) +static int feed_receive_hook(void *state_) { struct receive_hook_feed_state *state = state_; struct command *cmd = state->cmd; @@ -884,9 +816,7 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep) state->skip_broken && (cmd->error_string || cmd->did_not_exist)) cmd = cmd->next; if (!cmd) - return -1; /* EOF */ - if (!bufp) - return 0; /* OK, can feed something. */ + return 1; /* EOF - close the pipe*/ strbuf_reset(&state->buf); if (!state->report) state->report = cmd->report; @@ -910,32 +840,36 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep) cmd->ref_name); state->cmd = cmd->next; } - if (bufp) { - *bufp = state->buf.buf; - *sizep = state->buf.len; - } return 0; } -static int run_receive_hook(struct command *commands, - const char *hook_name, - int skip_broken, - const struct string_list *push_options) +static int feed_receive_hook_cb(struct strbuf *pipe, void *pp_cb, void *pp_task_cb) { - struct receive_hook_feed_state state; - int status; - - strbuf_init(&state.buf, 0); - state.cmd = commands; - state.skip_broken = skip_broken; - state.report = NULL; - if (feed_receive_hook(&state, NULL, NULL)) - return 0; - state.cmd = commands; - state.push_options = push_options; - status = run_and_feed_hook(hook_name, feed_receive_hook, &state); - strbuf_release(&state.buf); - return status; + struct hook *hook = pp_task_cb; + struct receive_hook_feed_state *feed_state = hook->feed_pipe_cb_data; + int rc; + + /* first-time setup */ + if (!feed_state) { + struct hook_cb_data *hook_cb = pp_cb; + struct run_hooks_opt *opt = hook_cb->options; + struct receive_hook_feed_context *ctx = opt->feed_pipe_ctx; + if (!ctx) + BUG("run_hooks_opt.feed_pipe_ctx required for receive hook"); + + feed_state = xmalloc(sizeof(struct receive_hook_feed_state)); + strbuf_init(&feed_state->buf, 0); + feed_state->cmd = ctx->cmd; + feed_state->skip_broken = ctx->skip_broken; + feed_state->report = NULL; + + hook->feed_pipe_cb_data = feed_state; + } + + rc = feed_receive_hook(feed_state); + if (!rc) + strbuf_addbuf(pipe, &feed_state->buf); + return rc; } static void hook_output_to_sideband(struct strbuf *output, void *cb_data) @@ -971,6 +905,55 @@ static void hook_output_to_sideband(struct strbuf *output, void *cb_data) send_sideband(1, 2, output->buf, output->len, use_sideband); } +static int run_receive_hook(struct command *commands, + const char *hook_name, + int skip_broken, + const struct string_list *push_options) +{ + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_ASYNC; + struct receive_hook_feed_context ctx; + int rc; + struct command *iter = commands; + + /* if there are no valid commands, don't invoke the hook at all. */ + while (iter && skip_broken && (iter->error_string || iter->did_not_exist)) + iter = iter->next; + if (!iter) + return 0; + + /* pre-receive hooks should run in series as the hook updates refs */ + if (!strcmp(hook_name, "pre-receive")) + opt.jobs = 1; + + if (push_options) { + int i; + for (i = 0; i < push_options->nr; i++) + strvec_pushf(&opt.env, "GIT_PUSH_OPTION_%d=%s", i, + push_options->items[i].string); + strvec_pushf(&opt.env, "GIT_PUSH_OPTION_COUNT=%d", push_options->nr); + } else + strvec_push(&opt.env, "GIT_PUSH_OPTION_COUNT"); + + if (tmp_objdir) + strvec_pushv(&opt.env, tmp_objdir_env(tmp_objdir)); + + prepare_push_cert_sha1(&opt); + + /* set up sideband printer */ + if (use_sideband) + opt.consume_sideband = hook_output_to_sideband; + + /* set up stdin callback */ + ctx.cmd = commands; + ctx.skip_broken = skip_broken; + opt.feed_pipe = feed_receive_hook_cb; + opt.feed_pipe_ctx = &ctx; + + rc = run_hooks(hook_name, &opt); + run_hooks_opt_clear(&opt); + return rc; +} + static int run_update_hook(struct command *cmd) { struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_ASYNC; From patchwork Tue Dec 22 00:04:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11985483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1E8BC433E0 for ; Tue, 22 Dec 2020 00:06:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4C7D22AED for ; Tue, 22 Dec 2020 00:06:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726292AbgLVAGi (ORCPT ); Mon, 21 Dec 2020 19:06:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbgLVAGh (ORCPT ); Mon, 21 Dec 2020 19:06:37 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C8E9C0619D2 for ; Mon, 21 Dec 2020 16:05:15 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id z62so15603734yba.23 for ; Mon, 21 Dec 2020 16:05:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=13m9umWzWchNSUyzLQzXZdvVhBzh116z7X5uxpA1VA8=; b=bPJk8qE9fV5pYCslVk6rulLmMDHEXj86qjKXNeKmHmaq2He4ljU0dfgQaAu7dwZ0cA FlR+J3fUKxSW/nijtaY/uHHRSVO2fTqHXYM11onX3H4Yxge/TYlKAbUY4Vel9g34DmPg /MijtFbMsbj9qZ5fOsKT4ZVbFQ212HWX/qREUILwQdLPoBiVycj04jXHMfhWamTxbFuz wkOQeR0+EtRzhjFU1Tpj7cB2ouqepkhC11APdDObtkZLkbXJ5Rklqr3noH4guxMt9hJG CppvHUmtjTSWH6n+rSz9IxiJaUZYqsSFpnT7YdbDSqqdXEjwX6jOLR6Cohe8VX/IRxek 4GzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=13m9umWzWchNSUyzLQzXZdvVhBzh116z7X5uxpA1VA8=; b=rTBGAJmsxiMP6oa1Zv8r3k+sy0jTgt4VWQ/wtLrldSVeEVJoiADOlEdAPzOWFMUm5b bmaQmv+Na6+3LYTnM3ohuNm2BwBn6i2YDNCnXjvuVuGyCPGLDp2cnLORfEqtqS06EGSW znohRZxdOnceLxAf6TUMC28dUgh7zMewNe/XzCw37/gBVrb9DD/Liy/4Y06qasvfOYi9 CXKEphn0Hg7Rrhe5OcWRQF1irbFwOH4UdhZtcARnUXz3LOOXpj+gb38WDwDVTqr70nMd khjAtMZivRr3ZdrWZVO56rLpIYCugqVf0o8vJXSb1GQZCqmoNwX4gmbh2tltyXUa1P83 YTqw== X-Gm-Message-State: AOAM532NOgQU5CuFkzwkD52pLYm4DOWIShOTJ1fchZh00CoFCAoK4UXj p1xQcIwL2Iu+1WMr/SrNKgBElHNXhXrQWbZeIc7k8c7mdh1dOHxT0KbkUBPm4PVu5+GduO+uqO0 ugM0WE515EdIvOY6V6tEJFWqF2Kn3lyDwQQiSYtzcbUgGr1T1sgyuV5S2XkJzYJCtG9vHyArlwQ == X-Google-Smtp-Source: ABdhPJwAgyoDI/2OxiJ8Y7hVcbXKPJzv3NiY3YWLUGHSMm2YsiNuqlXihs8ey4nWSNZxnT0hGys0ikaetQ4b+8dlS4o= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:a25:d0cf:: with SMTP id h198mr25430782ybg.384.1608595514321; Mon, 21 Dec 2020 16:05:14 -0800 (PST) Date: Mon, 21 Dec 2020 16:04:35 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201222000435.1529768-18-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201222000435.1529768-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 17/17] run-command: stop thinking about hooks From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org hook.h has replaced all run-command.h hook-related functionality. run-command.h:run_hooks_le/ve and find_hook are no longer used anywhere in the codebase. So, let's delete the dead code - or, in the one case where it's still needed, move it to an internal function in hook.c. Signed-off-by: Emily Shaffer --- hook.c | 39 ++++++++++++++++++++++++++++-- run-command.c | 66 --------------------------------------------------- run-command.h | 24 ------------------- 3 files changed, 37 insertions(+), 92 deletions(-) diff --git a/hook.c b/hook.c index dc241f7ec5..0ac984983e 100644 --- a/hook.c +++ b/hook.c @@ -196,6 +196,41 @@ static int should_include_hookdir(const char *path, enum hookdir_opt cfg) } } +static const char *find_legacy_hook(const char *name) +{ + static struct strbuf path = STRBUF_INIT; + + strbuf_reset(&path); + strbuf_git_path(&path, "hooks/%s", name); + if (access(path.buf, X_OK) < 0) { + int err = errno; + +#ifdef STRIP_EXTENSION + strbuf_addstr(&path, STRIP_EXTENSION); + if (access(path.buf, X_OK) >= 0) + return path.buf; + if (errno == EACCES) + err = errno; +#endif + + if (err == EACCES && advice_ignored_hook) { + static struct string_list advise_given = STRING_LIST_INIT_DUP; + + if (!string_list_lookup(&advise_given, name)) { + string_list_insert(&advise_given, name); + advise(_("The '%s' hook was ignored because " + "it's not set as executable.\n" + "You can disable this warning with " + "`git config advice.ignoredHook false`."), + path.buf); + } + } + return NULL; + } + return path.buf; +} + + struct list_head* hook_list(const struct strbuf* hookname) { struct strbuf hook_key = STRBUF_INIT; @@ -213,7 +248,7 @@ struct list_head* hook_list(const struct strbuf* hookname) git_config(hook_config_lookup, (void*)&cb_data); if (have_git_dir()) - legacy_hook_path = find_hook(hookname->buf); + legacy_hook_path = find_legacy_hook(hookname->buf); /* Unconditionally add legacy hook, but annotate it. */ if (legacy_hook_path) { @@ -244,7 +279,7 @@ int hook_exists(const char *hookname, enum hookdir_opt should_run_hookdir) int could_run_hookdir = (should_run_hookdir == HOOKDIR_INTERACTIVE || should_run_hookdir == HOOKDIR_WARN || should_run_hookdir == HOOKDIR_YES) - && !!find_hook(hookname); + && !!find_legacy_hook(hookname); strbuf_addf(&hook_key, "hook.%s.command", hookname); diff --git a/run-command.c b/run-command.c index 0dce6bec83..16656135dd 100644 --- a/run-command.c +++ b/run-command.c @@ -1310,72 +1310,6 @@ int async_with_fork(void) #endif } -const char *find_hook(const char *name) -{ - static struct strbuf path = STRBUF_INIT; - - strbuf_reset(&path); - strbuf_git_path(&path, "hooks/%s", name); - if (access(path.buf, X_OK) < 0) { - int err = errno; - -#ifdef STRIP_EXTENSION - strbuf_addstr(&path, STRIP_EXTENSION); - if (access(path.buf, X_OK) >= 0) - return path.buf; - if (errno == EACCES) - err = errno; -#endif - - if (err == EACCES && advice_ignored_hook) { - static struct string_list advise_given = STRING_LIST_INIT_DUP; - - if (!string_list_lookup(&advise_given, name)) { - string_list_insert(&advise_given, name); - advise(_("The '%s' hook was ignored because " - "it's not set as executable.\n" - "You can disable this warning with " - "`git config advice.ignoredHook false`."), - path.buf); - } - } - return NULL; - } - return path.buf; -} - -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 2ad8271f56..e67bd22c5a 100644 --- a/run-command.h +++ b/run-command.h @@ -194,30 +194,6 @@ int finish_command_in_signal(struct child_process *); */ int run_command(struct child_process *); -/* - * Returns the path to the hook file, or NULL if the hook is missing - * or disabled. Note that this points to static storage that will be - * overwritten by further calls to find_hook and run_hook_*. - */ -const char *find_hook(const char *name); - -/** - * 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, ...); -int run_hook_ve(const char *const *env, const char *name, va_list args); - /* * Trigger an auto-gc */ From patchwork Mon Dec 28 22:40:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11991761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-31.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08BE0C4332D for ; Mon, 28 Dec 2020 23:23:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCC6522475 for ; Mon, 28 Dec 2020 23:23:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729958AbgL1Wzj (ORCPT ); Mon, 28 Dec 2020 17:55:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729660AbgL1Wk7 (ORCPT ); Mon, 28 Dec 2020 17:40:59 -0500 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FC9DC061796 for ; Mon, 28 Dec 2020 14:40:19 -0800 (PST) Received: by mail-qv1-xf49.google.com with SMTP id j5so10079573qvu.22 for ; Mon, 28 Dec 2020 14:40:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:subject:from:to:cc; bh=nfrg2zG1zF4wLlLGq+Xouw/vEtdcn+A9nGN2VNincK8=; b=WzWfPatX9wxqiG7ziZ8sTT8fIwAislt3GWZLl4ldxT9oNvt1l4m8WLe9kMYrTPu4jl 9/5qHFDMUNIYcdjd84R+P96FYh0gsCVCrY+Ojes+iZvNF2zX0Ht7sopSsj7iAoIEYv3E eVTvvvbd/pXHCkiWGolnMIbcrpSEhYxZJJivuLK+kVivm2PJNR6URrPeJJdk3dXBAiQD aKjRr0EY3mdAXAHjLGMRMaXTRMb2H29eRy9itU66hkZiDN7XkZ0iBH9S6JqD3G6wdYfp Dsab/Bwph1MyiFI2d5aLoxbe1/J3YSaOmfnUdlSw8dVCpiFsQ6n+mGGaDLRtEzN62neJ tfmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :subject:from:to:cc; bh=nfrg2zG1zF4wLlLGq+Xouw/vEtdcn+A9nGN2VNincK8=; b=gQci5XpT7IiptTKkzjGRY0uAfhQHx/xJG/KECLhDfk5kFALnvZT6/n9dnUJioCzrKo 2hyI6wzcJqQLTHdQRe3qNweDfj46vjDNOSq0cYznypidzxuE5pY8YFYNuiffOeYdzD5o CLofT7P7QWShkHKz2hy3CtQMJU5Ke2ITMmcUJZSFtLOUlbrsyb9C9sTsHHZc8rlj9Dea B1j3N3x+KPiymQ4ItOM7rlC5VCUAKJiQh5qeT79GH7BMhDNmYTZDrbyhR94QrfoUiwkd 9H7okqoh5rZYNOz0sdMdkS51s6GqdM5KZhIZTV3nVYgv+IN5nFeDxV4rHqXU/yEiIk3Z VJpQ== X-Gm-Message-State: AOAM531G2Lsz82gvB7PbdBDoGdHtCwT9RRAcFScu+ilVSunfcRW1AgO7 GEl+G2e2O63QOoCm5fg8GW+nKRv/0vr6ubNCSvfhoBhYxhiuzVTj58Gbm1rRE0LW9PsZ12e5Q1+ ShpJE9csUfI2uxLRDQPqWXwgBkl1xMYluFs9ojWB8PIShGcF3RuKBlayQx8Uqz+zA2bgIPWDZqQ == X-Google-Smtp-Source: ABdhPJwLqq7chRWRx+lzKf3o4mKNe+OZKHABuP23b/rWxcAuMd1tHDHyf/Si3xbuAxfiGkUEP4fYuLfMA3g+nTJzgXA= Sender: "emilyshaffer via sendgmr" X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:1ea0:b8ff:fe77:f690]) (user=emilyshaffer job=sendgmr) by 2002:ad4:5bce:: with SMTP id t14mr49284889qvt.6.1609195218531; Mon, 28 Dec 2020 14:40:18 -0800 (PST) Date: Mon, 28 Dec 2020 14:40:15 -0800 In-Reply-To: <20201222000435.1529768-1-emilyshaffer@google.com> Message-Id: <20201228224015.286845-1-emilyshaffer@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.490.gc7ae633391 Subject: [PATCH v3 18/17] doc: make git-hook.txt point of truth From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer , Jeff King , Junio C Hamano , James Ramsay , Jonathan Nieder , "brian m. carlson" , " =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= " , Phillip Wood , Josh Steadmon , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By showing the list of all hooks in 'git help hook' for users to refer to, 'git help hook' becomes a one-stop shop for hook authorship. Since some may still have muscle memory for 'git help githooks', though, reference the 'git hook' commands and otherwise don't remove content. Signed-off-by: Emily Shaffer --- Sorry for the wonky subject. It seemed unnecessary to send the entirety of the topic again when there were no changes. (I was able to push this patch to my fork without -f, so indeed the rest is unchanged.) I'd really prefer if 'git help githooks' opens the 'git-hook.txt' manpage, but I couldn't figure out how to do that. This seemed like the next best thing to me - users can still find information at the old manpage, but get a little nudge towards the new manpage in case they didn't notice it. Extremely open to other notes about the direction of these docs; I'm not confident in anything except that it'd be annoying to have 'git help githooks' remain unchanged. - Emily Documentation/git-hook.txt | 5 + Documentation/githooks.txt | 701 +------------------------------------ 2 files changed, 13 insertions(+), 693 deletions(-) diff --git a/Documentation/git-hook.txt b/Documentation/git-hook.txt index 01cee4ad81..cb8e383ec9 100644 --- a/Documentation/git-hook.txt +++ b/Documentation/git-hook.txt @@ -112,6 +112,11 @@ CONFIGURATION ------------- include::config/hook.txt[] +HOOKS +----- + +include::native-hooks.txt[] + GIT --- Part of the linkgit:git[1] suite diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index c450f7a27e..4d06369924 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -8,15 +8,20 @@ githooks - Hooks used by Git SYNOPSIS -------- $GIT_DIR/hooks/* (or \`git config core.hooksPath`/*) +[verse] +'git hook' list +'git hook' run DESCRIPTION ----------- -Hooks are programs you can place in a hooks directory to trigger -actions at certain points in git's execution. Hooks that don't have +Hooks are programs you can place in a hooks directory or specify in the config +to trigger actions at certain points in Git's execution. Hooks that don't have the executable bit set are ignored. +For information about specifying hooks in the config, check linkgit:git-hook[1]. + By default the hooks directory is `$GIT_DIR/hooks`, but that can be changed via the `core.hooksPath` configuration variable (see linkgit:git-config[1]). @@ -42,697 +47,7 @@ The currently supported hooks are described below. HOOKS ----- -applypatch-msg -~~~~~~~~~~~~~~ - -This hook is invoked by linkgit:git-am[1]. It takes a single -parameter, the name of the file that holds the proposed commit -log message. Exiting with a non-zero status causes `git am` to abort -before applying the patch. - -The hook is allowed to edit the message file in place, and can -be used to normalize the message into some project standard -format. It can also be used to refuse the commit after inspecting -the message file. - -The default 'applypatch-msg' hook, when enabled, runs the -'commit-msg' hook, if the latter is enabled. - -Hooks run during 'applypatch-msg' will not be parallelized. - -pre-applypatch -~~~~~~~~~~~~~~ - -This hook is invoked by linkgit:git-am[1]. It takes no parameter, and is -invoked after the patch is applied, but before a commit is made. - -If it exits with non-zero status, then the working tree will not be -committed after applying the patch. - -It can be used to inspect the current working tree and refuse to -make a commit if it does not pass certain test. - -The default 'pre-applypatch' hook, when enabled, runs the -'pre-commit' hook, if the latter is enabled. - -Hooks run during 'pre-applypatch' will be run in parallel by default. - -post-applypatch -~~~~~~~~~~~~~~~ - -This hook is invoked by linkgit:git-am[1]. It takes no parameter, -and is invoked after the patch is applied and a commit is made. - -This hook is meant primarily for notification, and cannot affect -the outcome of `git am`. - -Hooks run during 'post-applypatch' will be run in parallel by default. - -pre-commit -~~~~~~~~~~ - -This hook is invoked by linkgit:git-commit[1], and can be bypassed -with the `--no-verify` option. It takes no parameters, and is -invoked before obtaining the proposed commit log message and -making a commit. Exiting with a non-zero status from this script -causes the `git commit` command to abort before creating a commit. - -The default 'pre-commit' hook, when enabled, catches introduction -of lines with trailing whitespaces and aborts the commit when -such a line is found. - -All the `git commit` hooks are invoked with the environment -variable `GIT_EDITOR=:` if the command will not bring up an editor -to modify the commit message. - -The default 'pre-commit' hook, when enabled--and with the -`hooks.allownonascii` config option unset or set to false--prevents -the use of non-ASCII filenames. - -Hooks executed during 'pre-commit' will not be parallelized. - -pre-merge-commit -~~~~~~~~~~~~~~~~ - -This hook is invoked by linkgit:git-merge[1], and can be bypassed -with the `--no-verify` option. It takes no parameters, and is -invoked after the merge has been carried out successfully and before -obtaining the proposed commit log message to -make a commit. Exiting with a non-zero status from this script -causes the `git merge` command to abort before creating a commit. - -The default 'pre-merge-commit' hook, when enabled, runs the -'pre-commit' hook, if the latter is enabled. - -This hook is invoked with the environment variable -`GIT_EDITOR=:` if the command will not bring up an editor -to modify the commit message. - -If the merge cannot be carried out automatically, the conflicts -need to be resolved and the result committed separately (see -linkgit:git-merge[1]). At that point, this hook will not be executed, -but the 'pre-commit' hook will, if it is enabled. - -Hooks executed during 'pre-merge-commit' will not be parallelized. - -prepare-commit-msg -~~~~~~~~~~~~~~~~~~ - -This hook is invoked by linkgit:git-commit[1] right after preparing the -default log message, and before the editor is started. - -It takes one to three parameters. The first is the name of the file -that contains the commit log message. The second is the source of the commit -message, and can be: `message` (if a `-m` or `-F` option was -given); `template` (if a `-t` option was given or the -configuration option `commit.template` is set); `merge` (if the -commit is a merge or a `.git/MERGE_MSG` file exists); `squash` -(if a `.git/SQUASH_MSG` file exists); or `commit`, followed by -a commit SHA-1 (if a `-c`, `-C` or `--amend` option was given). - -If the exit status is non-zero, `git commit` will abort. - -The purpose of the hook is to edit the message file in place, and -it is not suppressed by the `--no-verify` option. A non-zero exit -means a failure of the hook and aborts the commit. It should not -be used as replacement for pre-commit hook. - -The sample `prepare-commit-msg` hook that comes with Git removes the -help message found in the commented portion of the commit template. - -Hooks executed during 'prepare-commit-msg' will not be parallelized. - -commit-msg -~~~~~~~~~~ - -This hook is invoked by linkgit:git-commit[1] and linkgit:git-merge[1], and can be -bypassed with the `--no-verify` option. It takes a single parameter, -the name of the file that holds the proposed commit log message. -Exiting with a non-zero status causes the command to abort. - -The hook is allowed to edit the message file in place, and can be used -to normalize the message into some project standard format. It -can also be used to refuse the commit after inspecting the message -file. - -The default 'commit-msg' hook, when enabled, detects duplicate -`Signed-off-by` trailers, and aborts the commit if one is found. - -Hooks executed during 'commit-msg' will not be parallelized. - -post-commit -~~~~~~~~~~~ - -This hook is invoked by linkgit:git-commit[1]. It takes no parameters, and is -invoked after a commit is made. - -This hook is meant primarily for notification, and cannot affect -the outcome of `git commit`. - -Hooks executed during 'post-commit' will run in parallel by default. - -pre-rebase -~~~~~~~~~~ - -This hook is called by linkgit:git-rebase[1] and can be used to prevent a -branch from getting rebased. The hook may be called with one or -two parameters. The first parameter is the upstream from which -the series was forked. The second parameter is the branch being -rebased, and is not set when rebasing the current branch. - -Hooks executed during 'pre-rebase' will run in parallel by default. - -post-checkout -~~~~~~~~~~~~~ - -This hook is invoked when a linkgit:git-checkout[1] or -linkgit:git-switch[1] is run after having updated the -worktree. The hook is given three parameters: the ref of the previous HEAD, -the ref of the new HEAD (which may or may not have changed), and a flag -indicating whether the checkout was a branch checkout (changing branches, -flag=1) or a file checkout (retrieving a file from the index, flag=0). -This hook cannot affect the outcome of `git switch` or `git checkout`, -other than that the hook's exit status becomes the exit status of -these two commands. - -It is also run after linkgit:git-clone[1], unless the `--no-checkout` (`-n`) option is -used. The first parameter given to the hook is the null-ref, the second the -ref of the new HEAD and the flag is always 1. Likewise for `git worktree add` -unless `--no-checkout` is used. - -This hook can be used to perform repository validity checks, auto-display -differences from the previous HEAD if different, or set working dir metadata -properties. - -Hooks executed during 'post-checkout' will not be parallelized. - -post-merge -~~~~~~~~~~ - -This hook is invoked by linkgit:git-merge[1], which happens when a `git pull` -is done on a local repository. The hook takes a single parameter, a status -flag specifying whether or not the merge being done was a squash merge. -This hook cannot affect the outcome of `git merge` and is not executed, -if the merge failed due to conflicts. - -This hook can be used in conjunction with a corresponding pre-commit hook to -save and restore any form of metadata associated with the working tree -(e.g.: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl -for an example of how to do this. - -Hooks executed during 'post-merge' will run in parallel by default. - -pre-push -~~~~~~~~ - -This hook is called by linkgit:git-push[1] and can be used to prevent -a push from taking place. The hook is called with two parameters -which provide the name and location of the destination remote, if a -named remote is not being used both values will be the same. - -Information about what is to be pushed is provided on the hook's standard -input with lines of the form: - - SP SP SP LF - -For instance, if the command +git push origin master:foreign+ were run the -hook would receive a line like the following: - - refs/heads/master 67890 refs/heads/foreign 12345 - -although the full, 40-character SHA-1s would be supplied. If the foreign ref -does not yet exist the `` will be 40 `0`. If a ref is to be -deleted, the `` will be supplied as `(delete)` and the `` will be 40 `0`. If the local commit was specified by something other -than a name which could be expanded (such as `HEAD~`, or a SHA-1) it will be -supplied as it was originally given. - -If this hook exits with a non-zero status, `git push` will abort without -pushing anything. Information about why the push is rejected may be sent -to the user by writing to standard error. - -Hooks executed during 'pre-push' will run in parallel by default. - -[[pre-receive]] -pre-receive -~~~~~~~~~~~ - -This hook is invoked by linkgit:git-receive-pack[1] when it reacts to -`git push` and updates reference(s) in its repository. -Just before starting to update refs on the remote repository, the -pre-receive hook is invoked. Its exit status determines the success -or failure of the update. - -This hook executes once for the receive operation. It takes no -arguments, but for each ref to be updated it receives on standard -input a line of the format: - - SP SP LF - -where `` is the old object name stored in the ref, -`` is the new object name to be stored in the ref and -`` is the full name of the ref. -When creating a new ref, `` is 40 `0`. - -If the hook exits with non-zero status, none of the refs will be -updated. If the hook exits with zero, updating of individual refs can -still be prevented by the <> hook. - -Both standard output and standard error output are forwarded to -`git send-pack` on the other end, so you can simply `echo` messages -for the user. - -The number of push options given on the command line of -`git push --push-option=...` can be read from the environment -variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are -found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,... -If it is negotiated to not use the push options phase, the -environment variables will not be set. If the client selects -to use push options, but doesn't transmit any, the count variable -will be set to zero, `GIT_PUSH_OPTION_COUNT=0`. - -See the section on "Quarantine Environment" in -linkgit:git-receive-pack[1] for some caveats. - -Hooks executed during 'pre-receive' will not be parallelized. - -[[update]] -update -~~~~~~ - -This hook is invoked by linkgit:git-receive-pack[1] when it reacts to -`git push` and updates reference(s) in its repository. -Just before updating the ref on the remote repository, the update hook -is invoked. Its exit status determines the success or failure of -the ref update. - -The hook executes once for each ref to be updated, and takes -three parameters: - - - the name of the ref being updated, - - the old object name stored in the ref, - - and the new object name to be stored in the ref. - -A zero exit from the update hook allows the ref to be updated. -Exiting with a non-zero status prevents `git receive-pack` -from updating that ref. - -This hook can be used to prevent 'forced' update on certain refs by -making sure that the object name is a commit object that is a -descendant of the commit object named by the old object name. -That is, to enforce a "fast-forward only" policy. - -It could also be used to log the old..new status. However, it -does not know the entire set of branches, so it would end up -firing one e-mail per ref when used naively, though. The -<> hook is more suited to that. - -In an environment that restricts the users' access only to git -commands over the wire, this hook can be used to implement access -control without relying on filesystem ownership and group -membership. See linkgit:git-shell[1] for how you might use the login -shell to restrict the user's access to only git commands. - -Both standard output and standard error output are forwarded to -`git send-pack` on the other end, so you can simply `echo` messages -for the user. - -The default 'update' hook, when enabled--and with -`hooks.allowunannotated` config option unset or set to false--prevents -unannotated tags to be pushed. - -Hooks executed during 'update' are run in parallel by default. - -[[proc-receive]] -proc-receive -~~~~~~~~~~~~ - -This hook is invoked by linkgit:git-receive-pack[1]. If the server has -set the multi-valued config variable `receive.procReceiveRefs`, and the -commands sent to 'receive-pack' have matching reference names, these -commands will be executed by this hook, instead of by the internal -`execute_commands()` function. This hook is responsible for updating -the relevant references and reporting the results back to 'receive-pack'. - -This hook executes once for the receive operation. It takes no -arguments, but uses a pkt-line format protocol to communicate with -'receive-pack' to read commands, push-options and send results. In the -following example for the protocol, the letter 'S' stands for -'receive-pack' and the letter 'H' stands for this hook. - - # Version and features negotiation. - S: PKT-LINE(version=1\0push-options atomic...) - S: flush-pkt - H: PKT-LINE(version=1\0push-options...) - H: flush-pkt - - # Send commands from server to the hook. - S: PKT-LINE( ) - S: ... ... - S: flush-pkt - # Send push-options only if the 'push-options' feature is enabled. - S: PKT-LINE(push-option) - S: ... ... - S: flush-pkt - - # Receive result from the hook. - # OK, run this command successfully. - H: PKT-LINE(ok ) - # NO, I reject it. - H: PKT-LINE(ng ) - # Fall through, let 'receive-pack' to execute it. - H: PKT-LINE(ok ) - H: PKT-LINE(option fall-through) - # OK, but has an alternate reference. The alternate reference name - # and other status can be given in option directives. - H: PKT-LINE(ok ) - H: PKT-LINE(option refname ) - H: PKT-LINE(option old-oid ) - H: PKT-LINE(option new-oid ) - H: PKT-LINE(option forced-update) - H: ... ... - H: flush-pkt - -Each command for the 'proc-receive' hook may point to a pseudo-reference -and always has a zero-old as its old-oid, while the 'proc-receive' hook -may update an alternate reference and the alternate reference may exist -already with a non-zero old-oid. For this case, this hook will use -"option" directives to report extended attributes for the reference given -by the leading "ok" directive. - -The report of the commands of this hook should have the same order as -the input. The exit status of the 'proc-receive' hook only determines -the success or failure of the group of commands sent to it, unless -atomic push is in use. - -It is forbidden to specify more than one hook for 'proc-receive'. If a -globally-configured 'proc-receive' must be overridden, use -'hookcmd..skip = true' to ignore it. - -[[post-receive]] -post-receive -~~~~~~~~~~~~ - -This hook is invoked by linkgit:git-receive-pack[1] when it reacts to -`git push` and updates reference(s) in its repository. -It executes on the remote repository once after all the refs have -been updated. - -This hook executes once for the receive operation. It takes no -arguments, but gets the same information as the -<> -hook does on its standard input. - -This hook does not affect the outcome of `git receive-pack`, as it -is called after the real work is done. - -This supersedes the <> hook in that it gets -both old and new values of all the refs in addition to their -names. - -Both standard output and standard error output are forwarded to -`git send-pack` on the other end, so you can simply `echo` messages -for the user. - -The default 'post-receive' hook is empty, but there is -a sample script `post-receive-email` provided in the `contrib/hooks` -directory in Git distribution, which implements sending commit -emails. - -The number of push options given on the command line of -`git push --push-option=...` can be read from the environment -variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are -found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,... -If it is negotiated to not use the push options phase, the -environment variables will not be set. If the client selects -to use push options, but doesn't transmit any, the count variable -will be set to zero, `GIT_PUSH_OPTION_COUNT=0`. - -Hooks executed during 'post-receive' are run in parallel by default. - -[[post-update]] -post-update -~~~~~~~~~~~ - -This hook is invoked by linkgit:git-receive-pack[1] when it reacts to -`git push` and updates reference(s) in its repository. -It executes on the remote repository once after all the refs have -been updated. - -It takes a variable number of parameters, each of which is the -name of ref that was actually updated. - -This hook is meant primarily for notification, and cannot affect -the outcome of `git receive-pack`. - -The 'post-update' hook can tell what are the heads that were pushed, -but it does not know what their original and updated values are, -so it is a poor place to do log old..new. The -<> hook does get both original and -updated values of the refs. You might consider it instead if you need -them. - -When enabled, the default 'post-update' hook runs -`git update-server-info` to keep the information used by dumb -transports (e.g., HTTP) up to date. If you are publishing -a Git repository that is accessible via HTTP, you should -probably enable this hook. - -Both standard output and standard error output are forwarded to -`git send-pack` on the other end, so you can simply `echo` messages -for the user. - -Hooks run during 'post-update' will be run in parallel by default. - -reference-transaction -~~~~~~~~~~~~~~~~~~~~~ - -This hook is invoked by any Git command that performs reference -updates. It executes whenever a reference transaction is prepared, -committed or aborted and may thus get called multiple times. - -The hook takes exactly one argument, which is the current state the -given reference transaction is in: - - - "prepared": All reference updates have been queued to the - transaction and references were locked on disk. - - - "committed": The reference transaction was committed and all - references now have their respective new value. - - - "aborted": The reference transaction was aborted, no changes - were performed and the locks have been released. - -For each reference update that was added to the transaction, the hook -receives on standard input a line of the format: - - SP SP LF - -The exit status of the hook is ignored for any state except for the -"prepared" state. In the "prepared" state, a non-zero exit status will -cause the transaction to be aborted. The hook will not be called with -"aborted" state in that case. - -Hooks run during 'reference-transaction' will be run in parallel by default. - -push-to-checkout -~~~~~~~~~~~~~~~~ - -This hook is invoked by linkgit:git-receive-pack[1] when it reacts to -`git push` and updates reference(s) in its repository, and when -the push tries to update the branch that is currently checked out -and the `receive.denyCurrentBranch` configuration variable is set to -`updateInstead`. Such a push by default is refused if the working -tree and the index of the remote repository has any difference from -the currently checked out commit; when both the working tree and the -index match the current commit, they are updated to match the newly -pushed tip of the branch. This hook is to be used to override the -default behaviour. - -The hook receives the commit with which the tip of the current -branch is going to be updated. It can exit with a non-zero status -to refuse the push (when it does so, it must not modify the index or -the working tree). Or it can make any necessary changes to the -working tree and to the index to bring them to the desired state -when the tip of the current branch is updated to the new commit, and -exit with a zero status. - -For example, the hook can simply run `git read-tree -u -m HEAD "$1"` -in order to emulate `git fetch` that is run in the reverse direction -with `git push`, as the two-tree form of `git read-tree -u -m` is -essentially the same as `git switch` or `git checkout` -that switches branches while -keeping the local changes in the working tree that do not interfere -with the difference between the branches. - -Hooks executed during 'push-to-checkout' will not be parallelized. - -pre-auto-gc -~~~~~~~~~~~ - -This hook is invoked by `git gc --auto` (see linkgit:git-gc[1]). It -takes no parameter, and exiting with non-zero status from this script -causes the `git gc --auto` to abort. - -Hooks run during 'pre-auto-gc' will be run in parallel by default. - -post-rewrite -~~~~~~~~~~~~ - -This hook is invoked by commands that rewrite commits -(linkgit:git-commit[1] when called with `--amend` and -linkgit:git-rebase[1]; however, full-history (re)writing tools like -linkgit:git-fast-import[1] or -https://github.com/newren/git-filter-repo[git-filter-repo] typically -do not call it!). Its first argument denotes the command it was -invoked by: currently one of `amend` or `rebase`. Further -command-dependent arguments may be passed in the future. - -The hook receives a list of the rewritten commits on stdin, in the -format - - SP [ SP ] LF - -The 'extra-info' is again command-dependent. If it is empty, the -preceding SP is also omitted. Currently, no commands pass any -'extra-info'. - -The hook always runs after the automatic note copying (see -"notes.rewrite." in linkgit:git-config[1]) has happened, and -thus has access to these notes. - -Hooks run during 'post-rewrite' will be run in parallel by default. - -The following command-specific comments apply: - -rebase:: - For the 'squash' and 'fixup' operation, all commits that were - squashed are listed as being rewritten to the squashed commit. - This means that there will be several lines sharing the same - 'new-sha1'. -+ -The commits are guaranteed to be listed in the order that they were -processed by rebase. - -sendemail-validate -~~~~~~~~~~~~~~~~~~ - -This hook is invoked by linkgit:git-send-email[1]. It takes a single parameter, -the name of the file that holds the e-mail to be sent. Exiting with a -non-zero status causes `git send-email` to abort before sending any -e-mails. - -fsmonitor-watchman -~~~~~~~~~~~~~~~~~~ - -This hook is invoked when the configuration option `core.fsmonitor` is -set to `.git/hooks/fsmonitor-watchman` or `.git/hooks/fsmonitor-watchmanv2` -depending on the version of the hook to use. - -Version 1 takes two arguments, a version (1) and the time in elapsed -nanoseconds since midnight, January 1, 1970. - -Version 2 takes two arguments, a version (2) and a token that is used -for identifying changes since the token. For watchman this would be -a clock id. This version must output to stdout the new token followed -by a NUL before the list of files. - -The hook should output to stdout the list of all files in the working -directory that may have changed since the requested time. The logic -should be inclusive so that it does not miss any potential changes. -The paths should be relative to the root of the working directory -and be separated by a single NUL. - -It is OK to include files which have not actually changed. All changes -including newly-created and deleted files should be included. When -files are renamed, both the old and the new name should be included. - -Git will limit what files it checks for changes as well as which -directories are checked for untracked files based on the path names -given. - -An optimized way to tell git "all files have changed" is to return -the filename `/`. - -The exit status determines whether git will use the data from the -hook to limit its search. On error, it will fall back to verifying -all files and folders. - -p4-changelist -~~~~~~~~~~~~~ - -This hook is invoked by `git-p4 submit`. - -The `p4-changelist` hook is executed after the changelist -message has been edited by the user. It can be bypassed with the -`--no-verify` option. It takes a single parameter, the name -of the file that holds the proposed changelist text. Exiting -with a non-zero status causes the command to abort. - -The hook is allowed to edit the changelist file and can be used -to normalize the text into some project standard format. It can -also be used to refuse the Submit after inspect the message file. - -Run `git-p4 submit --help` for details. - -p4-prepare-changelist -~~~~~~~~~~~~~~~~~~~~~ - -This hook is invoked by `git-p4 submit`. - -The `p4-prepare-changelist` hook is executed right after preparing -the default changelist message and before the editor is started. -It takes one parameter, the name of the file that contains the -changelist text. Exiting with a non-zero status from the script -will abort the process. - -The purpose of the hook is to edit the message file in place, -and it is not supressed by the `--no-verify` option. This hook -is called even if `--prepare-p4-only` is set. - -Run `git-p4 submit --help` for details. - -p4-post-changelist -~~~~~~~~~~~~~~~~~~ - -This hook is invoked by `git-p4 submit`. - -The `p4-post-changelist` hook is invoked after the submit has -successfully occurred in P4. It takes no parameters and is meant -primarily for notification and cannot affect the outcome of the -git p4 submit action. - -Run `git-p4 submit --help` for details. - -p4-pre-submit -~~~~~~~~~~~~~ - -This hook is invoked by `git-p4 submit`. It takes no parameters and nothing -from standard input. Exiting with non-zero status from this script prevent -`git-p4 submit` from launching. It can be bypassed with the `--no-verify` -command line option. Run `git-p4 submit --help` for details. - - - -post-index-change -~~~~~~~~~~~~~~~~~ - -This hook is invoked when the index is written in read-cache.c -do_write_locked_index. - -The first parameter passed to the hook is the indicator for the -working directory being updated. "1" meaning working directory -was updated or "0" when the working directory was not updated. - -The second parameter passed to the hook is the indicator for whether -or not the index was updated and the skip-worktree bit could have -changed. "1" meaning skip-worktree bits could have been updated -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. - -Hooks run during 'post-index-change' will be run in parallel by default. +include::native-hooks.txt[] GIT ---