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

Re: [PATCH v2 2/4] config: report config parse errors using cb

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 24, 2023, 01:19 UTC
Message-ID
<xmqqttspck4a.fsf@gitster.g>
In-Reply-To
<cb92a1f2e3098bede386d04da32fcc4f27fca51f.1692827403.git.steadmon@google.com>
Josh Steadmon <steadmon@google.com> writes:
Show 5 quoted lines
> From: Glen Choo <chooglen@google.com>
>
> In a subsequent commit, config parsing will become its own library, and
> it's likely that the caller will want flexibility in handling errors
> (instead of being limited to the error handling we have in-tree).

And the in-tree error handling is abstracted out as the git_config_err_fn() function; in other words, we become the first client of the library interface, which makes sense.

Show 14 quoted lines
> @@ -1035,8 +1088,6 @@ static int git_parse_source(struct config_source *cs, config_fn_t fn,
>  	int comment = 0;
>  	size_t baselen = 0;
>  	struct strbuf *var = &cs->var;
> ...
> +	/*
> +	 * FIXME for whatever reason, do_event passes the _previous_ event, so
> +	 * in order for our callback to receive the error event, we have to call
> +	 * do_event twice
> +	 */
> +	do_event(cs, CONFIG_EVENT_ERROR, &event_data);
> +	do_event(cs, CONFIG_EVENT_ERROR, &event_data);
> +	return -1;
>  }

This indeed is very curious and needs to be looked into before we proceed further. How does the current control flow cope with the behaviour?

Show 11 quoted lines
> @@ -2322,7 +2342,9 @@ void read_early_config(config_fn_t cb, void *data)
>   */
>  void read_very_early_config(config_fn_t cb, void *data)
>  {
> -	struct config_options opts = { 0 };
> +	struct config_options opts = {
> +		.parse_options = CP_OPTS_INIT(CONFIG_ERROR_DIE),
> +	};
>  
>  	opts.respect_includes = 1;
>  	opts.ignore_repo = 1;

This uses a bit more assignments to various members of opts. to initialize it, which could have been done with designated initializer, like the one in read_protected_config() used to do.

Show 16 quoted lines
> @@ -2760,12 +2784,14 @@ int repo_config_get_pathname(struct repository *repo,
>  static void read_protected_config(void)
>  {
>  	struct config_options opts = {
> -		.respect_includes = 1,
> -		.ignore_repo = 1,
> -		.ignore_worktree = 1,
> -		.system_gently = 1,
> +		.parse_options = CP_OPTS_INIT(CONFIG_ERROR_DIE),
>  	};
>  
> +	opts.respect_includes = 1;
> +	opts.ignore_repo = 1;
> +	opts.ignore_worktree = 1;
> +	opts.system_gently = 1;
> +

It is curious why you want to switch to manual assignment, instead of keeping the designated initializer for this one. I would have expected the initialization in read_very_early_config() to start using designated initializer to be consistent, instead.

Thanks.
Previous: Josh SteadmonNext: Jonathan Tan
Message 23 of 49 in “config-parse: create config parsing library”
  1. 0/2 config-parse: create config parsing libraryGlen Choo via GitGitGadget, Jul 20, 2023
  2. 1/2 config: return positive from git_config_parse_key()Glen Choo via GitGitGadget, Jul 20, 2023
  3. Jonathan TanJul 20, 2023
  4. Junio C HamanoJul 21, 2023
  5. Glen ChooJul 21, 2023
  6. Junio C HamanoJul 21, 2023
  7. 2/2 config-parse: split library out of config.[c|h]Glen Choo via GitGitGadget, Jul 20, 2023
  8. Jonathan TanJul 21, 2023
  9. Glen ChooJul 21, 2023
  10. 0/5 config-parse: create config parsing libraryGlen Choo, Jul 31, 2023
  11. 1/5 config: return positive from git_config_parse_key()Glen Choo, Jul 31, 2023
  12. 3/5 config: report config parse errors using cbGlen Choo, Jul 31, 2023
  13. Jonathan TanAug 4, 2023
  14. 2/5 config: split out config_parse_optionsGlen Choo, Jul 31, 2023
  15. 4/5 config.c: accept config_parse_options in git_config_from_stdinGlen Choo, Jul 31, 2023
  16. 5/5 config-parse: split library out of config.[c|h]Glen Choo, Jul 31, 2023
  17. 0/4 config-parse: create config parsing libraryJosh Steadmon, Aug 23, 2023
  18. 1/4 config: split out config_parse_optionsJosh Steadmon, Aug 23, 2023
  19. Junio C HamanoAug 23, 2023
  20. Josh SteadmonSep 21, 2023
  21. 3/4 config.c: accept config_parse_options in git_config_from_stdinJosh Steadmon, Aug 23, 2023
  22. 2/4 config: report config parse errors using cbJosh Steadmon, Aug 23, 2023
  23. Junio C HamanoAug 24, 2023
  24. Jonathan TanAug 24, 2023
  25. Junio C HamanoAug 24, 2023
  26. Josh SteadmonSep 21, 2023
  27. Junio C HamanoSep 21, 2023
  28. 4/4 config-parse: split library out of config.[c|h]Josh Steadmon, Aug 23, 2023
  29. Josh SteadmonAug 24, 2023
  30. 0/5 config-parse: create config parsing libraryJosh Steadmon, Sep 21, 2023
  31. 1/5 config: split out config_parse_optionsJosh Steadmon, Sep 21, 2023
  32. Jonathan TanOct 23, 2023
  33. Taylor BlauOct 23, 2023
  34. 5/5 config-parse: split library out of config.[c|h]Josh Steadmon, Sep 21, 2023
  35. Jonathan TanOct 23, 2023
  36. 2/5 config: split do_event() into start and flush operationsJosh Steadmon, Sep 21, 2023
  37. Jonathan TanOct 23, 2023
  38. 3/5 config: report config parse errors using cbJosh Steadmon, Sep 21, 2023
  39. Jonathan TanOct 23, 2023
  40. Taylor BlauOct 23, 2023
  41. Junio C HamanoOct 23, 2023
  42. 4/5 config.c: accept config_parse_options in git_config_from_stdinJosh Steadmon, Sep 21, 2023
  43. Jonathan TanOct 23, 2023
  44. Junio C HamanoOct 17, 2023
  45. Taylor BlauOct 23, 2023
  46. Junio C HamanoOct 23, 2023
  47. Jonathan TanOct 24, 2023
  48. Josh SteadmonOct 25, 2023
  49. Junio C HamanoOct 27, 2023

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.