aboutsummaryrefslogtreecommitdiffstats
path: root/log-tree.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2025-09-16 19:13:59 -0400
committerJunio C Hamano <gitster@pobox.com>2025-09-16 17:59:53 -0700
commite9330ae4b820147c98e723399e9438c8bee60a80 (patch)
treea11428abbe26af8cefa925e99cd81f233d997799 /log-tree.c
parentpretty: use format_commit_context.auto_color as colorbool (diff)
downloadgit-e9330ae4b820147c98e723399e9438c8bee60a80.tar.gz
git-e9330ae4b820147c98e723399e9438c8bee60a80.zip
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>
Diffstat (limited to 'log-tree.c')
-rw-r--r--log-tree.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/log-tree.c b/log-tree.c
index 233bf9f227..a2cd5c587b 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -57,7 +57,7 @@ static const char *color_decorate_slots[] = {
[DECORATION_GRAFTED] = "grafted",
};
-static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
+static const char *decorate_get_color(enum git_colorbool decorate_use_color, enum decoration_type ix)
{
if (want_color(decorate_use_color))
return decoration_colors[ix];
@@ -341,7 +341,7 @@ static void show_name(struct strbuf *sb, const struct name_decoration *decoratio
*/
void format_decorations(struct strbuf *sb,
const struct commit *commit,
- int use_color,
+ enum git_colorbool use_color,
const struct decoration_options *opts)
{
const struct name_decoration *decoration;