[PATCH 1/3] diff: flip the default diff.bwoutputonly to true

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This switches the default behaviour of "diff -w/-b" back to the
traditional "ignore whitespace affects only output of patch text, not
status nor diff header", and allows the planned new semantics to be asked
in advance by setting diff.bwoutputonly configuration to false.

Also a loud warning is issued when the configuration is not set at all,
so that we can flip the default later more smoothly.

Update tests to check cases where the configuration is set to true, false
and not set at all; make sure the warning is issued when and only when
necessary.

Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
---
 diff.c                       |   23 ++++++++++---
 t/t4015-diff-whitespace.sh   |   70 +++++++++++++++++++++++++++++++++---------
 t/t4040-whitespace-status.sh |   48 ++++++++++++++++++----------
 3 files changed, 103 insertions(+), 38 deletions(-)

diff --git a/diff.c b/diff.c
index 6e7c47c..fb93a22 100644
--- a/diff.c
+++ b/diff.c
@@ -29,7 +29,8 @@ static const char *diff_word_regex_cfg;
 static const char *external_diff_cmd_cfg;
 int diff_auto_refresh_index = 1;
 static int diff_mnemonic_prefix;
-static int diff_b_w_output_only;
+static int diff_b_w_output_only = 1;
+static int diff_b_w_output_only_given;
 
 static char diff_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_RESET,
@@ -135,6 +136,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
 	}
 
 	if (!strcmp(var, "diff.bwoutputonly")) {
+		diff_b_w_output_only_given = 1;
 		diff_b_w_output_only = git_config_bool(var, value);
 		return 0;
 	}
@@ -2521,9 +2523,15 @@ void diff_setup(struct diff_options *options)
 	}
 }
 
