git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Stephen Boyd <bebarino@gmail.com>
Date
Feb 18, 2010, 09:56 UTC
Message-ID
<4B7D0EDC.8070309@gmail.com>
In-Reply-To
<1266382558-26325-1-git-send-email-lodatom@gmail.com>
On 02/16/2010 08:55 PM, Mark Lodato wrote:
Show 11 quoted lines
> @@ -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);
Previous: Mark Lodato
Message 2 of 2 in “[PATCHv2] Add an optional argument for --color options”
  1. Mark LodatoFeb 17, 2010
  2. Stephen BoydFeb 18, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.