diff options
| author | Jeff King <peff@peff.net> | 2025-09-16 19:13:59 -0400 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-09-16 17:59:53 -0700 |
| commit | e9330ae4b820147c98e723399e9438c8bee60a80 (patch) | |
| tree | a11428abbe26af8cefa925e99cd81f233d997799 /parse-options-cb.c | |
| parent | pretty: use format_commit_context.auto_color as colorbool (diff) | |
| download | git-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 'parse-options-cb.c')
| -rw-r--r-- | parse-options-cb.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/parse-options-cb.c b/parse-options-cb.c index e13e0a9e33..976cc86385 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -50,7 +50,7 @@ int parse_opt_expiry_date_cb(const struct option *opt, const char *arg, int parse_opt_color_flag_cb(const struct option *opt, const char *arg, int unset) { - int value; + enum git_colorbool value; if (!arg) arg = unset ? "never" : (const char *)opt->defval; |
