summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f1c9626)
raw | patch | inline | side by side (parent: f1c9626)
author | Jeff King <peff@peff.net> | |
Thu, 18 Aug 2011 05:03:48 +0000 (22:03 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 18 Aug 2011 21:48:29 +0000 (14:48 -0700) |
Usually this function figures out for itself whether stdout
is a tty. However, it has an extra parameter just to allow
git-config to override the auto-detection for its
--get-colorbool option.
Instead of an extra parameter, let's just use a global
variable. This makes calling easier in the common case, and
will make refactoring the colorbool code much simpler.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
is a tty. However, it has an extra parameter just to allow
git-config to override the auto-detection for its
--get-colorbool option.
Instead of an extra parameter, let's just use a global
variable. This makes calling easier in the common case, and
will make refactoring the colorbool code much simpler.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c | patch | blob | history | |
builtin/commit.c | patch | blob | history | |
builtin/config.c | patch | blob | history | |
builtin/grep.c | patch | blob | history | |
builtin/show-branch.c | patch | blob | history | |
color.c | patch | blob | history | |
color.h | patch | blob | history | |
diff.c | patch | blob | history | |
parse-options.c | patch | blob | history |
diff --git a/builtin/branch.c b/builtin/branch.c
index 3142daa57a6fa1c8a7d21095946bf5d26443d0e0..b15fee5e31893ece7f0d9f7d6cd2b8c1f51ab6f4 100644 (file)
--- a/builtin/branch.c
+++ b/builtin/branch.c
static int git_branch_config(const char *var, const char *value, void *cb)
{
if (!strcmp(var, "color.branch")) {
- branch_use_color = git_config_colorbool(var, value, -1);
+ branch_use_color = git_config_colorbool(var, value);
return 0;
}
if (!prefixcmp(var, "color.branch.")) {
diff --git a/builtin/commit.c b/builtin/commit.c
index e1af9b19f0be71484ae9341762dc2bf89cabb70c..295803a265fbf04345af6b98af8f28873735143f 100644 (file)
--- a/builtin/commit.c
+++ b/builtin/commit.c
return 0;
}
if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
- s->use_color = git_config_colorbool(k, v, -1);
+ s->use_color = git_config_colorbool(k, v);
return 0;
}
if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
diff --git a/builtin/config.c b/builtin/config.c
index 211e118d575411b712ccf0387db2408708576902..5505ced8c13c5b7a93baa02fe6bd23c54fc1b1b1 100644 (file)
--- a/builtin/config.c
+++ b/builtin/config.c
fputs(parsed_color, stdout);
}
-static int stdout_is_tty;
static int get_colorbool_found;
static int get_diff_color_found;
static int git_get_colorbool_config(const char *var, const char *value,
void *cb)
{
- if (!strcmp(var, get_colorbool_slot)) {
- get_colorbool_found =
- git_config_colorbool(var, value, stdout_is_tty);
- }
- if (!strcmp(var, "diff.color")) {
- get_diff_color_found =
- git_config_colorbool(var, value, stdout_is_tty);
- }
- if (!strcmp(var, "color.ui")) {
- git_use_color_default = git_config_colorbool(var, value, stdout_is_tty);
- return 0;
- }
+ if (!strcmp(var, get_colorbool_slot))
+ get_colorbool_found = git_config_colorbool(var, value);
+ else if (!strcmp(var, "diff.color"))
+ get_diff_color_found = git_config_colorbool(var, value);
+ else if (!strcmp(var, "color.ui"))
+ git_use_color_default = git_config_colorbool(var, value);
return 0;
}
}
else if (actions == ACTION_GET_COLORBOOL) {
if (argc == 1)
- stdout_is_tty = git_config_bool("command line", argv[0]);
- else if (argc == 0)
- stdout_is_tty = isatty(1);
+ color_stdout_is_tty = git_config_bool("command line", argv[0]);
return get_colorbool(argc != 0);
}
diff --git a/builtin/grep.c b/builtin/grep.c
index 871afaa3c76ea34b67671a6e4a46957a08a946e5..c17d7de562d1903fdd5ed8736d05014fec4e9f4a 100644 (file)
--- a/builtin/grep.c
+++ b/builtin/grep.c
}
if (!strcmp(var, "color.grep"))
- opt->color = git_config_colorbool(var, value, -1);
+ opt->color = git_config_colorbool(var, value);
else if (!strcmp(var, "color.grep.context"))
color = opt->color_context;
else if (!strcmp(var, "color.grep.filename"))
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index facc63a79ec0c86fd9df59792cd4f20030af5db1..e6650b483722b9c5ad2df1d6eb59af1cb9a88c39 100644 (file)
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
}
if (!strcmp(var, "color.showbranch")) {
- showbranch_use_color = git_config_colorbool(var, value, -1);
+ showbranch_use_color = git_config_colorbool(var, value);
return 0;
}
index 3db214c24720496f13481b718e46810c21f53b8d..67affa4765cff33186766143f935f7f7ec3ec91c 100644 (file)
--- a/color.c
+++ b/color.c
#include "color.h"
int git_use_color_default = 0;
+int color_stdout_is_tty = -1;
/*
* The list of available column colors.
die("bad color value '%.*s' for variable '%s'", value_len, value, var);
}
-int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
+int git_config_colorbool(const char *var, const char *value)
{
if (value) {
if (!strcasecmp(value, "never"))
/* any normal truth value defaults to 'auto' */
auto_color:
- if (stdout_is_tty < 0)
- stdout_is_tty = isatty(1);
- if (stdout_is_tty || (pager_in_use() && pager_use_color)) {
+ if (color_stdout_is_tty < 0)
+ color_stdout_is_tty = isatty(1);
+ if (color_stdout_is_tty || (pager_in_use() && pager_use_color)) {
char *term = getenv("TERM");
if (term && strcmp(term, "dumb"))
return 1;
int git_color_default_config(const char *var, const char *value, void *cb)
{
if (!strcmp(var, "color.ui")) {
- git_use_color_default = git_config_colorbool(var, value, -1);
+ git_use_color_default = git_config_colorbool(var, value);
return 0;
}
index 68a926a2cdfb870ae0da0bfbc4c5b36681609911..a190a2522b12aa8711ff1ec74bd9a861b8267e35 100644 (file)
--- a/color.h
+++ b/color.h
extern const char *column_colors_ansi[];
extern const int column_colors_ansi_max;
+/*
+ * Generally the color code will lazily figure this out itself, but
+ * this provides a mechanism for callers to override autodetection.
+ */
+extern int color_stdout_is_tty;
+
/*
* Use this instead of git_default_config if you need the value of color.ui.
*/
int git_color_default_config(const char *var, const char *value, void *cb);
-int git_config_colorbool(const char *var, const char *value, int stdout_is_tty);
+int git_config_colorbool(const char *var, const char *value);
void color_parse(const char *value, const char *var, char *dst);
void color_parse_mem(const char *value, int len, const char *var, char *dst);
__attribute__((format (printf, 3, 4)))
index cd5ad7525babd815b36797aded562f7049bb5895..1f87f23190fd9817a2bae388197a1ca26cd7e1ae 100644 (file)
--- a/diff.c
+++ b/diff.c
int git_diff_ui_config(const char *var, const char *value, void *cb)
{
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
- diff_use_color_default = git_config_colorbool(var, value, -1);
+ diff_use_color_default = git_config_colorbool(var, value);
return 0;
}
if (!strcmp(var, "diff.renames")) {
else if (!strcmp(arg, "--color"))
options->use_color = 1;
else if (!prefixcmp(arg, "--color=")) {
- int value = git_config_colorbool(NULL, arg+8, -1);
+ int value = git_config_colorbool(NULL, arg+8);
if (value == 0)
options->use_color = 0;
else if (value > 0)
diff --git a/parse-options.c b/parse-options.c
index 73bd28ad90986af1618d82176076133186d045de..12a5b25d09ca8725c7e948192235f3d53b331b18 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
if (!arg)
arg = unset ? "never" : (const char *)opt->defval;
- value = git_config_colorbool(NULL, arg, -1);
+ value = git_config_colorbool(NULL, arg);
if (value < 0)
return opterror(opt,
"expects \"always\", \"auto\", or \"never\"", 0);