git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v8 11/15] bugreport: collect list of populated hooks

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 20, 2020, 20:58 UTC
Message-ID
<xmqqeeup9ds7.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20200220015858.181086-12-emilyshaffer@google.com>
Emily Shaffer <emilyshaffer@google.com> writes:
Show 6 quoted lines
> +static void get_populated_hooks(struct strbuf *hook_info, int nongit)
> +{
> +	/*
> +	 * Doesn't look like there is a list of all possible hooks; so below is
> +	 * a transcription of `git help hooks`.
> +	 */
It may want to become a NEEDSWORK comment.
Show 23 quoted lines
> +	const char *hooks = "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-changex";
Typo here?
Show 13 quoted lines
> +	struct string_list hooks_list = STRING_LIST_INIT_DUP;
> +	struct string_list_item *iter = NULL;
> +
> +
> +	if (nongit) {
> +		strbuf_addstr(hook_info,
> +			"not run from a git repository - no hooks to show\n");
> +		return;
> +	}
> +
> +	string_list_split(&hooks_list, hooks, ',', -1);
> +
> +	for_each_string_list_item(iter, &hooks_list) {

I do not get why you want to use string_list for this, especially if you need to use string_list_split.

To me,
	int i;
	const char *hook[] = {
		"applypatch-msg",
	        "pre-applypatch",
		...
		"post-index-change",
	};
	for (i = 0; i < ARRAY_SIZE(hook); i++) {
		if (hook[i] is enabled)
			strbuf_addf(hook_info, "%s\n", hook[i]);
	}

would be far easier to understand. Do you have an external source that can feed you a single long string of comma separated hook names in mind, so that the initialization of *hooks will become simpler that way, or something?

Show 20 quoted lines
> +		if (find_hook(iter->string)) {
> +			strbuf_addstr(hook_info, iter->string);
> +			strbuf_complete_line(hook_info);
> +		}
> +	}
> +}
> +
>  static const char * const bugreport_usage[] = {
>  	N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
>  	NULL
> @@ -166,6 +216,9 @@ int cmd_main(int argc, const char **argv)
>  	get_header(&buffer, "Safelisted Config Info");
>  	get_safelisted_config(&buffer);
>  
> +	get_header(&buffer, "Enabled Hooks");
> +	get_populated_hooks(&buffer, nongit_ok);
> +
>  	report = fopen_for_writing(report_path.buf);
>  
>  	if (report == NULL) {
Previous: Emily ShafferNext: Emily Shaffer
Message 39 of 87 in “add git-bugreport tool”
  1. 00/15 add git-bugreport toolEmily Shaffer, Feb 20, 2020
  2. 02/15 help: add shell-path to --build-optionsEmily Shaffer, Feb 20, 2020
  3. Junio C HamanoFeb 20, 2020
  4. Emily ShafferFeb 20, 2020
  5. 01/15 help: move list_config_help to builtin/helpEmily Shaffer, Feb 20, 2020
  6. 03/15 bugreport: add tool to generate debugging infoEmily Shaffer, Feb 20, 2020
  7. Junio C HamanoFeb 20, 2020
  8. Emily ShafferFeb 20, 2020
  9. Johannes SchindelinFeb 26, 2020
  10. 04/15 bugreport: gather git version and build infoEmily Shaffer, Feb 20, 2020
  11. Junio C HamanoFeb 20, 2020
  12. Emily ShafferFeb 20, 2020
  13. Junio C HamanoFeb 20, 2020
  14. 05/15 bugreport: add uname infoEmily Shaffer, Feb 20, 2020
  15. Junio C HamanoFeb 20, 2020
  16. Emily ShafferFeb 20, 2020
  17. 06/15 bugreport: add compiler infoEmily Shaffer, Feb 20, 2020
  18. Danh DoanFeb 20, 2020
  19. Emily ShafferFeb 20, 2020
  20. Junio C HamanoFeb 20, 2020
  21. Junio C HamanoFeb 21, 2020
  22. 07/15 bugreport: add git-remote-https versionEmily Shaffer, Feb 20, 2020
  23. Junio C HamanoFeb 20, 2020
  24. Emily ShafferFeb 20, 2020
  25. Junio C HamanoFeb 21, 2020
  26. Emily ShafferFeb 25, 2020
  27. Junio C HamanoFeb 25, 2020
  28. Emily ShafferFeb 25, 2020
  29. Junio C HamanoFeb 25, 2020
  30. Emily ShafferFeb 25, 2020
  31. 08/15 bugreport: include user interactive shellEmily Shaffer, Feb 20, 2020
  32. 09/15 bugreport: generate config safelist based on docsEmily Shaffer, Feb 20, 2020
  33. Junio C HamanoFeb 20, 2020
  34. Johannes SchindelinFeb 26, 2020
  35. Junio C HamanoFeb 26, 2020
  36. 10/15 bugreport: add config values from safelistEmily Shaffer, Feb 20, 2020
  37. Junio C HamanoFeb 20, 2020
  38. 11/15 bugreport: collect list of populated hooksEmily Shaffer, Feb 20, 2020
  39. Junio C HamanoFeb 20, 2020
  40. Emily ShafferFeb 25, 2020
  41. 12/15 bugreport: count loose objectsEmily Shaffer, Feb 20, 2020
  42. Junio C HamanoFeb 20, 2020
  43. Emily ShafferFeb 25, 2020
  44. Emily ShafferFeb 25, 2020
  45. 13/15 bugreport: add packed object summaryEmily Shaffer, Feb 20, 2020
  46. Junio C HamanoFeb 20, 2020
  47. Emily ShafferFeb 25, 2020
  48. 14/15 bugreport: list contents of $OBJDIR/infoEmily Shaffer, Feb 20, 2020
  49. Junio C HamanoFeb 20, 2020
  50. 15/15 bugreport: summarize contents of alternates fileEmily Shaffer, Feb 20, 2020
  51. Johannes SchindelinFeb 20, 2020
  52. Junio C HamanoFeb 20, 2020
  53. 0/5 add git-bugreport toolEmily Shaffer, Mar 2, 2020
  54. 1/5 help: move list_config_help to builtin/helpEmily Shaffer, Mar 2, 2020
  55. 2/5 bugreport: add tool to generate debugging infoEmily Shaffer, Mar 2, 2020
  56. Johannes SchindelinMar 3, 2020
  57. Johannes SchindelinMar 4, 2020
  58. Jeff HostetlerMar 5, 2020
  59. Johannes SchindelinMar 6, 2020
  60. Junio C HamanoMar 6, 2020
  61. Junio C HamanoMar 6, 2020
  62. Jeff HostetlerMar 6, 2020
  63. Johannes SchindelinMar 8, 2020
  64. Junio C HamanoMar 9, 2020
  65. Johannes SchindelinMar 9, 2020
  66. Junio C HamanoMar 9, 2020
  67. Johannes SchindelinMar 10, 2020
  68. Junio C HamanoMar 10, 2020
  69. Johannes SchindelinMar 10, 2020
  70. Emily ShafferMar 19, 2020
  71. Junio C HamanoMar 20, 2020
  72. Johannes SchindelinMar 20, 2020
  73. Emily ShafferMar 23, 2020
  74. Johannes SchindelinMar 20, 2020
  75. Emily ShafferMar 23, 2020
  76. Junio C HamanoMar 20, 2020
  77. Johannes SchindelinMar 20, 2020
  78. Junio C HamanoMar 20, 2020
  79. Johannes SchindelinMar 21, 2020
  80. 3/5 bugreport: gather git version and build infoEmily Shaffer, Mar 2, 2020
  81. Junio C HamanoMar 23, 2020
  82. 4/5 bugreport: add uname infoEmily Shaffer, Mar 2, 2020
  83. 5/5 bugreport: add compiler infoEmily Shaffer, Mar 2, 2020
  84. Danh DoanMar 3, 2020
  85. Junio C HamanoMar 3, 2020
  86. Johannes SchindelinMar 4, 2020
  87. Emily ShafferMar 23, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.