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

Re: [PATCH 1/7] builtin/verify-tag: stop using `the_repository`

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 17, 2025, 10:22 UTC
Message-ID
<Z7MN8-9rzf7h9zZi@pks.im>
In-Reply-To
<CAPSxiM8vcH_csM21vtF11APtxfNy_QC91mfYkctaSP-8TyPmyA@mail.gmail.com>
On Mon, Feb 17, 2025 at 03:35:05PM +0530, Usman Akinyemi wrote:
Show 41 quoted lines
> On Mon, Feb 17, 2025 at 12:25 PM Patrick Steinhardt <ps@pks.im> wrote:
> >
> > On Sat, Feb 15, 2025 at 04:27:17AM +0530, Usman Akinyemi wrote:
> > > @@ -35,7 +34,8 @@ int cmd_verify_tag(int argc,
> > >               OPT_END()
> > >       };
> > >
> > > -     git_config(git_default_config, NULL);
> > > +     if (repo)
> > > +             repo_config(repo, git_default_config, NULL);
> > >
> >
> > I recently noticed that we have `usage_with_options_if_asked()`. Should
> > we use that function rather than making the call to `git_config()`
> > conditional? Otherwise it's not obvious why we have the conditional in
> > the first place.
> Hi Patrick,
> 
> I think the function is `show_usage_with_options_if_asked()`. The function
> is quite different from `git_config()` or the `repo_config()`.  The
> config function consults the configuration file for setting up config
> values and it uses the `repo` variable during this. While
> `show_usage_with_options_if_asked()` is used when the "-h" option is
> passed to the builtin functions to display the help string.
> 
> In a case when "-h" is passed to the builtin functions which use the
> RUN_SETUP macro, the `repo` config will be NULL.
> 
> There are some builtin commands functions that which has
> the`git_config()` function comes before
> `show_usage_with_options_if_asked()` or it's variant and some,
> `git_config()` comes after.
> 
> For those that have `git_config()` comes after
> `show_usage_with_options_if_asked()` , no need for the check, since
> the `show_usage_with_options_if_asked()`call will exit without
> reaching `git_config()`. For scenario where the `git_config()` comes
> earlier, we have to check the `repo` to see if it is NULL, if it is
> NULL, we are sure this happens when the "-h" is passed to the function
> and we do not need to setup and configuration since
> `show_usage_with_options_if_asked()` will exit.

Exactly, this is what my suggestion is. If we introduced new calls to `show_usage_with_options_if_asked()` before `git_config()` we wouldn't have to check for a `NULL` repository in the first place because we know that we'd have already exited if there was a "-h" parameter.

