Re: [PATCH 4/8] scalar: implement the `help` subcommand
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Aug 31, 2022, 16:48 UTC
- Message-ID
- <220831.8635dc9wzx.gmgdl@evledraar.gmail.com>
- In-Reply-To
- <46d0fddfe8fbc2c568cb5a3d14594276db2bc1a9.1661961746.git.gitgitgadget@gmail.com>
On Wed, Aug 31 2022, Johannes Schindelin via GitGitGadget wrote:
Show 25 quoted lines
> From: Johannes Schindelin <johasc@microsoft.com>
>
> It is merely handing off to `git help scalar`.
>
> Signed-off-by: Johannes Schindelin <johasc@microsoft.com>
> Signed-off-by: Victoria Dye <vdye@github.com>
> ---
> scalar.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/scalar.c b/scalar.c
> index 642d16124eb..675d7a6b0a9 100644
> --- a/scalar.c
> +++ b/scalar.c
> @@ -819,6 +819,25 @@ static int cmd_delete(int argc, const char **argv)
> return res;
> }
>
> +static int cmd_help(int argc, const char **argv)
> +{
> + struct option options[] = {
> + OPT_END(),
> + };
> + const char * const usage[] = {
> + N_("scalar help"),This should not have N_(), as it's a literal command.
Show 7 quoted lines
> + NULL > + }; > + > + argc = parse_options(argc, argv, NULL, options, > + usage, 0); > + > + if (argc != 0)
If we're re-rolling anyway we usually just do "if (argc)". We don't need to worry about argc < 0 (despite the signed type, which is a historical C wart).
> + usage_with_options(usage, options);
> +
> + return run_git("help", "scalar", NULL);Performance isn't sensitive here, but have you tried just calling cmd_help() instead with the appropriate arguments? It would avoid spawning another command..