From 53e8a435ba94cc222f74efe49efc9f386ad2f490 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 16 Sep 2025 16:14:07 -0400 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- color.c | 2 +- color.h | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/color.c b/color.c index 22aa453fef..f3adce0141 100644 --- a/color.c +++ b/color.c @@ -369,7 +369,7 @@ bad: #undef OUT } -int git_config_colorbool(const char *var, const char *value) +enum git_colorbool git_config_colorbool(const char *var, const char *value) { if (value) { if (!strcasecmp(value, "never")) diff --git a/color.h b/color.h index 7ed259a35b..303e2c9a6d 100644 --- a/color.h +++ b/color.h @@ -73,10 +73,12 @@ struct strbuf; * returned from git_config_colorbool. The "auto" value can be returned from * config_colorbool, and will be converted by want_color() into either 0 or 1. */ -#define GIT_COLOR_UNKNOWN -1 -#define GIT_COLOR_NEVER 0 -#define GIT_COLOR_ALWAYS 1 -#define GIT_COLOR_AUTO 2 +enum git_colorbool { + GIT_COLOR_UNKNOWN = -1, + GIT_COLOR_NEVER = 0, + GIT_COLOR_ALWAYS = 1, + GIT_COLOR_AUTO = 2, +}; /* A default list of colors to use for commit graphs and show-branch output */ extern const char *column_colors_ansi[]; @@ -98,7 +100,7 @@ int git_color_config(const char *var, const char *value, void *cb); * GIT_COLOR_ALWAYS for "always" or a positive boolean, * and GIT_COLOR_AUTO for "auto". */ -int git_config_colorbool(const char *var, const char *value); +enum git_colorbool git_config_colorbool(const char *var, const char *value); /* * Return a boolean whether to use color, where the argument 'var' is -- 2.47.3