git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 17:16 UTC

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

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 13, 2026, 17:54 UTC
Message-ID
<xmqqzf4b4ntq.fsf@gitster.g>
In-Reply-To
<4fb9c915-7246-4c55-b7c6-b4ef7ca91230@malon.dev>
Tian Yuchen <cat@malon.dev> writes:
Show 31 quoted lines
> On 3/14/26 00:03, Junio C Hamano wrote:
>
>> 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.
>
> I was completely blown away Σ( ° △ °)
>
> Thanks for pointing that out. Otherwise, I wouldn’t have been able to 
> figure it out no matter how hard I try.
>
> I just took a quick look at the code:
>
>> 	const struct option option[] = {
>> 		OPT_BOOL('z', NULL, &nul_term_line, N_("input is NUL terminated")),
>> 		OPT_SET_INT( 0 , "missing", &allow_missing, N_("allow missing objects"), 1),
>> 		OPT_SET_INT( 0 , "batch", &is_batch_mode, N_("allow creation of more than one tree"), 1),
>> 		OPT_END()
>> 	};
>> 
>> 	ac = parse_options(ac, av, prefix, option, mktree_usage, 0);
>> 	getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
>> 
>> 	while (!got_eof) {
>> 		while (1) { ...
>
> I think if there's a '-h' parameter, it gets intercepted in 
> parse_options() and the process exits before repo is called. So there’s 
> nothing to worry about, right?
Correct.  The function calls parse_options() before it looks at "repo".
> By the way, I find it a bit confusing that the'`-h' parameter — which is 
> solely used for documentation query — is parsed and intercepted within a 
> function that handles actual business logic.

I strongly disagree your idea that 'z' is more business logic than 'h' is. Both are equally relevant.

Previous: Tian YuchenNext: Tian Yuchen
Message 7 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.