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

Re: [PATCH v7 3/9] config API: add and use a "git_config_get()" family of functions

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 14, 2023, 11:21 UTC
Message-ID
<230314.86pm9by3oz.gmgdl@evledraar.gmail.com>
In-Reply-To
<kl6ledpxhi3t.fsf@chooglen-macbookpro.roam.corp.google.com>
On Thu, Mar 09 2023, Glen Choo wrote:
Show 25 quoted lines
> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> diff --git a/config.h b/config.h
>> index 7606246531a..7dd62ca81bf 100644
>> --- a/config.h
>> +++ b/config.h
>> @@ -465,6 +465,9 @@ void git_configset_clear(struct config_set *cs);
>>   * value in the 'dest' pointer.
>>   */
>>  
>> +RESULT_MUST_BE_USED
>> +int git_configset_get(struct config_set *cs, const char *key);
>
> IIRC, feedback on v4 [1] mentioned that since git_configset_get() can
> return negative values, it probably shouldn't come under this comment:
>
>   /*
>   * These functions return 1 if not found, and 0 if found, leaving the found
>   * value in the 'dest' pointer.
>   */
>
> I think moving it to before the comment would suffice, maybe with a
> pointer to the corresponding repo_* or git_*.
>
> 1. https://lore.kernel.org/git/xmqqv8kjpqoe.fsf@gitster.g/

I'll fix this, FWIW I was trying to juggle this so that I'd avoid future churn for a subsequent cleanup of the interface & documentation...

