Skip to content

Commit 53e8a43

Browse files
peffgitster
authored andcommitted
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>
1 parent 3c3e9b8 commit 53e8a43

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

color.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ int color_parse_mem(const char *value, int value_len, char *dst)
369369
#undef OUT
370370
}
371371

372-
int git_config_colorbool(const char *var, const char *value)
372+
enum git_colorbool git_config_colorbool(const char *var, const char *value)
373373
{
374374
if (value) {
375375
if (!strcasecmp(value, "never"))

color.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ struct strbuf;
7373
* returned from git_config_colorbool. The "auto" value can be returned from
7474
* config_colorbool, and will be converted by want_color() into either 0 or 1.
7575
*/
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+
};
8082

8183
/* A default list of colors to use for commit graphs and show-branch output */
8284
extern const char *column_colors_ansi[];
@@ -98,7 +100,7 @@ int git_color_config(const char *var, const char *value, void *cb);
98100
* GIT_COLOR_ALWAYS for "always" or a positive boolean,
99101
* and GIT_COLOR_AUTO for "auto".
100102
*/
101-
int git_config_colorbool(const char *var, const char *value);
103+
enum git_colorbool git_config_colorbool(const char *var, const char *value);
102104

103105
/*
104106
* Return a boolean whether to use color, where the argument 'var' is

0 commit comments

Comments
 (0)