Subject: Re: [PATCHv2] Add an optional argument for --color options

From: Stephen Boyd <[email-masked]>
Date: Thu, 18 Feb 2010 01:56:44 -0800

On 02/16/2010 08:55 PM, Mark Lodato wrote:
> @@ -599,6 +600,22 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
>  	return 0;
>  }
>  
> +int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
> +			    int unset)
> +{
> +	int value;
> +	if (unset && arg)
> +		return opterror(opt, "takes no value", OPT_UNSET);
>   

We can't have unset and arg both set at the same time. This exact case
is handled by get_value() in parse-options.c (did you copy that?)

> +	if (!arg)
> +		arg = unset ? "never" : (const char *)opt->defval;
>   

I've always been annoyed that the OPTION_CALLBACK doesn't set the
option's value to the defval before calling the callback when it's
PARSE_OPT_OPTARG. If it did we could drop half of this if condition too.

Here's something to squash
--->8----

diff --git a/parse-options.c b/parse-options.c
index 22da9be..0986314 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -604,8 +604,6 @@ int parse_opt_color_flag_cb(const struct option *opt, const 
                            int unset)
 {
        int value;
-       if (unset && arg)
-               return opterror(opt, "takes no value", OPT_UNSET);
        if (!arg)
                arg = unset ? "never" : (const char *)opt->defval;
        value = git_config_colorbool(NULL, arg, -1);