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

Re: [PATCH 00/18] setup: drop uses of `the_repository`

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 21, 2026, 09:41 UTC
Message-ID
<aedFNjsLDsFj_InR@pks.im>
In-Reply-To
<xmqqy0ihpnf6.fsf@gitster.g>
On Mon, Apr 20, 2026 at 10:11:09AM -0700, Junio C Hamano wrote:
Show 6 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > Message-Id: <20260420-pks-setup-wo-the-repository-v1-0-f4a81c4988e8@pks.im>
> 
> There seem to be some tool errors that made this marked as v1 (hence
> no References/In-Reply-To).

Yeah, I noticed this, too. As mentioned in the mail to Elijah, I think this happens when I'm overeager and already switch branches while b4 is still busy sending out mails. In that case, it doesn't update the series to vN+1 :/

Show 33 quoted lines
> >   -  9/18: setup: stop using `the_repository` in `setup_work_tree()`
> 
> > diff --git a/setup.c b/setup.c
> > index dca32addae..80dd94b261 100644
> > --- a/setup.c
> > +++ b/setup.c
> > @@ -26,7 +26,6 @@
> >  #include "trace2.h"
> >  #include "worktree.h"
> >  
> > -static int work_tree_config_is_bogus;
> 
> Once we start "setting up" more than one instance of "struct
> repository", "the worktree configuration given to us is bogus" bit
> cannot be a singleton global that applies across repositories.
> 
> Hopefully nobody sets core.bare and core.worktree in configuration
> files other than the repository local one.  Otherwise a lot of
> interesting would break ;-)
> 
> I am not quite sure the reasoning behind removing "initialized"
> global without any replacement was properly explained, with "should
> ultimately be idempotent".  This can give us a huge performance
> regression, if the callers have been relying on setup_work_tree() to
> be _cheap_ when they call it "just in case" no other potential
> callsites have called it, even though all of them know that the
> current code works only with the_repository (in other words, they
> call because the switched into the_repository---they do not know for
> sure if other call sites have called it).
> 
> Or does the current code never call setup_work_tree() twice, because
> everybody knows that we never work with anything other than
> the_repository?

`setup_work_tree()` is typically executed via "git.c" in case NEED_WORK_TREE is set. Some other top-level commands end up executing it manually in case the bit is not set.

Other than that it's called in a couple more sites:
  - "builtin/check-attr.c", "builtin/clone.c", "builtin/describe.c",
    "builtin/diff-index.c", "builtin/diff.c", "builtin/difftool.c",
    "builtin/grep.c", "builtin/ls-files.c", "builtin/read-tree.c",
    "builtin/reset.c", "builtin/rm.c", "builtin/submodule--helper.c", :
    Not marked with NEED_WORK_TREE, executed exactly once.
  - "builtin/sparse-checkout.c": we have multiple callsites here for the
    subcommands, but also call it via `update_working_directory()`. We
    execute it a fixed number of times only though, but I doubt that the
    performance overhead of this matters in practice. That being said,
    all sites leading up to this have already called `setup_work_tree()`
    beforehand, so it would be trivial to fix.
  - "builtin/update-index.c": it may be executed multiple times via
    command line options, e.g. in case you execute `git update-index
    --refresh --refresh`. Again, I doubt this matters.
  - "blame.c": executed exactly once via `setup_scoreboard()`, which in
    turn is executed once only via "builtin/blame.c", which is not
    marked with NEED_WORK_TREE. So this is fine.
  - "wt-status.c": executed once when printing a verbose status. This
    will result in a second invocation for git-status(1) and
    git-commit(1), but again it's bounded.
  - "t/helper/test-subprocess.c": executed exactly once, but doesn't
    matter much anyway.

So overall I think it's fine as in most cases we really only execute it once, and in the remaining cases we only execute it a limited amount of times (twice or thrice). In addition to that, getenv(3p) and setenv(3p) shouldn't be inherently expensive, and the chnotify callbacks we register are all rather cheap, too.

We _could_ prepare git-sparse-checkout(1) and git-update-index(1) to handle this, but I'm not sure this is really needed. All the other callsites are fine, as far as I can see.

