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

Re: [PATCH v1] builtin/mktree: remove USE_THE_REPOSITORY_VARIABLE

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 13, 2026, 16:03 UTC
Message-ID
<xmqqpl577m3y.fsf@gitster.g>
In-Reply-To
<af2c4ae3-c273-40ba-bbca-cbbf687b1b91@malon.dev>
Tian Yuchen <cat@malon.dev> writes:
Show 11 quoted lines
>> That is, can `repo` ever be `NULL`? For that
>> you have to look at "git.c" and figure out whether or not the command
>> requires a repository to exist.
> I checked git.c and found that there is:
>
> { "mktree", cmd_mktree, RUN_SETUP }
>
> in commands[]. If my understanding is correct, before cmd_mktree is 
> called, setup_git_directory() must have been fully executed. In that 
> case, if the current directory isn't a valid repository (NULL), it 
> should have already exited at an earlier stage, right?

There is one corner case; upon "git foo -h", your cmd_foo() will get repo==NULL when the command is run outside a repository. As long as your cmd_foo() asks parse_options() to react to "-h" (which gives the help message and then exits) before it uses repo assuming it cannot be NULL, you are safe.

Previous: Patrick SteinhardtNext: Tian Yuchen
Message 5 of 10 in “builtin/mktree: remove USE_THE_REPOSITORY_VARIABLE”
  1. builtin/mktree: remove USE_THE_REPOSITORY_VARIABLETian Yuchen, Mar 11, 2026
  2. Patrick SteinhardtMar 12, 2026
  3. Tian YuchenMar 12, 2026
  4. Patrick SteinhardtMar 13, 2026
  5. Junio C HamanoMar 13, 2026
  6. Tian YuchenMar 13, 2026
  7. Junio C HamanoMar 13, 2026
  8. Tian YuchenMar 13, 2026
  9. Junio C HamanoMar 13, 2026
  10. Tian YuchenMar 14, 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.