git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] config: refactor management of color.ui's default value
@ 2013-06-10 14:26 Matthieu Moy
  2013-06-10 14:26 ` [PATCH 2/2] make color.ui default to 'auto' Matthieu Moy
  2013-06-10 20:50 ` [PATCH 1/2] config: refactor management of color.ui's default value Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Matthieu Moy @ 2013-06-10 14:26 UTC (permalink / raw)
  To: git, gitster; +Cc: Matthieu Moy

The meaning of get_colorbool_found and get_diff_color_found is "the
config value if found, and -1 otherwise", but get_color_ui_found had a
slightly different meaning, as it has the value 0 (which corresponds to
the default value from the user point of view) when color.ui is unset.

Make get_color_ui_found default to -1, and make it explicit that 0 is the
default value when nothing else is found.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
This one is just a resend of what's already in pu.

 builtin/config.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/builtin/config.c b/builtin/config.c
index 33c9bf9..057bb61 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -329,6 +329,7 @@ static int get_colorbool(int print)
 {
 	get_colorbool_found = -1;
 	get_diff_color_found = -1;
+	get_color_ui_found = -1;
 	git_config_with_options(git_get_colorbool_config, NULL,
 				given_config_file, respect_includes);
 
@@ -339,6 +340,10 @@ static int get_colorbool(int print)
 			get_colorbool_found = get_color_ui_found;
 	}
 
+	if (get_colorbool_found < 0)
+		/* default value if none found in config */
+		get_colorbool_found = 0;
+
 	get_colorbool_found = want_color(get_colorbool_found);
 
 	if (print) {
-- 
1.8.3.rc3.8.g5e49f30

^ permalink raw reply related	[flat|nested] 4+ messages in thread
* Re: [PATCH v2] make color.ui default to 'auto'
@ 2013-05-15 16:52 Matthieu Moy
  2013-05-15 17:00 ` [PATCH 1/2] config: refactor management of color.ui's default value Matthieu Moy
  0 siblings, 1 reply; 4+ messages in thread
From: Matthieu Moy @ 2013-05-15 16:52 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johan Herland, Felipe Contreras

Junio C Hamano <gitster@pobox.com> writes:

> Matthieu Moy <Matthieu.Moy@imag.fr> writes:
>
>> diff --git a/builtin/config.c b/builtin/config.c
>> index 000d27c..ecfceca 100644
>> --- a/builtin/config.c
>> +++ b/builtin/config.c
>> @@ -316,7 +316,7 @@ static void get_color(const char *def_color)
>>  
>>  static int get_colorbool_found;
>>  static int get_diff_color_found;
>> -static int get_color_ui_found;
>> +static int get_color_ui_found = GIT_COLOR_AUTO;
>
> It is curious to notice that we have these three and only one is
> initialized to the new default value, while the other two get -1
> at the beginning of get_colorbool().

Right. The meaning of the _found suffix is clear for the first two, but
not the last.

> I wonder if it would be cleaner to statically initialize all three
> to -1 here, drop the assignment of -1 to two of them from the
> beginning of get_colorbool(), and then have a final fallback inside
> the want_color() call itself, i.e.

I've left the assignments within the function (I like the initialisation
right before usage, I don't have to worry about how many times the
function is called then), but I've added a patch that initializes
get_color_ui_found to -1 like the others, and does essentially this:

> 	get_colorbool_found = want_color(get_colorbool_found < 0
>         				? GIT_COLOR_AUTO
>                                         : get_colorbool_found);

Except I've made it a separate if statement. Then PATCH 2/2 is really
crystal clear.

Reroll comming, with an improved commit message that should adress the
points in the other message.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-06-10 20:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-10 14:26 [PATCH 1/2] config: refactor management of color.ui's default value Matthieu Moy
2013-06-10 14:26 ` [PATCH 2/2] make color.ui default to 'auto' Matthieu Moy
2013-06-10 20:50 ` [PATCH 1/2] config: refactor management of color.ui's default value Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2013-05-15 16:52 [PATCH v2] make color.ui default to 'auto' Matthieu Moy
2013-05-15 17:00 ` [PATCH 1/2] config: refactor management of color.ui's default value Matthieu Moy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).