Thanks!
Patrick
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 28 of 73 in “setup: drop uses of `the_repository`”
  1. 00/18 setup: drop uses of `the_repository`Patrick Steinhardt, Apr 20, 2026
  2. 01/18 setup: replace use of `the_repository` in static functionsPatrick Steinhardt, Apr 20, 2026
  3. 02/18 setup: stop using `the_repository` in `is_inside_worktree()`Patrick Steinhardt, Apr 20, 2026
  4. Tian YuchenMay 17, 2026
  5. Junio C HamanoMay 17, 2026
  6. Patrick SteinhardtMay 18, 2026
  7. Junio C HamanoMay 19, 2026
  8. Patrick SteinhardtMay 19, 2026
  9. 03/18 setup: stop using `the_repository` in `is_inside_git_dir()`Patrick Steinhardt, Apr 20, 2026
  10. 04/18 setup: stop using `the_repository` in `prefix_path()`Patrick Steinhardt, Apr 20, 2026
  11. 05/18 setup: stop using `the_repository` in `path_inside_repo()`Patrick Steinhardt, Apr 20, 2026
  12. 06/18 setup: stop using `the_repository` in `verify_filename()`Patrick Steinhardt, Apr 20, 2026
  13. 07/18 setup: stop using `the_repository` in `verify_non_filename()`Patrick Steinhardt, Apr 20, 2026
  14. 08/18 setup: stop using `the_repository` in `enter_repo()`Patrick Steinhardt, Apr 20, 2026
  15. 09/18 setup: stop using `the_repository` in `setup_work_tree()`Patrick Steinhardt, Apr 20, 2026
  16. 10/18 setup: stop using `the_repository` in `set_git_work_tree()`Patrick Steinhardt, Apr 20, 2026
  17. 11/18 setup: stop using `the_repository` in `setup_git_env()`Patrick Steinhardt, Apr 20, 2026
  18. 12/18 setup: stop using `the_repository` in `setup_git_directory_gently()`Patrick Steinhardt, Apr 20, 2026
  19. 13/18 setup: stop using `the_repository` in `setup_git_directory()`Patrick Steinhardt, Apr 20, 2026
  20. 14/18 setup: stop using `the_repository` in `upgrade_repository_format()`Patrick Steinhardt, Apr 20, 2026
  21. 15/18 setup: stop using `the_repository` in `check_repository_format()`Patrick Steinhardt, Apr 20, 2026
  22. 16/18 setup: stop using `the_repository` in `initialize_repository_version()`Patrick Steinhardt, Apr 20, 2026
  23. 17/18 setup: stop using `the_repository` in `create_reference_database()`Patrick Steinhardt, Apr 20, 2026
  24. 18/18 setup: stop using `the_repository` in `init_db()`Patrick Steinhardt, Apr 20, 2026
  25. Elijah NewrenApr 20, 2026
  26. Patrick SteinhardtApr 21, 2026
  27. Junio C HamanoApr 20, 2026
  28. Patrick SteinhardtApr 21, 2026
  29. 00/18 setup: drop uses of `the_repository`Patrick Steinhardt, May 18, 2026
  30. 01/18 setup: replace use of `the_repository` in static functionsPatrick Steinhardt, May 18, 2026
  31. Karthik NayakMay 19, 2026
  32. 02/18 setup: stop using `the_repository` in `is_inside_worktree()`Patrick Steinhardt, May 18, 2026
  33. Karthik NayakMay 19, 2026
  34. Patrick SteinhardtMay 19, 2026
  35. 03/18 setup: stop using `the_repository` in `is_inside_git_dir()`Patrick Steinhardt, May 18, 2026
  36. Karthik NayakMay 19, 2026
  37. 04/18 setup: stop using `the_repository` in `prefix_path()`Patrick Steinhardt, May 18, 2026
  38. 05/18 setup: stop using `the_repository` in `path_inside_repo()`Patrick Steinhardt, May 18, 2026
  39. 06/18 setup: stop using `the_repository` in `verify_filename()`Patrick Steinhardt, May 18, 2026
  40. 07/18 setup: stop using `the_repository` in `verify_non_filename()`Patrick Steinhardt, May 18, 2026
  41. 08/18 setup: stop using `the_repository` in `enter_repo()`Patrick Steinhardt, May 18, 2026
  42. 09/18 setup: stop using `the_repository` in `setup_work_tree()`Patrick Steinhardt, May 18, 2026
  43. 10/18 setup: stop using `the_repository` in `set_git_work_tree()`Patrick Steinhardt, May 18, 2026
  44. 11/18 setup: stop using `the_repository` in `setup_git_env()`Patrick Steinhardt, May 18, 2026
  45. 12/18 setup: stop using `the_repository` in `setup_git_directory_gently()`Patrick Steinhardt, May 18, 2026
  46. 13/18 setup: stop using `the_repository` in `setup_git_directory()`Patrick Steinhardt, May 18, 2026
  47. 14/18 setup: stop using `the_repository` in `upgrade_repository_format()`Patrick Steinhardt, May 18, 2026
  48. 15/18 setup: stop using `the_repository` in `check_repository_format()`Patrick Steinhardt, May 18, 2026
  49. 16/18 setup: stop using `the_repository` in `initialize_repository_version()`Patrick Steinhardt, May 18, 2026
  50. 17/18 setup: stop using `the_repository` in `create_reference_database()`Patrick Steinhardt, May 18, 2026
  51. 18/18 setup: stop using `the_repository` in `init_db()`Patrick Steinhardt, May 18, 2026
  52. Karthik NayakMay 19, 2026
  53. Patrick SteinhardtMay 19, 2026
  54. 00/18 setup: drop uses of `the_repository`Patrick Steinhardt, May 19, 2026
  55. 01/18 setup: replace use of `the_repository` in static functionsPatrick Steinhardt, May 19, 2026
  56. 02/18 setup: stop using `the_repository` in `is_inside_git_dir()`Patrick Steinhardt, May 19, 2026
  57. 03/18 setup: stop using `the_repository` in `is_inside_work_tree()`Patrick Steinhardt, May 19, 2026
  58. 04/18 setup: stop using `the_repository` in `prefix_path()`Patrick Steinhardt, May 19, 2026
  59. 05/18 setup: stop using `the_repository` in `path_inside_repo()`Patrick Steinhardt, May 19, 2026
  60. 06/18 setup: stop using `the_repository` in `verify_filename()`Patrick Steinhardt, May 19, 2026
  61. 07/18 setup: stop using `the_repository` in `verify_non_filename()`Patrick Steinhardt, May 19, 2026
  62. 08/18 setup: stop using `the_repository` in `enter_repo()`Patrick Steinhardt, May 19, 2026
  63. 09/18 setup: stop using `the_repository` in `setup_work_tree()`Patrick Steinhardt, May 19, 2026
  64. 10/18 setup: stop using `the_repository` in `set_git_work_tree()`Patrick Steinhardt, May 19, 2026
  65. 11/18 setup: stop using `the_repository` in `setup_git_env()`Patrick Steinhardt, May 19, 2026
  66. 12/18 setup: stop using `the_repository` in `setup_git_directory_gently()`Patrick Steinhardt, May 19, 2026
  67. 14/18 setup: stop using `the_repository` in `upgrade_repository_format()`Patrick Steinhardt, May 19, 2026
  68. 13/18 setup: stop using `the_repository` in `setup_git_directory()`Patrick Steinhardt, May 19, 2026
  69. 15/18 setup: stop using `the_repository` in `check_repository_format()`Patrick Steinhardt, May 19, 2026
  70. 16/18 setup: stop using `the_repository` in `initialize_repository_version()`Patrick Steinhardt, May 19, 2026
  71. 17/18 setup: stop using `the_repository` in `create_reference_database()`Patrick Steinhardt, May 19, 2026
  72. 18/18 setup: stop using `the_repository` in `init_db()`Patrick Steinhardt, May 19, 2026
  73. Junio C HamanoMay 20, 2026

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.