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

Re: [PATCH 08/20] config: introduce missing setters that take repo as parameter

From
Justin Tobler <jltobler@gmail.com>
Date
Aug 9, 2024, 20:07 UTC
Message-ID
<rg5j5ehur5a2qvpt65ezfub5dmmqrbn7if5f2r7ibweuupsnm2@qeciml3qvdvy>
In-Reply-To
<feae2ad31ac91baae75c46c22c5c3ef3b58c1897.1723013714.git.ps@pks.im>
On 24/08/07 08:57AM, Patrick Steinhardt wrote:
> While we already provide some of the config-setting interfaces with a
> `struct repository` as parameter, others only have a variant that
> implicitly depend on `the_repository`. Fill in those gaps such that we
s/depend/depends/
Show 18 quoted lines
> can start to deprecate the repo-less variants.
> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  config.c | 93 ++++++++++++++++++++++++++++++++++++++++++++------------
>  config.h | 15 ++++++++-
>  2 files changed, 87 insertions(+), 21 deletions(-)
> 
> diff --git a/config.c b/config.c
> index 6421894614..ac89b708e7 100644
> --- a/config.c
> +++ b/config.c
> @@ -3178,21 +3178,39 @@ static void maybe_remove_section(struct config_store_data *store,
>  		*end_offset = store->parsed[store->parsed_nr - 1].end;
>  }
>  
> +int repo_config_set_in_file_gently(struct repository *r, const char *config_filename,
> +				   const char *key, const char *comment, const char *value)

Instead of prefixing with `repo_`, should we instead use the `config_` prefix? Maybe `config_repo_`? It might be nice for names to align with the config subsystem here.

[snip]
Show 57 quoted lines
> diff --git a/config.h b/config.h
> index 54b47dec9e..b13e1bfb8d 100644
> --- a/config.h
> +++ b/config.h
> @@ -298,14 +298,18 @@ int git_config_pathname(char **, const char *, const char *);
>  int git_config_expiry_date(timestamp_t *, const char *, const char *);
>  int git_config_color(char *, const char *, const char *);
>  int git_config_set_in_file_gently(const char *, const char *, const char *, const char *);
> +int repo_config_set_in_file_gently(struct repository *r, const char *config_filename,
> +				   const char *key, const char *comment, const char *value);
>  
>  /**
>   * write config values to a specific config file, takes a key/value pair as
>   * parameter.
>   */
>  void git_config_set_in_file(const char *, const char *, const char *);
> +void repo_config_set_in_file(struct repository *, const char *, const char *, const char *);
>  
>  int git_config_set_gently(const char *, const char *);
> +int repo_config_set_gently(struct repository *r, const char *, const char *);
>  
>  /**
>   * Write a config value that should apply to the current worktree. If
> @@ -318,6 +322,7 @@ int repo_config_set_worktree_gently(struct repository *, const char *, const cha
>   * write config values to `.git/config`, takes a key/value pair as parameter.
>   */
>  void git_config_set(const char *, const char *);
> +void repo_config_set(struct repository *, const char *, const char *);
>  
>  int git_config_parse_key(const char *, char **, size_t *);
>  
> @@ -341,9 +346,11 @@ int git_config_parse_key(const char *, char **, size_t *);
>  #define CONFIG_FLAGS_FIXED_VALUE (1 << 1)
>  
>  int git_config_set_multivar_gently(const char *, const char *, const char *, unsigned);
> -void git_config_set_multivar(const char *, const char *, const char *, unsigned);
>  int repo_config_set_multivar_gently(struct repository *, const char *, const char *, const char *, unsigned);
> +void git_config_set_multivar(const char *, const char *, const char *, unsigned);
> +void repo_config_set_multivar(struct repository *r, const char *, const char *, const char *, unsigned);
>  int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, const char *, unsigned);
> +int repo_config_set_multivar_in_file_gently(struct repository *, const char *, const char *, const char *, const char *, const char *, unsigned);
>  
>  char *git_config_prepare_comment_string(const char *);
>  
> @@ -372,6 +379,12 @@ void git_config_set_multivar_in_file(const char *config_filename,
>  				     const char *value,
>  				     const char *value_pattern,
>  				     unsigned flags);
> +void repo_config_set_multivar_in_file(struct repository *r,
> +				      const char *config_filename,
> +				      const char *key,
> +				      const char *value,
> +				      const char *value_pattern,
> +				      unsigned flags);
>  
>  /**
>   * rename or remove sections in the config file

The rest of this patch is simply implementing variations of existing functions that explicitly inject a repository and looks good to me.

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 21 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.