Revert "color: check color.ui in git_default_config()"

This reverts commit 136c8c8b8fa39f1315713248473dececf20f8fe7. That commit was trying to address a bug caused by 4c7f1819b3 (make color.ui default to 'auto', 2013-06-10), in which plumbing like diff-tree defaulted to "auto" color, but did not respect a "color.ui" directive to disable it. But it also meant that we started respecting "color.ui" set to "always". This was a known problem, but 4c7f1819b3 argued that nobody ought to be doing that. However, that turned out to be wrong, and we got a number of bug reports related to "add -p" regressing in v2.14.2. Let's revert 136c8c8b8, fixing the regression to "add -p". This leaves the problem from 4c7f1819b3 unfixed, but: 1. It's a pretty obscure problem in the first place. I only noticed it while working on the color code, and we haven't got a single bug report or complaint about it. 2. We can make a more moderate fix on top by respecting "never" but not "always" for plumbing commands. This is just the minimal fix to go back to the working state we had before v2.14.2. Note that this isn't a pure revert. We now have a test in t3701 which shows off the "add -p" regression. This can be flipped to success. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 13, 2017 at 13:24 UTC 33c643bb083133376f3fdcb190ebc58f9eef12bb
8 files changed +17 -9
builtin/branch.c
+1 -1
@@ -92,7 +92,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
92 return config_error_nonbool(var);
93 return color_parse(value, branch_colors[slot]);
94 }
95 - return git_default_config(var, value, cb);
95 + return git_color_default_config(var, value, cb);
96 }
97
98 static const char *branch_get_color(enum color_branch ix)
builtin/clean.c
+2 -1
@@ -125,7 +125,8 @@ static int git_clean_config(const char *var, const char *value, void *cb)
125 return 0;
126 }
127
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);
130 }
131
132 static const char *clean_get_color(enum color_clean ix)
builtin/grep.c
+1 -1
@@ -284,7 +284,7 @@ static int wait_all(void)
284 static int grep_cmd_config(const char *var, const char *value, void *cb)
285 {
286 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)
288 st = -1;
289
290 if (!strcmp(var, "grep.threads")) {
builtin/show-branch.c
+1 -1
@@ -554,7 +554,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
554 return 0;
555 }
556
557 - return git_default_config(var, value, cb);
557 + return git_color_default_config(var, value, cb);
558 }
559
560 static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
color.c
+8
@@ -361,6 +361,14 @@ int git_color_config(const char *var, const char *value, void *cb)
361 return 0;
362 }
363
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 +
372 void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb)
373 {
374 if (*color)
config.c
-4
@@ -16,7 +16,6 @@
16 #include "string-list.h"
17 #include "utf8.h"
18 #include "dir.h"
19 -#include "color.h"
19
20 struct config_source {
21 struct config_source *prev;
@@ -1351,9 +1350,6 @@ int git_default_config(const char *var, const char *value, void *dummy)
1350 if (starts_with(var, "advice."))
1351 return git_default_advice_config(var, value);
1352
1354 - if (git_color_config(var, value, dummy) < 0)
1355 - return -1;
1356 -
1353 if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
1354 pager_use_color = git_config_bool(var,value);
1355 return 0;
diff.c
+3
@@ -299,6 +299,9 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
299 return 0;
300 }
301
302 + if (git_color_config(var, value, cb) < 0)
303 + return -1;
304 +
305 return git_diff_basic_config(var, value, cb);
306 }
307
t/t3701-add-interactive.sh
+1 -1
@@ -483,7 +483,7 @@ test_expect_success 'hunk-editing handles custom comment char' '
483 git diff --exit-code
484 '
485
486 -test_expect_failure 'add -p works even with color.ui=always' '
486 +test_expect_success 'add -p works even with color.ui=always' '
487 git reset --hard &&
488 echo change >>file &&
489 test_config color.ui always &&