+static const char *bw_option_warning =
+	"ignore-whitespace options will stop showing diff headers in later\n"
+	"versions of git; set diff.bwoutputonly to true to keep the old\n"
+	"behaviour, or set.bwoutputonly to false to squelch this message.\n";
+
 int diff_setup_done(struct diff_options *options)
 {
 	int count = 0;
+	int bw_options;
 
 	if (options->output_format & DIFF_FORMAT_NAME)
 		count++;
@@ -2542,11 +2550,14 @@ int diff_setup_done(struct diff_options *options)
 	 * --ignore-whitespace* options force us to look
 	 * inside contents.
 	 */
-
-	if (!diff_b_w_output_only &&
-	    (DIFF_XDL_TST(options, IGNORE_WHITESPACE) ||
-	     DIFF_XDL_TST(options, IGNORE_WHITESPACE_CHANGE) ||
-	     DIFF_XDL_TST(options, IGNORE_WHITESPACE_AT_EOL)))
+	bw_options = (DIFF_XDL_TST(options, IGNORE_WHITESPACE) ||
+		      DIFF_XDL_TST(options, IGNORE_WHITESPACE_CHANGE) ||
+		      DIFF_XDL_TST(options, IGNORE_WHITESPACE_AT_EOL));
+	if (!diff_b_w_output_only_given && bw_options && bw_option_warning) {
+		warning("%s", bw_option_warning);
+		bw_option_warning = NULL;
+	}
+	if (!diff_b_w_output_only && bw_options)
 		DIFF_OPT_SET(options, DIFF_FROM_CONTENTS);
 	else
 		DIFF_OPT_CLR(options, DIFF_FROM_CONTENTS);
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 90f3342..310421b 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -92,16 +92,30 @@ EOF
 git diff > out
 test_expect_success 'another test, without options' 'test_cmp expect out'
 
-cat << EOF > expect
+test_w_b () {
+	note=$1
+	for o in "-w" "-w -b" "-w --ignore-space-at-eol" "-w -b --ignore-space-at-eol"
+	do
+		test_expect_success "with $o ($note)" '
+			git diff $o >actual &&
+			test_cmp expect actual
+		'
+	done
+}
+
+git config diff.bwoutputonly false
+> expect
+test_w_b "bwoutputonly=false"
+
+git config diff.bwoutputonly true
+cat <<EOF >expect
+diff --git a/x b/x
+index d99af23..8b32fb5 100644
 EOF
-git diff -w > out
-test_expect_success 'another test, with -w' 'test_cmp expect out'
-git diff -w -b > out
-test_expect_success 'another test, with -w -b' 'test_cmp expect out'
-git diff -w --ignore-space-at-eol > out
-test_expect_success 'another test, with -w --ignore-space-at-eol' 'test_cmp expect out'
-git diff -w -b --ignore-space-at-eol > out
-test_expect_success 'another test, with -w -b --ignore-space-at-eol' 'test_cmp expect out'
+test_w_b "bwoutputonly=true"
+
+git config --unset diff.bwoutputonly
+test_w_b "bwoutputonly unset"
 
 tr 'Q' '\015' << EOF > expect
 diff --git a/x b/x
@@ -384,20 +398,47 @@ test_expect_success 'checkdiff allows new blank lines' '
 	git diff --check
 '
 
-cat <<EOF >expect
-EOF
-test_expect_success 'whitespace-only changes not reported' '
+test_expect_success 'whitespace-only changes shown' '
+	git config --unset diff.bwoutputonly
 	git reset --hard &&
 	echo >x "hello world" &&
 	git add x &&
 	git commit -m "hello 1" &&
 	echo >x "hello  world" &&
 	git diff -b >actual &&
-	test_cmp expect actual
+	test 2 = $(wc -l <actual)
 '
 
-test_expect_success 'combined diff with autocrlf conversion' '
+test_expect_success 'whitespace-only changes shown with diff.bwoutputonly' '
+	git config diff.bwoutputonly true &&
+	git diff -b >actual &&
+	test 2 = $(wc -l <actual)
+'
+
+test_expect_success 'whitespace-only changes hidden with !diff.bwoutputonly' '
+	git config diff.bwoutputonly false &&
+	git diff -b >actual &&
+	! test -s actual
+'
+
+test_expect_success 'no warning with diff.bwoutputonly given' '
+	git diff -b 2>errors &&
+	! grep warn errors
+'
 
+test_expect_success 'no warning without diff.bwoutputonly' '
+	git config --unset diff.bwoutputonly
+	git diff -p 2>errors &&
+	! grep "stop showing" errors
+'
+
+test_expect_success 'warning without diff.bwoutputonly' '
+	git config --unset diff.bwoutputonly
+	git diff -b 2>errors &&
+	grep "stop showing" errors
+'
+
+test_expect_success 'combined diff with autocrlf conversion' '
 	git reset --hard &&
 	echo >x hello &&
 	git commit -m "one side" x &&
@@ -409,7 +450,6 @@ test_expect_success 'combined diff with autocrlf conversion' '
 
 	git diff | sed -e "1,/^@@@/d" >actual &&
 	! grep "^-" actual
-
 '
 
 test_done
diff --git a/t/t4040-whitespace-status.sh b/t/t4040-whitespace-status.sh
index a30b03b..95a93f7 100755
--- a/t/t4040-whitespace-status.sh
+++ b/t/t4040-whitespace-status.sh
@@ -19,45 +19,59 @@ test_expect_success setup '
 	git add a/d
 '
 
-test_expect_success 'diff-tree --exit-code' '
+test_once () {
+	note=$1 tmf=$2
+
+test_expect_success "diff-tree --exit-code ($note)" '
 	test_must_fail git diff --exit-code HEAD^ HEAD &&
 	test_must_fail git diff-tree --exit-code HEAD^ HEAD
 '
 
-test_expect_success 'diff-tree -b --exit-code' '
-	git diff -b --exit-code HEAD^ HEAD &&
-	git diff-tree -b -p --exit-code HEAD^ HEAD &&
-	git diff-tree -b --exit-code HEAD^ HEAD
+test_expect_success "diff-tree -b --exit-code ($note)" '
+	$tmf git diff -b --exit-code HEAD^ HEAD &&
+	$tmf git diff-tree -b -p --exit-code HEAD^ HEAD &&
+	$tmf git diff-tree -b --exit-code HEAD^ HEAD
 '
 
-test_expect_success 'diff-index --cached --exit-code' '
+test_expect_success "diff-index --cached --exit-code ($note)" '
 	test_must_fail git diff --cached --exit-code HEAD &&
 	test_must_fail git diff-index --cached --exit-code HEAD
 '
 
-test_expect_success 'diff-index -b -p --cached --exit-code' '
-	git diff -b --cached --exit-code HEAD &&
-	git diff-index -b -p --cached --exit-code HEAD
+test_expect_success "diff-index -b -p --cached --exit-code ($note)" '
+	$tmf git diff -b --cached --exit-code HEAD &&
+	$tmf git diff-index -b -p --cached --exit-code HEAD
 '
 
-test_expect_success 'diff-index --exit-code' '
+test_expect_success "diff-index --exit-code ($note)" '
 	test_must_fail git diff --exit-code HEAD &&
 	test_must_fail git diff-index --exit-code HEAD
 '
 
-test_expect_success 'diff-index -b -p --exit-code' '
-	git diff -b --exit-code HEAD &&
-	git diff-index -b -p --exit-code HEAD
+test_expect_success "diff-index -b -p --exit-code ($note)" '
+	$tmf git diff -b --exit-code HEAD &&
+	$tmf git diff-index -b -p --exit-code HEAD
 '
 
-test_expect_success 'diff-files --exit-code' '
+test_expect_success "diff-files --exit-code ($note)" '
 	test_must_fail git diff --exit-code &&
 	test_must_fail git diff-files --exit-code
 '
 
-test_expect_success 'diff-files -b -p --exit-code' '
-	git diff -b --exit-code &&
-	git diff-files -b -p --exit-code
+test_expect_success "diff-files -b -p --exit-code ($note)" '
+	$tmf git diff -b --exit-code &&
+	$tmf git diff-files -b -p --exit-code
 '
 
+}
+
+git config diff.bwoutputonly true
+test_once "bwoutputonly=true" "test_must_fail"
+
+git config diff.bwoutputonly false
+test_once "bwoutputonly=false" ""
+
+git config --unset diff.bwoutputonly
+test_once "bwoutputonly unset" "test_must_fail"
+
 test_done
-- 
1.6.6.rc0.61.g41d5b.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]