Patrick
Previous: Usman AkinyemiNext: Usman Akinyemi
Message 5 of 63 in “[Outreachy] stop using the_repository global variable.”
  1. 0/7 [Outreachy] stop using the_repository global variable.Usman Akinyemi, Feb 14, 2025
  2. 1/7 builtin/verify-tag: stop using `the_repository`Usman Akinyemi, Feb 14, 2025
  3. Patrick SteinhardtFeb 17, 2025
  4. Usman AkinyemiFeb 17, 2025
  5. Patrick SteinhardtFeb 17, 2025
  6. Usman AkinyemiFeb 17, 2025
  7. Patrick SteinhardtFeb 17, 2025
  8. 2/7 builtin/verify-commit.c: stop using `the_repository`Usman Akinyemi, Feb 14, 2025
  9. shejialuoFeb 16, 2025
  10. Usman AkinyemiFeb 17, 2025
  11. 3/7 builtin/send-pack.c: stop using `the_repository`Usman Akinyemi, Feb 14, 2025
  12. 4/7 builtin/pack-refs: stop using `the_repository`Usman Akinyemi, Feb 14, 2025
  13. 5/7 builtin/ls-files: stop using `the_repository`Usman Akinyemi, Feb 14, 2025
  14. Patrick SteinhardtFeb 17, 2025
  15. Usman AkinyemiFeb 17, 2025
  16. 6/7 builtin/for-each-ref: stop using `the_repository`Usman Akinyemi, Feb 14, 2025
  17. 7/7 builtin/checkout-index.c: stop using `the_repository`Usman Akinyemi, Feb 14, 2025
  18. shejialuoFeb 16, 2025
  19. Usman AkinyemiFeb 17, 2025
  20. 00/12 [Outreachy] stop using the_repository global variable.Usman Akinyemi, Feb 19, 2025
  21. 01/12 builtin/verify-tag: refactor `cmd_verify_tag()`Usman Akinyemi, Feb 19, 2025
  22. Junio C HamanoFeb 20, 2025
  23. 02/12 builtin/verify-tag: stop using `the_repository`Usman Akinyemi, Feb 19, 2025
  24. Junio C HamanoFeb 20, 2025
  25. Usman AkinyemiFeb 27, 2025
  26. Junio C HamanoFeb 27, 2025
  27. 03/12 builtin/verify-commit: refactor `cmd_verify_commit()`Usman Akinyemi, Feb 19, 2025
  28. 04/12 builtin/verify-commit: stop using `the_repository`Usman Akinyemi, Feb 19, 2025
  29. 05/12 builtin/send-pack: refactor `cmd_send_pack()`Usman Akinyemi, Feb 19, 2025
  30. 06/12 builtin/send-pack: stop using `the_repository`Usman Akinyemi, Feb 19, 2025
  31. 07/12 builtin/pack-refs: refactor `cmd_pack_refs()`Usman Akinyemi, Feb 19, 2025
  32. 08/12 builtin/pack-refs: stop using `the_repository`Usman Akinyemi, Feb 19, 2025
  33. 09/12 builtin/ls-files: stop using `the_repository`Usman Akinyemi, Feb 19, 2025
  34. 10/12 builtin/for-each-ref: refactor `cmd_for_each_ref()`Usman Akinyemi, Feb 19, 2025
  35. 11/12 builtin/for-each-ref: stop using `the_repository`Usman Akinyemi, Feb 19, 2025
  36. 12/12 builtin/checkout-index: stop using `the_repository`Usman Akinyemi, Feb 19, 2025
  37. 0/8 stop using the_repository global variable.Usman Akinyemi, Mar 6, 2025
  38. 1/8 config: teach repo_config to allow `repo` to be NULLUsman Akinyemi, Mar 6, 2025
  39. Junio C HamanoMar 6, 2025
  40. Usman AkinyemiMar 7, 2025
  41. Phillip WoodMar 7, 2025
  42. 2/8 builtin/verify-tag: stop using `the_repository`Usman Akinyemi, Mar 6, 2025
  43. Junio C HamanoMar 6, 2025
  44. 3/8 builtin/verify-commit: stop using `the_repository`Usman Akinyemi, Mar 6, 2025
  45. 4/8 builtin/send-pack: stop using `the_repository`Usman Akinyemi, Mar 6, 2025
  46. 5/8 builtin/pack-refs: stop using `the_repository`Usman Akinyemi, Mar 6, 2025
  47. 6/8 builtin/ls-files: stop using `the_repository`Usman Akinyemi, Mar 6, 2025
  48. Junio C HamanoMar 6, 2025
  49. 7/8 builtin/for-each-ref: stop using `the_repository`Usman Akinyemi, Mar 6, 2025
  50. 8/8 builtin/checkout-index: stop using `the_repository`Usman Akinyemi, Mar 6, 2025
  51. Junio C HamanoMar 6, 2025
  52. Usman AkinyemiMar 7, 2025
  53. Junio C HamanoMar 7, 2025
  54. Usman AkinyemiMar 7, 2025
  55. 0/8 stop using the_repository global variable.Usman Akinyemi, Mar 7, 2025
  56. 1/8 config: teach repo_config to allow `repo` to be NULLUsman Akinyemi, Mar 7, 2025
  57. 2/8 builtin/verify-tag: stop using `the_repository`Usman Akinyemi, Mar 7, 2025
  58. 3/8 builtin/verify-commit: stop using `the_repository`Usman Akinyemi, Mar 7, 2025
  59. 4/8 builtin/send-pack: stop using `the_repository`Usman Akinyemi, Mar 7, 2025
  60. 5/8 builtin/pack-refs: stop using `the_repository`Usman Akinyemi, Mar 7, 2025
  61. 6/8 builtin/ls-files: stop using `the_repository`Usman Akinyemi, Mar 7, 2025
  62. 7/8 builtin/for-each-ref: stop using `the_repository`Usman Akinyemi, Mar 7, 2025
  63. 8/8 builtin/checkout-index: stop using `the_repository`Usman Akinyemi, Mar 7, 2025

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.