git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] bugreport: collect list of populated hooks
@ 2020-04-24 23:38 Emily Shaffer
  2020-04-25  0:30 ` Jonathan Nieder
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Emily Shaffer @ 2020-04-24 23:38 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

Occasionally a failure a user is seeing may be related to a specific
hook which is being run, perhaps without the user realizing. While the
contents of hooks can be sensitive - containing user data or process
information specific to the user's organization - simply knowing that a
hook is being run at a certain stage can help us to understand whether
something is going wrong.

Without a definitive list of hook names within the code, we compile our
own list from the documentation. This is likely prone to bitrot. To
reduce the amount of code humans need to read, we turn the list into a
string_list and iterate over it (as we are calling the same find_hook
operation on each string). However, since bugreport should primarily be
called by the user, the performance loss from massaging the string
seems acceptable.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
Based on es/bugreport.

 Documentation/git-bugreport.txt |  1 +
 bugreport.c                     | 52 +++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt
index 643d1b2884..7fe9aef34e 100644
--- a/Documentation/git-bugreport.txt
+++ b/Documentation/git-bugreport.txt
@@ -28,6 +28,7 @@ The following information is captured automatically:
  - 'git version --build-options'
  - uname sysname, release, version, and machine strings
  - Compiler-specific info string
+ - A list of enabled hooks
 
 This tool is invoked via the typical Git setup process, which means that in some
 cases, it might not be able to launch - for example, if a relevant config file
diff --git a/bugreport.c b/bugreport.c
index 089b939a87..ce32145bce 100644
--- a/bugreport.c
+++ b/bugreport.c
@@ -5,6 +5,8 @@
 #include "time.h"
 #include "help.h"
 #include "compat/compiler.h"
+#include "run-command.h"
+
 
 static void get_system_info(struct strbuf *sys_info)
 {
@@ -33,6 +35,53 @@ static void get_system_info(struct strbuf *sys_info)
 	get_libc_info(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)
+	 */
+	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;
+
+	if (nongit) {
+		strbuf_addstr(hook_info,
+			"not run from a git repository - no hooks to show\n");
+		return;
+	}
+
+	for (i=0; i < ARRAY_SIZE(hook); i++)
+		if (find_hook(hook[i]))
+			strbuf_addf(hook_info, "%s\n", hook[i]);
+}
+
 static const char * const bugreport_usage[] = {
 	N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
 	NULL
@@ -116,6 +165,9 @@ int cmd_main(int argc, const char **argv)
 	get_header(&buffer, _("System Info"));
 	get_system_info(&buffer);
 
+	get_header(&buffer, "Enabled Hooks");
+	get_populated_hooks(&buffer, nongit_ok);
+
 	/* fopen doesn't offer us an O_EXCL alternative, except with glibc. */
 	report = open(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666);
 
-- 
2.26.2.303.gf8c07b1a785-goog


^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2020-05-11 23:46 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-24 23:38 [PATCH] bugreport: collect list of populated hooks Emily Shaffer
2020-04-25  0:30 ` Jonathan Nieder
2020-04-27 20:48   ` [PATCH] bugreport: drop time.h include Emily Shaffer
2020-04-27 21:03     ` Jonathan Nieder
2020-04-27 21:25       ` Junio C Hamano
2020-04-27 21:41         ` Junio C Hamano
2020-04-27 21:56           ` Emily Shaffer
2020-04-27 23:27             ` Junio C Hamano
2020-04-27 23:42     ` [PATCH v2] bugreport: drop extraneous includes Emily Shaffer
2020-04-27 23:46       ` Jonathan Nieder
2020-04-25  4:52 ` [PATCH] bugreport: collect list of populated hooks Junio C Hamano
2020-04-27 19:02   ` Emily Shaffer
2020-04-27 20:46     ` Junio C Hamano
2020-04-27 20:49       ` Emily Shaffer
2020-04-27 23:38 ` [PATCH v2] " Emily Shaffer
2020-04-27 23:45   ` Jonathan Nieder
2020-04-28  0:04     ` Junio C Hamano
2020-04-30  0:01     ` Emily Shaffer
2020-04-30  1:24   ` [PATCH v3] " Emily Shaffer
2020-04-30  1:50     ` Jonathan Nieder
2020-04-30  1:53       ` Jonathan Nieder
2020-04-30 17:44       ` Junio C Hamano
2020-04-30 22:09         ` Junio C Hamano
2020-05-07 21:08           ` Emily Shaffer
2020-05-07 23:06             ` Junio C Hamano
2020-05-11 21:26               ` Emily Shaffer
2020-05-08  0:53     ` [PATCH v4] " Emily Shaffer
2020-05-08  1:20       ` Junio C Hamano
2020-05-08  1:34       ` Đoàn Trần Công Danh
2020-05-11 21:22         ` Emily Shaffer
2020-05-11 22:14       ` [PATCH v5] " Emily Shaffer
2020-05-11 23:26         ` Jonathan Nieder
2020-05-11 23:45         ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).