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

Re: [PATCH 1/6] config.c: plumb config_source through static fns

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 3, 2023, 18:02 UTC
Message-ID
<xmqqh6v1g1d3.fsf@gitster.g>
In-Reply-To
<ad513d832d8267f9e4805db5e7a9e8915fc62a23.1677631097.git.gitgitgadget@gmail.com>
"Glen Choo via GitGitGadget" <gitgitgadget@gmail.com> writes:
> -static int handle_path_include(const char *path, struct config_include_data *inc)
> +static int handle_path_include(struct config_source *cs, const char *path,
> +			       struct config_include_data *inc)

Because handle_path_include() has no remaining reference to cf after this patch, it may make sense to name the parameter "cf", instead of "cs", taking advantage of the fact that it will cover/hide the global.

> -static int prepare_include_condition_pattern(struct strbuf *pat)
> +static int prepare_include_condition_pattern(struct config_source *cs,
> +					     struct strbuf *pat)
Ditto.
> -static int include_by_gitdir(const struct config_options *opts,
> +static int include_by_gitdir(struct config_source *cs,
> +			     const struct config_options *opts,
>  			     const char *cond, size_t cond_len, int icase)
Ditto.
> +static int include_condition_is_true(struct config_source *cs,
> +				     struct config_include_data *inc,
>  				     const char *cond, size_t cond_len)
Ditto.
> @@ -441,16 +445,16 @@ static int git_config_include(const char *var, const char *value, void *data)

Adding a member to the callback data struct to pass cf around would be the natural next step, I presume. I wonder if that makes the result too big if it is done in this same commit. I suspect that it would be easier to grok the whole picture if it were done in the same commit, though.

If not (IOW, if we deliberately leave some use of the global in the callchains unfixed with this step), it may make the resulting patch much easier to read if you (1) rename the global to a longer name that stands out more, e.g. cf_global, and (2) add a new parameter 'cf' to these helper functions and pass 'cf_global' through to the callchain.

> -static int get_next_char(void)
> +static int get_next_char(struct config_source *cs)
Ditto for "cs" -> "cf".
> -static char *parse_value(void)
> +static char *parse_value(struct config_source *cs)
Ditto.
> -static int get_value(config_fn_t fn, void *data, struct strbuf *name)
> +static int get_value(struct config_source *cs, config_fn_t fn, void *data,
> +		     struct strbuf *name)
Ditto.
> -static int get_extended_base_var(struct strbuf *name, int c)
> +static int get_extended_base_var(struct config_source *cs, struct strbuf *name,
> +				 int c)
Ditto.
> -static int get_base_var(struct strbuf *name)
> +static int get_base_var(struct config_source *cs, struct strbuf *name)
Ditto.
> -static int do_event(enum config_event_t type, struct parse_event_data *data)
> +static int do_event(struct config_source *cs, enum config_event_t type,
> +		    struct parse_event_data *data)
Ditto.
Show 5 quoted lines
> -static int git_parse_source(config_fn_t fn, void *data,
> -			    const struct config_options *opts)
> +static int git_parse_source(struct config_source *cs, config_fn_t fn,
> +			    void *data, const struct config_options *opts)
>  {
Ditto.
> -static void die_bad_number(const char *name, const char *value)
> +static void die_bad_number(struct config_source *cs, const char *name,
> +			   const char *value)
Ditto.
Show 6 quoted lines
> @@ -1304,7 +1312,7 @@ int git_config_int(const char *name, const char *value)
>  {
>  	int ret;
>  	if (!git_parse_int(value, &ret))
> -		die_bad_number(name, value);
> +		die_bad_number(cf, name, value);

And using a more visible name like cf_global will leave us a reminder here what is remaining to be converted, like this place and the callback function driven by config_with_options().

Previous: Glen Choo via GitGitGadgetNext: Glen Choo via GitGitGadget
Message 4 of 72 in “[RFC] config.c: use struct for config reading state”
  1. 0/6 [RFC] config.c: use struct for config reading stateGlen Choo via GitGitGadget, Mar 1, 2023
  2. 2/6 config.c: don't assign to "cf" directlyGlen Choo via GitGitGadget, Mar 1, 2023
  3. 1/6 config.c: plumb config_source through static fnsGlen Choo via GitGitGadget, Mar 1, 2023
  4. Junio C HamanoMar 3, 2023
  5. 3/6 config.c: create config_reader and the_readerGlen Choo via GitGitGadget, Mar 1, 2023
  6. Junio C HamanoMar 3, 2023
  7. 5/6 config.c: remove current_config_kviGlen Choo via GitGitGadget, Mar 1, 2023
  8. Calvin WanMar 6, 2023
  9. 4/6 config.c: plumb the_reader through callbacksGlen Choo via GitGitGadget, Mar 1, 2023
  10. Ævar Arnfjörð BjarmasonMar 8, 2023
  11. Glen ChooMar 8, 2023
  12. Junio C HamanoMar 8, 2023
  13. 6/6 config.c: remove current_parsing_scopeGlen Choo via GitGitGadget, Mar 1, 2023
  14. Jonathan TanMar 6, 2023
  15. Glen ChooMar 6, 2023
  16. Jonathan TanMar 6, 2023
  17. Ævar Arnfjörð BjarmasonMar 8, 2023
  18. Glen ChooMar 8, 2023
  19. Ævar Arnfjörð BjarmasonMar 7, 2023
  20. Glen ChooMar 7, 2023
  21. Ævar Arnfjörð BjarmasonMar 7, 2023
  22. Junio C HamanoMar 7, 2023
  23. Glen ChooMar 7, 2023
  24. Ævar Arnfjörð BjarmasonMar 8, 2023
  25. Glen ChooMar 8, 2023
  26. 0/8 config.c: use struct for config reading stateGlen Choo via GitGitGadget, Mar 16, 2023
  27. 2/8 config.c: don't assign to "cf_global" directlyGlen Choo via GitGitGadget, Mar 16, 2023
  28. Jonathan TanMar 16, 2023
  29. Junio C HamanoMar 16, 2023
  30. Glen ChooMar 16, 2023
  31. 1/8 config.c: plumb config_source through static fnsGlen Choo via GitGitGadget, Mar 16, 2023
  32. Jonathan TanMar 16, 2023
  33. 3/8 config.c: create config_reader and the_readerGlen Choo via GitGitGadget, Mar 16, 2023
  34. Jonathan TanMar 16, 2023
  35. 4/8 config.c: plumb the_reader through callbacksGlen Choo via GitGitGadget, Mar 16, 2023
  36. 6/8 config.c: remove current_parsing_scopeGlen Choo via GitGitGadget, Mar 16, 2023
  37. 5/8 config.c: remove current_config_kviGlen Choo via GitGitGadget, Mar 16, 2023
  38. 7/8 config: report cached filenames in die_bad_number()Glen Choo via GitGitGadget, Mar 16, 2023
  39. Jonathan TanMar 16, 2023
  40. Glen ChooMar 16, 2023
  41. 8/8 config.c: rename "struct config_source cf"Glen Choo via GitGitGadget, Mar 16, 2023
  42. Glen ChooMar 16, 2023
  43. Jonathan TanMar 16, 2023
  44. 0/5 bypass config.c global state with configsetÆvar Arnfjörð Bjarmason, Mar 17, 2023
  45. 1/5 config.h: move up "struct key_value_info"Ævar Arnfjörð Bjarmason, Mar 17, 2023
  46. 2/5 config.c: use "enum config_origin_type", not "int"Ævar Arnfjörð Bjarmason, Mar 17, 2023
  47. 3/5 config API: add a config_origin_type_name() helperÆvar Arnfjörð Bjarmason, Mar 17, 2023
  48. 4/5 config.c: refactor configset_iter()Ævar Arnfjörð Bjarmason, Mar 17, 2023
  49. 5/5 config API: add and use a repo_config_kvi()Ævar Arnfjörð Bjarmason, Mar 17, 2023
  50. Junio C HamanoMar 17, 2023
  51. Jonathan TanMar 17, 2023
  52. Junio C HamanoMar 17, 2023
  53. Glen ChooMar 17, 2023
  54. Glen ChooMar 17, 2023
  55. Glen ChooMar 17, 2023
  56. Ævar Arnfjörð BjarmasonMar 29, 2023
  57. 0/8 config.c: use struct for config reading stateGlen Choo via GitGitGadget, Mar 28, 2023
  58. 1/8 config.c: plumb config_source through static fnsGlen Choo via GitGitGadget, Mar 28, 2023
  59. 2/8 config.c: don't assign to "cf_global" directlyGlen Choo via GitGitGadget, Mar 28, 2023
  60. 3/8 config.c: create config_reader and the_readerGlen Choo via GitGitGadget, Mar 28, 2023
  61. Ævar Arnfjörð BjarmasonMar 29, 2023
  62. Junio C HamanoMar 29, 2023
  63. Glen ChooMar 29, 2023
  64. Glen ChooMar 30, 2023
  65. 4/8 config.c: plumb the_reader through callbacksGlen Choo via GitGitGadget, Mar 28, 2023
  66. 5/8 config.c: remove current_config_kviGlen Choo via GitGitGadget, Mar 28, 2023
  67. 6/8 config.c: remove current_parsing_scopeGlen Choo via GitGitGadget, Mar 28, 2023
  68. 7/8 config: report cached filenames in die_bad_number()Glen Choo via GitGitGadget, Mar 28, 2023
  69. 8/8 config.c: rename "struct config_source cf"Glen Choo via GitGitGadget, Mar 28, 2023
  70. Glen ChooMar 28, 2023
  71. Junio C HamanoMar 28, 2023
  72. Glen ChooMar 28, 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.