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

Re: [PATCH 20/20] config: hide functions using `the_repository` by default

From
Justin Tobler <jltobler@gmail.com>
Date
Aug 9, 2024, 21:13 UTC
Message-ID
<oksb4qyur7ucqurshkp3232lk3ipqckcwbk56ulungkwozwsf5@w55hc5w6ml4h>
In-Reply-To
<43757f30770bf5a27fd8d7ac55a343185dbe62b3.1723013714.git.ps@pks.im>
On 24/08/07 08:58AM, Patrick Steinhardt wrote:
> The config subsytem provides a bunch of legacy functions that read or
s/subsytem/subsystem/
Show 9 quoted lines
> set configuration for `the_repository`. The use of those functions is
> discouraged, and it is easy to miss the implicit dependency on
> `the_repository` that calls to those functions may cause.
> 
> Move all config-related functions that use `the_repository` into a block
> that gets only conditionally compiled depending on whether or not the
> macro has been defined. This also removes all dependencies on that
> variable in "config.c", allowing us to remove the definition of said
> preprocessor macro.

Here we are making the same change done earlier to "path.h". Use of config functions that rely on `the_repository` implicitly now require the caller to define `USE_THE_REPOSITORY_VARIABLE` explicitly. Thus improving visibility of use.

> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
[snip]
Show 135 quoted lines
> +# ifdef USE_THE_REPOSITORY_VARIABLE
> +static inline void git_config(config_fn_t fn, void *data)
> +{
> +	repo_config(the_repository, fn, data);
> +}
> +
> +static inline void git_config_clear(void)
> +{
> +	repo_config_clear(the_repository);
> +}
> +
> +static inline int git_config_get(const char *key)
> +{
> +	return repo_config_get(the_repository, key);
> +}
> +
> +static inline int git_config_get_value(const char *key, const char **value)
> +{
> +	return repo_config_get_value(the_repository, key, value);
> +}
> +
> +static inline int git_config_get_value_multi(const char *key, const struct string_list **dest)
> +{
> +	return repo_config_get_value_multi(the_repository, key, dest);
> +}
> +
> +static inline int git_config_get_string_multi(const char *key,
> +				const struct string_list **dest)
> +{
> +	return repo_config_get_string_multi(the_repository, key, dest);
> +}
> +
> +static inline int git_config_get_string(const char *key, char **dest)
> +{
> +	return repo_config_get_string(the_repository, key, dest);
> +}
> +
> +static inline int git_config_get_string_tmp(const char *key, const char **dest)
> +{
> +	return repo_config_get_string_tmp(the_repository, key, dest);
> +}
> +
> +static inline int git_config_get_int(const char *key, int *dest)
> +{
> +	return repo_config_get_int(the_repository, key, dest);
> +}
> +
> +static inline int git_config_get_ulong(const char *key, unsigned long *dest)
> +{
> +	return repo_config_get_ulong(the_repository, key, dest);
> +}
> +
> +static inline int git_config_get_bool(const char *key, int *dest)
> +{
> +	return repo_config_get_bool(the_repository, key, dest);
> +}
> +
> +static inline int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest)
> +{
> +	return repo_config_get_bool_or_int(the_repository, key, is_bool, dest);
> +}
> +
> +static inline int git_config_get_maybe_bool(const char *key, int *dest)
> +{
> +	return repo_config_get_maybe_bool(the_repository, key, dest);
> +}
> +
> +static inline int git_config_get_pathname(const char *key, char **dest)
> +{
> +	return repo_config_get_pathname(the_repository, key, dest);
> +}
> +
> +static inline void git_config_set_in_file(const char *config_filename,
> +					  const char *key, const char *value)
> +{
> +	repo_config_set_in_file(the_repository, config_filename, key, value);
> +}
> +
> +static inline int git_config_set_gently(const char *key, const char *value)
> +{
> +	return repo_config_set_gently(the_repository, key, value);
> +}
> +
> +static inline void git_config_set(const char *key, const char *value)
> +{
> +	repo_config_set(the_repository, key, value);
> +}
> +
> +static inline int git_config_set_in_file_gently(
> +	const char *config_filename,
> +	const char *key,
> +	const char *comment,
> +	const char *value)
> +{
> +	return repo_config_set_in_file_gently(the_repository, config_filename,
> +					      key, comment, value);
> +}
> +
> +static inline int git_config_set_multivar_in_file_gently(
> +	const char *config_filename,
> +	const char *key, const char *value,
> +	const char *value_pattern,
> +	const char *comment,
> +	unsigned flags)
> +{
> +	return repo_config_set_multivar_in_file_gently(the_repository, config_filename,
> +						       key, value, value_pattern,
> +						       comment, flags);
> +}
> +
> +static inline void git_config_set_multivar_in_file(
> +	const char *config_filename,
> +	const char *key,
> +	const char *value,
> +	const char *value_pattern,
> +	unsigned flags)
> +{
> +	repo_config_set_multivar_in_file(the_repository, config_filename,
> +					 key, value, value_pattern, flags);
> +}
> +
> +static inline int git_config_set_multivar_gently(const char *key, const char *value,
> +				   const char *value_pattern, unsigned flags)
> +{
> +	return repo_config_set_multivar_gently(the_repository, key, value,
> +					       value_pattern, flags);
> +}
> +
> +static inline void git_config_set_multivar(const char *key, const char *value,
> +			     const char *value_pattern, unsigned flags)
> +{
> +	repo_config_set_multivar(the_repository, key, value,
> +				 value_pattern, flags);
> +}
> +# endif /* USE_THE_REPOSITORY_VARIABLE */

