Skip to content

Commit e3e3c6a

Browse files
committed
Merge branch 'jk/ref-filter-colors-fix' into maint
This is the "theoretically more correct" approach of simply stepping back to the state before plumbing commands started paying attention to "color.ui" configuration variable. * jk/ref-filter-colors-fix: tag: respect color.ui config Revert "color: check color.ui in git_default_config()" Revert "t6006: drop "always" color config tests" Revert "color: make "always" the same as "auto" in config" color: make "always" the same as "auto" in config provide --color option for all ref-filter users t3205: use --color instead of color.branch=always t3203: drop "always" color test t6006: drop "always" color config tests t7502: use diff.noprefix for --verbose test t7508: use test_terminal for color output t3701: use test-terminal to collect color output t4015: prefer --color to -c color.diff=always test-terminal: set TERM=vt100
2 parents 4e4a0c6 + b521fd1 commit e3e3c6a

23 files changed

+103
-71
lines changed

Documentation/git-for-each-ref.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ OPTIONS
5757
`xx`; for example `%00` interpolates to `\0` (NUL),
5858
`%09` to `\t` (TAB) and `%0a` to `\n` (LF).
5959

60+
--color[=<when>]:
61+
Respect any colors specified in the `--format` option. The
62+
`<when>` field must be one of `always`, `never`, or `auto` (if
63+
`<when>` is absent, behave as if `always` was given).
64+
6065
--shell::
6166
--perl::
6267
--python::

Documentation/git-tag.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ options for details.
115115
variable if it exists, or lexicographic order otherwise. See
116116
linkgit:git-config[1].
117117

118+
--color[=<when>]:
119+
Respect any colors specified in the `--format` option. The
120+
`<when>` field must be one of `always`, `never`, or `auto` (if
121+
`<when>` is absent, behave as if `always` was given).
122+
118123
-i::
119124
--ignore-case::
120125
Sorting and filtering tags are case insensitive.

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
9292
return config_error_nonbool(var);
9393
return color_parse(value, branch_colors[slot]);
9494
}
95-
return git_default_config(var, value, cb);
95+
return git_color_default_config(var, value, cb);
9696
}
9797

9898
static const char *branch_get_color(enum color_branch ix)

builtin/clean.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ static int git_clean_config(const char *var, const char *value, void *cb)
125125
return 0;
126126
}
127127

128-
return git_default_config(var, value, cb);
128+
/* inspect the color.ui config variable and others */
129+
return git_color_default_config(var, value, cb);
129130
}
130131

131132
static const char *clean_get_color(enum color_clean ix)

builtin/for-each-ref.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
3636
OPT_GROUP(""),
3737
OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")),
3838
OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")),
39+
OPT__COLOR(&format.use_color, N_("respect format colors")),
3940
OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
4041
N_("field name to sort on"), &parse_opt_ref_sorting),
4142
OPT_CALLBACK(0, "points-at", &filter.points_at,

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static int wait_all(void)
284284
static int grep_cmd_config(const char *var, const char *value, void *cb)
285285
{
286286
int st = grep_config(var, value, cb);
287-
if (git_default_config(var, value, cb) < 0)
287+
if (git_color_default_config(var, value, cb) < 0)
288288
st = -1;
289289

290290
if (!strcmp(var, "grep.threads")) {

builtin/show-branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
554554
return 0;
555555
}
556556

557-
return git_default_config(var, value, cb);
557+
return git_color_default_config(var, value, cb);
558558
}
559559

560560
static int omit_in_dense(struct commit *commit, struct commit **rev, int n)

builtin/tag.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static int git_tag_config(const char *var, const char *value, void *cb)
158158

159159
if (starts_with(var, "column."))
160160
return git_column_config(var, value, "tag", &colopts);
161-
return git_default_config(var, value, cb);
161+
return git_color_default_config(var, value, cb);
162162
}
163163

164164
static void write_tag_body(int fd, const struct object_id *oid)
@@ -411,6 +411,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
411411
},
412412
OPT_STRING( 0 , "format", &format.format, N_("format"),
413413
N_("format to use for the output")),
414+
OPT__COLOR(&format.use_color, N_("respect format colors")),
414415
OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
415416
OPT_END()
416417
};

color.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ int git_color_config(const char *var, const char *value, void *cb)
361361
return 0;
362362
}
363363

364+
int git_color_default_config(const char *var, const char *value, void *cb)
365+
{
366+
if (git_color_config(var, value, cb) < 0)
367+
return -1;
368+
369+
return git_default_config(var, value, cb);
370+
}
371+
364372
void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb)
365373
{
366374
if (*color)

config.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "string-list.h"
1717
#include "utf8.h"
1818
#include "dir.h"
19-
#include "color.h"
2019

2120
struct config_source {
2221
struct config_source *prev;
@@ -1351,9 +1350,6 @@ int git_default_config(const char *var, const char *value, void *dummy)
13511350
if (starts_with(var, "advice."))
13521351
return git_default_advice_config(var, value);
13531352

1354-
if (git_color_config(var, value, dummy) < 0)
1355-
return -1;
1356-
13571353
if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
13581354
pager_use_color = git_config_bool(var,value);
13591355
return 0;

0 commit comments

Comments
 (0)