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

Re: [PATCH v2 1/2] builtin/sparse-checkout: remove NEED_WORK_TREE flag

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 7, 2023, 16:38 UTC
Message-ID
<xmqqttxrk5qn.fsf@gitster.g>
In-Reply-To
<20230407161655.GB3117@szeder.dev>
SZEDER Gábor <szeder.dev@gmail.com> writes:
Show 25 quoted lines
>>                 struct option builtin_sparse_checkout_options[] = {
>>                         OPT_SUBCOMMAND("list", &fn, sparse_checkout_list),
>>                         OPT_SUBCOMMAND("init", &fn, sparse_checkout_init),
>>                         OPT_SUBCOMMAND("set", &fn, sparse_checkout_set),
>>                         OPT_SUBCOMMAND("add", &fn, sparse_checkout_add),
>>                         OPT_SUBCOMMAND("reapply", &fn, sparse_checkout_reapply),
>>                         OPT_SUBCOMMAND("disable", &fn, sparse_checkout_disable),
>>                         OPT_END(),
>>                 };
>> 
>> yet we have to sprinkle setup_work_tree() to all of these functions'
>> implementation.  If we were able to describe which selected ones do
>> not need the setup call, we could let the parse-options API to look
>> up the function and then before calling "fn" we could make the setup
>> call.  That would allow us to maintain the subcommands much nicely.
>
> It's easy enough to do in this particular case: there is an
> OPT_SUBCOMMAND_F() variant which takes an additional flags parameter,
> so we could add a PARSE_OPT_SETUP_WORK_TREE flag, check it in e.g.
> parse_subcommand(), and act accordingly if it's set.
>
> However, this wouldn't work when the command has a default operation
> mode and is invoked without any subcommands.  And I'm not sure about
> doing this in parse-options, because it's about, well, parsing
> options, not about doing fancy setup stuff.
Yes, exactly.  What I was imagining was more along the lines of
	parse_opt_subcommand_fn *fn = NULL;
	parse_opt_subcommand_fn *fn_with_setup = NULL;
	options[] = {
		OPT_SUBCOMMAND("list", &fn_with_setup, sparse_checkout_list),
		...
		OPT_SUBCOMMAND("check-rules", &fn, sparse_check_rules),
	};
	parse_options(...);
        if (fn_with_setup) {
		setup_worktree();
		fn = fn_with_setup;
	}
	fn(...);

But of course as a "safety" measure, one options[] array can all point at the same "fn" variable or parse_options() becomes unhappy, so the above does not work out of the box.

Previous: SZEDER GáborNext: William Sprent via GitGitGadget
Message 15 of 18 in “builtin/sparse-checkout: add check-rules command”
  1. 0/2 builtin/sparse-checkout: add check-rules commandWilliam Sprent via GitGitGadget, Mar 8, 2023
  2. 1/2 builtin/sparse-checkout: remove NEED_WORK_TREE flagWilliam Sprent via GitGitGadget, Mar 8, 2023
  3. Junio C HamanoMar 8, 2023
  4. Junio C HamanoMar 8, 2023
  5. Elijah NewrenMar 9, 2023
  6. Junio C HamanoMar 9, 2023
  7. 2/2 builtin/sparse-checkout: add check-rules commandWilliam Sprent via GitGitGadget, Mar 8, 2023
  8. Elijah NewrenMar 19, 2023
  9. William SprentMar 20, 2023
  10. Elijah NewrenMar 19, 2023
  11. 0/2 builtin/sparse-checkout: add check-rules commandWilliam Sprent via GitGitGadget, Mar 27, 2023
  12. 1/2 builtin/sparse-checkout: remove NEED_WORK_TREE flagWilliam Sprent via GitGitGadget, Mar 27, 2023
  13. Junio C HamanoMar 27, 2023
  14. SZEDER GáborApr 7, 2023
  15. Junio C HamanoApr 7, 2023
  16. 2/2 builtin/sparse-checkout: add check-rules commandWilliam Sprent via GitGitGadget, Mar 27, 2023
  17. Elijah NewrenApr 1, 2023
  18. Junio C HamanoApr 3, 2023

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.