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

Re: [PATCH v2 6/7] config: allow configuration of multiple hook error behavior

From
Jeff King <peff@peff.net>
Date
May 16, 2019, 05:02 UTC
Message-ID
<20190516050200.GB7241@sigill.intra.peff.net>
In-Reply-To
<20190514002332.121089-8-sandals@crustytoothpaste.net>
On Tue, May 14, 2019 at 12:23:31AM +0000, brian m. carlson wrote:
Show 6 quoted lines
> There are a variety of situations in which a user may want an error
> behavior for multiple hooks other than the default. Add a config option,
> hook.<name>.errorBehavior to allow users to customize this behavior on a
> per-hook basis. Provide options for the default behavior (exiting
> early), executing all hooks and succeeding if all hooks succeed, or
> executing all hooks and succeeding if any hook succeeds.

Thanks for using that naming scheme. I think if we do move to allowing config-based hooks, the config schemes will mesh together well.

Show 8 quoted lines
> +static int git_default_hook_config(const char *key, const char *value)
> +{
> +	const char *hook;
> +	size_t key_len;
> +	uintptr_t behavior;
> +
> +	key += strlen("hook.");
> +	if (strip_suffix(key, ".errorbehavior", &key_len)) {

There's an undocumented assumption that the caller has confirmed that the key starts with "hook." here. Can we be a little more defensive and do:

  if (skip_prefix(key, "hook.", &key))
	return 0;
here (we could even drop the check in git_default_config).
Or we could use parse_key(), which is designed for this:
  if (parse_key(key, "hook", &subsection, &subsection_len, &key) < 0 ||
      !subsection)
	return 0;
  if (!strcmp(key, "errorbehavior"))
	...
> +	/* Use -2 as sentinel because failure to exec is -1. */
> +	int ret = -2;

Maybe this would be simpler to follow by using an enum for the handler return value?

Aside from these nits, the code looked sensible to me.
-Peff
Previous: Jeff KingNext: brian m. carlson
Message 23 of 34 in “Multiple hook support”
  1. 0/7 Multiple hook supportbrian m. carlson, May 14, 2019
  2. 1/7 run-command: add preliminary support for multiple hooksbrian m. carlson, May 14, 2019
  3. Duy NguyenMay 14, 2019
  4. brian m. carlsonMay 15, 2019
  5. brian m. carlsonMay 29, 2019
  6. Johannes SchindelinMay 14, 2019
  7. brian m. carlsonMay 15, 2019
  8. Johannes SixtMay 16, 2019
  9. Johannes SchindelinMay 17, 2019
  10. 2/7 builtin/receive-pack: add support for multiple hooksbrian m. carlson, May 14, 2019
  11. 3/7 rebase: add support for multiple hooksbrian m. carlson, May 14, 2019
  12. Duy NguyenMay 14, 2019
  13. Johannes SixtMay 14, 2019
  14. brian m. carlsonMay 15, 2019
  15. Duy NguyenMay 16, 2019
  16. 3/7 sequencer: add support for multiple hooksbrian m. carlson, May 14, 2019
  17. 4/7 builtin/worktree: add support for multiple post-checkout hooksbrian m. carlson, May 14, 2019
  18. 5/7 transport: add support for multiple pre-push hooksbrian m. carlson, May 14, 2019
  19. 6/7 config: allow configuration of multiple hook error behaviorbrian m. carlson, May 14, 2019
  20. Duy NguyenMay 14, 2019
  21. brian m. carlsonMay 15, 2019
  22. Jeff KingMay 16, 2019
  23. Jeff KingMay 16, 2019
  24. brian m. carlsonMay 16, 2019
  25. Jeff KingMay 16, 2019
  26. 7/7 docs: document multiple hooksbrian m. carlson, May 14, 2019
  27. Duy NguyenMay 14, 2019
  28. Jonathan NiederMay 14, 2019
  29. brian m. carlsonMay 14, 2019
  30. Jonathan NiederMay 14, 2019
  31. brian m. carlsonMay 16, 2019
  32. Jonathan NiederMay 16, 2019
  33. Jeff KingMay 16, 2019
  34. Duy NguyenMay 14, 2019

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.