Once again, very neat to see this guarded behind `USE_THE_REPOSITORY_VARIABLE` now. :)

-Justin
Previous: Patrick SteinhardtNext: Ghanshyam Thakkar
Message 40 of 69 in “Stop using `the_repository` in "config.c"”
  1. 00/20 Stop using `the_repository` in "config.c"Patrick Steinhardt, Aug 7, 2024
  2. 01/20 path: expose `do_git_path()` as `repo_git_pathv()`Patrick Steinhardt, Aug 7, 2024
  3. Justin ToblerAug 9, 2024
  4. Patrick SteinhardtAug 13, 2024
  5. 02/20 path: expose `do_git_common_path()` as `strbuf_git_common_pathv()`Patrick Steinhardt, Aug 7, 2024
  6. Justin ToblerAug 9, 2024
  7. Junio C HamanoAug 9, 2024
  8. Patrick SteinhardtAug 13, 2024
  9. Junio C HamanoAug 13, 2024
  10. 03/20 editor: do not rely on `the_repository` for interactive editsPatrick Steinhardt, Aug 7, 2024
  11. Justin ToblerAug 9, 2024
  12. 04/20 hooks: remove implicit dependency on `the_repository`Patrick Steinhardt, Aug 7, 2024
  13. 05/20 path: stop relying on `the_repository` when reporting garbagePatrick Steinhardt, Aug 7, 2024
  14. 06/20 path: stop relying on `the_repository` in `worktree_git_path()`Patrick Steinhardt, Aug 7, 2024
  15. Justin ToblerAug 9, 2024
  16. Patrick SteinhardtAug 13, 2024
  17. 07/20 path: hide functions using `the_repository` by defaultPatrick Steinhardt, Aug 7, 2024
  18. Justin ToblerAug 9, 2024
  19. Patrick SteinhardtAug 13, 2024
  20. 08/20 config: introduce missing setters that take repo as parameterPatrick Steinhardt, Aug 7, 2024
  21. Justin ToblerAug 9, 2024
  22. Patrick SteinhardtAug 13, 2024
  23. 09/20 config: expose `repo_config_clear()`Patrick Steinhardt, Aug 7, 2024
  24. 10/20 config: pass repo to `git_config_get_index_threads()`Patrick Steinhardt, Aug 7, 2024
  25. 11/20 config: pass repo to `git_config_get_split_index()`Patrick Steinhardt, Aug 7, 2024
  26. 12/20 config: pass repo to `git_config_get_max_percent_split_change()`Patrick Steinhardt, Aug 7, 2024
  27. 13/20 config: pass repo to `git_config_get_expiry()`Patrick Steinhardt, Aug 7, 2024
  28. 14/20 config: pass repo to `git_config_get_expiry_in_days()`Patrick Steinhardt, Aug 7, 2024
  29. Justin ToblerAug 9, 2024
  30. Junio C HamanoAug 9, 2024
  31. 15/20 config: pass repo to `git_die_config()`Patrick Steinhardt, Aug 7, 2024
  32. 16/20 config: pass repo to functions that rename or copy sectionsPatrick Steinhardt, Aug 7, 2024
  33. 17/20 config: don't have setters depend on `the_repository`Patrick Steinhardt, Aug 7, 2024
  34. 18/20 config: don't depend on `the_repository` with branch conditionsPatrick Steinhardt, Aug 7, 2024
  35. Justin ToblerAug 9, 2024
  36. Patrick SteinhardtAug 13, 2024
  37. 19/20 global: prepare for hiding away repo-less config functionsPatrick Steinhardt, Aug 7, 2024
  38. Justin ToblerAug 9, 2024
  39. 20/20 config: hide functions using `the_repository` by defaultPatrick Steinhardt, Aug 7, 2024
  40. Justin ToblerAug 9, 2024
  41. Ghanshyam ThakkarAug 7, 2024
  42. Patrick SteinhardtAug 7, 2024
  43. 00/20 Stop using `the_repository` in "config.c"Patrick Steinhardt, Aug 13, 2024
  44. 01/20 path: expose `do_git_path()` as `repo_git_pathv()`Patrick Steinhardt, Aug 13, 2024
  45. 02/20 path: expose `do_git_common_path()` as `repo_common_pathv()`Patrick Steinhardt, Aug 13, 2024
  46. 03/20 editor: do not rely on `the_repository` for interactive editsPatrick Steinhardt, Aug 13, 2024
  47. 04/20 hooks: remove implicit dependency on `the_repository`Patrick Steinhardt, Aug 13, 2024
  48. 05/20 path: stop relying on `the_repository` when reporting garbagePatrick Steinhardt, Aug 13, 2024
  49. Calvin WanAug 14, 2024
  50. Patrick SteinhardtAug 15, 2024
  51. 06/20 path: stop relying on `the_repository` in `worktree_git_path()`Patrick Steinhardt, Aug 13, 2024
  52. 07/20 path: hide functions using `the_repository` by defaultPatrick Steinhardt, Aug 13, 2024
  53. 08/20 config: introduce missing setters that take repo as parameterPatrick Steinhardt, Aug 13, 2024
  54. 09/20 config: expose `repo_config_clear()`Patrick Steinhardt, Aug 13, 2024
  55. 10/20 config: pass repo to `git_config_get_index_threads()`Patrick Steinhardt, Aug 13, 2024
  56. 11/20 config: pass repo to `git_config_get_split_index()`Patrick Steinhardt, Aug 13, 2024
  57. 12/20 config: pass repo to `git_config_get_max_percent_split_change()`Patrick Steinhardt, Aug 13, 2024
  58. 13/20 config: pass repo to `git_config_get_expiry()`Patrick Steinhardt, Aug 13, 2024
  59. 14/20 config: pass repo to `git_config_get_expiry_in_days()`Patrick Steinhardt, Aug 13, 2024
  60. 15/20 config: pass repo to `git_die_config()`Patrick Steinhardt, Aug 13, 2024
  61. 16/20 config: pass repo to functions that rename or copy sectionsPatrick Steinhardt, Aug 13, 2024
  62. 17/20 config: don't have setters depend on `the_repository`Patrick Steinhardt, Aug 13, 2024
  63. 18/20 config: don't depend on `the_repository` with branch conditionsPatrick Steinhardt, Aug 13, 2024
  64. 19/20 global: prepare for hiding away repo-less config functionsPatrick Steinhardt, Aug 13, 2024
  65. 20/20 config: hide functions using `the_repository` by defaultPatrick Steinhardt, Aug 13, 2024
  66. Junio C HamanoAug 13, 2024
  67. Calvin WanAug 14, 2024
  68. Patrick SteinhardtAug 15, 2024
  69. Justin ToblerAug 15, 2024

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.