]> git.ipfire.org Git - thirdparty/git.git/commit
color: use git_colorbool enum type to store colorbools
authorJeff King <peff@peff.net>
Tue, 16 Sep 2025 23:13:59 +0000 (19:13 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Sep 2025 00:59:53 +0000 (17:59 -0700)
commite9330ae4b820147c98e723399e9438c8bee60a80
treea11428abbe26af8cefa925e99cd81f233d997799
parent5e9ddd3c0652ad4e16cc33525d611e23f61dc6a5
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>
23 files changed:
add-interactive.c
advice.c
builtin/branch.c
builtin/clean.c
builtin/commit.c
builtin/config.c
builtin/push.c
builtin/show-branch.c
color.c
color.h
combine-diff.c
diff.c
diff.h
grep.h
log-tree.c
log-tree.h
parse-options-cb.c
pretty.c
pretty.h
ref-filter.h
sideband.c
transport.c
wt-status.h