From: Eric Sunshine <sunshine@sunshineco.com>
To: Stefan Beller <sbeller@google.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Git List <git@vger.kernel.org>,
Jonathan Nieder <jrnieder@gmail.com>,
Johannes Schindelin <johannes.schindelin@gmail.com>,
Jens Lehmann <Jens.Lehmann@web.de>, Jeff King <peff@peff.net>
Subject: Re: [PATCHv4 1/3] submodule: implement `list` as a builtin helper
Date: Tue, 1 Sep 2015 19:17:28 -0400 [thread overview]
Message-ID: <CAPig+cTBK0Zw6ECJY4cDeP-eYOoGrCGAPXAvj1Xk-HABeBv-_A@mail.gmail.com> (raw)
In-Reply-To: <1441131869-29474-2-git-send-email-sbeller@google.com>
On Tue, Sep 1, 2015 at 2:24 PM, Stefan Beller <sbeller@google.com> wrote:
> Most of the submodule operations work on a set of submodules.
> Calculating and using this set is usually done via:
>
> module_list "$@" | {
> while read mode sha1 stage sm_path
> do
> # the actual operation
> done
> }
>
> Currently the function `module_list` is implemented in the
> git-submodule.sh as a shell script wrapping a perl script.
> The rewrite is in C, such that it is faster and can later be
> easily adapted when other functions are rewritten in C.
>
> [...]
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> +struct cmd_struct {
> + const char *cmd;
> + int (*fct)(int, const char **, const char *);
It would be better to stick with a more idiomatic name such as 'f' or
'func' than invent an entirely new one ('fct').
> +};
> +
> +static struct cmd_struct commands[] = {
> + {"list", module_list},
> +};
> +
> +int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
> +{
> + int i;
> + if (argc < 2)
> + goto out;
> +
> + for (i = 0; i < ARRAY_SIZE(commands); i++)
> + if (!strcmp(argv[1], commands[i].cmd))
> + return commands[i].fct(argc - 1, argv + 1, prefix);
> +
> +out:
> + if (argc > 1)
> + fprintf(stderr, _("fatal: '%s' is not a valid submodule--helper "
> + "subcommand, which are:\n"), argv[1]);
> + else
> + fprintf(stderr, _("fatal: submodule--helper subcommand must be "
> + "called with a subcommand, which are:\n"));
> +
> + for (i = 0; i < ARRAY_SIZE(commands); i++)
> + fprintf(stderr, "\t%s\n", commands[i].cmd);
A couple observations:
1. git-submodule--helper isn't the only Git command featuring
subcommands which could benefit from this dispatching and error
reporting code, so making it re-usable would be sensible rather than
hiding it away inside this one (very low-level, not user-facing)
command. If you go that route, it would deserve its own patch series,
and well thought out design and interface. However...
2. I realize that the suggestion of listing available subcommands was
put forth tentatively by Junio[1], but it seems overkill for a command
like this which is not user-facing, and is inconsistent with other
subcommand-bearing commands. At this stage, it should be sufficient
merely to emit a plain error message (without any usage information):
unrecognized subcommand: %s
missing subcommand
at which point the user can consult the man page or "git
subcommand--helper -h" to find out what went wrong.
[1]: http://article.gmane.org/gmane.comp.version-control.git/276935
> +
> + exit(129);
> +}
next prev parent reply other threads:[~2015-09-01 23:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-01 18:24 [PATCHv4 0/3] submodule--helper: Have some refactoring only patches first Stefan Beller
2015-09-01 18:24 ` [PATCHv4 1/3] submodule: implement `list` as a builtin helper Stefan Beller
2015-09-01 19:55 ` Junio C Hamano
2015-09-02 7:20 ` Junio C Hamano
2015-09-01 23:17 ` Eric Sunshine [this message]
2015-09-01 18:24 ` [PATCHv4 2/3] submodule: implement `name` " Stefan Beller
2015-09-01 19:01 ` Eric Sunshine
2015-09-01 18:24 ` [PATCHv4 3/3] submodule: implement `clone` " Stefan Beller
2015-09-01 18:52 ` Eric Sunshine
2015-09-01 19:05 ` Jeff King
2015-09-01 19:15 ` Eric Sunshine
2015-09-01 19:13 ` Junio C Hamano
[not found] <1441148863-9139-1-git-send-email-sbeller@google.com>
2015-09-01 23:07 ` [PATCHv4 1/3] submodule: implement `list` " Stefan Beller
2015-09-01 23:08 ` Stefan Beller
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=CAPig+cTBK0Zw6ECJY4cDeP-eYOoGrCGAPXAvj1Xk-HABeBv-_A@mail.gmail.com \
--to=sunshine@sunshineco.com \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmail.com \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
--cc=sbeller@google.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).