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

Re: [PATCH v2] git.c: remove the_repository dependence in run_builtin()

From
Lidong Yan <502024330056@smail.nju.edu.cn>
Date
Jun 15, 2025, 01:49 UTC
Message-ID
<BE43915C-E780-4166-9C23-81F9A8CBDEDC@smail.nju.edu.cn>
In-Reply-To
<xmqqwm9d6gn0.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 8 quoted lines
> Sorry, but the above makes it sound as if 246deeac (environment:
> make `get_git_dir()` accept a repository, 2024-09-12) that retired
> get_git_dir() and introduced repo_get_git_dir() was the culprit that
> made their semantics change, but is that really true?  It appears
> that in the version immediately before that commit, get_git_dir()
> was also a reference to a variable, without any lazy initialization
> the above message says that the code tries to avoid, so I am even
> more confused after reading the above.

I was reading the code in master and noticed that repo_get_git_dir() no longer sets up the environment. I’ve learned that I should use git blame to identify which commit changed the code, so I can make my message clearer.

Show 5 quoted lines
> Perhaps you have 73f192c9 (setup: don't perform lazy initialization
> of repository state, 2017-06-20) in mind?  That one did stop calling
> setup_git_env() and instead force a hard BUG("") when git_dir is not
> set up yet.  And that BUG("") still survives in repo_get_git_dir()
> we have today.
Exactly
Show 13 quoted lines
> So the call to repo_get_git_dir() may still not be made from this
> code path.  It may not attempt to set up, but instead it would die
> if we haven't successfully set up the repository before.  The
> relevance of the comment was not changed by 246deeac that moved this
> code from get_git_dir() to repo_get_git_dir(), and more importantly,
> it was not changed by this patch we are reviewing here.
> 
> But stepping back a bit, is it what a9ca8a85 originally wanted to
> achieve with this comment to "avoid calling get_git_dir()" in the
> first place?  Once the guarding condition is satisfied, it calls
> trace_repo_setup(), which in turn calls get_git_dir() anyway.
> Perhaps it wanted to explain why startup_info->have_repository is
> checked here?

Yes, I think so. Maybe updating the comment to say “call repo_get_git_dir() after setting up the_repository” would be more appropriate.

Thank you for your review, Lidong

Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 16 in “git.c: remove the_repository dependence in run_builtin()”
  1. git.c: remove the_repository dependence in run_builtin()Lidong Yan, Jun 12, 2025
  2. Junio C HamanoJun 12, 2025
  3. lidongyanJun 13, 2025
  4. Junio C HamanoJun 13, 2025
  5. git.c: remove the_repository dependence in run_builtin()Lidong Yan, Jun 14, 2025
  6. Junio C HamanoJun 14, 2025
  7. Lidong YanJun 15, 2025
  8. Junio C HamanoJun 16, 2025
  9. Lidong YanJun 16, 2025
  10. Junio C HamanoJun 16, 2025
  11. 0/2 small fixes for git.c and setup.cLidong Yan, Jun 15, 2025
  12. 1/2 git.c: remove the_repository dependence in run_builtin()Lidong Yan, Jun 15, 2025
  13. 2/2 setup: fix NEEDSWORK in setup_git_directory_gently()Lidong Yan, Jun 15, 2025
  14. Junio C HamanoJun 16, 2025
  15. Lidong YanJun 16, 2025
  16. git.c: remove the_repository dependence in run_builtin()Lidong Yan, Jun 16, 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.