]> git.ipfire.org Git - thirdparty/git.git/commitdiff
color: return enum from git_config_colorbool()
authorJeff King <peff@peff.net>
Tue, 16 Sep 2025 20:14:07 +0000 (16:14 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Sep 2025 20:37:04 +0000 (13:37 -0700)
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>
color.c
color.h

diff --git a/color.c b/color.c
index 22aa453fefa36418375ba3c0ff422cfb74335384..f3adce01415b1f36704d6c5adf26506322f41881 100644 (file)
--- 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 7ed259a35bb450ea5a0b479d2a0c9929f2f1b47a..303e2c9a6dcf2a9bdb28229cde2e521717f9a2aa 100644 (file)
--- 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