Git fork

color: return enum from git_config_colorbool()

The git_config_colorbool() function returns an integer which is always
one of the GIT_COLOR_* constants UNKNOWN, NEVER, ALWAYS, or AUTO. We
define these constants with macros, but let's switch to using an enum.
Even though the compiler does not strictly enforce enum/int conversions,
this should make the intent clearer to human readers. And as a bonus,
enum names are typically available to debuggers, making it more pleasant
to step through the code there.

This patch updates the return type of git_config_colorbool(), but holds
off on updating all of the callers. There's some trickiness to some of
them, and in the meantime it's perfectly fine to assign an enum into an
int.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Jeff King and committed by
Junio C Hamano
53e8a435 3c3e9b83

+8 -6
+1 -1
color.c
··· 369 369 #undef OUT 370 370 } 371 371 372 - int git_config_colorbool(const char *var, const char *value) 372 + enum git_colorbool git_config_colorbool(const char *var, const char *value) 373 373 { 374 374 if (value) { 375 375 if (!strcasecmp(value, "never"))
+7 -5
color.h
··· 73 73 * returned from git_config_colorbool. The "auto" value can be returned from 74 74 * config_colorbool, and will be converted by want_color() into either 0 or 1. 75 75 */ 76 - #define GIT_COLOR_UNKNOWN -1 77 - #define GIT_COLOR_NEVER 0 78 - #define GIT_COLOR_ALWAYS 1 79 - #define GIT_COLOR_AUTO 2 76 + enum git_colorbool { 77 + GIT_COLOR_UNKNOWN = -1, 78 + GIT_COLOR_NEVER = 0, 79 + GIT_COLOR_ALWAYS = 1, 80 + GIT_COLOR_AUTO = 2, 81 + }; 80 82 81 83 /* A default list of colors to use for commit graphs and show-branch output */ 82 84 extern const char *column_colors_ansi[]; ··· 98 100 * GIT_COLOR_ALWAYS for "always" or a positive boolean, 99 101 * and GIT_COLOR_AUTO for "auto". 100 102 */ 101 - int git_config_colorbool(const char *var, const char *value); 103 + enum git_colorbool git_config_colorbool(const char *var, const char *value); 102 104 103 105 /* 104 106 * Return a boolean whether to use color, where the argument 'var' is