Taylor Blau <m...@ttaylorr.com> writes:

> diff --git a/builtin/config.c b/builtin/config.c
> index 92fb8d56b1..bd7a8d0ce7 100644
> --- a/builtin/config.c
> +++ b/builtin/config.c
> @@ -61,6 +61,58 @@ static int show_origin;
>  #define TYPE_PATH            4
>  #define TYPE_EXPIRY_DATE     5
>  
> +#define OPT_CALLBACK_VALUE(s, l, v, h, i) \
> +     { OPTION_CALLBACK, (s), (l), (v), NULL, (h), PARSE_OPT_NOARG | \
> +     PARSE_OPT_NONEG, option_parse_type, (i) }
> +
> +static struct option builtin_config_options[];
> +
> +static int option_parse_type(const struct option *opt, const char *arg,
> +                          int unset)
> +{

Declare all local variables here.  We do not accept decl-after-statement.

> +     if (unset) {
> +             *((int *) opt->value) = 0;
> +             return 0;
> +     }
> +
> +     /*
> +      * To support '--<type>' style flags, begin with new_type equal to
> +      * opt->defval.
> +      */
> +     int new_type = opt->defval;

Like this one and ...

> +     if (!new_type) {
> +             if (!strcmp(arg, "bool"))
> +                     new_type = TYPE_BOOL;
> +             else if (!strcmp(arg, "int"))
> +                     new_type = TYPE_INT;
> +             else if (!strcmp(arg, "bool-or-int"))
> +                     new_type = TYPE_BOOL_OR_INT;
> +             else if (!strcmp(arg, "path"))
> +                     new_type = TYPE_PATH;
> +             else if (!strcmp(arg, "expiry-date"))
> +                     new_type = TYPE_EXPIRY_DATE;
> +             else
> +                     die(_("unrecognized --type argument, %s"), arg);
> +     }
> +
> +     int *to_type = opt->value;

... this one.

> +     if (*to_type && *to_type != new_type) {
> +             /*
> +              * Complain when there is a new type not equal to the old type.
> +              * This allows for combinations like '--int --type=int' and
> +              * '--type=int --type=int', but disallows ones like '--type=bool
> +              * --int' and '--type=bool
> +              * --type=int'.
> +              */
> +             error("only one type at a time.");
> +             usage_with_options(builtin_config_usage,
> +                     builtin_config_options);
> +     }
> +     *to_type = new_type;
> +
> +     return 0;
> +}
> +

Reply via email to