diff options
author | Jeff King <peff@peff.net> | 2011-08-17 22:03:48 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-08-18 14:48:29 -0700 |
commit | e269eb7946d0a4ba6a4e175133b5479446ac04a5 (patch) | |
tree | 65da98cebb4776458fa7944ba7101c2f4149f1f7 /builtin | |
parent | f1c9626105d5e4962a5ccaa4620114d03f32ad02 (diff) | |
download | git-e269eb7946d0a4ba6a4e175133b5479446ac04a5.tar.gz |
git_config_colorbool: refactor stdout_is_tty handling
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>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/branch.c | 2 | ||||
-rw-r--r-- | builtin/commit.c | 2 | ||||
-rw-r--r-- | builtin/config.c | 23 | ||||
-rw-r--r-- | builtin/grep.c | 2 | ||||
-rw-r--r-- | builtin/show-branch.c | 2 |
5 files changed, 11 insertions, 20 deletions
diff --git a/builtin/branch.c b/builtin/branch.c index 3142daa57a..b15fee5e31 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -71,7 +71,7 @@ static int parse_branch_color_slot(const char *var, int ofs) 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 e1af9b19f0..295803a265 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1144,7 +1144,7 @@ static int git_status_config(const char *k, const char *v, void *cb) 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 211e118d57..5505ced8c1 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -303,24 +303,17 @@ static void get_color(const char *def_color) 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; } @@ -510,9 +503,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) } 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 871afaa3c7..c17d7de562 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -316,7 +316,7 @@ static int grep_config(const char *var, const char *value, void *cb) } 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 facc63a79e..e6650b4837 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -573,7 +573,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb) } if (!strcmp(var, "color.showbranch")) { - showbranch_use_color = git_config_colorbool(var, value, -1); + showbranch_use_color = git_config_colorbool(var, value); return 0; } |