Merge branch 'jk/color-and-pager'
* jk/color-and-pager: want_color: automatically fallback to color.ui diff: don't load color config in plumbing config: refactor get_colorbool function color: delay auto-color decision until point of use git_config_colorbool: refactor stdout_is_tty handling diff: refactor COLOR_DIFF from a flag into an int setup_pager: set GIT_PAGER_IN_USE t7006: use test_config helpers test-lib: add helper functions for config t7006: modernize calls to unset Conflicts: builtin/commit.c parse-options.c
This commit is contained in:
commit
f946b465d7
@ -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)
|
static int git_branch_config(const char *var, const char *value, void *cb)
|
||||||
{
|
{
|
||||||
if (!strcmp(var, "color.branch")) {
|
if (!strcmp(var, "color.branch")) {
|
||||||
branch_use_color = git_config_colorbool(var, value, -1);
|
branch_use_color = git_config_colorbool(var, value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!prefixcmp(var, "color.branch.")) {
|
if (!prefixcmp(var, "color.branch.")) {
|
||||||
@ -88,7 +88,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
|
|||||||
|
|
||||||
static const char *branch_get_color(enum color_branch ix)
|
static const char *branch_get_color(enum color_branch ix)
|
||||||
{
|
{
|
||||||
if (branch_use_color > 0)
|
if (want_color(branch_use_color))
|
||||||
return branch_colors[ix];
|
return branch_colors[ix];
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -673,9 +673,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
git_config(git_branch_config, NULL);
|
git_config(git_branch_config, NULL);
|
||||||
|
|
||||||
if (branch_use_color == -1)
|
|
||||||
branch_use_color = git_use_color_default;
|
|
||||||
|
|
||||||
track = git_branch_track;
|
track = git_branch_track;
|
||||||
|
|
||||||
head = resolve_ref("HEAD", head_sha1, 0, NULL);
|
head = resolve_ref("HEAD", head_sha1, 0, NULL);
|
||||||
|
@ -1141,7 +1141,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
|
if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
|
||||||
@ -1234,10 +1234,6 @@ int cmd_status(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
if (s.relative_paths)
|
if (s.relative_paths)
|
||||||
s.prefix = prefix;
|
s.prefix = prefix;
|
||||||
if (s.use_color == -1)
|
|
||||||
s.use_color = git_use_color_default;
|
|
||||||
if (diff_use_color_default == -1)
|
|
||||||
diff_use_color_default = git_use_color_default;
|
|
||||||
|
|
||||||
switch (status_format) {
|
switch (status_format) {
|
||||||
case STATUS_FORMAT_SHORT:
|
case STATUS_FORMAT_SHORT:
|
||||||
@ -1393,8 +1389,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
|||||||
git_config(git_commit_config, &s);
|
git_config(git_commit_config, &s);
|
||||||
determine_whence(&s);
|
determine_whence(&s);
|
||||||
|
|
||||||
if (s.use_color == -1)
|
|
||||||
s.use_color = git_use_color_default;
|
|
||||||
if (get_sha1("HEAD", sha1))
|
if (get_sha1("HEAD", sha1))
|
||||||
current_head = NULL;
|
current_head = NULL;
|
||||||
else {
|
else {
|
||||||
@ -1404,11 +1398,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
argc = parse_and_validate_options(argc, argv, builtin_commit_usage,
|
argc = parse_and_validate_options(argc, argv, builtin_commit_usage,
|
||||||
prefix, current_head, &s);
|
prefix, current_head, &s);
|
||||||
if (dry_run) {
|
if (dry_run)
|
||||||
if (diff_use_color_default == -1)
|
|
||||||
diff_use_color_default = git_use_color_default;
|
|
||||||
return dry_run_commit(argc, argv, prefix, current_head, &s);
|
return dry_run_commit(argc, argv, prefix, current_head, &s);
|
||||||
}
|
|
||||||
index_file = prepare_index(argc, argv, prefix, current_head, 0);
|
index_file = prepare_index(argc, argv, prefix, current_head, 0);
|
||||||
|
|
||||||
/* Set up everything for writing the commit object. This includes
|
/* Set up everything for writing the commit object. This includes
|
||||||
|
@ -303,24 +303,18 @@ static void get_color(const char *def_color)
|
|||||||
fputs(parsed_color, stdout);
|
fputs(parsed_color, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stdout_is_tty;
|
|
||||||
static int get_colorbool_found;
|
static int get_colorbool_found;
|
||||||
static int get_diff_color_found;
|
static int get_diff_color_found;
|
||||||
|
static int get_color_ui_found;
|
||||||
static int git_get_colorbool_config(const char *var, const char *value,
|
static int git_get_colorbool_config(const char *var, const char *value,
|
||||||
void *cb)
|
void *cb)
|
||||||
{
|
{
|
||||||
if (!strcmp(var, get_colorbool_slot)) {
|
if (!strcmp(var, get_colorbool_slot))
|
||||||
get_colorbool_found =
|
get_colorbool_found = git_config_colorbool(var, value);
|
||||||
git_config_colorbool(var, value, stdout_is_tty);
|
else if (!strcmp(var, "diff.color"))
|
||||||
}
|
get_diff_color_found = git_config_colorbool(var, value);
|
||||||
if (!strcmp(var, "diff.color")) {
|
else if (!strcmp(var, "color.ui"))
|
||||||
get_diff_color_found =
|
get_color_ui_found = git_config_colorbool(var, value);
|
||||||
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;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,9 +328,11 @@ static int get_colorbool(int print)
|
|||||||
if (!strcmp(get_colorbool_slot, "color.diff"))
|
if (!strcmp(get_colorbool_slot, "color.diff"))
|
||||||
get_colorbool_found = get_diff_color_found;
|
get_colorbool_found = get_diff_color_found;
|
||||||
if (get_colorbool_found < 0)
|
if (get_colorbool_found < 0)
|
||||||
get_colorbool_found = git_use_color_default;
|
get_colorbool_found = get_color_ui_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_colorbool_found = want_color(get_colorbool_found);
|
||||||
|
|
||||||
if (print) {
|
if (print) {
|
||||||
printf("%s\n", get_colorbool_found ? "true" : "false");
|
printf("%s\n", get_colorbool_found ? "true" : "false");
|
||||||
return 0;
|
return 0;
|
||||||
@ -510,9 +506,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
else if (actions == ACTION_GET_COLORBOOL) {
|
else if (actions == ACTION_GET_COLORBOOL) {
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
stdout_is_tty = git_config_bool("command line", argv[0]);
|
color_stdout_is_tty = git_config_bool("command line", argv[0]);
|
||||||
else if (argc == 0)
|
|
||||||
stdout_is_tty = isatty(1);
|
|
||||||
return get_colorbool(argc != 0);
|
return get_colorbool(argc != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,9 +277,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
|
|||||||
gitmodules_config();
|
gitmodules_config();
|
||||||
git_config(git_diff_ui_config, NULL);
|
git_config(git_diff_ui_config, NULL);
|
||||||
|
|
||||||
if (diff_use_color_default == -1)
|
|
||||||
diff_use_color_default = git_use_color_default;
|
|
||||||
|
|
||||||
init_revisions(&rev, prefix);
|
init_revisions(&rev, prefix);
|
||||||
|
|
||||||
/* If this is a no-index diff, just run it and exit there. */
|
/* If this is a no-index diff, just run it and exit there. */
|
||||||
|
@ -325,7 +325,7 @@ static int grep_config(const char *var, const char *value, void *cb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(var, "color.grep"))
|
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"))
|
else if (!strcmp(var, "color.grep.context"))
|
||||||
color = opt->color_context;
|
color = opt->color_context;
|
||||||
else if (!strcmp(var, "color.grep.filename"))
|
else if (!strcmp(var, "color.grep.filename"))
|
||||||
@ -898,8 +898,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
|
|||||||
strcpy(opt.color_sep, GIT_COLOR_CYAN);
|
strcpy(opt.color_sep, GIT_COLOR_CYAN);
|
||||||
opt.color = -1;
|
opt.color = -1;
|
||||||
git_config(grep_config, &opt);
|
git_config(grep_config, &opt);
|
||||||
if (opt.color == -1)
|
|
||||||
opt.color = git_use_color_default;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there is no -- then the paths must exist in the working
|
* If there is no -- then the paths must exist in the working
|
||||||
|
@ -359,9 +359,6 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
git_config(git_log_config, NULL);
|
git_config(git_log_config, NULL);
|
||||||
|
|
||||||
if (diff_use_color_default == -1)
|
|
||||||
diff_use_color_default = git_use_color_default;
|
|
||||||
|
|
||||||
init_revisions(&rev, prefix);
|
init_revisions(&rev, prefix);
|
||||||
rev.diff = 1;
|
rev.diff = 1;
|
||||||
rev.simplify_history = 0;
|
rev.simplify_history = 0;
|
||||||
@ -446,9 +443,6 @@ int cmd_show(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
git_config(git_log_config, NULL);
|
git_config(git_log_config, NULL);
|
||||||
|
|
||||||
if (diff_use_color_default == -1)
|
|
||||||
diff_use_color_default = git_use_color_default;
|
|
||||||
|
|
||||||
init_pathspec(&match_all, NULL);
|
init_pathspec(&match_all, NULL);
|
||||||
init_revisions(&rev, prefix);
|
init_revisions(&rev, prefix);
|
||||||
rev.diff = 1;
|
rev.diff = 1;
|
||||||
@ -524,9 +518,6 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
git_config(git_log_config, NULL);
|
git_config(git_log_config, NULL);
|
||||||
|
|
||||||
if (diff_use_color_default == -1)
|
|
||||||
diff_use_color_default = git_use_color_default;
|
|
||||||
|
|
||||||
init_revisions(&rev, prefix);
|
init_revisions(&rev, prefix);
|
||||||
init_reflog_walk(&rev.reflog_info);
|
init_reflog_walk(&rev.reflog_info);
|
||||||
rev.verbose_header = 1;
|
rev.verbose_header = 1;
|
||||||
@ -549,9 +540,6 @@ int cmd_log(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
git_config(git_log_config, NULL);
|
git_config(git_log_config, NULL);
|
||||||
|
|
||||||
if (diff_use_color_default == -1)
|
|
||||||
diff_use_color_default = git_use_color_default;
|
|
||||||
|
|
||||||
init_revisions(&rev, prefix);
|
init_revisions(&rev, prefix);
|
||||||
rev.always_show_header = 1;
|
rev.always_show_header = 1;
|
||||||
memset(&opt, 0, sizeof(opt));
|
memset(&opt, 0, sizeof(opt));
|
||||||
|
@ -390,8 +390,6 @@ static void finish(const unsigned char *new_head, const char *msg)
|
|||||||
opts.output_format |=
|
opts.output_format |=
|
||||||
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
|
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
|
||||||
opts.detect_rename = DIFF_DETECT_RENAME;
|
opts.detect_rename = DIFF_DETECT_RENAME;
|
||||||
if (diff_use_color_default > 0)
|
|
||||||
DIFF_OPT_SET(&opts, COLOR_DIFF);
|
|
||||||
if (diff_setup_done(&opts) < 0)
|
if (diff_setup_done(&opts) < 0)
|
||||||
die(_("diff_setup_done failed"));
|
die(_("diff_setup_done failed"));
|
||||||
diff_tree_sha1(head, new_head, "", &opts);
|
diff_tree_sha1(head, new_head, "", &opts);
|
||||||
@ -1033,10 +1031,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
git_config(git_merge_config, NULL);
|
git_config(git_merge_config, NULL);
|
||||||
|
|
||||||
/* for color.ui */
|
|
||||||
if (diff_use_color_default == -1)
|
|
||||||
diff_use_color_default = git_use_color_default;
|
|
||||||
|
|
||||||
if (branch_mergeoptions)
|
if (branch_mergeoptions)
|
||||||
parse_branch_merge_options(branch_mergeoptions);
|
parse_branch_merge_options(branch_mergeoptions);
|
||||||
argc = parse_options(argc, argv, prefix, builtin_merge_options,
|
argc = parse_options(argc, argv, prefix, builtin_merge_options,
|
||||||
|
@ -26,14 +26,14 @@ static const char **default_arg;
|
|||||||
|
|
||||||
static const char *get_color_code(int idx)
|
static const char *get_color_code(int idx)
|
||||||
{
|
{
|
||||||
if (showbranch_use_color)
|
if (want_color(showbranch_use_color))
|
||||||
return column_colors_ansi[idx % column_colors_ansi_max];
|
return column_colors_ansi[idx % column_colors_ansi_max];
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *get_color_reset_code(void)
|
static const char *get_color_reset_code(void)
|
||||||
{
|
{
|
||||||
if (showbranch_use_color)
|
if (want_color(showbranch_use_color))
|
||||||
return GIT_COLOR_RESET;
|
return GIT_COLOR_RESET;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -573,7 +573,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(var, "color.showbranch")) {
|
if (!strcmp(var, "color.showbranch")) {
|
||||||
showbranch_use_color = git_config_colorbool(var, value, -1);
|
showbranch_use_color = git_config_colorbool(var, value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,9 +685,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
|||||||
|
|
||||||
git_config(git_show_branch_config, NULL);
|
git_config(git_show_branch_config, NULL);
|
||||||
|
|
||||||
if (showbranch_use_color == -1)
|
|
||||||
showbranch_use_color = git_use_color_default;
|
|
||||||
|
|
||||||
/* If nothing is specified, try the default first */
|
/* If nothing is specified, try the default first */
|
||||||
if (ac == 1 && default_num) {
|
if (ac == 1 && default_num) {
|
||||||
ac = default_num;
|
ac = default_num;
|
||||||
|
46
color.c
46
color.c
@ -1,7 +1,8 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
|
|
||||||
int git_use_color_default = 0;
|
static int git_use_color_default = 0;
|
||||||
|
int color_stdout_is_tty = -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The list of available column colors.
|
* The list of available column colors.
|
||||||
@ -157,7 +158,7 @@ bad:
|
|||||||
die("bad color value '%.*s' for variable '%s'", value_len, value, var);
|
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 (value) {
|
||||||
if (!strcasecmp(value, "never"))
|
if (!strcasecmp(value, "never"))
|
||||||
@ -165,7 +166,7 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
|
|||||||
if (!strcasecmp(value, "always"))
|
if (!strcasecmp(value, "always"))
|
||||||
return 1;
|
return 1;
|
||||||
if (!strcasecmp(value, "auto"))
|
if (!strcasecmp(value, "auto"))
|
||||||
goto auto_color;
|
return GIT_COLOR_AUTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!var)
|
if (!var)
|
||||||
@ -176,10 +177,14 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* any normal truth value defaults to 'auto' */
|
/* any normal truth value defaults to 'auto' */
|
||||||
auto_color:
|
return GIT_COLOR_AUTO;
|
||||||
if (stdout_is_tty < 0)
|
}
|
||||||
stdout_is_tty = isatty(1);
|
|
||||||
if (stdout_is_tty || (pager_in_use() && pager_use_color)) {
|
static int check_auto_color(void)
|
||||||
|
{
|
||||||
|
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");
|
char *term = getenv("TERM");
|
||||||
if (term && strcmp(term, "dumb"))
|
if (term && strcmp(term, "dumb"))
|
||||||
return 1;
|
return 1;
|
||||||
@ -187,13 +192,36 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_color_default_config(const char *var, const char *value, void *cb)
|
int want_color(int var)
|
||||||
|
{
|
||||||
|
static int want_auto = -1;
|
||||||
|
|
||||||
|
if (var < 0)
|
||||||
|
var = git_use_color_default;
|
||||||
|
|
||||||
|
if (var == GIT_COLOR_AUTO) {
|
||||||
|
if (want_auto < 0)
|
||||||
|
want_auto = check_auto_color();
|
||||||
|
return want_auto;
|
||||||
|
}
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
|
int git_color_config(const char *var, const char *value, void *cb)
|
||||||
{
|
{
|
||||||
if (!strcmp(var, "color.ui")) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int git_color_default_config(const char *var, const char *value, void *cb)
|
||||||
|
{
|
||||||
|
if (git_color_config(var, value, cb) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return git_default_config(var, value, cb);
|
return git_default_config(var, value, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
color.h
22
color.h
@ -49,20 +49,34 @@ struct strbuf;
|
|||||||
#define GIT_COLOR_NIL "NIL"
|
#define GIT_COLOR_NIL "NIL"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This variable stores the value of color.ui
|
* The first three are chosen to match common usage in the code, and what is
|
||||||
|
* returned from git_config_colorbool. The "auto" value can be returned from
|
||||||
|
* config_colorbool, and will be converted by want_color() into either 0 or 1.
|
||||||
*/
|
*/
|
||||||
extern int git_use_color_default;
|
#define GIT_COLOR_UNKNOWN -1
|
||||||
|
#define GIT_COLOR_NEVER 0
|
||||||
|
#define GIT_COLOR_ALWAYS 1
|
||||||
|
#define GIT_COLOR_AUTO 2
|
||||||
|
|
||||||
/* A default list of colors to use for commit graphs and show-branch output */
|
/* A default list of colors to use for commit graphs and show-branch output */
|
||||||
extern const char *column_colors_ansi[];
|
extern const char *column_colors_ansi[];
|
||||||
extern const int column_colors_ansi_max;
|
extern const int column_colors_ansi_max;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use this instead of git_default_config if you need the value of color.ui.
|
* 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 the first one if you need only color config; the second is a convenience
|
||||||
|
* if you are just going to change to git_default_config, too.
|
||||||
|
*/
|
||||||
|
int git_color_config(const char *var, const char *value, void *cb);
|
||||||
int git_color_default_config(const char *var, const char *value, void *cb);
|
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);
|
||||||
|
int want_color(int var);
|
||||||
void color_parse(const char *value, const char *var, char *dst);
|
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);
|
void color_parse_mem(const char *value, int len, const char *var, char *dst);
|
||||||
__attribute__((format (printf, 3, 4)))
|
__attribute__((format (printf, 3, 4)))
|
||||||
|
@ -702,9 +702,8 @@ static void show_combined_header(struct combine_diff_path *elem,
|
|||||||
int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
|
int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
|
||||||
const char *a_prefix = opt->a_prefix ? opt->a_prefix : "a/";
|
const char *a_prefix = opt->a_prefix ? opt->a_prefix : "a/";
|
||||||
const char *b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
|
const char *b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
|
||||||
int use_color = DIFF_OPT_TST(opt, COLOR_DIFF);
|
const char *c_meta = diff_get_color_opt(opt, DIFF_METAINFO);
|
||||||
const char *c_meta = diff_get_color(use_color, DIFF_METAINFO);
|
const char *c_reset = diff_get_color_opt(opt, DIFF_RESET);
|
||||||
const char *c_reset = diff_get_color(use_color, DIFF_RESET);
|
|
||||||
const char *abb;
|
const char *abb;
|
||||||
int added = 0;
|
int added = 0;
|
||||||
int deleted = 0;
|
int deleted = 0;
|
||||||
@ -964,7 +963,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
|||||||
show_combined_header(elem, num_parent, dense, rev,
|
show_combined_header(elem, num_parent, dense, rev,
|
||||||
mode_differs, 1);
|
mode_differs, 1);
|
||||||
dump_sline(sline, cnt, num_parent,
|
dump_sline(sline, cnt, num_parent,
|
||||||
DIFF_OPT_TST(opt, COLOR_DIFF), result_deleted);
|
opt->use_color, result_deleted);
|
||||||
}
|
}
|
||||||
free(result);
|
free(result);
|
||||||
|
|
||||||
|
53
diff.c
53
diff.c
@ -137,7 +137,7 @@ static int git_config_rename(const char *var, const char *value)
|
|||||||
int git_diff_ui_config(const char *var, const char *value, void *cb)
|
int git_diff_ui_config(const char *var, const char *value, void *cb)
|
||||||
{
|
{
|
||||||
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!strcmp(var, "diff.renames")) {
|
if (!strcmp(var, "diff.renames")) {
|
||||||
@ -164,6 +164,9 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
|
|||||||
if (!strcmp(var, "diff.ignoresubmodules"))
|
if (!strcmp(var, "diff.ignoresubmodules"))
|
||||||
handle_ignore_submodules_arg(&default_diff_options, value);
|
handle_ignore_submodules_arg(&default_diff_options, value);
|
||||||
|
|
||||||
|
if (git_color_config(var, value, cb) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return git_diff_basic_config(var, value, cb);
|
return git_diff_basic_config(var, value, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +215,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
|
|||||||
if (!prefixcmp(var, "submodule."))
|
if (!prefixcmp(var, "submodule."))
|
||||||
return parse_submodule_config_option(var, value);
|
return parse_submodule_config_option(var, value);
|
||||||
|
|
||||||
return git_color_default_config(var, value, cb);
|
return git_default_config(var, value, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *quote_two(const char *one, const char *two)
|
static char *quote_two(const char *one, const char *two)
|
||||||
@ -583,11 +586,10 @@ static void emit_rewrite_diff(const char *name_a,
|
|||||||
struct diff_options *o)
|
struct diff_options *o)
|
||||||
{
|
{
|
||||||
int lc_a, lc_b;
|
int lc_a, lc_b;
|
||||||
int color_diff = DIFF_OPT_TST(o, COLOR_DIFF);
|
|
||||||
const char *name_a_tab, *name_b_tab;
|
const char *name_a_tab, *name_b_tab;
|
||||||
const char *metainfo = diff_get_color(color_diff, DIFF_METAINFO);
|
const char *metainfo = diff_get_color(o->use_color, DIFF_METAINFO);
|
||||||
const char *fraginfo = diff_get_color(color_diff, DIFF_FRAGINFO);
|
const char *fraginfo = diff_get_color(o->use_color, DIFF_FRAGINFO);
|
||||||
const char *reset = diff_get_color(color_diff, DIFF_RESET);
|
const char *reset = diff_get_color(o->use_color, DIFF_RESET);
|
||||||
static struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT;
|
static struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT;
|
||||||
const char *a_prefix, *b_prefix;
|
const char *a_prefix, *b_prefix;
|
||||||
char *data_one, *data_two;
|
char *data_one, *data_two;
|
||||||
@ -623,7 +625,7 @@ static void emit_rewrite_diff(const char *name_a,
|
|||||||
size_two = fill_textconv(textconv_two, two, &data_two);
|
size_two = fill_textconv(textconv_two, two, &data_two);
|
||||||
|
|
||||||
memset(&ecbdata, 0, sizeof(ecbdata));
|
memset(&ecbdata, 0, sizeof(ecbdata));
|
||||||
ecbdata.color_diff = color_diff;
|
ecbdata.color_diff = want_color(o->use_color);
|
||||||
ecbdata.found_changesp = &o->found_changes;
|
ecbdata.found_changesp = &o->found_changes;
|
||||||
ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
|
ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
|
||||||
ecbdata.opt = o;
|
ecbdata.opt = o;
|
||||||
@ -1004,7 +1006,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
|
|||||||
|
|
||||||
const char *diff_get_color(int diff_use_color, enum color_diff ix)
|
const char *diff_get_color(int diff_use_color, enum color_diff ix)
|
||||||
{
|
{
|
||||||
if (diff_use_color)
|
if (want_color(diff_use_color))
|
||||||
return diff_colors[ix];
|
return diff_colors[ix];
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -1808,11 +1810,10 @@ static int is_conflict_marker(const char *line, int marker_size, unsigned long l
|
|||||||
static void checkdiff_consume(void *priv, char *line, unsigned long len)
|
static void checkdiff_consume(void *priv, char *line, unsigned long len)
|
||||||
{
|
{
|
||||||
struct checkdiff_t *data = priv;
|
struct checkdiff_t *data = priv;
|
||||||
int color_diff = DIFF_OPT_TST(data->o, COLOR_DIFF);
|
|
||||||
int marker_size = data->conflict_marker_size;
|
int marker_size = data->conflict_marker_size;
|
||||||
const char *ws = diff_get_color(color_diff, DIFF_WHITESPACE);
|
const char *ws = diff_get_color(data->o->use_color, DIFF_WHITESPACE);
|
||||||
const char *reset = diff_get_color(color_diff, DIFF_RESET);
|
const char *reset = diff_get_color(data->o->use_color, DIFF_RESET);
|
||||||
const char *set = diff_get_color(color_diff, DIFF_FILE_NEW);
|
const char *set = diff_get_color(data->o->use_color, DIFF_FILE_NEW);
|
||||||
char *err;
|
char *err;
|
||||||
char *line_prefix = "";
|
char *line_prefix = "";
|
||||||
struct strbuf *msgbuf;
|
struct strbuf *msgbuf;
|
||||||
@ -2157,7 +2158,7 @@ static void builtin_diff(const char *name_a,
|
|||||||
memset(&xecfg, 0, sizeof(xecfg));
|
memset(&xecfg, 0, sizeof(xecfg));
|
||||||
memset(&ecbdata, 0, sizeof(ecbdata));
|
memset(&ecbdata, 0, sizeof(ecbdata));
|
||||||
ecbdata.label_path = lbl;
|
ecbdata.label_path = lbl;
|
||||||
ecbdata.color_diff = DIFF_OPT_TST(o, COLOR_DIFF);
|
ecbdata.color_diff = want_color(o->use_color);
|
||||||
ecbdata.found_changesp = &o->found_changes;
|
ecbdata.found_changesp = &o->found_changes;
|
||||||
ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
|
ecbdata.ws_rule = whitespace_rule(name_b ? name_b : name_a);
|
||||||
if (ecbdata.ws_rule & WS_BLANK_AT_EOF)
|
if (ecbdata.ws_rule & WS_BLANK_AT_EOF)
|
||||||
@ -2205,7 +2206,7 @@ static void builtin_diff(const char *name_a,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DIFF_OPT_TST(o, COLOR_DIFF)) {
|
if (want_color(o->use_color)) {
|
||||||
struct diff_words_style *st = ecbdata.diff_words->style;
|
struct diff_words_style *st = ecbdata.diff_words->style;
|
||||||
st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD);
|
st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD);
|
||||||
st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW);
|
st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW);
|
||||||
@ -2855,7 +2856,7 @@ static void run_diff_cmd(const char *pgm,
|
|||||||
*/
|
*/
|
||||||
fill_metainfo(msg, name, other, one, two, o, p,
|
fill_metainfo(msg, name, other, one, two, o, p,
|
||||||
&must_show_header,
|
&must_show_header,
|
||||||
DIFF_OPT_TST(o, COLOR_DIFF) && !pgm);
|
want_color(o->use_color) && !pgm);
|
||||||
xfrm_msg = msg->len ? msg->buf : NULL;
|
xfrm_msg = msg->len ? msg->buf : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3021,8 +3022,7 @@ void diff_setup(struct diff_options *options)
|
|||||||
|
|
||||||
options->change = diff_change;
|
options->change = diff_change;
|
||||||
options->add_remove = diff_addremove;
|
options->add_remove = diff_addremove;
|
||||||
if (diff_use_color_default > 0)
|
options->use_color = diff_use_color_default;
|
||||||
DIFF_OPT_SET(options, COLOR_DIFF);
|
|
||||||
options->detect_rename = diff_detect_rename_default;
|
options->detect_rename = diff_detect_rename_default;
|
||||||
|
|
||||||
if (diff_no_prefix) {
|
if (diff_no_prefix) {
|
||||||
@ -3412,24 +3412,21 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
|||||||
else if (!strcmp(arg, "--follow"))
|
else if (!strcmp(arg, "--follow"))
|
||||||
DIFF_OPT_SET(options, FOLLOW_RENAMES);
|
DIFF_OPT_SET(options, FOLLOW_RENAMES);
|
||||||
else if (!strcmp(arg, "--color"))
|
else if (!strcmp(arg, "--color"))
|
||||||
DIFF_OPT_SET(options, COLOR_DIFF);
|
options->use_color = 1;
|
||||||
else if (!prefixcmp(arg, "--color=")) {
|
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)
|
if (value < 0)
|
||||||
DIFF_OPT_CLR(options, COLOR_DIFF);
|
|
||||||
else if (value > 0)
|
|
||||||
DIFF_OPT_SET(options, COLOR_DIFF);
|
|
||||||
else
|
|
||||||
return error("option `color' expects \"always\", \"auto\", or \"never\"");
|
return error("option `color' expects \"always\", \"auto\", or \"never\"");
|
||||||
|
options->use_color = value;
|
||||||
}
|
}
|
||||||
else if (!strcmp(arg, "--no-color"))
|
else if (!strcmp(arg, "--no-color"))
|
||||||
DIFF_OPT_CLR(options, COLOR_DIFF);
|
options->use_color = 0;
|
||||||
else if (!strcmp(arg, "--color-words")) {
|
else if (!strcmp(arg, "--color-words")) {
|
||||||
DIFF_OPT_SET(options, COLOR_DIFF);
|
options->use_color = 1;
|
||||||
options->word_diff = DIFF_WORDS_COLOR;
|
options->word_diff = DIFF_WORDS_COLOR;
|
||||||
}
|
}
|
||||||
else if (!prefixcmp(arg, "--color-words=")) {
|
else if (!prefixcmp(arg, "--color-words=")) {
|
||||||
DIFF_OPT_SET(options, COLOR_DIFF);
|
options->use_color = 1;
|
||||||
options->word_diff = DIFF_WORDS_COLOR;
|
options->word_diff = DIFF_WORDS_COLOR;
|
||||||
options->word_regex = arg + 14;
|
options->word_regex = arg + 14;
|
||||||
}
|
}
|
||||||
@ -3442,7 +3439,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
|||||||
if (!strcmp(type, "plain"))
|
if (!strcmp(type, "plain"))
|
||||||
options->word_diff = DIFF_WORDS_PLAIN;
|
options->word_diff = DIFF_WORDS_PLAIN;
|
||||||
else if (!strcmp(type, "color")) {
|
else if (!strcmp(type, "color")) {
|
||||||
DIFF_OPT_SET(options, COLOR_DIFF);
|
options->use_color = 1;
|
||||||
options->word_diff = DIFF_WORDS_COLOR;
|
options->word_diff = DIFF_WORDS_COLOR;
|
||||||
}
|
}
|
||||||
else if (!strcmp(type, "porcelain"))
|
else if (!strcmp(type, "porcelain"))
|
||||||
|
5
diff.h
5
diff.h
@ -58,7 +58,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
|
|||||||
#define DIFF_OPT_SILENT_ON_REMOVE (1 << 5)
|
#define DIFF_OPT_SILENT_ON_REMOVE (1 << 5)
|
||||||
#define DIFF_OPT_FIND_COPIES_HARDER (1 << 6)
|
#define DIFF_OPT_FIND_COPIES_HARDER (1 << 6)
|
||||||
#define DIFF_OPT_FOLLOW_RENAMES (1 << 7)
|
#define DIFF_OPT_FOLLOW_RENAMES (1 << 7)
|
||||||
#define DIFF_OPT_COLOR_DIFF (1 << 8)
|
/* (1 << 8) unused */
|
||||||
/* (1 << 9) unused */
|
/* (1 << 9) unused */
|
||||||
#define DIFF_OPT_HAS_CHANGES (1 << 10)
|
#define DIFF_OPT_HAS_CHANGES (1 << 10)
|
||||||
#define DIFF_OPT_QUICK (1 << 11)
|
#define DIFF_OPT_QUICK (1 << 11)
|
||||||
@ -101,6 +101,7 @@ struct diff_options {
|
|||||||
const char *single_follow;
|
const char *single_follow;
|
||||||
const char *a_prefix, *b_prefix;
|
const char *a_prefix, *b_prefix;
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
|
int use_color;
|
||||||
int context;
|
int context;
|
||||||
int interhunkcontext;
|
int interhunkcontext;
|
||||||
int break_opt;
|
int break_opt;
|
||||||
@ -160,7 +161,7 @@ enum color_diff {
|
|||||||
};
|
};
|
||||||
const char *diff_get_color(int diff_use_color, enum color_diff ix);
|
const char *diff_get_color(int diff_use_color, enum color_diff ix);
|
||||||
#define diff_get_color_opt(o, ix) \
|
#define diff_get_color_opt(o, ix) \
|
||||||
diff_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)
|
diff_get_color((o)->use_color, ix)
|
||||||
|
|
||||||
|
|
||||||
extern const char mime_boundary_leader[];
|
extern const char mime_boundary_leader[];
|
||||||
|
2
graph.c
2
graph.c
@ -347,7 +347,7 @@ static struct commit_list *first_interesting_parent(struct git_graph *graph)
|
|||||||
|
|
||||||
static unsigned short graph_get_current_column_color(const struct git_graph *graph)
|
static unsigned short graph_get_current_column_color(const struct git_graph *graph)
|
||||||
{
|
{
|
||||||
if (!DIFF_OPT_TST(&graph->revs->diffopt, COLOR_DIFF))
|
if (!want_color(graph->revs->diffopt.use_color))
|
||||||
return column_colors_max;
|
return column_colors_max;
|
||||||
return graph->default_column_color;
|
return graph->default_column_color;
|
||||||
}
|
}
|
||||||
|
2
grep.c
2
grep.c
@ -430,7 +430,7 @@ static int word_char(char ch)
|
|||||||
static void output_color(struct grep_opt *opt, const void *data, size_t size,
|
static void output_color(struct grep_opt *opt, const void *data, size_t size,
|
||||||
const char *color)
|
const char *color)
|
||||||
{
|
{
|
||||||
if (opt->color && color && color[0]) {
|
if (want_color(opt->color) && color && color[0]) {
|
||||||
opt->output(opt, color, strlen(color));
|
opt->output(opt, color, strlen(color));
|
||||||
opt->output(opt, data, size);
|
opt->output(opt, data, size);
|
||||||
opt->output(opt, GIT_COLOR_RESET, strlen(GIT_COLOR_RESET));
|
opt->output(opt, GIT_COLOR_RESET, strlen(GIT_COLOR_RESET));
|
||||||
|
@ -31,7 +31,7 @@ static char decoration_colors[][COLOR_MAXLEN] = {
|
|||||||
|
|
||||||
static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
|
static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
|
||||||
{
|
{
|
||||||
if (decorate_use_color)
|
if (want_color(decorate_use_color))
|
||||||
return decoration_colors[ix];
|
return decoration_colors[ix];
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ int parse_decorate_color_config(const char *var, const int ofs, const char *valu
|
|||||||
* for showing the commit sha1, use the same check for --decorate
|
* for showing the commit sha1, use the same check for --decorate
|
||||||
*/
|
*/
|
||||||
#define decorate_get_color_opt(o, ix) \
|
#define decorate_get_color_opt(o, ix) \
|
||||||
decorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)
|
decorate_get_color((o)->use_color, ix)
|
||||||
|
|
||||||
static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
|
static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
|
||||||
{
|
{
|
||||||
|
8
pager.c
8
pager.c
@ -11,8 +11,6 @@
|
|||||||
* something different on Windows.
|
* something different on Windows.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int spawned_pager;
|
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
static void pager_preexec(void)
|
static void pager_preexec(void)
|
||||||
{
|
{
|
||||||
@ -78,7 +76,7 @@ void setup_pager(void)
|
|||||||
if (!pager)
|
if (!pager)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
spawned_pager = 1; /* means we are emitting to terminal */
|
setenv("GIT_PAGER_IN_USE", "true", 1);
|
||||||
|
|
||||||
/* spawn the pager */
|
/* spawn the pager */
|
||||||
pager_argv[0] = pager;
|
pager_argv[0] = pager;
|
||||||
@ -109,10 +107,6 @@ void setup_pager(void)
|
|||||||
int pager_in_use(void)
|
int pager_in_use(void)
|
||||||
{
|
{
|
||||||
const char *env;
|
const char *env;
|
||||||
|
|
||||||
if (spawned_pager)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
env = getenv("GIT_PAGER_IN_USE");
|
env = getenv("GIT_PAGER_IN_USE");
|
||||||
return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0;
|
return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
|
|||||||
|
|
||||||
if (!arg)
|
if (!arg)
|
||||||
arg = unset ? "never" : (const char *)opt->defval;
|
arg = unset ? "never" : (const char *)opt->defval;
|
||||||
value = git_config_colorbool(NULL, arg, -1);
|
value = git_config_colorbool(NULL, arg);
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
return opterror(opt,
|
return opterror(opt,
|
||||||
"expects \"always\", \"auto\", or \"never\"", 0);
|
"expects \"always\", \"auto\", or \"never\"", 0);
|
||||||
|
@ -13,7 +13,7 @@ cleanup_fail() {
|
|||||||
|
|
||||||
test_expect_success 'setup' '
|
test_expect_success 'setup' '
|
||||||
sane_unset GIT_PAGER GIT_PAGER_IN_USE &&
|
sane_unset GIT_PAGER GIT_PAGER_IN_USE &&
|
||||||
test_might_fail git config --unset core.pager &&
|
test_unconfig core.pager &&
|
||||||
|
|
||||||
PAGER="cat >paginated.out" &&
|
PAGER="cat >paginated.out" &&
|
||||||
export PAGER &&
|
export PAGER &&
|
||||||
@ -94,21 +94,19 @@ test_expect_success TTY 'no pager with --no-pager' '
|
|||||||
|
|
||||||
test_expect_success TTY 'configuration can disable pager' '
|
test_expect_success TTY 'configuration can disable pager' '
|
||||||
rm -f paginated.out &&
|
rm -f paginated.out &&
|
||||||
test_might_fail git config --unset pager.grep &&
|
test_unconfig pager.grep &&
|
||||||
test_terminal git grep initial &&
|
test_terminal git grep initial &&
|
||||||
test -e paginated.out &&
|
test -e paginated.out &&
|
||||||
|
|
||||||
rm -f paginated.out &&
|
rm -f paginated.out &&
|
||||||
git config pager.grep false &&
|
test_config pager.grep false &&
|
||||||
test_when_finished "git config --unset pager.grep" &&
|
|
||||||
test_terminal git grep initial &&
|
test_terminal git grep initial &&
|
||||||
! test -e paginated.out
|
! test -e paginated.out
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success TTY 'git config uses a pager if configured to' '
|
test_expect_success TTY 'git config uses a pager if configured to' '
|
||||||
rm -f paginated.out &&
|
rm -f paginated.out &&
|
||||||
git config pager.config true &&
|
test_config pager.config true &&
|
||||||
test_when_finished "git config --unset pager.config" &&
|
|
||||||
test_terminal git config --list &&
|
test_terminal git config --list &&
|
||||||
test -e paginated.out
|
test -e paginated.out
|
||||||
'
|
'
|
||||||
@ -116,8 +114,7 @@ test_expect_success TTY 'git config uses a pager if configured to' '
|
|||||||
test_expect_success TTY 'configuration can enable pager (from subdir)' '
|
test_expect_success TTY 'configuration can enable pager (from subdir)' '
|
||||||
rm -f paginated.out &&
|
rm -f paginated.out &&
|
||||||
mkdir -p subdir &&
|
mkdir -p subdir &&
|
||||||
git config pager.bundle true &&
|
test_config pager.bundle true &&
|
||||||
test_when_finished "git config --unset pager.bundle" &&
|
|
||||||
|
|
||||||
git bundle create test.bundle --all &&
|
git bundle create test.bundle --all &&
|
||||||
rm -f paginated.out subdir/paginated.out &&
|
rm -f paginated.out subdir/paginated.out &&
|
||||||
@ -150,7 +147,7 @@ test_expect_success 'tests can detect color' '
|
|||||||
|
|
||||||
test_expect_success 'no color when stdout is a regular file' '
|
test_expect_success 'no color when stdout is a regular file' '
|
||||||
rm -f colorless.log &&
|
rm -f colorless.log &&
|
||||||
git config color.ui auto ||
|
test_config color.ui auto ||
|
||||||
cleanup_fail &&
|
cleanup_fail &&
|
||||||
|
|
||||||
git log >colorless.log &&
|
git log >colorless.log &&
|
||||||
@ -159,7 +156,7 @@ test_expect_success 'no color when stdout is a regular file' '
|
|||||||
|
|
||||||
test_expect_success TTY 'color when writing to a pager' '
|
test_expect_success TTY 'color when writing to a pager' '
|
||||||
rm -f paginated.out &&
|
rm -f paginated.out &&
|
||||||
git config color.ui auto ||
|
test_config color.ui auto ||
|
||||||
cleanup_fail &&
|
cleanup_fail &&
|
||||||
|
|
||||||
(
|
(
|
||||||
@ -170,9 +167,21 @@ test_expect_success TTY 'color when writing to a pager' '
|
|||||||
colorful paginated.out
|
colorful paginated.out
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success TTY 'colors are suppressed by color.pager' '
|
||||||
|
rm -f paginated.out &&
|
||||||
|
test_config color.ui auto &&
|
||||||
|
test_config color.pager false &&
|
||||||
|
(
|
||||||
|
TERM=vt100 &&
|
||||||
|
export TERM &&
|
||||||
|
test_terminal git log
|
||||||
|
) &&
|
||||||
|
! colorful paginated.out
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'color when writing to a file intended for a pager' '
|
test_expect_success 'color when writing to a file intended for a pager' '
|
||||||
rm -f colorful.log &&
|
rm -f colorful.log &&
|
||||||
git config color.ui auto ||
|
test_config color.ui auto ||
|
||||||
cleanup_fail &&
|
cleanup_fail &&
|
||||||
|
|
||||||
(
|
(
|
||||||
@ -184,6 +193,17 @@ test_expect_success 'color when writing to a file intended for a pager' '
|
|||||||
colorful colorful.log
|
colorful colorful.log
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success TTY 'colors are sent to pager for external commands' '
|
||||||
|
test_config alias.externallog "!git log" &&
|
||||||
|
test_config color.ui auto &&
|
||||||
|
(
|
||||||
|
TERM=vt100 &&
|
||||||
|
export TERM &&
|
||||||
|
test_terminal git -p externallog
|
||||||
|
) &&
|
||||||
|
colorful paginated.out
|
||||||
|
'
|
||||||
|
|
||||||
# Use this helper to make it easy for the caller of your
|
# Use this helper to make it easy for the caller of your
|
||||||
# terminal-using function to specify whether it should fail.
|
# terminal-using function to specify whether it should fail.
|
||||||
# If you write
|
# If you write
|
||||||
@ -221,7 +241,7 @@ test_default_pager() {
|
|||||||
|
|
||||||
$test_expectation SIMPLEPAGER,TTY "$cmd - default pager is used by default" "
|
$test_expectation SIMPLEPAGER,TTY "$cmd - default pager is used by default" "
|
||||||
sane_unset PAGER GIT_PAGER &&
|
sane_unset PAGER GIT_PAGER &&
|
||||||
test_might_fail git config --unset core.pager &&
|
test_unconfig core.pager &&
|
||||||
rm -f default_pager_used ||
|
rm -f default_pager_used ||
|
||||||
cleanup_fail &&
|
cleanup_fail &&
|
||||||
|
|
||||||
@ -244,7 +264,7 @@ test_PAGER_overrides() {
|
|||||||
|
|
||||||
$test_expectation TTY "$cmd - PAGER overrides default pager" "
|
$test_expectation TTY "$cmd - PAGER overrides default pager" "
|
||||||
sane_unset GIT_PAGER &&
|
sane_unset GIT_PAGER &&
|
||||||
test_might_fail git config --unset core.pager &&
|
test_unconfig core.pager &&
|
||||||
rm -f PAGER_used ||
|
rm -f PAGER_used ||
|
||||||
cleanup_fail &&
|
cleanup_fail &&
|
||||||
|
|
||||||
@ -277,7 +297,7 @@ test_core_pager() {
|
|||||||
|
|
||||||
PAGER=wc &&
|
PAGER=wc &&
|
||||||
export PAGER &&
|
export PAGER &&
|
||||||
git config core.pager 'wc >core.pager_used' &&
|
test_config core.pager 'wc >core.pager_used' &&
|
||||||
$full_command &&
|
$full_command &&
|
||||||
${if_local_config}test -e core.pager_used
|
${if_local_config}test -e core.pager_used
|
||||||
"
|
"
|
||||||
@ -307,7 +327,7 @@ test_pager_subdir_helper() {
|
|||||||
PAGER=wc &&
|
PAGER=wc &&
|
||||||
stampname=\$(pwd)/core.pager_used &&
|
stampname=\$(pwd)/core.pager_used &&
|
||||||
export PAGER stampname &&
|
export PAGER stampname &&
|
||||||
git config core.pager 'wc >\"\$stampname\"' &&
|
test_config core.pager 'wc >\"\$stampname\"' &&
|
||||||
mkdir sub &&
|
mkdir sub &&
|
||||||
(
|
(
|
||||||
cd sub &&
|
cd sub &&
|
||||||
@ -324,7 +344,7 @@ test_GIT_PAGER_overrides() {
|
|||||||
rm -f GIT_PAGER_used ||
|
rm -f GIT_PAGER_used ||
|
||||||
cleanup_fail &&
|
cleanup_fail &&
|
||||||
|
|
||||||
git config core.pager wc &&
|
test_config core.pager wc &&
|
||||||
GIT_PAGER='wc >GIT_PAGER_used' &&
|
GIT_PAGER='wc >GIT_PAGER_used' &&
|
||||||
export GIT_PAGER &&
|
export GIT_PAGER &&
|
||||||
$full_command &&
|
$full_command &&
|
||||||
@ -402,21 +422,21 @@ test_core_pager_subdir expect_success test_must_fail \
|
|||||||
'git -p apply </dev/null'
|
'git -p apply </dev/null'
|
||||||
|
|
||||||
test_expect_success TTY 'command-specific pager' '
|
test_expect_success TTY 'command-specific pager' '
|
||||||
unset PAGER GIT_PAGER;
|
sane_unset PAGER GIT_PAGER &&
|
||||||
echo "foo:initial" >expect &&
|
echo "foo:initial" >expect &&
|
||||||
>actual &&
|
>actual &&
|
||||||
git config --unset core.pager &&
|
test_unconfig core.pager &&
|
||||||
git config pager.log "sed s/^/foo:/ >actual" &&
|
test_config pager.log "sed s/^/foo:/ >actual" &&
|
||||||
test_terminal git log --format=%s -1 &&
|
test_terminal git log --format=%s -1 &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success TTY 'command-specific pager overrides core.pager' '
|
test_expect_success TTY 'command-specific pager overrides core.pager' '
|
||||||
unset PAGER GIT_PAGER;
|
sane_unset PAGER GIT_PAGER &&
|
||||||
echo "foo:initial" >expect &&
|
echo "foo:initial" >expect &&
|
||||||
>actual &&
|
>actual &&
|
||||||
git config core.pager "exit 1"
|
test_config core.pager "exit 1"
|
||||||
git config pager.log "sed s/^/foo:/ >actual" &&
|
test_config pager.log "sed s/^/foo:/ >actual" &&
|
||||||
test_terminal git log --format=%s -1 &&
|
test_terminal git log --format=%s -1 &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
@ -425,7 +445,7 @@ test_expect_success TTY 'command-specific pager overridden by environment' '
|
|||||||
GIT_PAGER="sed s/^/foo:/ >actual" && export GIT_PAGER &&
|
GIT_PAGER="sed s/^/foo:/ >actual" && export GIT_PAGER &&
|
||||||
>actual &&
|
>actual &&
|
||||||
echo "foo:initial" >expect &&
|
echo "foo:initial" >expect &&
|
||||||
git config pager.log "exit 1" &&
|
test_config pager.log "exit 1" &&
|
||||||
test_terminal git log --format=%s -1 &&
|
test_terminal git log --format=%s -1 &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
@ -361,6 +361,24 @@ test_chmod () {
|
|||||||
git update-index --add "--chmod=$@"
|
git update-index --add "--chmod=$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Unset a configuration variable, but don't fail if it doesn't exist.
|
||||||
|
test_unconfig () {
|
||||||
|
git config --unset-all "$@"
|
||||||
|
config_status=$?
|
||||||
|
case "$config_status" in
|
||||||
|
5) # ok, nothing to unset
|
||||||
|
config_status=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
return $config_status
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set git config, automatically unsetting it after the test is over.
|
||||||
|
test_config () {
|
||||||
|
test_when_finished "test_unconfig '$1'" &&
|
||||||
|
git config "$@"
|
||||||
|
}
|
||||||
|
|
||||||
# Use test_set_prereq to tell that a particular prerequisite is available.
|
# Use test_set_prereq to tell that a particular prerequisite is available.
|
||||||
# The prerequisite can later be checked for in two ways:
|
# The prerequisite can later be checked for in two ways:
|
||||||
#
|
#
|
||||||
|
@ -26,7 +26,9 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
|
|||||||
|
|
||||||
static const char *color(int slot, struct wt_status *s)
|
static const char *color(int slot, struct wt_status *s)
|
||||||
{
|
{
|
||||||
const char *c = s->use_color > 0 ? s->color_palette[slot] : "";
|
const char *c = "";
|
||||||
|
if (want_color(s->use_color))
|
||||||
|
c = s->color_palette[slot];
|
||||||
if (slot == WT_STATUS_ONBRANCH && color_is_nil(c))
|
if (slot == WT_STATUS_ONBRANCH && color_is_nil(c))
|
||||||
c = s->color_palette[WT_STATUS_HEADER];
|
c = s->color_palette[WT_STATUS_HEADER];
|
||||||
return c;
|
return c;
|
||||||
@ -681,7 +683,7 @@ static void wt_status_print_verbose(struct wt_status *s)
|
|||||||
* will have checked isatty on stdout).
|
* will have checked isatty on stdout).
|
||||||
*/
|
*/
|
||||||
if (s->fp != stdout)
|
if (s->fp != stdout)
|
||||||
DIFF_OPT_CLR(&rev.diffopt, COLOR_DIFF);
|
rev.diffopt.use_color = 0;
|
||||||
run_diff_index(&rev, 1);
|
run_diff_index(&rev, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user