From patchwork Sat Dec 5 01:49: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: 11952795 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, URIBL_BLOCKED,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 8D138C433FE for ; Sat, 5 Dec 2020 01:50:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A74322DFB for ; Sat, 5 Dec 2020 01:50:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731012AbgLEBuj (ORCPT ); Fri, 4 Dec 2020 20:50:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726210AbgLEBuj (ORCPT ); Fri, 4 Dec 2020 20:50:39 -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 021C1C061A51 for ; Fri, 4 Dec 2020 17:49:53 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 4so9319342ybv.11 for ; Fri, 04 Dec 2020 17:49: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=DKmsIxc4f89WV+IsjEfUFNY3Ih4tONMREdtf+PB9Zak=; b=aJsl1Padspq8zI5/uydB3V+nUlmfWRthvpm7cDVHVbGK2I4HP0wZcrtQI8Jve9CvJv sn4E157WNfpL5JCdA5lI8F2ac+GzBlVoZsuPgHpUXANnXI/GsoqJXbsUFFYuqPqi0z5K LwiNzPSaygMvGBJboNnlHTYj2zRmwWe9xpe1J9xLfFNEQPwQknHTTLuU5cJ9yiy0yqkG 8SXZY34xprA4n3iwZwvR7bkATWqazLZ+zCIm9S5e+TGqtBQr39yVapMflSAdCOGh4lyA WvmdqleqxSDfAh/m7nWbYmvaKZ5TEqwBblSWY36DYL3VdmEYg3/PGzAr+qvPw8gFRFCM kCtw== 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=degrtsovRh4Bf37nMRwhkseoTOwbGyXUE0kjh2BxpKR4nFxQXvzKOr6Oc6y52qBzam +J81zedfBqiNRhzCZlmn0LgLUyFkF5sqffbgjKDCEp2zqNP1SmahgRb1Hmzlqn4NZwi4 SD3ip8DYR31dZ04QwapOvAST9Fz4P7pCTITbcNwT96mtKqd5TMCnzlib4rgRt/GDBLBx YAVppXZuQN/D4EtG6sYiGrzdNW5/H3iDIC6EaZwn1DISQ/WPEZYYjYZ69wAgFYSW4G7+ tx8XW3JOuX4D1nQlm/XCdObOLjjTLDHvSrmz02ifx5MYKbuHjlA8LtlmjG3eTJpCim4o 2N2A== X-Gm-Message-State: AOAM533Jz73J8M0JFBD/Jsxd9mQBEy/Rq6v+KEcUfEfQ40HP14y3ffaf aPCup2rsDbg0vC2YzUeSnfAC88xMdy5Hcqu0iZdZ4WWLzT6CWyE86h3IAL0fcEgpu/CYxuM8ZOQ UcqQu9RJnXhSd6ksjY8Zu1iygvNsu3VkmLxqrCIOHxpFan+5un2RswE6F8nHahFF6I85WWKo5xw == X-Google-Smtp-Source: ABdhPJz+VLfzTiZyFWF3Minf5eDMChx1EyMXruqiCoheP5+8tLXIf98jyjQ80hsUIlXFQZlUMBp7TkuqTmE0RcXhGMc= 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:38c1:: with SMTP id f184mr9226288yba.41.1607132992227; Fri, 04 Dec 2020 17:49:52 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:29 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 Sat Dec 5 01:49: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: 11952799 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 88EF1C433FE for ; Sat, 5 Dec 2020 01:50:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 430CA22E01 for ; Sat, 5 Dec 2020 01:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731060AbgLEBum (ORCPT ); Fri, 4 Dec 2020 20:50:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726210AbgLEBul (ORCPT ); Fri, 4 Dec 2020 20:50:41 -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 F2948C061A52 for ; Fri, 4 Dec 2020 17:49:54 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id i184so9282165ybg.7 for ; Fri, 04 Dec 2020 17:49: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=QuFgqQ38kuuOuGbPFEj0v9gRTsM5mCpbZ9OoGbpfPIY=; b=By7cpzpN5phVazgX1DmtCFhNqO90vPLNCuWeve2UdG4arQN8MNboRGdW+jW2BRTucj 6aTrjavoNq8iHf7SzncAJ6VGQg3do2yaDPnYCZzoV9Ktfs4LkMWzCsgy7lJ0Qw/rq1nJ wIz9kIl3dOxrd6XRAmZrQTHrNNH9cDOLj8fem1zzEzqWNrZn/evhkiKqOlDJ59P8bc/1 sZyZy1sKlEdD0iX6yh+d/7z/Zj5SFgFjtl0OCPjlDa0O2y8WyRT8RRRWIQamiev8CiMM HYaMZ5UyTsrtWxCiwtJCYQmObnZRRJXjunkn3CupJTtBloNzzqa6GrfbxEJup+hqGRDZ kOnQ== 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=m2cWEzl0fpsvWoHHmZGrwRhsvzVPZvNMLUzArwTsgpRUw8uFpmAVWr/4iHnspxCqfZ +xlLXIq8f4Rff28npsxaLWsOINo8MF9M7jZYTg+quC/9/0QIFjMGVpikEAqBnrFWgepU 0H6+BtwkbHZZDL1feIwgopleN8SNHJzicuRt4GbLNQE19jTRCD9hk8cQnI8UpXt1uG3x k+QcjJfMCJmwAy3FwwMGYs21BiZBpTcF/37r0Ej8keWbQpiRgd/IHMQ/9ouvfws6BV2Z 431Si3owoSc5hImBdHVlPfsK+b+rvaX/c6KVn1nw2GZ3lJ3x660r+4BMT5HOdfFnHiUz 0rxg== X-Gm-Message-State: AOAM5338HI25h3ySGl2Ue59YuCUwIgwzgUsssbXKT4/sWbqZjyfSKFl8 LoshwM+5YWun2mtJZGhV/MasImBfxgt+R2g7zAWMPLVPc52slDLFiCS9uc4JsN5T0sDNzzAXMhp H36+H1kDroWxDtcJwG7ScWzOTvHsPWET9p36BBkRlL2dLwbMQiXx/zxZoAwuvnB2m8mDQaQyGkQ == X-Google-Smtp-Source: ABdhPJx2BM4GWBsY6EON3/sye02bareB/bjNe5dY8ipmCGwWuKvLBGcm3qqzJ2qCcyu72MHmy9C8gdxjvvfnIta7nIQ= 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:ce8e:: with SMTP id x136mr9717455ybe.488.1607132994187; Fri, 04 Dec 2020 17:49:54 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:30 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 Sat Dec 5 01:49: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: 11952797 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 5D84DC4361A for ; Sat, 5 Dec 2020 01:50:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DB3A22DFB for ; Sat, 5 Dec 2020 01:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731126AbgLEBun (ORCPT ); Fri, 4 Dec 2020 20:50:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731013AbgLEBum (ORCPT ); Fri, 4 Dec 2020 20:50:42 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8E5AC061A53 for ; Fri, 4 Dec 2020 17:49:56 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id c1so4350285pjo.6 for ; Fri, 04 Dec 2020 17:49: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=JBKVjRnbzqESSv9JqchxvmDRnDuoKg97DbxCNoBxVeU=; b=LRIh3JDz6eZE+Dw8WOsopSpg2X4xGSphGm4fp4IHg8OxsF5gmbGFMIfEVuUJNcdikX fkQWDuvm/07pYLG1eGb4mohMW7H2wwNytMnrF0wVbJ5NIPlWAQOmdVR5ubGpIpgUUjZ9 sI4A/JMMdmEP96uV3pQsdagXqHUD1RzlZfcFNn883xr1GP2kgwP6xeRo+HJ4W3DOFhgd S2yHySIlpNncasweUrBc0EBlEH88vY5amDQfuo5OSc4y642St1RtRemqG+ULHMaUU0XU dKEE3znxC4X94SLMKhxSx9P9/M0f9RawRcHOya3TvhYoIPGxxpLUUsOEtkybjrS+KOGV Gtgg== 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=duVMjQVIxz22CX/jV95McmiT2iXnx8m5xijkVURE6h/biSM4ZlYM6s4DVY4c3AX01G wY2SZ/CHIAxh/kzfdkeSD5ldQqA6ElUKokfBPqKQQjs08iKqxQHZOfimfrjA8vxv7cGD oOHizi5QskBnZwP3eNaYBMhm/Wix+wwGOXSbLP3DDKUY75WTpvIoNuf2dlourLM/9SCN ivOEtbHG6WKAFsSNRADfPRILIbJ/Dz5TSpx/5w1U3widhRbrD37c9xiqM2oecqq0FoJf ECq1/QdEBUFjSz6tbNb7hyt727lfKYnlymcgDZrgVKDvx19yK2f8Vbkh1azrX+bHbCln W24g== X-Gm-Message-State: AOAM531IUOytDDFPctSpwtedTMVN1ufJMN608tvc/t6mYcjRs/B8JTuB euUzXNENpHydz/DEOVSeWLbJFr862CWbKk6bEz686QdQOA5Vgoq8iLX88F2Hq8YdwgBzWZ+BszT SB9pL2WEKXWw5YIvOQyj62trIJLa3qI+9CYD+/FihmuRH8+K4a9HZeA/WDRh01eII2Ml/vpd4YQ == X-Google-Smtp-Source: ABdhPJwxZdMVAw24+jSqamdDPtEz/vPNwX0A1/6pCEYUBMP+fu4z2cTVRcfJ5yGOZL6/A6cd+kDNR3K+0oZxG4FnMu0= 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:90a:fa0c:: with SMTP id cm12mr6683903pjb.87.1607132996090; Fri, 04 Dec 2020 17:49:56 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:31 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 Sat Dec 5 01:49: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: 11952803 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 6BAA8C4361A for ; Sat, 5 Dec 2020 01:50:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 462E722DFB for ; Sat, 5 Dec 2020 01:50:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731174AbgLEBu5 (ORCPT ); Fri, 4 Dec 2020 20:50:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726242AbgLEBu5 (ORCPT ); Fri, 4 Dec 2020 20:50:57 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E77C3C061A54 for ; Fri, 4 Dec 2020 17:49:58 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id s9so7071054qks.2 for ; Fri, 04 Dec 2020 17:49: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=MhrNwqVyKYFixrNJm9hDFpWMUz/77TSmZOCW/lmC/y4=; b=RpwUq2rNwInWQCBt+OtwoeVRO8oSKgsKkJCQSysnUVw1rUcVj2vwSnz2ENMS6SA0wz bDrXGyVyXc3lsALNhSdPKzX/4lQjxEG5QEwFz/kNpJ+HwebMMTSH0kjcg8DC9usgjN0X AooKCLLcPjLXlprsB2wYM0nSgkXuSm5pFyG1XQITRjJz1/FPI3bG3WXxE/WeXQrhcK0S zmcU9pD7JKp+KdO1oQ/gsMVe0zdPIuAiyuw9NPmUhQfT9uaMzDNiQkkfFxTHnhczOQJi Dl2wHoIopHIkDTJjUm2+vnkNFFEUDpE+QQ/MdMQ2LvUAdFJfZBhA6LvvOIbx/Nu3FSHN 6wXQ== 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=MhrNwqVyKYFixrNJm9hDFpWMUz/77TSmZOCW/lmC/y4=; b=WAex9L4ws79qsTUY4iP+ltGZ1uiJGrT1tkvLFsmaLp236KknOpVVT+HALAdhgOLs8b 0g8UaL9X+57UmY/AZJz8mybQSmzXQlyEhW9qr05UrcZY07bsR1cFhtn6boGWT8fPYfhC SkeeC7t/CSvElLOTgTlZaBSWkcBIrkp4OTb6DWhQ4axxVTeAdAF+2IXSDHIfmI90M4o9 6yE9lo1CPcy5isj/g13fIDsuQC4Z89u7K2/wxGRAqgIdTvRs9g5f1LIqoknu14TLRw76 mx9vz/9VKJ9NP0sRaFLPozLY9ijx+REPjZqGQJY5DKBRGDa0lDLTiMocYV460tODgZJX znXA== X-Gm-Message-State: AOAM53229//gPODutj49xdH0uAznWeoSzpAVONZ8UHdlzUxv9j92Hjkt wrs6eWbC+yuXHwRowZkIG1srH+ONKoY3lEzZSzNDOTpZbyfZjeX2o3OvYXlcVcHuDGf8u7LK5// wd68bEKaMKNYRZdVuTrr6zOsONJ3uAKC2zCTxOWYBACs3j8CvgBsoPAe6Y1vdmElMr1lwakWJfg == X-Google-Smtp-Source: ABdhPJys/fZzqWqR/qDNBNfezv0F3v+4ZV/OCpExo2Ny4ELldnKCY/6m518EAU30nE5jow/1h+6+cpgXBCLHMKc+h7s= 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:a69:: with SMTP id ef9mr9265847qvb.50.1607132997934; Fri, 04 Dec 2020 17:49:57 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:32 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 3e8d76fd5a..b01b6eb5fd 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 Sat Dec 5 01:49: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: 11952801 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 A3A1FC433FE for ; Sat, 5 Dec 2020 01:50:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BDFC22DFB for ; Sat, 5 Dec 2020 01:50:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731178AbgLEBu6 (ORCPT ); Fri, 4 Dec 2020 20:50:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731013AbgLEBu5 (ORCPT ); Fri, 4 Dec 2020 20:50: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 9B217C061A55 for ; Fri, 4 Dec 2020 17:50:00 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id v12so9336533ybi.6 for ; Fri, 04 Dec 2020 17:50:00 -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=sYCHehlm9fyI2CH+m18OL9+sFmirYaYPtv9tSGACbUeI0zoDyMka3oEfat/OfvlVs8 i6V7yU15R7QcVtznIrUXprmlek5Co1JsE9JO7gCMutOHpbZSgJFK9/pWaJ6DYp7DyEOj zQquVbrWfKe3PavXROUB9WJd4bGAqTS6TR04eVGVT3OGuWs7SXCrQ7uPDZ3oOQz9lSqD ROHeGmW0OQIRAoT/OisTSktb9OlNVa3dT8RK70CAGyRk59312rqDygX6oJR3tppbDzrt /HNM1Cw7Ycy6Ly52VZ9XD2PbwNAGgs9XnnqxNG13NjwvfvXF+XqeACT8UEKXd5HepgSj PcOg== 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=lc8BhlAsHdTRq/Hhf1M6FMfVrJja+kLZ9lQXHJ1aJuVzFcpvolfhYVqMKpLlDHycFi dDhUvwfonXs3dqLKZH3QIvJJI6zaXnDoUfwBvCFza08QYNmBJ/hF1t14gYRVc2gjhjAM l0eSHNeCO73zn2yGXJWX0IZkccdeDMu4FWn9xZdctpso7OKeqx1Slz9Pm5XTRrojwOJp iWlAhXgLFhUIGDG2RNRx1yb6fa11qCDgXQJs01fYUlqOnsMOGs7DOXEeskqzvTyKB7sE 41ATNLjI/qDX3w7tg8JlaaHP8bQPf2ovaE7hFPWWV6XARqpyBXUMjloQ3rUetVVLYiQm sLbQ== X-Gm-Message-State: AOAM533BvzBMpaJwy4pmFnjNxSZX/DpXqmnHKiNqu9s2SvEWF2xn2ZxZ Ahi5ouHbBkxpj9LVEyEc/JGzGq1zBj6VEbIkG2TDECl6v084vlvdHIZdYyTINyLGhbW4KM1U0h/ oNW9/RhZJtuJfPhS/d3tvY74gQ5cgcHFktV5xAk0xSxAz1+fcemL9s7MQF/gNWt2hgoc1Skm3lA == X-Google-Smtp-Source: ABdhPJzQz2wcrQKp3gqGpaB+4o96IKeV6RlkilM8un+GzSkVs1Wvh2C72Kn1/Hb6+iOS4xci9eh8oHPCFs1HsxOwCdQ= 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:254a:: with SMTP id l71mr10191891ybl.439.1607132999805; Fri, 04 Dec 2020 17:49:59 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:33 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 Sat Dec 5 01:49: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: 11952807 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 3A3B7C4167B for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11439229C4 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731214AbgLEBvN (ORCPT ); Fri, 4 Dec 2020 20:51:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727765AbgLEBvL (ORCPT ); Fri, 4 Dec 2020 20:51:11 -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 43074C061A56 for ; Fri, 4 Dec 2020 17:50:02 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id c9so9259436ybs.8 for ; Fri, 04 Dec 2020 17:50:02 -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=dWikadKDJMgBKavg/7MJclZOlG35SIXdWIe1nVnCddiWDnR+0PA+S731LPrctZP9yR rZMV/7jIrWKQuJImp8z42SnEKgi9JCtWQSK4pR6U1CN9gy8aKR4rRHG8fm6dltyAnPL5 sXNAtT7iBYhpVkK2GeyUpsw4/TG42AkHjEFi9kRS/yhBC7Sd5OJOUeX8YEe0koj4SNz4 RJ7eg9nrYz+9SbGGt5LD4U2NHFw6tvNO+HlXlKwak4i6h56ID8XSZNvi6knDcdujvC+Q ri3PECWpQhmPbZI+SqNdDjcJmyUQ4DWlK3GcTE5WiSgq0BCQ9ICo3VMCgPtu6nkotTgw wu7A== 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=aawTLTywEBTG5FbKCIV2juf+NINRMGPbbJant9eBhyCKVW+e56cEbc8GXKJtDj7ftG WWUgV/qvq/A4VtKbYnPn6RNHJTt8YfvcniHzaRjMP4duK1OFAQtUWvINM+upcxY1IBt2 DF+13sWy6wO2s5ca550tFb1/OUA/3gVIC/jytg8ZnXwuJEnMp8KcY9mWWWQItFiJ3RBy Cu1yXUOOxMOfQYTg+p5UgUVlenkzZTBsVb1LJKvd63oeMrl4nouek2Z/id7ja5nmU4jH a6LgFojqk/wYeSXyj3zsex87nCSXHfHGMM2afzLWM+ZhEWEzhP+9iTvjE2nNeqPhfyns ZT3Q== X-Gm-Message-State: AOAM530VNZ7AlyosDffpdOJjxuDExCNBDrcFloS9J/7eURPq+f2KqLHt BRHf3bv9KmHIyzel6OyVQIPGVAn95xvyCueE+aXIFFeTTZ+wvI/0u/Ca7jOqPkQpfgFm3l6kcEt sKOQTPJiur1bIHQBdZ5PR3Gn1FScjXFO+TsYMRk4lvturKXBELtESQ1rkaiV96IMCletY5kUJrA == X-Google-Smtp-Source: ABdhPJxpED5G0N8azYEQ9obhcYUiwycUPvkUP19p39NYCqCZB0KmeLl7E9B+JJ+RVKS6JUPrXp0mWyQSIoBvc5qOFU8= 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:6951:: with SMTP id e78mr10202953ybc.42.1607133001500; Fri, 04 Dec 2020 17:50:01 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:34 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-7-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 Sat Dec 5 01:49: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: 11952809 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 241F3C4361B for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E372B22E00 for ; Sat, 5 Dec 2020 01:51:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731216AbgLEBvN (ORCPT ); Fri, 4 Dec 2020 20:51:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731207AbgLEBvL (ORCPT ); Fri, 4 Dec 2020 20:51:11 -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 16DF2C08C5F2 for ; Fri, 4 Dec 2020 17:50:04 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id k196so9290797ybf.9 for ; Fri, 04 Dec 2020 17:50:04 -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=+mnr8yMgYpEUZu44Y7m+nf6hxutdvOIMK3KN13V6zVA=; b=ZC38tXSpJetuysisfyHwaJf1MWcLpU7HC6MFfGM4m6XXya1W9R9bM0jKkDGz3MKveb CzYbXBS6QVfo8Rx+sh9cjDdqnAiJUCNlspUTrCzbiSUOXIoQZgqo2OfiRa6DyO6i5svy Qg/D0cw/bM/XmkpZ57JA7WCEC+LXfRnVNWyGWZxiOd5uxIawMAcUcqQWP1CiPrVeGHfX mZaIvViXvMUzaTGR4Tl7zj92Q99Pn4UZDBY2PEoAigsQRw/h4J/PG0CJRGSNQLZ8sLFJ COkWeYD3XmjAzdyrxpv81rI5hc/a2+LnT9kLQZSzmtjQ9XZC34wwci3ujubg+bnHpKPP s+Cg== 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=+mnr8yMgYpEUZu44Y7m+nf6hxutdvOIMK3KN13V6zVA=; b=OxItwfxq1dqBZFBvJ3GHFzTLxdbjpH2yxIYJWsXo62Sw7+T6GvNujvffuNlGSsyK+p okLI+xgqN8sod1R4ikYAGwSZ4v7/m0CrDRGsu3bEiGxa1Cpv+tldXYdldaOvbk9ukd2p YFlPq2giGsDzPfEZESOMYxzlwmtiq2pmqA5NIx7Fz44Z5fa+gC5s9PSkkMAZP2+jFuCV t62CX+a+/jJB8aMOKqRcDknTZOiQgygh5XyO+bOvKXfkEM2m2xKhYs3LISlA2Mzl09Q6 zJDCtIChZNXVNMPV8Mo35byXjrPZ+Ysa/shUt/Q3yDdeuvxapyafn4MQ42BE4MtiSOo/ G1xg== X-Gm-Message-State: AOAM533FoETtlx2ptklj/ShGYKL7pL82lKMRzHGonrhkSruc/LuT2t9y VVjB+gD1L1QuF3hxTppJpJtirO/lQPa5x4U1NEpEiOUGjjdthaJzzhT0gNlnmcU2tbY2wfsxLg2 4kIZ/BiCzjzR6aEH2IzHouI1uat6rMF5hjD81Rk+VlpGowQtxx0SPhamfZJ0Pg/mf9aeoKGq8uQ == X-Google-Smtp-Source: ABdhPJzNBnahfRdz7FWUAFXpbpdIAV2mnZBXjZ29pB65GqOsV0oFsWNl4JDssPWB6NULo7+N9xoOB/4wXlODRbSSx0M= 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:497:: with SMTP id 145mr3068755ybe.275.1607133003260; Fri, 04 Dec 2020 17:50:03 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:35 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-8-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 f1f0f7bef6..d64a3076be 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 "), @@ -1427,12 +1428,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) @@ -1456,7 +1463,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 Sat Dec 5 01:49:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11952823 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, URIBL_BLOCKED,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 92C41C1B087 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E856229C4 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731234AbgLEBvT (ORCPT ); Fri, 4 Dec 2020 20:51:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731209AbgLEBvT (ORCPT ); Fri, 4 Dec 2020 20:51:19 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCA19C08E85E for ; Fri, 4 Dec 2020 17:50:05 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id kk4so4344888pjb.7 for ; Fri, 04 Dec 2020 17:50: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=DkPnR/H7PAZzH4bbaf0ld6sKav/CB6vmj5JV5jjTvg8=; b=jLJtx6Z+9jJf2xcUxd+SalRuktljdNuqIlXBoul/uAseI6IKlWREZiukHtokx8Bb48 zzhKBsEXcBlp8/myjo9n5HcX8lyIrNCKtB1VL1Oo9qy3G3/wZEav1gfL+l804Icpo2bn hnebg6mk4+CfFCDnd6+SVy4ptRubv1VQqzGQKG1X8QoHmxHcw9gV/ChgQ0vcvLVo+Xq7 A0FM7LVbocY0170Ir7h7zgWGkE5wmW6QuzRdsK9QeNyJCk0X0trjuAXS2Jx45GOtokkA JBappjLRQvH3HCvAwHCQCJ1b6rHXda0moqci2DXNc1OCVUbunwCy2XGMJxMyPyEFsOv4 8LpA== 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=DkPnR/H7PAZzH4bbaf0ld6sKav/CB6vmj5JV5jjTvg8=; b=XRiZFBStO1omNtsfVhrVWIAJ1x2ulRjG4ZmJ1+Ok4QWNTxdhq9r5EY2oiuI99lG+Bb yw+q64sI+yjm4MwoVJ3neLmmFrL0nrYQyg6vt/NfThs1Au0Zla3n+8iLPeDtRKuTa8xW whibLoeW7wyi7CB6bkQpP4pfKGtoCcF8Ez6Lx490VUJCgwqccoozyzYAGouwUereQFak NbsXy3aHeW1FctWdMVGHqvcJdqTpNFvqKkiZ9Oo+3D7I6iRlng9oCdCLXisMb7NIIGq4 JejIGlTA5ll8/B3wGxoJNN0Zz9BqcTJHc6grDSxc/HZxMpr02Ido80bdP/j0vPVrZf5+ Md2g== X-Gm-Message-State: AOAM532GMo3xqXjCdnkhkzqBoFsLy0bua9aK4MVrEVLn3d1veWSWECkw VwMcJagUnUK8XsISJVlgzLRS0J6Ets/VqZWpClIAGrOVsXeY8suC+Cb28o2wyGMSUO8gA+Y0lgv ySWbL/g6/34wvuYiotizNUAvlDKeZkQeK7olW9ZQ2T8pFSFfBeVxcs+h+OMiSDQY+bh56GRX0WQ == X-Google-Smtp-Source: ABdhPJwpFR1lOvkjzA89sE5WsgbjiyiIZBmzb+EieH3N9BE/hLzwB8uvv7nf8b7Vd+QIjiqiUgwSAuhnc9RWpOrYFKg= 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:6a00:14cd:b029:18b:fac7:d88 with SMTP id w13-20020a056a0014cdb029018bfac70d88mr6432640pfu.6.1607133005254; Fri, 04 Dec 2020 17:50:05 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:36 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-9-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 :) git-p4.py | 70 +++++++------------------------------------------------ 1 file changed, 9 insertions(+), 61 deletions(-) diff --git a/git-p4.py b/git-p4.py index 6ae5bbfe99..73161a56d9 100755 --- a/git-p4.py +++ b/git-p4.py @@ -208,70 +208,18 @@ 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): + print('ESS: entering run_git_hook') + 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]) + print ('ESS: args:') + print (args) + return subprocess.call(args) == 0 def write_pipe(c, stdin): if verbose: From patchwork Sat Dec 5 01:49:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11952813 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, URIBL_BLOCKED,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 73EBAC19437 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E8C622E00 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731241AbgLEBvT (ORCPT ); Fri, 4 Dec 2020 20:51:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731226AbgLEBvT (ORCPT ); Fri, 4 Dec 2020 20:51:19 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E229CC08E85F for ; Fri, 4 Dec 2020 17:50:07 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id o13so4362343pjp.1 for ; Fri, 04 Dec 2020 17:50: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=LUxw/hFdF9lowPah09S7Zj467fY7yAG7wcNTSHnpxaE=; b=GBJRC2rWJpp3T02x873IbFrZOToRiJa8/0fgQ523BIUxfk2CopYp2rDrnr71e5HzYk /ctyudQJ15jEZ1QdFbKxGB13/LoqUSN63uMQpWd2JDKCWTuO9qeE8UaC56DEIwsFt7q4 gpFL1HVygvPkvP68CAB0NRu9s7rbvD0UdbO7lxaHa08YN5IYTCTw4u/TvzF6P3JHKkQU I0Li8XRqck/5t6YnA+DEFUBCmGeOWfvTuBjP1eAclCIIyjYTJJVerW9X8gSe/XTkOF0e tMIApfEgd37Jck8wyOX/WdHos5fZKeL853uhTaG9mnnOuwqvmESaizHODoHAudcSAWDV PCmw== 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=grtVCiZ65/dpdnFjLSU5utDwhHE+did70/llChREmuDXW2j3ovEbmdav1YnbhAzRmk KkUImugD1svOnEoZPVzHhaf/WsUSM/HznhBg2sYMpnvMVPaYBGOMfTCdg1hck94F9hUk glAeW/BntbFTu5lpu2lAmuc6hzq9EMmNon3N+V2iKj5d4m8hbQCAacuwAiOryWgIuprf zgz9TKKjd94QuRGjQyFJJ87pAfMKWWBHVAzOT9+UlzJiI6z+HtVFy4UKnB/+FQeVYki5 6AxxUIiELvsXH8p3/MAgj7SY/OzGGtGyoQ9Ph9LdgwbBLfV8l+0yfnHK3Qt/DNdLFbKq XwAQ== X-Gm-Message-State: AOAM532qN5OaHgOlZEM4PzM1FYlPZNpndJ0xP+EVaDkxxIDl9aKVvCNb qwKtf4idg+WqXYTnrpgs9K6m4CDcEe8qEogbqxMG72lR7e0BzQGmT4Va8IDUpK4TUOB0XHjBQUf UtT8j71GOnwjOqkZW4DZgjFjTyyCfJS517ehgTzz5CnPGwg2gJPAsGaDPc7C+ROG+S11uxlRxEw == X-Google-Smtp-Source: ABdhPJwEHrzlzimhxLjPmnJQKcWPSDqpL1ko/fqTzUV7M6/bZP6nZd238D3QkoWpi96AtPnQkTMQok3BE8g1D4mVb7o= 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:a62:8388:0:b029:19b:816e:9cca with SMTP id h130-20020a6283880000b029019b816e9ccamr6624373pfe.31.1607133007311; Fri, 04 Dec 2020 17:50:07 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:37 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-10-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 Sat Dec 5 01:49:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11952825 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, URIBL_BLOCKED,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 DDB6FC1B0E3 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2C6D229C4 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731251AbgLEBv3 (ORCPT ); Fri, 4 Dec 2020 20:51:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725550AbgLEBv2 (ORCPT ); Fri, 4 Dec 2020 20:51:28 -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 EBD1DC08E860 for ; Fri, 4 Dec 2020 17:50:09 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id l11so4933323pfc.16 for ; Fri, 04 Dec 2020 17:50: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=isU6Nqto7xVPug27tZI9gPvrR9M1DsWKGAAsSUX9RKA=; b=D19CsepcJIYRmdaz8oiCUXj+f/SlzJZRqbNat8KYxVs/bymlNvlU09n48sukA5W0uV QNELMQoms9zvx7IHPGJaunZg/+lf6dmhIV1B0ZmZ/h89WaewMSbhk9KKwz6bsQRys38+ JBxL0V+aUgFpZTe0Jo/RhP4tReG6SzC9cVOhPi6BRSvGI+O8r2+/wnzxIg1ZtIH0NmT5 2RG4O5X8a0JSitF9VUKJI133nlqbQSTln6WYQ7LhDtZy87I2XJP1IGDpBAx8mAxpzGf5 Q+l1FsUJnJEMhbfTiMouxiDcEIcDK0uXCkf8t2p+8kqUd3Ga6hUMK8eT1I/XGT5FcXxM NUUA== 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=isU6Nqto7xVPug27tZI9gPvrR9M1DsWKGAAsSUX9RKA=; b=EoRfVnevvJtXpOFAhNLEizcEE7rclokZPbi4tjo1utqt/43RnGQetV7hPkPkTs8wFr 3pdYmREyfPehfdZb5UqfL+LfZnkDyn1GkFBKZaHjC8xiz3qpl6iA9x5JNf6E0B6XbRMT f5goGo/GxA8F+Qf25XxO6FV6Sym+x1rNqCrZ6v5q73LhkdQLUivElIxMXwXdQeXcgN/Z KcT4fXzzu/XXNY/UDW7FmTJFy7M+0Y2e8xNW/bguGZQ9uw7BaK93mjRtFbTSm38vBGFD oGNPyRgmyLTrx2T224RMDXpy2gwbHTIwIvIFJWLUujZZW4YHRhkUBHGHarWZ2j/y0iAq E52A== X-Gm-Message-State: AOAM531u+82z4W1AyW/ctDtViUj/Q10/LIbpvNUR+ZsJ1ttGTZfb1C4i PmVVAX9EFVROE/dTwumyzJXiJhxWLyytIaYQL7a102csbKw0RAEVmtCq3mhiEozKPUz03Cgko51 WZbZB0zlG3SOY7KAXLs7LF/7k0u9IpQvVEefaRlRWSwI+zvQTjfqOib6I7hKJKweXKbUw2ulQag == X-Google-Smtp-Source: ABdhPJyW/eETJyctMjE2Q2AnBBLSbQzfueS3kBUqWJ5Kb4TEXRlLqpra7NQMRD7OSw3n8GQC7w84+f+2zRqFbgG8ikQ= 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:6a00:848:b029:197:e659:e236 with SMTP id q8-20020a056a000848b0290197e659e236mr6402483pfk.74.1607133009190; Fri, 04 Dec 2020 17:50:09 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:38 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-11-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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. 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 Sat Dec 5 01:49:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11952817 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, URIBL_BLOCKED,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 E3DCFC2BB40 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C753522DFB for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731247AbgLEBv3 (ORCPT ); Fri, 4 Dec 2020 20:51:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731089AbgLEBv2 (ORCPT ); Fri, 4 Dec 2020 20:51:28 -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 DCDD8C08E861 for ; Fri, 4 Dec 2020 17:50:11 -0800 (PST) Received: by mail-qv1-xf4a.google.com with SMTP id p3so6380712qvn.15 for ; Fri, 04 Dec 2020 17:50: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=Donh/FHvh4F0njzTIN5avuchvXoVkUEY0MU53TswrPI=; b=TgSiQ/3aOT6pn84Eu7n9WPUe7AAiltIB7TezhTWHI31xupEgPOMetZPiDEFi6Qg4IA kGTnEosiW5wfQf7XPgHrll+qo2SbUhSok8jmhGk6Y0KTqs+3psR3Zd/kM6i9UU/0vRGC B7rnimuLteE9W0LCnTGgbBUzn8WO3M3ohHXI6wFESWTWz1XUJq20qBfHAL5k7fkZp+Uc g8ZFeQLbkVx29soe2PhuUMHoYoBR7+gINqhw3ShuOsHDPnh+ZkGtai22163DV/mfP2TK KrvnNKsaYFHZD4yzsatLsAz/o2qkk69sHe5CPtBJz/fQ7zVri1ZWuuBR6a+50thlf8Fw b6Pg== 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=Donh/FHvh4F0njzTIN5avuchvXoVkUEY0MU53TswrPI=; b=KlhXMzSq6Vdyr11bJiugIZnQbe2WxpxVVPS2G2d+fbvHFNHidzUPGh5aYRSyFaJixa +MY6Zcm2b27btw6t7hFbs4s0w3wue6H3PzWDimibVivW1qqxl2qZSBznmYHHTJnNL2zq +8JzkRQ4rxWULhHqllr7NysfYm6hTcIyEKaHUBU24LA8GLsGxymB6v/psluQQx/vxOGY nUhtzvGbOC4kdX+RrrV7H3GWHTAfKDdAjM/f74dLG7/iky7uynf2UgY5NK3TC8JNoAiq l40Js3/SNNgDFzIJJlSvss0zVNCyPPqs44v59FEgF85LD3SPH788jPl+ZseLactsSDE8 qKpw== X-Gm-Message-State: AOAM531xsaWdkeMCjOStIhFoGJi1kTHw/ZsOOWraoTM2k0Z3gcbj+XUI 4ltCJMOhbefeunGYu9s3Gy3xWSuZJK6e1kp+/+MmI/bQjG/hoYvijNs+yWVaSfIPZ9yaG0lTXbE mfJrqnOf4MPJHuWmRD/OLRZz7k3q1+dccGOzujSm4f7s7FB64FkxtsX2X+RCTzIRtZtFSBKlXdg == X-Google-Smtp-Source: ABdhPJzTOtVgxmdvrpvr9bW6v3/jQAt9+aZS3kOoNtg8ikMyvrhjtfYyD+hYcAwYer7t1u0Vsbd+frrwNwyr+WmQqoY= 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:190f:: with SMTP id er15mr8938620qvb.33.1607133011010; Fri, 04 Dec 2020 17:50:11 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:39 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-12-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 47da955e4f..6c67bc0fea 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] = { @@ -1162,31 +1163,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; @@ -1195,30 +1178,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 Sat Dec 5 01:49:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11952815 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, URIBL_BLOCKED,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 C8BA3C1B0D8 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 939D322E00 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731242AbgLEBvX (ORCPT ); Fri, 4 Dec 2020 20:51:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730950AbgLEBvW (ORCPT ); Fri, 4 Dec 2020 20:51:22 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 579A5C08E862 for ; Fri, 4 Dec 2020 17:50:13 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id q13so1765953pfn.18 for ; Fri, 04 Dec 2020 17:50: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=ji++r9XLN8Rr7X/IEi+t7ZCiQClY2IJFMJyN2+5q56Y=; b=ApAiT8bo7JDboJPw9+ErzjKWfMUTsJja84JzeF/x7C73Ep2r0MBYkbJcE1/yoXcbFF UiVuJbmplZk5LnHxKlFpNyBQCaekmFlBz9XO+hd5J3wf28CZP2wITYDw848NH+Mu1/nJ +T0mgRnoBQErLCkQK2Md9K9FJAwZUmZp4flplvz0S9fjJRw2EuaQpOPjfreV7tF2biOM wIE3wMyMnrQ+CdH8fOvk2Z7RaTOElh+Be6XdAxodNIlQEPZ05LOXXdxxSyldU+FZnwsh rsewQs0ABOBvyxd3kUr+sqj/saytKrkoZe8rld6e95pOHCk1BqsZsH1yoGWpDkMg6R4L rMJw== 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=ji++r9XLN8Rr7X/IEi+t7ZCiQClY2IJFMJyN2+5q56Y=; b=OrmVvvLsuYFd2yu+TZmSlmcE8Z1pyRdllUMxuQbrWrCgL2+ZyVxRlQrz7qdCMR3ZAY hKuqxfbCjYtK0QkvwCcp9PCADW6dMgUwhmq45rKg/+JmtidHUYIv2epdectX6r4TqmSF Mw+QW4+bcVTt9sFVTAFcDCY/ZhDLFND0pf8eVhSOkASPvI1avXV4q4hHe+/mr1QtY8ue BJ3t93bRnZAXI3uoBMqPc/H0wbmjq/gPwM5TXidXBto89ds16zr3xI/2ZT1I8nMJSJcC 2L+744cOSq5dWV7sFMIkDMUZteIljEUh1TApBbc8NFVT5c2wZ2Zwf3mBy0iwAbKfXPHg yRyQ== X-Gm-Message-State: AOAM531F5HqU3ZmEsvr3Tr46o8FuVqDW+ClIFUpplagxtrMvgKcFSbt5 bntzKx84Lkh94sAVjMgApI6ywrTCaQDvbJL55xk8acQlR29OnpmLH4SgttNMVAV79gIJ+30UBHb d/wKUXLBpMNxb3qMFefSSYNalt8ouek5eP4UcXmy+t2mhqUeQ0Kc/DCAkmGPy+7Y3utVPIhJD7g == X-Google-Smtp-Source: ABdhPJw+03e6aAiHRG+pi5u/W+wryB6CVhS+eR8ZziTXZKLIJX49ha/t1qyHtdVOZYi/v5EFRgt3hvZ1O9udpVcesio= 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:a62:37c4:0:b029:197:bfa9:2078 with SMTP id e187-20020a6237c40000b0290197bfa92078mr6346496pfa.15.1607133012802; Fri, 04 Dec 2020 17:50:12 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:40 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-13-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 | 33 +++++++------------------------- t/t1416-ref-transaction-hooks.sh | 8 ++++---- 3 files changed, 13 insertions(+), 30 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..b67bca367e 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,27 @@ 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; - hook = find_hook("reference-transaction"); - if (!hook) - 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]; strbuf_reset(&buf); - strbuf_addf(&buf, "%s %s %s\n", + strbuf_addf(&buf, "%s %s %s", 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; - } + 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 Sat Dec 5 01:49:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11952827 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, URIBL_BLOCKED,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 9A9DFC1B0D9 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EFC822DFB for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731245AbgLEBvX (ORCPT ); Fri, 4 Dec 2020 20:51:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725550AbgLEBvW (ORCPT ); Fri, 4 Dec 2020 20:51:22 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74D65C08E863 for ; Fri, 4 Dec 2020 17:50:15 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id o25so7083659qkj.1 for ; Fri, 04 Dec 2020 17:50: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=KfyNWTOqk9ML8wcpWDyF/xpuy7l+UvJ5ELVq1/XBd6E=; b=JD+AF3HJEWTyIMdlEi7WqaHdmn7bdJVNaGrVxsaet2YektLGfZDREC8aGXVKqC7KOo 17h9VbrTFzq9+zhZ3QBFoiEbpvpe5417DBI9f4hM89pHk0JWAC2RcU+zlF9/+OL2tZKL 2YoMsJCK7zfiYt/FOW8zUCmosxVVaQCe/JunvOpwPM6S7ek3wfbXwtm4CPJ3UrlxmGix IxB9ikeXBQem9NbSiWTlspnBuAuAC7iW5OjH89fF4oF0OZC96k7X2lAzjmYKZ154kt5j hGCAT3U6N4CwDm2jbnK4SXVqd7gpsjNlSo1mg0HYJBJVlwJm3TWiGOX/rhttGUGWiS1K N4Lw== 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=KfyNWTOqk9ML8wcpWDyF/xpuy7l+UvJ5ELVq1/XBd6E=; b=NjazkmNjGpW8WyPFNMLMkQgxnRzFHlcwbsE1cmoulZWeyhyQs8BbwKKdggTSa1Fe1o czucWX/8zuUDAf/3SgQuMK2tJ6AwFUora0FbmMDOeZ+KVSoXwOvlBDSo/rOmpp2P3ELA nchqP3ep1BDdqgA4h0/4R4b2eM6UhX++VByh/ZXvNgQBFeUs62aMSo3U5Qei1MS+ydAY CYIBGXAXXEA5Wct3b3REYB6s4pR9EJgmZbCbT31jQQcOZedgbYN01LbQcPkyCo/CKL6c u0qqJvICTFR+5SVlvsIjjIgtz5MlxLovc95g0dc/F89jMr1z37T7pYVX4vpyx2IPIVT9 G5pw== X-Gm-Message-State: AOAM5303KkIizMmTdV3YMzWq6LLjhXzeHPo+HPzAK0baarrvJfroH2EB ExgwaP00QY45MA4nvhPbfwAdDxOKTjRyPpn6Gie7a169k21GXUX9WtFmD+5cNLqYLzbCfrmwVy5 OGtQil6QL3aCKvdHaimfqy6zvvwkTN983pcCt7wRoJcBUD8sI6umJNXkhyRh4MJbiFlXQyMyCoA == X-Google-Smtp-Source: ABdhPJzzoG+0vYhsi2w0p1Wmu7Otqnuaq34D1SeckwgKgJcKJPsRFOeKWsk4O0j35PZhaTZXsOTnPP5lrwwk7qNwJgo= 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:ec41:: with SMTP id n1mr9162029qvq.42.1607133014559; Fri, 04 Dec 2020 17:50:14 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:41 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-14-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 d64a3076be..cd79ad6bdc 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -930,33 +930,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 Sat Dec 5 01:49:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11952811 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, URIBL_BLOCKED,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 4622CC0018C for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2969722DFB for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731225AbgLEBvS (ORCPT ); Fri, 4 Dec 2020 20:51:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731209AbgLEBvS (ORCPT ); Fri, 4 Dec 2020 20:51:18 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70B4BC0613D1 for ; Fri, 4 Dec 2020 17:50:17 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id a68so383933qke.9 for ; Fri, 04 Dec 2020 17:50:17 -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=laI+uaEe5qVGexpios/bNivrDFPmGSTg0P4eL31+qu4=; b=HvMm7FVNLobbIxbZHiNbrvhxkRKoqjN0TDvCC+dRxEPo3QbJxZy056h7YS7HMNVQ8x DogpuLdZ3mlFGbTk9dM9mONfwS9TmGYvj81f9XaXxkrp9TruvGpP9eX0tqrIUUUG9Nce 282hezfqrmArCYlAFMiQjAXGKo+HvVUJNyDn41CHCe9ojq7qcN1fV3sMdmBPeY0Tt6L3 FYj7WZpNMobeqCvNXGHUujqa6MtU5YInPvx8SvFY11SBrDXHajRl+JartcPwgZkawJ4f +/yKkdXph/wRfI1BMn2/vcqD5dohoyNEeXXcPE+jTW6gzK1w2Kt95BRrc94ZhixpWdzt LsOw== 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=laI+uaEe5qVGexpios/bNivrDFPmGSTg0P4eL31+qu4=; b=cXmfVT/sjNJAhdFo2sHAV2cMCwiXCM5j15AqBosWhGnwtgAa9FGE6TlKT/mZmW7aw8 LoEHsvu8W0N2dIEdCJ4sI/4Jgau+vWVMuoQwDzc05SH5RWNKYtbaDnA0fVqMWMR2cI4r KGW/ZvzE8FKHWCjRlhPij2QkfeGMceXX7lq2Z5IxKNJdPbUuMQoxKseWGxV25XlNIRDW EBwhfTJ9EqwCZr31p1lyr/n+TSTl+aBgyL34jR/667ChLqDYMarR3rLk9jRAw3SQnI88 35+4/n4vHWpJWy6DCUGzXFG2Oq8vwBsm3QN4lLD0545KYVMLWzYu77vblkpAJLKTvbFh gfyg== X-Gm-Message-State: AOAM533zY24fXaTJGH8iEDDvYckPSgxvDZGEJ6XPSkwhVzLOueaIxaoa AAJFycUD4Ahsa7vxB1sfiU5szpn7WBzlB3QaQNAWdj4J8wE52QUQxl5s1fT5tF4CvjPaTNcZzWv vtmgGSNa43iuvTEierUTcFSBSLKl71ba+Bl19SluR8joHe7Zmi96YnjyZ4RG+KQhclNfWxFR0KA == X-Google-Smtp-Source: ABdhPJxQZQhQrHVpnHXtDB2JGGfH9Byqfcrsi0HzWpUzjB7wrS8CTgUDnPY349NyGB9J0xMATP11fLc0W+m0b2f5lKQ= 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:aed4:: with SMTP id n20mr9007235qvd.16.1607133016573; Fri, 04 Dec 2020 17:50:16 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:42 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-15-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 cd79ad6bdc..b929a3505c 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1137,11 +1137,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..de07b27b88 --- /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/master/topic" + EOF + + git -C "$upstream" config --add "hook.proc-receive.command" proc-receive && + cp proc-receive "$upstream/hooks/proc-receive" +' + +# Refs of upstream : master(A) +# Refs of workbench: master(A) tags/v123 +# git push : next(A) refs/for/master/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/master/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/master/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/master/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/master + refs/heads/next + EOF + test_cmp expect actual +' + +# Refs of upstream : master(A) next(A) +# Refs of workbench: master(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 Sat Dec 5 01:49:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11952805 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 06C12C433FE for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA7C522DFB for ; Sat, 5 Dec 2020 01:51:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731219AbgLEBvN (ORCPT ); Fri, 4 Dec 2020 20:51:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731209AbgLEBvM (ORCPT ); Fri, 4 Dec 2020 20:51:12 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14B97C08E864 for ; Fri, 4 Dec 2020 17:50:19 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id q25so7038253qkm.17 for ; Fri, 04 Dec 2020 17:50: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:references:subject :from:to:cc; bh=Mv8LHfO4l+/7PUxhwyKCCiixlZeZ4LmqRPhF2OIQZmM=; b=hJS9UZOX7QDGFpebfa1b5k/BuytG/wxOdQDX2Cp2xzxAirtkuJuORTZ4HjTouuLLo8 MyHSgzSLI+Qb8OLxtJKdpXNxVgoUTo4aYB1EsCeSv9kbKsYFIRVOjwoeDZnyICbmHGDC ORpikle2NaOdJAzT49vPWz+JOATcaSl8AbgPqY1qnYLz6Ty6vR3FrnOj00mXVVRtAcue I85oKDY/axT8Ja5+wg8U0WZfCiuEUvpMhgZzYKU7wlrJCIXH63rzaOWvxiyenJN6weFd F5oveK8ZkQqzKVzK9rjjizQ45eFpfk9CpkXqdOhpKRPuU2KZBmEs5oHm8zDXJi1VhU5q 0zVw== 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=Mv8LHfO4l+/7PUxhwyKCCiixlZeZ4LmqRPhF2OIQZmM=; b=J4qwgz38BrGhNOl+muxXYPb84F9WUpwcNLUYQYLS+v5dbiZL3z4HQUDqBMMhKBXV3B PHkuZPcnmpZN/gObccRFB/ZOl+vML6fvFbA4au3xFFHiNjBT2lX0K19npp9kugCEJ8hi 2dwExXeA3KS8VubJvQMy83A4LplhC+9HpJEaoUyvvTxNBiyyL2kKInPFE67wH9jrNzaO 7Cq2Lmf7rk19AQNZgKaOWnPc3LpHmJN9fjyfB/6ZierrBnfz7yuNAs2RS7yyq/UxBElu xVNuYCjAlFrK3SB9J3vuCBD4ydra7E7Eevld4ZbooHoHv9WxPMAH8CfAmgfNe9zKCvRN KEZQ== X-Gm-Message-State: AOAM5300i61yAQEaFZriahrOwQpnzdgrozcj3SGnOl78UsanBgrhmK7y /Wxdy/PWjKfC+XNL83vAMqbf0CRb1YmcOfdTmPWap+dW/Kd4kvDqgLQ6tdPzccs72gIj3qqCHjy Eq96rbDuF3TFd1FeGmtRQYYSVMAe5DSJxoft4Lfova5iv3oNbIeVmrjJwvz1ZIqrtIYMf6D1jmg == X-Google-Smtp-Source: ABdhPJzaw1ad+uyLtU4AfSmBrtLWqYEVoKW1p/0KSoVeaIjhuc767H2kzbgfhr2Uq341bR5lk/gn6HSW5nHV40yAVY0= 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:44ef:: with SMTP id p15mr9429020qvt.37.1607133018270; Fri, 04 Dec 2020 17:50:18 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:43 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-16-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 b929a3505c..66af00fd8c 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1678,33 +1678,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 Sat Dec 5 01:49:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11952819 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, URIBL_BLOCKED,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 13D91C2BB3F for ; Sat, 5 Dec 2020 01:51:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E266122E00 for ; Sat, 5 Dec 2020 01:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731263AbgLEBvi (ORCPT ); Fri, 4 Dec 2020 20:51:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729421AbgLEBvh (ORCPT ); Fri, 4 Dec 2020 20:51:37 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB9C3C08E9AA for ; Fri, 4 Dec 2020 17:50:20 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id w135so1087977pff.1 for ; Fri, 04 Dec 2020 17:50:20 -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=0NUjdothNmnFTQszroPBkq+yi75nXjc+7SeH/Ejj9Yw=; b=DMsB8/lzpShToxMIdM0aHK3xC4WPdIx1pgl8vy+auxjoVcc6OsF+JMsWEdbahm+ZZM yEqAtYDky07gHnAU8G3kTf0QzGySciYlQfEBeP2DvoLgvQGp1h6jMFJQBYQ+dSE1ZM1v h1vDnBezLMBjVXSb2XIla0pJbIH0C3Ctj+Sx7skZiqEtdYyZLse5WvUKA/Cl8E1UbMqn /rYelRKN7erwJRo4Wn8+2NRs416zRr5NJ4o+2vHjRZ4uNOTw7hiCE60SBpda4ntBEKJe +rb/MSZ9IQpgGboAKDcUL7DiZQ3pu1y3fiRhfsqLvWsf9GPvd65SfmAeg05XA5A4JjWR L6nA== 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=0NUjdothNmnFTQszroPBkq+yi75nXjc+7SeH/Ejj9Yw=; b=NGbnzqtpFCs0Mii4JxySJOXy2vMKp/XvUroWOb53GafzEo1/fezXGhFwlllBCRpuFA wY43AGWq9tvUYq2XJh8deiofeuWacsJ8mVCpmue95JGrbo+mWXRaqVNqlOu4D9dRpFiS Uih1LwsBoOfo0ru/kI8sggZUztcbQ8+lw4aoHUK9HxlbACdOTcq/07sRivGeT8g0NmPQ rLS/XVjtE2aULznLtQt0U0QNUYXv8bJ24yEkOw+p554hFdb/dcGx/Eq3EMiGGHXj5Tek jP1jVlU1tHSiuYKv0xexARZM0pZWIuqPsj1hiI0zFSjJifxY/0QWVlIgCOT1WXKNIJcn 1g3w== X-Gm-Message-State: AOAM532l7Lv0nt6K+r+Nr0mbEEHrBoBByi7N6HtgPTziPxKs+8wwZ9Bp U7L2h4IhYH0cts5hY5ylpT6KxTulC55bOFgQv3AoW4vbn3FZVgofFD6Xcu1qARUpnSZfnSOCLId fGnZPySUCbwsiEKo833u3lX848byEI6GayoWCBXUgjR0z8e6lDJQ62SJsEtCr6Fl5G/YosLXMUQ == X-Google-Smtp-Source: ABdhPJyrU1/MSrPbO+WbBTf/Ve3/Ntw4AuWjI1c9qshWpVZYtazBaJkNGpLtSJMSAGwOLxOVIRnOF939TCPcP5UWijk= 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:90a:578a:: with SMTP id g10mr6626665pji.197.1607133020200; Fri, 04 Dec 2020 17:50:20 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:44 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-17-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 66af00fd8c..c30c8e3a55 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -740,7 +740,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; @@ -764,110 +764,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; @@ -876,9 +808,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; @@ -902,32 +832,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) @@ -963,6 +897,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 Sat Dec 5 01:49:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11952821 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 30684C2BB48 for ; Sat, 5 Dec 2020 01:51:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02E05229C4 for ; Sat, 5 Dec 2020 01:51:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731258AbgLEBvi (ORCPT ); Fri, 4 Dec 2020 20:51:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731111AbgLEBvh (ORCPT ); Fri, 4 Dec 2020 20:51:37 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4EF4C08ED7E for ; Fri, 4 Dec 2020 17:50:22 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id 141so7053298qkh.18 for ; Fri, 04 Dec 2020 17:50:22 -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=3QYHXqQKW+jhRQyMmmXKWe0AW395ERpQXdVL/vuJUSQ=; b=USk0mthItq+PgYraVFJw/1YuMz41xjJiKbxPa57hI/KswEiMkq0KzgfokdVSHmjEwi FC1IMHfHG8qmMmuYHHKIttboPErIcNrxKQLQJuHD+iChmWWGaBhNgN2KmOSpZPjsUtai OxqoG6MZWfQa+/B6g6/MVB+zbxAC98SX0qHIPocnjI2ZJtFzWPWux3t7LANvzSrCBxYh GLhXzGvNYxS9URyZCeFegjWwgAkrWvmwCS6cfD7llXrhbdQuOhJcJfIhpXh64jR/AMwd Vv5HW/QEqyhJKd/zfm9FNgBd+JNSvlV2HfAJPdhXuT+J6trlRRCXx9XmZwFJ5qR0OdAt 67sw== 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=3QYHXqQKW+jhRQyMmmXKWe0AW395ERpQXdVL/vuJUSQ=; b=Xpuo4jlqUOqTwpoVy/yvrFGnI25GSk56XgawnJSlJ0ddbumMLo5zIy5lHp5e4VLDiP nWOv9SlfzBTvGqwTw6m4eq+rD7U9eWkBc0ByUKcmdtvmXz+5tZm48claXNqXBRS6Iwqy pGqj7PiucMipSeodTBd6qCTbNEPof6k9vRxBCBpKSLt4YQ+A/GNlmZ1uHZqjZxG1Mmqm Ld3h2VG+D3mBXOrnCQNSgmk4JyQJCom0d5rIbGixgXYxg1Lkbr3hMeC67+thvtBptKz4 noA/1XI7Cjl4vDI/LIT/B24MzazUK9PYJr23Y2HvSr+qEm53/1SJXwY4kn5CXqBDiLxE W9dg== X-Gm-Message-State: AOAM532TJ6rBFv/BKLRRkuUAQZdcqSkiks+dYjAxAohZL0KhswHgwdy3 2Xi10Glkc2pN6P/GY8I8fMu7HJwxdeTBHKtSNY2HsJBJUloKjRbVvtfwpBHG69g5dOhsY0q9Y2Q 1g73pIU2r+YBrfNLUp2hRwPkzopNWXWGwfIxz9Mul4+d0KlGXXisABlx5VFnQsTcj6om8GIfgMQ == X-Google-Smtp-Source: ABdhPJzXHYzCZlwULEwKsbCwFvISA5lik5S6aZhbypFwRibr1brWqmXTn54rjCA99lpLjXqK/MpHo0+OMF2lldtGB4A= 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:5762:: with SMTP id r2mr9118875qvx.45.1607133021919; Fri, 04 Dec 2020 17:50:21 -0800 (PST) Date: Fri, 4 Dec 2020 17:49:45 -0800 In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com> Message-Id: <20201205014945.1502660-18-emilyshaffer@google.com> Mime-Version: 1.0 References: <20201205014945.1502660-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.28.0.226.g0268cb6820 Subject: [PATCH 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 78d7721b74..85fd59865d 100644 --- a/hook.c +++ b/hook.c @@ -197,6 +197,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; @@ -214,7 +249,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) { @@ -245,7 +280,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 */