From: Junio C Hamano <gitster@pobox.com>
To: "SZEDER Gábor" <szeder.dev@gmail.com>
Cc: William Sprent via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, Victoria Dye <vdye@github.com>,
Elijah Newren <newren@gmail.com>,
William Sprent <williams@unity3d.com>
Subject: Re: [PATCH v2 1/2] builtin/sparse-checkout: remove NEED_WORK_TREE flag
Date: Fri, 07 Apr 2023 09:38:08 -0700 [thread overview]
Message-ID: <xmqqttxrk5qn.fsf@gitster.g> (raw)
In-Reply-To: <20230407161655.GB3117@szeder.dev> ("SZEDER Gábor"'s message of "Fri, 7 Apr 2023 18:16:55 +0200")
SZEDER Gábor <szeder.dev@gmail.com> writes:
>> 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.
next prev parent reply other threads:[~2023-04-07 16:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-08 13:49 [PATCH 0/2] builtin/sparse-checkout: add check-rules command William Sprent via GitGitGadget
2023-03-08 13:49 ` [PATCH 1/2] builtin/sparse-checkout: remove NEED_WORK_TREE flag William Sprent via GitGitGadget
2023-03-08 18:14 ` Junio C Hamano
2023-03-08 19:27 ` Junio C Hamano
2023-03-09 15:31 ` Elijah Newren
2023-03-09 22:19 ` Junio C Hamano
2023-03-08 13:49 ` [PATCH 2/2] builtin/sparse-checkout: add check-rules command William Sprent via GitGitGadget
2023-03-19 4:26 ` Elijah Newren
2023-03-20 15:49 ` William Sprent
2023-03-19 4:28 ` [PATCH 0/2] " Elijah Newren
2023-03-27 7:55 ` [PATCH v2 " William Sprent via GitGitGadget
2023-03-27 7:55 ` [PATCH v2 1/2] builtin/sparse-checkout: remove NEED_WORK_TREE flag William Sprent via GitGitGadget
2023-03-27 17:51 ` Junio C Hamano
2023-04-07 16:16 ` SZEDER Gábor
2023-04-07 16:38 ` Junio C Hamano [this message]
2023-03-27 7:55 ` [PATCH v2 2/2] builtin/sparse-checkout: add check-rules command William Sprent via GitGitGadget
2023-04-01 18:49 ` [PATCH v2 0/2] " Elijah Newren
2023-04-03 17:07 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqttxrk5qn.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=newren@gmail.com \
--cc=szeder.dev@gmail.com \
--cc=vdye@github.com \
--cc=williams@unity3d.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).