parse-options: allow ll_callback with OPTION_CALLBACK
OPTION_CALLBACK is much simpler/safer to use, but parse_opt_cb does not allow access to parse_opt_ctx_t, which sometimes is useful (e.g. to obtain the prefix). Extending parse_opt_cb to take parse_opt_cb could result in a lot of changes. Instead let's just allow ll_callback to be used with OPTION_CALLBACK. The user will have to be careful, not to change anything in ctx, or return wrong result code. But that's the price for ll_callback. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
f41179f16b
commit
3ebbe28989
@ -848,13 +848,15 @@ static int parse_new_style_cacheinfo(const char *arg,
|
||||
}
|
||||
|
||||
static enum parse_opt_result cacheinfo_callback(
|
||||
struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
|
||||
struct parse_opt_ctx_t *ctx, const struct option *opt,
|
||||
const char *arg, int unset)
|
||||
{
|
||||
struct object_id oid;
|
||||
unsigned int mode;
|
||||
const char *path;
|
||||
|
||||
BUG_ON_OPT_NEG(unset);
|
||||
BUG_ON_OPT_ARG(arg);
|
||||
|
||||
if (!parse_new_style_cacheinfo(ctx->argv[1], &mode, &oid, &path)) {
|
||||
if (add_cacheinfo(mode, &oid, path, 0))
|
||||
@ -874,11 +876,13 @@ static enum parse_opt_result cacheinfo_callback(
|
||||
}
|
||||
|
||||
static enum parse_opt_result stdin_cacheinfo_callback(
|
||||
struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
|
||||
struct parse_opt_ctx_t *ctx, const struct option *opt,
|
||||
const char *arg, int unset)
|
||||
{
|
||||
int *nul_term_line = opt->value;
|
||||
|
||||
BUG_ON_OPT_NEG(unset);
|
||||
BUG_ON_OPT_ARG(arg);
|
||||
|
||||
if (ctx->argc != 1)
|
||||
return error("option '%s' must be the last argument", opt->long_name);
|
||||
@ -888,11 +892,13 @@ static enum parse_opt_result stdin_cacheinfo_callback(
|
||||
}
|
||||
|
||||
static enum parse_opt_result stdin_callback(
|
||||
struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
|
||||
struct parse_opt_ctx_t *ctx, const struct option *opt,
|
||||
const char *arg, int unset)
|
||||
{
|
||||
int *read_from_stdin = opt->value;
|
||||
|
||||
BUG_ON_OPT_NEG(unset);
|
||||
BUG_ON_OPT_ARG(arg);
|
||||
|
||||
if (ctx->argc != 1)
|
||||
return error("option '%s' must be the last argument", opt->long_name);
|
||||
@ -901,12 +907,14 @@ static enum parse_opt_result stdin_callback(
|
||||
}
|
||||
|
||||
static enum parse_opt_result unresolve_callback(
|
||||
struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
|
||||
struct parse_opt_ctx_t *ctx, const struct option *opt,
|
||||
const char *arg, int unset)
|
||||
{
|
||||
int *has_errors = opt->value;
|
||||
const char *prefix = startup_info->prefix;
|
||||
|
||||
BUG_ON_OPT_NEG(unset);
|
||||
BUG_ON_OPT_ARG(arg);
|
||||
|
||||
/* consume remaining arguments. */
|
||||
*has_errors = do_unresolve(ctx->argc, ctx->argv,
|
||||
@ -920,12 +928,14 @@ static enum parse_opt_result unresolve_callback(
|
||||
}
|
||||
|
||||
static enum parse_opt_result reupdate_callback(
|
||||
struct parse_opt_ctx_t *ctx, const struct option *opt, int unset)
|
||||
struct parse_opt_ctx_t *ctx, const struct option *opt,
|
||||
const char *arg, int unset)
|
||||
{
|
||||
int *has_errors = opt->value;
|
||||
const char *prefix = startup_info->prefix;
|
||||
|
||||
BUG_ON_OPT_NEG(unset);
|
||||
BUG_ON_OPT_ARG(arg);
|
||||
|
||||
/* consume remaining arguments. */
|
||||
setup_work_tree();
|
||||
|
Reference in New Issue
Block a user