Show 80 quoted lines
>> @@ -485,6 +488,14 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha
>>  /* Functions for reading a repository's config */
>>  struct repository;
>>  void repo_config(struct repository *repo, config_fn_t fn, void *data);
>> +
>> +/**
>> + * Run only the discover part of the repo_config_get_*() functions
>> + * below, in addition to 1 if not found, returns negative values on
>> + * error (e.g. if the key itself is invalid).
>> + */
>> +RESULT_MUST_BE_USED
>> +int repo_config_get(struct repository *repo, const char *key);
>>  int repo_config_get_value(struct repository *repo,
>>  			  const char *key, const char **value);
>>  const struct string_list *repo_config_get_value_multi(struct repository *repo,
>> @@ -521,8 +532,15 @@ void git_protected_config(config_fn_t fn, void *data);
>>   * manner, the config API provides two functions `git_config_get_value`
>>   * and `git_config_get_value_multi`. They both read values from an internal
>>   * cache generated previously from reading the config files.
>> + *
>> + * For those git_config_get*() functions that aren't documented,
>> + * consult the corresponding repo_config_get*() function's
>> + * documentation.
>>   */
>
> After rereading config.h, I really appreciate comments like this that
> try to control the documentation load. We have configset*, repo* and
> git*, _and_ the comments are spread out hapzardly around config.h with
> no pointers to the corresponding comments. I think we're overdue for
> reorganization, and this sort of comment helps a lot with that.
>
> As a suggestion, it seems like the git_config_get*() functions are
> actually the better documented ones - nearly all of them have comments,
> whereas the repo_config_get_*() ones typically don't, so maybe adding
> the comment to git_config_get() instead of repo_config_get() would be
> better for this series:
>
> ----- >8 --------- >8 --------- >8 --------- >8 --------- >8 ----
>   diff --git a/config.h b/config.h
>   index 7dd62ca81b..aa9bdf8df4 100644
>   --- a/config.h
>   +++ b/config.h
>   @@ -489,10 +489,10 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha
>   struct repository;
>   void repo_config(struct repository *repo, config_fn_t fn, void *data);
>
>   -/**
>   - * Run only the discover part of the repo_config_get_*() functions
>   - * below, in addition to 1 if not found, returns negative values on
>   - * error (e.g. if the key itself is invalid).
>   +/*
>   + * These repo_config_get*() functions each correspond to to a git_config_get*()
>   + * function. Consult the corresponding git_config_get*() documentation for more
>   + * information.
>     */
>   RESULT_MUST_BE_USED
>   int repo_config_get(struct repository *repo, const char *key);
>   @@ -532,12 +532,13 @@ void git_protected_config(config_fn_t fn, void *data);
>     * manner, the config API provides two functions `git_config_get_value`
>     * and `git_config_get_value_multi`. They both read values from an internal
>     * cache generated previously from reading the config files.
>   - *
>   - * For those git_config_get*() functions that aren't documented,
>   - * consult the corresponding repo_config_get*() function's
>   - * documentation.
>     */
>
>   +/**
>   + * Run only the discover part of the repo_config_get_*() functions
>   + * below, in addition to 1 if not found, returns negative values on
>   + * error (e.g. if the key itself is invalid).
>   + */
>   RESULT_MUST_BE_USED
>   int git_config_get(const char *key);
> ----- >8 --------- >8 --------- >8 --------- >8 --------- >8 ----
>
> Though in the long run, I'd prefer having the docs on the more "general"
> APIs (configset_*, repo_*) instead of the more "specific" ones (git_*).
> Perhaps you had a similar intent while making this change, but I think
> this might be better left as a cleanup.

...yes, that's why I put the primary documentation on the repo_*() version here, as with other implicit "the_repository" and "the_index" migrations I think we should be moving towards using those, and eventually removing the non-repo_*() ones (in some cases they're almost unused, or it's easy enough to migrate the rest).

But let's leave that for some future cleanup, but for now I think it's OK to leave this slight inconsistency in place, with an eye to such future consolidation.

> As an aside, I really appreciate your effort in sticking with the config
> interface work. I think it's grown quite unruly, and it's worth trying
> to tame it.
Thanks, hopefully a trivial & upcoming v8 will be the last version...
Previous: Glen ChooNext: Ævar Arnfjörð Bjarmason
Message 111 of 134 in “config API: make "multi" safe, fix numerous segfaults”
  1. 00/10 config API: make "multi" safe, fix numerous segfaultsÆvar Arnfjörð Bjarmason, Oct 26, 2022
  2. 01/10 config API: have *_multi() return an "int" and take a "dest"Ævar Arnfjörð Bjarmason, Oct 26, 2022
  3. SZEDER GáborOct 26, 2022
  4. Ævar Arnfjörð BjarmasonOct 26, 2022
  5. Junio C HamanoOct 27, 2022
  6. 02/10 for-each-repo: error on bad --configÆvar Arnfjörð Bjarmason, Oct 26, 2022
  7. 03/10 config API: mark *_multi() with RESULT_MUST_BE_USEDÆvar Arnfjörð Bjarmason, Oct 26, 2022
  8. 04/10 string-list API: mark "struct_string_list" to "for_each_string_list" constÆvar Arnfjörð Bjarmason, Oct 26, 2022
  9. Junio C HamanoOct 27, 2022
  10. Ævar Arnfjörð BjarmasonOct 27, 2022
  11. 05/10 string-list API: make has_string() and list_lookup() "const"Ævar Arnfjörð Bjarmason, Oct 26, 2022
  12. 06/10 builtin/gc.c: use "unsorted_string_list_has_string()" where appropriateÆvar Arnfjörð Bjarmason, Oct 26, 2022
  13. Junio C HamanoOct 27, 2022
  14. Ævar Arnfjörð BjarmasonOct 27, 2022
  15. 08/10 config tests: add "NULL" tests for *_get_value_multi()Ævar Arnfjörð Bjarmason, Oct 26, 2022
  16. Junio C HamanoOct 27, 2022
  17. 07/10 config API: add and use "lookup_value" functionsÆvar Arnfjörð Bjarmason, Oct 26, 2022
  18. Junio C HamanoOct 27, 2022
  19. 10/10 for-each-repo: with bad config, don't conflate <path> and <cmd>Ævar Arnfjörð Bjarmason, Oct 26, 2022
  20. 09/10 config API: add "string" version of *_value_multi(), fix segfaultsÆvar Arnfjörð Bjarmason, Oct 26, 2022
  21. Junio C HamanoOct 27, 2022
  22. Junio C HamanoOct 27, 2022
  23. Ævar Arnfjörð BjarmasonOct 27, 2022
  24. Junio C HamanoOct 28, 2022
  25. Ævar Arnfjörð BjarmasonOct 31, 2022
  26. Junio C HamanoOct 27, 2022
  27. 0/9 config API: make "multi" safe, fix numerous segfaultsÆvar Arnfjörð Bjarmason, Nov 1, 2022
  28. 1/9 for-each-repo tests: test bad --config keysÆvar Arnfjörð Bjarmason, Nov 1, 2022
  29. 2/9 config tests: cover blind spots in git_die_config() testsÆvar Arnfjörð Bjarmason, Nov 1, 2022
  30. 3/9 config tests: add "NULL" tests for *_get_value_multi()Ævar Arnfjörð Bjarmason, Nov 1, 2022
  31. 4/9 versioncmp.c: refactor config reading next commitÆvar Arnfjörð Bjarmason, Nov 1, 2022
  32. 5/9 config API: have *_multi() return an "int" and take a "dest"Ævar Arnfjörð Bjarmason, Nov 1, 2022
  33. 7/9 config API users: test for *_get_value_multi() segfaultsÆvar Arnfjörð Bjarmason, Nov 1, 2022
  34. 6/9 for-each-repo: error on bad --configÆvar Arnfjörð Bjarmason, Nov 1, 2022
  35. 8/9 config API: add "string" version of *_value_multi(), fix segfaultsÆvar Arnfjörð Bjarmason, Nov 1, 2022
  36. 9/9 for-each-repo: with bad config, don't conflate <path> and <cmd>Ævar Arnfjörð Bjarmason, Nov 1, 2022
  37. Taylor BlauNov 2, 2022
  38. 0/9 config API: make "multi" safe, fix numerous segfaultsÆvar Arnfjörð Bjarmason, Nov 25, 2022
  39. 1/9 for-each-repo tests: test bad --config keysÆvar Arnfjörð Bjarmason, Nov 25, 2022
  40. 4/9 versioncmp.c: refactor config reading next commitÆvar Arnfjörð Bjarmason, Nov 25, 2022
  41. 3/9 config tests: add "NULL" tests for *_get_value_multi()Ævar Arnfjörð Bjarmason, Nov 25, 2022
  42. Glen ChooJan 19, 2023
  43. 2/9 config tests: cover blind spots in git_die_config() testsÆvar Arnfjörð Bjarmason, Nov 25, 2022
  44. Glen ChooJan 19, 2023
  45. 6/9 for-each-repo: error on bad --configÆvar Arnfjörð Bjarmason, Nov 25, 2022
  46. 5/9 config API: have *_multi() return an "int" and take a "dest"Ævar Arnfjörð Bjarmason, Nov 25, 2022
  47. Glen ChooJan 19, 2023
  48. 7/9 config API users: test for *_get_value_multi() segfaultsÆvar Arnfjörð Bjarmason, Nov 25, 2022
  49. Glen ChooJan 19, 2023
  50. 8/9 config API: add "string" version of *_value_multi(), fix segfaultsÆvar Arnfjörð Bjarmason, Nov 25, 2022
  51. Glen ChooJan 19, 2023
  52. 9/9 for-each-repo: with bad config, don't conflate <path> and <cmd>Ævar Arnfjörð Bjarmason, Nov 25, 2022
  53. Glen ChooJan 19, 2023
  54. 0/9 config API: make "multi" safe, fix numerous segfaultsÆvar Arnfjörð Bjarmason, Feb 2, 2023
  55. 1/9 config tests: cover blind spots in git_die_config() testsÆvar Arnfjörð Bjarmason, Feb 2, 2023
  56. Junio C HamanoFeb 3, 2023
  57. Glen ChooFeb 6, 2023
  58. 2/9 config tests: add "NULL" tests for *_get_value_multi()Ævar Arnfjörð Bjarmason, Feb 2, 2023
  59. Junio C HamanoFeb 2, 2023
  60. Glen ChooFeb 6, 2023
  61. Ævar Arnfjörð BjarmasonFeb 6, 2023
  62. Glen ChooFeb 6, 2023
  63. 4/9 versioncmp.c: refactor config reading next commitÆvar Arnfjörð Bjarmason, Feb 2, 2023
  64. Junio C HamanoFeb 3, 2023
  65. 3/9 config API: add and use a "git_config_get()" family of functionsÆvar Arnfjörð Bjarmason, Feb 2, 2023
  66. Junio C HamanoFeb 2, 2023
  67. Ævar Arnfjörð BjarmasonFeb 7, 2023
  68. Glen ChooFeb 6, 2023
  69. Glen ChooFeb 6, 2023
  70. Ævar Arnfjörð BjarmasonFeb 7, 2023
  71. 6/9 for-each-repo: error on bad --configÆvar Arnfjörð Bjarmason, Feb 2, 2023
  72. Glen ChooFeb 6, 2023
  73. 5/9 config API: have *_multi() return an "int" and take a "dest"Ævar Arnfjörð Bjarmason, Feb 2, 2023
  74. 7/9 config API users: test for *_get_value_multi() segfaultsÆvar Arnfjörð Bjarmason, Feb 2, 2023
  75. 9/9 for-each-repo: with bad config, don't conflate <path> and <cmd>Ævar Arnfjörð Bjarmason, Feb 2, 2023
  76. 8/9 config API: add "string" version of *_value_multi(), fix segfaultsÆvar Arnfjörð Bjarmason, Feb 2, 2023
  77. Glen ChooFeb 6, 2023
  78. 00/10 config API: make "multi" safe, fix segfaults, propagate "ret"Ævar Arnfjörð Bjarmason, Feb 7, 2023
  79. 01/10 config tests: cover blind spots in git_die_config() testsÆvar Arnfjörð Bjarmason, Feb 7, 2023
  80. 02/10 config tests: add "NULL" tests for *_get_value_multi()Ævar Arnfjörð Bjarmason, Feb 7, 2023
  81. Glen ChooFeb 9, 2023
  82. 04/10 versioncmp.c: refactor config reading next commitÆvar Arnfjörð Bjarmason, Feb 7, 2023
  83. 03/10 config API: add and use a "git_config_get()" family of functionsÆvar Arnfjörð Bjarmason, Feb 7, 2023
  84. Glen ChooFeb 9, 2023
  85. Ævar Arnfjörð BjarmasonFeb 9, 2023
  86. Ævar Arnfjörð BjarmasonFeb 9, 2023
  87. Glen ChooFeb 9, 2023
  88. 05/10 config API: have *_multi() return an "int" and take a "dest"Ævar Arnfjörð Bjarmason, Feb 7, 2023
  89. 06/10 config API: don't lose the git_*get*() return valuesÆvar Arnfjörð Bjarmason, Feb 7, 2023
  90. 07/10 for-each-repo: error on bad --configÆvar Arnfjörð Bjarmason, Feb 7, 2023
  91. 08/10 config API users: test for *_get_value_multi() segfaultsÆvar Arnfjörð Bjarmason, Feb 7, 2023
  92. 09/10 config API: add "string" version of *_value_multi(), fix segfaultsÆvar Arnfjörð Bjarmason, Feb 7, 2023
  93. 10/10 for-each-repo: with bad config, don't conflate <path> and <cmd>Ævar Arnfjörð Bjarmason, Feb 7, 2023
  94. Junio C HamanoFeb 7, 2023
  95. 0/9 config API: make "multi" safe, fix segfaults, propagate "ret"Ævar Arnfjörð Bjarmason, Mar 7, 2023
  96. 1/9 config tests: cover blind spots in git_die_config() testsÆvar Arnfjörð Bjarmason, Mar 7, 2023
  97. 4/9 versioncmp.c: refactor config reading next commitÆvar Arnfjörð Bjarmason, Mar 7, 2023
  98. 6/9 for-each-repo: error on bad --configÆvar Arnfjörð Bjarmason, Mar 7, 2023
  99. 3/9 config API: add and use a "git_config_get()" family of functionsÆvar Arnfjörð Bjarmason, Mar 7, 2023
  100. 5/9 config API: have *_multi() return an "int" and take a "dest"Ævar Arnfjörð Bjarmason, Mar 7, 2023
  101. 7/9 config API users: test for *_get_value_multi() segfaultsÆvar Arnfjörð Bjarmason, Mar 7, 2023
  102. 8/9 config API: add "string" version of *_value_multi(), fix segfaultsÆvar Arnfjörð Bjarmason, Mar 7, 2023
  103. 9/9 for-each-repo: with bad config, don't conflate <path> and <cmd>Ævar Arnfjörð Bjarmason, Mar 7, 2023
  104. 2/9 config tests: add "NULL" tests for *_get_value_multi()Ævar Arnfjörð Bjarmason, Mar 7, 2023
  105. Glen ChooMar 8, 2023
  106. 0/9 config API: make "multi" safe, fix segfaults, propagate "ret"Ævar Arnfjörð Bjarmason, Mar 8, 2023
  107. 1/9 config tests: cover blind spots in git_die_config() testsÆvar Arnfjörð Bjarmason, Mar 8, 2023
  108. 2/9 config tests: add "NULL" tests for *_get_value_multi()Ævar Arnfjörð Bjarmason, Mar 8, 2023
  109. 3/9 config API: add and use a "git_config_get()" family of functionsÆvar Arnfjörð Bjarmason, Mar 8, 2023
  110. Glen ChooMar 9, 2023
  111. Ævar Arnfjörð BjarmasonMar 14, 2023
  112. 4/9 versioncmp.c: refactor config reading next commitÆvar Arnfjörð Bjarmason, Mar 8, 2023
  113. 7/9 config API users: test for *_get_value_multi() segfaultsÆvar Arnfjörð Bjarmason, Mar 8, 2023
  114. 6/9 for-each-repo: error on bad --configÆvar Arnfjörð Bjarmason, Mar 8, 2023
  115. 8/9 config API: add "string" version of *_value_multi(), fix segfaultsÆvar Arnfjörð Bjarmason, Mar 8, 2023
  116. 9/9 for-each-repo: with bad config, don't conflate <path> and <cmd>Ævar Arnfjörð Bjarmason, Mar 8, 2023
  117. 5/9 config API: have *_multi() return an "int" and take a "dest"Ævar Arnfjörð Bjarmason, Mar 8, 2023
  118. Glen ChooMar 9, 2023
  119. Glen ChooMar 9, 2023
  120. Junio C HamanoMar 9, 2023
  121. 0/9 config API: make "multi" safe, fix segfaults, propagate "ret"Ævar Arnfjörð Bjarmason, Mar 28, 2023
  122. 1/9 config tests: cover blind spots in git_die_config() testsÆvar Arnfjörð Bjarmason, Mar 28, 2023
  123. 2/9 config tests: add "NULL" tests for *_get_value_multi()Ævar Arnfjörð Bjarmason, Mar 28, 2023
  124. 3/9 config API: add and use a "git_config_get()" family of functionsÆvar Arnfjörð Bjarmason, Mar 28, 2023
  125. 4/9 versioncmp.c: refactor config reading next commitÆvar Arnfjörð Bjarmason, Mar 28, 2023
  126. 5/9 config API: have *_multi() return an "int" and take a "dest"Ævar Arnfjörð Bjarmason, Mar 28, 2023
  127. 6/9 for-each-repo: error on bad --configÆvar Arnfjörð Bjarmason, Mar 28, 2023
  128. 8/9 config API: add "string" version of *_value_multi(), fix segfaultsÆvar Arnfjörð Bjarmason, Mar 28, 2023
  129. 7/9 config API users: test for *_get_value_multi() segfaultsÆvar Arnfjörð Bjarmason, Mar 28, 2023
  130. 9/9 for-each-repo: with bad config, don't conflate <path> and <cmd>Ævar Arnfjörð Bjarmason, Mar 28, 2023
  131. SZEDER GáborApr 7, 2023
  132. Glen ChooMar 28, 2023
  133. Junio C HamanoMar 28, 2023
  134. Junio C HamanoMar 29, 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.