From patchwork Tue Jun 29 18:54:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12350505 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 1947AC11F67 for ; Tue, 29 Jun 2021 18:54:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3A0461D88 for ; Tue, 29 Jun 2021 18:54:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234666AbhF2S4x (ORCPT ); Tue, 29 Jun 2021 14:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232315AbhF2S4v (ORCPT ); Tue, 29 Jun 2021 14:56:51 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A7CBC061760 for ; Tue, 29 Jun 2021 11:54:23 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id u8so374778wrq.8 for ; Tue, 29 Jun 2021 11:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zPA0+0mj2trZMF8MYkIOU4Lrp1ZEJ1Bijv1fh5CGZ9w=; b=dXmSmBMARgBX5lrBk11XlgbZ3b1qItAHXvZzw0rL1UxFh1+WWfMglpycDL5ZvG+crT ekfu+TkLbQ7sspcFyNlc/T6GJy+NkO2GRhZmw5+mkiQb+c7bp+3zO3LmzYxcL0+6gyRw qqdcPkFNVUycsqHWAI/MfFrufWPJFOjCQfOW+XW7joO3srU9Ai1PCe1XJPj+bctzZN6X RAv0ObFeXTs5Ux/8GTdxYLfv4CsvyhjBwI82jK+6ZW0w5RbCySBI5H1omxyajZEp516j UM0C8g/acCEbUxjdoaNXw5u7SXXSpyDgzk6wJd+qpxGeUrnUwcrHELMxzFNVICR964G5 ANcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zPA0+0mj2trZMF8MYkIOU4Lrp1ZEJ1Bijv1fh5CGZ9w=; b=bfiWoJXrH6f+kcHEhhwycY97/B1n1QQgaYGBY4VTXs9miPrCWzcw2GYB/ndVvoJOop ywq/0TTAP2Xcq6+xHJOAs662CGUCiLoLojeCeTVwxAuYJdAmQ6RVVcXpIpRUILBRKnY8 pujCp4q/EGKeIGVarOUViGfmysS30isBY8DzPkU6NpjUZU/EWwDPwBY0fr4cfkMq0esU HDQyXOZNP+qih5I7V42/anfMAL9qFsGqDNZFsZSyVVtXANXrCzGu80d4L7d+wtA23QNO wA/C/qIGul/971oo9VbqGKudwVr9EuPmJCZXYZOk7A8DnX93vXEUS0HkoCNKoazk9qa3 CATw== X-Gm-Message-State: AOAM531TTH3B9a34Ah856HNU8x8YzFz1upSYmXckc+vxlaGH0PQUPx53 FmcXHg75pB/QUFlNtJidw6/4qI4Qh42Muw== X-Google-Smtp-Source: ABdhPJxnxpBgZefkTBg02zwj8vRPV7YX2xhsxj7/LOF/j6AouqxBh1buUIa3A2ueDX5A5zEmQJMuVA== X-Received: by 2002:adf:9062:: with SMTP id h89mr34213291wrh.130.1624992861303; Tue, 29 Jun 2021 11:54:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id k13sm19025218wrp.73.2021.06.29.11.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 11:54:20 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff Hostetler , Johannes Schindelin , Felipe Contreras , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v2 1/3] hook.[ch]: move find_hook() to this new library Date: Tue, 29 Jun 2021 20:54:00 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.615.g90fb4d7369 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the find_hook() function from run-command.c to a new hook.c library. This change establishes a stub library that's pretty pointless right now, but will see much wider use with Emily Shaffer's upcoming "configuration-based hooks" series. Eventually all the hook related code will live in hook.[ch]. Let's start that process by moving the simple find_hook() function over as-is. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- Makefile | 1 + builtin/am.c | 1 + builtin/bugreport.c | 2 +- builtin/commit.c | 1 + builtin/merge.c | 1 + builtin/receive-pack.c | 1 + builtin/worktree.c | 1 + hook.c | 37 +++++++++++++++++++++++++++++++++++++ hook.h | 11 +++++++++++ refs.c | 1 + run-command.c | 35 +---------------------------------- run-command.h | 7 ------- sequencer.c | 1 + transport.c | 1 + 14 files changed, 59 insertions(+), 42 deletions(-) create mode 100644 hook.c create mode 100644 hook.h diff --git a/Makefile b/Makefile index 29a152cd4f..d155b7be21 100644 --- a/Makefile +++ b/Makefile @@ -903,6 +903,7 @@ LIB_OBJS += hash-lookup.o LIB_OBJS += hashmap.o LIB_OBJS += help.o LIB_OBJS += hex.o +LIB_OBJS += hook.o LIB_OBJS += ident.o LIB_OBJS += json-writer.o LIB_OBJS += kwset.o diff --git a/builtin/am.c b/builtin/am.c index 0b2d886c81..1c8a548903 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -11,6 +11,7 @@ #include "parse-options.h" #include "dir.h" #include "run-command.h" +#include "hook.h" #include "quote.h" #include "tempfile.h" #include "lockfile.h" diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 9915a5841d..596f079a7f 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -3,7 +3,7 @@ #include "strbuf.h" #include "help.h" #include "compat/compiler.h" -#include "run-command.h" +#include "hook.h" static void get_system_info(struct strbuf *sys_info) diff --git a/builtin/commit.c b/builtin/commit.c index 190d215d43..f1aafd67d4 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -19,6 +19,7 @@ #include "revision.h" #include "wt-status.h" #include "run-command.h" +#include "hook.h" #include "refs.h" #include "log-tree.h" #include "strbuf.h" diff --git a/builtin/merge.c b/builtin/merge.c index a8a843b1f5..be98d66b0a 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -13,6 +13,7 @@ #include "builtin.h" #include "lockfile.h" #include "run-command.h" +#include "hook.h" #include "diff.h" #include "diff-merges.h" #include "refs.h" diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index a34742513a..1e0e04c62f 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -7,6 +7,7 @@ #include "pkt-line.h" #include "sideband.h" #include "run-command.h" +#include "hook.h" #include "exec-cmd.h" #include "commit.h" #include "object.h" diff --git a/builtin/worktree.c b/builtin/worktree.c index 976bf8ed06..b1350640fe 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -8,6 +8,7 @@ #include "branch.h" #include "refs.h" #include "run-command.h" +#include "hook.h" #include "sigchain.h" #include "submodule.h" #include "utf8.h" diff --git a/hook.c b/hook.c new file mode 100644 index 0000000000..c4dbef1d0e --- /dev/null +++ b/hook.c @@ -0,0 +1,37 @@ +#include "cache.h" +#include "hook.h" +#include "run-command.h" + +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; +} diff --git a/hook.h b/hook.h new file mode 100644 index 0000000000..68624f1605 --- /dev/null +++ b/hook.h @@ -0,0 +1,11 @@ +#ifndef HOOK_H +#define HOOK_H + +/* + * 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); + +#endif diff --git a/refs.c b/refs.c index 8c9490235e..59be29cf08 100644 --- a/refs.c +++ b/refs.c @@ -10,6 +10,7 @@ #include "refs.h" #include "refs/refs-internal.h" #include "run-command.h" +#include "hook.h" #include "object-store.h" #include "object.h" #include "tag.h" diff --git a/run-command.c b/run-command.c index be6bc128cd..82fdf29656 100644 --- a/run-command.c +++ b/run-command.c @@ -8,6 +8,7 @@ #include "string-list.h" #include "quote.h" #include "config.h" +#include "hook.h" void child_process_init(struct child_process *child) { @@ -1320,40 +1321,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; diff --git a/run-command.h b/run-command.h index d08414a92e..b58531a7eb 100644 --- a/run-command.h +++ b/run-command.h @@ -201,13 +201,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 diff --git a/sequencer.c b/sequencer.c index 0bec01cf38..3de479f90e 100644 --- a/sequencer.c +++ b/sequencer.c @@ -8,6 +8,7 @@ #include "sequencer.h" #include "tag.h" #include "run-command.h" +#include "hook.h" #include "exec-cmd.h" #include "utf8.h" #include "cache-tree.h" diff --git a/transport.c b/transport.c index 50f5830eb6..2ed270171f 100644 --- a/transport.c +++ b/transport.c @@ -2,6 +2,7 @@ #include "config.h" #include "transport.h" #include "run-command.h" +#include "hook.h" #include "pkt-line.h" #include "fetch-pack.h" #include "remote.h" From patchwork Tue Jun 29 18:54:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12350509 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 D13A8C11F69 for ; Tue, 29 Jun 2021 18:54:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA0D461D84 for ; Tue, 29 Jun 2021 18:54:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235284AbhF2S46 (ORCPT ); Tue, 29 Jun 2021 14:56:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234521AbhF2S4w (ORCPT ); Tue, 29 Jun 2021 14:56:52 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F05D5C061767 for ; Tue, 29 Jun 2021 11:54:23 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id n33so258257wms.2 for ; Tue, 29 Jun 2021 11:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Arqb+YKlaGPIXcELVOJi/Fcn2FhlR4YsbU9HyKrUrRU=; b=vPo5NI/rDElXEiPZ4heqNLDAP3aMZS1jCS33xUdKFF7Xdtnf1sJIOgNiTYBOCjBGdb hQuOqqnVIgO9TxBZtJ6IYep3oDDSbTpUJro6LEN2PG612tiPAey5RbGYcYtxEirvpyM4 c3yaG30jUKb1zp5rFivIrctyOGOAaY+eKSlNrGqeJgrzVSpzqY1BN0NqnZGiBjaULrZC nkWkYsYQDYHTj9awrR1xWBOcOJaBbsWBq3fciD/VmumAesoXCgYEiE0XEke2aNCak4qI qyfstURwp3vFwd5E8Op7jDJdl0zLXG28WdhXcZBuHwKYgyAtfXuQiRovIHzGBiGFm8De BseQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Arqb+YKlaGPIXcELVOJi/Fcn2FhlR4YsbU9HyKrUrRU=; b=lD/waUt1NSwNViZjDh/WShVPL+agYzhSkcIbbWKpyo9drGo8+mZn+HGxVqo2WEBIO7 gMzDtouz5PREgJ9/4EcQ9itEfSwD/bu8SIk9epsxeugOXl7xY+oL3NhGCg4IJ0rcPHoT 22kNMaNGQlnwMZi1yKCtLb+DjpFIRh2dlAPUZ1otaNSEDCGHX4XEujXhkBy1Gvve6Adl Cc3awThD8lBnxNMkY3sfJNOA/R3YRrIPhgp8/8q9L5rnlX0bXJN611GTTGOXj8Q04Qu9 1NIVHfNHbuVtcICkywNU7vGGIxOHttovsD+esPofTn5I0Y6tDr3PDWTE3uiHypcO3x4s v6yA== X-Gm-Message-State: AOAM532DHmMgYHj0nhmUe82TinsXPVxuZmCbJ8y3PwpkIFWT4TXwS84Q fy+Qn3OXaILL8i3O+fYN/vftAWp8HKY/yQ== X-Google-Smtp-Source: ABdhPJzFStvstDvrey8OvAY5tmnWAnkXsfH3FfThXpBRnqlWtFFJ/3vlTMGW2xTlsnFmaj3T1VBwlg== X-Received: by 2002:a05:600c:21c4:: with SMTP id x4mr34191005wmj.30.1624992862293; Tue, 29 Jun 2021 11:54:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id k13sm19025218wrp.73.2021.06.29.11.54.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 11:54:21 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff Hostetler , Johannes Schindelin , Felipe Contreras , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v2 2/3] hook.c: add a hook_exists() wrapper and use it in bugreport.c Date: Tue, 29 Jun 2021 20:54:01 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.615.g90fb4d7369 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Add a boolean version of the find_hook() function for those callers who are only interested in checking whether the hook exists, not what the path to it is. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/bugreport.c | 2 +- hook.c | 5 +++++ hook.h | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 596f079a7f..941c8d5e27 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -82,7 +82,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit) } for (i = 0; i < ARRAY_SIZE(hook); i++) - if (find_hook(hook[i])) + if (hook_exists(hook[i])) strbuf_addf(hook_info, "%s\n", hook[i]); } diff --git a/hook.c b/hook.c index c4dbef1d0e..97cd799a32 100644 --- a/hook.c +++ b/hook.c @@ -35,3 +35,8 @@ const char *find_hook(const char *name) } return path.buf; } + +int hook_exists(const char *name) +{ + return !!find_hook(name); +} diff --git a/hook.h b/hook.h index 68624f1605..4c547ac15e 100644 --- a/hook.h +++ b/hook.h @@ -8,4 +8,9 @@ */ const char *find_hook(const char *name); +/* + * A boolean version of find_hook() + */ +int hook_exists(const char *hookname); + #endif From patchwork Tue Jun 29 18:54:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12350507 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 24169C11F68 for ; Tue, 29 Jun 2021 18:54:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDF6761DBC for ; Tue, 29 Jun 2021 18:54:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235261AbhF2S45 (ORCPT ); Tue, 29 Jun 2021 14:56:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234365AbhF2S4w (ORCPT ); Tue, 29 Jun 2021 14:56:52 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3E8FC061768 for ; Tue, 29 Jun 2021 11:54:24 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id o22so288499wms.0 for ; Tue, 29 Jun 2021 11:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EIoI9/RXBxyBYwBm/qCwrBieqzcwQRCbq6NaLIrL+jM=; b=GGDRjjISxucRSJXJXC5HXW2kghSaz7C+NnzXozEaZs6zNfz/h1hG8Ho0uA/P/epRDJ jjjw/vyWPfrB5w4bgvrHSJ1tLI9h0HlNTQ2LyXuMpUoLh0qg6t8ITulFX1lRUr0rvHxT cHqfwLQRwYH4n+qzmHlJFDGa+FrxeigPca+Pe5oMpmeCH3HdKWhhhsuEE81/i9zezjYf 65QPhRu7BjYkqy5j9m1coFUJntkk+5XhK8be1Q7eBV6fjXWHufQroTdL14j4s/AtDPgq RO0oVpK7tS4peVeGu3j0X5/NYlhFIUU/Yys6vrSx7nfCgMbLlDIuRkrAZueHE2GH/32l cYbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EIoI9/RXBxyBYwBm/qCwrBieqzcwQRCbq6NaLIrL+jM=; b=Lxirnxp4Pr4Z0zXEDlKGgkmqSMCi0JHB7ZCLD7P1irt+f8Jf3UZ5EcMrqeSMe3vu3R OHaHghA/ASG0kty8xaHYVll2jzYfufg9Xr0xkIbq8UexIyqT18IthZo7b6XOtC4GWsML Ex30N0/L7Gg6KwejtXX9Za10+nN0b7Ui+GBdG0icfUMEUmirKibNPD6u/5w7zlIX3K16 TUtq/9f7rDjfN3zQo1JZfnOps16I7mSMnA1zSBUHHmzfC/ZyUM8MpGkDrruyZl2aeoR+ xQOaFTaWzsNL6M1JaRWfdZB2x4xuTcI1NrD6RPzrkPX09GNyNsS/34WSAUtUql646Crb uJeg== X-Gm-Message-State: AOAM530tK87EQIWqU75iBNr7xcnw63vFpGwYYk2RKLKYfWEKWN+CEnzl nmD5AXsfwYBX0nkQ6x/fVXjykRZWu0eK/Q== X-Google-Smtp-Source: ABdhPJym6V9RidMNpGgW3A1Dx7jR/GVh2mMJ10rOB3VS/vTDv4DwFtaWIBqs0bo4GswUdy8wfgLQVg== X-Received: by 2002:a05:600c:3514:: with SMTP id h20mr305704wmq.46.1624992863192; Tue, 29 Jun 2021 11:54:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id k13sm19025218wrp.73.2021.06.29.11.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 11:54:22 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff Hostetler , Johannes Schindelin , Felipe Contreras , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v2 3/3] hook-list.h: add a generated list of hooks, like config-list.h Date: Tue, 29 Jun 2021 20:54:02 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.615.g90fb4d7369 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Make githooks(5) the source of truth for what hooks git supports, and die hooks we don't know about in find_hook(). This ensures that the documentation and the C code's idea about existing hooks doesn't diverge. We still have Perl and Python code running its own hooks, but that'll be addressed by Emily Shaffer's upcoming "git hook run" command. This resolves a long-standing TODO item in bugreport.c of there being no centralized listing of hooks, and fixes a bug with the bugreport listing only knowing about 1/4 of the p4 hooks. It didn't know about the recent "reference-transaction" hook either. I have not been able to directly test the CMake change being made here. Since 4c2c38e800 (ci: modification of main.yml to use cmake for vs-build job, 2020-06-26) some of the Windows CI has a hard dependency on CMake, this change works there, and is to my eyes an obviously correct use of a pattern established in previous CMake changes, namely: - 061c2240b1 (Introduce CMake support for configuring Git, 2020-06-12) - 709df95b78 (help: move list_config_help to builtin/help, 2020-04-16) - 976aaedca0 (msvc: add a Makefile target to pre-generate the Visual Studio solution, 2019-07-29) The LC_ALL=C is needed because at least in my locale the dash ("-") is ignored for the purposes of sorting, which results in a different order. I'm not aware of anything in git that has a hard dependency on the order, but e.g. the bugreport output would end up using whatever locale was in effect when git was compiled. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: René Scharfe --- .gitignore | 1 + Makefile | 10 ++++++- builtin/bugreport.c | 44 ++++++----------------------- contrib/buildsystems/CMakeLists.txt | 7 +++++ generate-hooklist.sh | 18 ++++++++++++ hook.c | 19 +++++++++++++ 6 files changed, 62 insertions(+), 37 deletions(-) create mode 100755 generate-hooklist.sh diff --git a/.gitignore b/.gitignore index 311841f9be..6be9de41ae 100644 --- a/.gitignore +++ b/.gitignore @@ -190,6 +190,7 @@ /gitweb/static/gitweb.min.* /config-list.h /command-list.h +/hook-list.h *.tar.gz *.dsc *.deb diff --git a/Makefile b/Makefile index d155b7be21..9b811d3548 100644 --- a/Makefile +++ b/Makefile @@ -817,6 +817,8 @@ XDIFF_LIB = xdiff/lib.a GENERATED_H += command-list.h GENERATED_H += config-list.h +GENERATED_H += hook-list.h + .PHONY: generated-hdrs generated-hdrs: $(GENERATED_H) @@ -2208,7 +2210,9 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS) help.sp help.s help.o: command-list.h -builtin/help.sp builtin/help.s builtin/help.o: config-list.h GIT-PREFIX +hook.sp hook.s hook.o: hook-list.h + +builtin/help.sp builtin/help.s builtin/help.o: config-list.h hook-list.h GIT-PREFIX builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \ '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \ '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \ @@ -2241,6 +2245,10 @@ command-list.h: $(wildcard Documentation/git*.txt) $(patsubst %,--exclude-program %,$(EXCLUDED_PROGRAMS)) \ command-list.txt >$@+ && mv $@+ $@ +hook-list.h: generate-hooklist.sh Documentation/githooks.txt + $(QUIET_GEN)$(SHELL_PATH) ./generate-hooklist.sh \ + >$@+ && mv $@+ $@ + SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\ $(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\ $(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV):\ diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 941c8d5e27..a7a1fcb8a7 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -4,6 +4,7 @@ #include "help.h" #include "compat/compiler.h" #include "hook.h" +#include "hook-list.h" static void get_system_info(struct strbuf *sys_info) @@ -41,39 +42,7 @@ static void get_system_info(struct strbuf *sys_info) static void get_populated_hooks(struct strbuf *hook_info, int nongit) { - /* - * NEEDSWORK: Doesn't look like there is a list of all possible hooks; - * so below is a transcription of `git help hooks`. Later, this should - * be replaced with some programmatically generated list (generated from - * doc or else taken from some library which tells us about all the - * hooks) - */ - static const char *hook[] = { - "applypatch-msg", - "pre-applypatch", - "post-applypatch", - "pre-commit", - "pre-merge-commit", - "prepare-commit-msg", - "commit-msg", - "post-commit", - "pre-rebase", - "post-checkout", - "post-merge", - "pre-push", - "pre-receive", - "update", - "post-receive", - "post-update", - "push-to-checkout", - "pre-auto-gc", - "post-rewrite", - "sendemail-validate", - "fsmonitor-watchman", - "p4-pre-submit", - "post-index-change", - }; - int i; + const char **p; if (nongit) { strbuf_addstr(hook_info, @@ -81,9 +50,12 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit) return; } - for (i = 0; i < ARRAY_SIZE(hook); i++) - if (hook_exists(hook[i])) - strbuf_addf(hook_info, "%s\n", hook[i]); + for (p = hook_name_list; *p; p++) { + const char *hook = *p; + + if (hook_exists(hook)) + strbuf_addf(hook_info, "%s\n", hook); + } } static const char * const bugreport_usage[] = { diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index a87841340e..c216940945 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -602,6 +602,13 @@ if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h) OUTPUT_FILE ${CMAKE_BINARY_DIR}/config-list.h) endif() +if(NOT EXISTS ${CMAKE_BINARY_DIR}/hook-list.h) + message("Generating hook-list.h") + execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-hooklist.sh + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_FILE ${CMAKE_BINARY_DIR}/hook-list.h) +endif() + include_directories(${CMAKE_BINARY_DIR}) #build diff --git a/generate-hooklist.sh b/generate-hooklist.sh new file mode 100755 index 0000000000..6d4e56d1a3 --- /dev/null +++ b/generate-hooklist.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# +# Usage: ./generate-hooklist.sh >hook-list.h + +cat <