@matheusbsbs / matheus-bagliano / commits / da8063522f
Fork 0

diff: move diff.wsErrorHighlight to "basic" config

We parse diff.wsErrorHighlight in git_diff_ui_config(), meaning that it doesn't take effect for plumbing commands, only for porcelains like git-diff itself. This is mildly annoying as it means scripts like add--interactive, which produce a user-visible diff with color, don't respect the option. We could teach that script to parse the config and pass it along as --ws-error-highlight to the diff plumbing. But there's a simpler solution. It should be reasonably safe for plumbing to respect this option, as it only kicks in when color is otherwise enabled. And anybody parsing colorized output must already deal with the fact that color.diff.* may change the exact output they see; those options have been part of git_diff_basic_config() since its inception in 9a1805a872 (add a "basic" diff config callback, 2008-01-04). So we can just move it to the "basic" config, which fixes add--interactive, along with any other script in the same boat, with a very low risk of hurting any plumbing users. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 31, 2020 at 04:57 UTC da8063522f7f797cf722f28979aefbe2a508f800
2 files changed +21 -8
diff.c
+8 -8
@@ -414,14 +414,6 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
414 return 0;
415 }
416
417 - if (!strcmp(var, "diff.wserrorhighlight")) {
418 - int val = parse_ws_error_highlight(value);
419 - if (val < 0)
420 - return -1;
421 - ws_error_highlight_default = val;
422 - return 0;
423 - }
424 -
417 if (git_color_config(var, value, cb) < 0)
418 return -1;
419
@@ -450,6 +442,14 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
442 return color_parse(value, diff_colors[slot]);
443 }
444
445 + if (!strcmp(var, "diff.wserrorhighlight")) {
446 + int val = parse_ws_error_highlight(value);
447 + if (val < 0)
448 + return -1;
449 + ws_error_highlight_default = val;
450 + return 0;
451 + }
452 +
453 /* like GNU diff's --suppress-blank-empty option */
454 if (!strcmp(var, "diff.suppressblankempty") ||
455 /* for backwards compatibility */
t/t3701-add-interactive.sh
+13
@@ -544,6 +544,19 @@ test_expect_success 'diffs can be colorized' '
544 grep "$(printf "\\033")" output
545 '
546
547 +test_expect_success 'colorized diffs respect diff.wsErrorHighlight' '
548 + git reset --hard &&
549 +
550 + echo "old " >test &&
551 + git add test &&
552 + echo "new " >test &&
553 +
554 + printf y >y &&
555 + force_color git -c diff.wsErrorHighlight=all add -p >output.raw 2>&1 <y &&
556 + test_decode_color <output.raw >output &&
557 + grep "old<" output
558 +'
559 +
560 test_expect_success 'diffFilter filters diff' '
561 git reset --hard &&
562