On Tue, Sep 1, 2015 at 2:24 PM, Stefan Beller <[email protected]> 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 <[email protected]>
> ---
> +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);
> +}
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html