From e9330ae4b820147c98e723399e9438c8bee60a80 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 16 Sep 2025 19:13:59 -0400 Subject: color: use git_colorbool enum type to store colorbools We traditionally used "int" to store and pass around the values defined by "enum git_colorbool" (which were originally just #define macros). Using an int doesn't produce incorrect results, but using the actual enum makes the intent of the code more clear. It would be nice if the compiler could catch cases where we used the enum and an int interchangeably, since it's very easy to accidentally check the boolean true/false of a colorbool like: if (branch_use_color) This is wrong because GIT_COLOR_UNKNOWN and GIT_COLOR_AUTO evaluate to true in C, even though we may ultimately decide not to use color. But C is pretty happy to convert between ints and enums (even with various -Wenum-* warnings). So this sadly doesn't protect us from such mistakes, but it hopefully does make the code easier to read. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'diff.h') diff --git a/diff.h b/diff.h index 62e5768a9a..8c345de7c8 100644 --- a/diff.h +++ b/diff.h @@ -7,6 +7,7 @@ #include "hash.h" #include "pathspec.h" #include "strbuf.h" +#include "color.h" struct oidset; @@ -283,7 +284,7 @@ struct diff_options { /* diff-filter bits */ unsigned int filter, filter_not; - int use_color; + enum git_colorbool use_color; /* Number of context lines to generate in patch output. */ int context; @@ -459,7 +460,7 @@ enum color_diff { DIFF_FILE_NEW_BOLD = 22, }; -const char *diff_get_color(int diff_use_color, enum color_diff ix); +const char *diff_get_color(enum git_colorbool diff_use_color, enum color_diff ix); #define diff_get_color_opt(o, ix) \ diff_get_color((o)->use_color, ix) -- cgit v1.2.3