]> git.ipfire.org Git - thirdparty/git.git/commit
color: return bool from want_color()
authorJeff King <peff@peff.net>
Tue, 16 Sep 2025 20:25:26 +0000 (16:25 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Sep 2025 01:00:25 +0000 (18:00 -0700)
commitb978f7803400b9f0c54f5874b085064c44a6c372
tree3e41aeb9c9bcb753fb8c6e506edaeb3d9cbd3f61
parente9330ae4b820147c98e723399e9438c8bee60a80
color: return bool from want_color()

The point of want_color() is to take in a git_colorbool enum value and
collapse it down to a single true/false boolean, letting UNKNOWN fall
back to the color.ui default and checking isatty() for AUTO.

Let's make that more clear in the type system by returning a bool rather
than an integer.

This sadly still does not help us much with compiler warnings for using
the two types interchangeably. But it helps make the intent more clear
to a human reader.

We still retain the idempotency of want_color(), because in C a bool
true/false converts to 1/0 when converted to an integer, which
corresponds to GIT_COLOR_ALWAYS and GIT_COLOR_NEVER. So you can store
the bool in a git_colorbool and get the right result (something a few
pieces of code still do, but which we'll clean up in further patches).

Note that we rely on this same bool/int conversion for
check_auto_color(). We cache its results in a tristate int with "-1" as
"not yet set", but we can assign to it (and return it) with implicit
conversions to/from bool.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
color.c
color.h