mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
5e9ddd3c06
commit
e9330ae4b8
@@ -39,7 +39,7 @@ static void init_color(struct repository *r, int use_color,
|
||||
static int check_color_config(struct repository *r, const char *var)
|
||||
{
|
||||
const char *value;
|
||||
int ret;
|
||||
enum git_colorbool ret;
|
||||
|
||||
if (repo_config_get_value(r, var, &value))
|
||||
ret = GIT_COLOR_UNKNOWN;
|
||||
|
||||
Reference in New Issue
Block a user