git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/5] diff: --ignore-case

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 20, 2012, 02:16 UTC
Message-ID
<1329704188-9955-6-git-send-email-gitster@pobox.com>
In-Reply-To
<1329704188-9955-1-git-send-email-gitster@pobox.com>

Teach the front-end to flip XDF_IGNORE_CASE bit with the options GNU diff uses.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/diff-options.txt |    4 ++++
 diff.c                         |    2 ++
 t/lib-diff-alternative.sh      |   45 ++++++++++++++++++++++++++++++++++++++--
 t/t4033-diff-patience.sh       |    6 ++++++
 t/t4050-diff-histogram.sh      |    2 ++
 5 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 9f7cba2..791e07f 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -404,6 +404,10 @@ endif::git-format-patch[]
 	differences even if one line has whitespace where the other
 	line has none.
 
+--ignore-case::
+	Ignore changes in case only; only ASCII alphabet is supported for
+	now.
+
 --inter-hunk-context=<lines>::
 	Show the context between diff hunks, up to the specified number
 	of lines, thereby fusing hunks that are close to each other.
diff --git a/diff.c b/diff.c
index 87b2ec1..d7604b7 100644
--- a/diff.c
+++ b/diff.c
@@ -3399,6 +3399,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		DIFF_XDL_SET(options, IGNORE_WHITESPACE_CHANGE);
 	else if (!strcmp(arg, "--ignore-space-at-eol"))
 		DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
+	else if (!strcmp(arg, "--ignore-case"))
+		DIFF_XDL_SET(options, IGNORE_CASE);
 	else if (!strcmp(arg, "--patience"))
 		options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
 	else if (!strcmp(arg, "--histogram"))
diff --git a/t/lib-diff-alternative.sh b/t/lib-diff-alternative.sh
index 75ffd91..45c665e 100644
--- a/t/lib-diff-alternative.sh
+++ b/t/lib-diff-alternative.sh
@@ -104,8 +104,9 @@ EOF
 
 	STRATEGY=$1
 
+	cmd='git diff --no-index'
 	test_expect_success "$STRATEGY diff" '
-		test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output &&
+		test_must_fail $cmd ${STRATEGY:+"--$STRATEGY"} file1 file2 >output &&
 		test_cmp expect output
 	'
 
@@ -157,9 +158,49 @@ EOF
 
 	STRATEGY=$1
 
+	cmd='git diff --no-index'
 	test_expect_success 'completely different files' '
-		test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output &&
+
+		test_must_fail $cmd  ${STRATEGY:+"--$STRATEGY"} uniq1 uniq2 >output &&
 		test_cmp expect output
 	'
 }
 
+test_diff_ignore () {
+
+	STRATEGY=$1
+
+	echo "A quick brown fox" >test.0
+	echo "A  quick brown fox" >test-b
+	echo " A quick brownfox" >test-w
+	echo "A quick brown fox " >test--ignore-space-at-eol
+	echo "A Quick Brown Fox" >test--ignore-case
+	echo "A Quick  Brown Fox" >test--ignore-case-b
+	echo "A quick brown fox jumps" >test
+	cases="-b -w --ignore-space-at-eol --ignore-case"
+
+	if test -z "$STRATEGY"
+	then
+		label=baseline
+	else
+		label=$STRATEGY
+	fi
+
+	cmd="git diff --no-index ${STRATEGY:+--$STRATEGY}"
+
+	test_expect_success "$label diff" '
+		test_must_fail $cmd test.0 test
+	'
+	for case in $cases
+	do
+		test_expect_success "$label diff $case" '
+			$cmd $case test.0 test$case &&
+			test_must_fail $cmd test.0 test
+		'
+	done
+
+	test_expect_success "$label diff -b --ignore-case" '
+		$cmd -b --ignore-case test.0 test--ignore-case-b
+	'
+
+}
diff --git a/t/t4033-diff-patience.sh b/t/t4033-diff-patience.sh
index 3c9932e..c7f8c6c 100755
--- a/t/t4033-diff-patience.sh
+++ b/t/t4033-diff-patience.sh
@@ -5,8 +5,14 @@ test_description='patience diff algorithm'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-diff-alternative.sh
 
+# baseline
+test_diff_unique ""
+test_diff_ignore ""
+
 test_diff_frobnitz "patience"
 
 test_diff_unique "patience"
 
+test_diff_ignore "patience"
+
 test_done
diff --git a/t/t4050-diff-histogram.sh b/t/t4050-diff-histogram.sh
index fd3e86a..98c6686 100755
--- a/t/t4050-diff-histogram.sh
+++ b/t/t4050-diff-histogram.sh
@@ -9,4 +9,6 @@ test_diff_frobnitz "histogram"
 
 test_diff_unique "histogram"
 
+test_diff_ignore "histogram"
+
 test_done
-- 
1.7.9.1.265.g25f75
Previous: Jakub NarebskiNext: Junio C Hamano
Message 7 of 14 in “diff --ignore-case”
  1. 0/5 diff --ignore-caseJunio C Hamano, Feb 20, 2012
  2. 1/5 xdiff: remove XDL_PATCH_* macrosJunio C Hamano, Feb 20, 2012
  3. 2/5 xdiff: PATIENCE/HISTOGRAM are not independent option bitsJunio C Hamano, Feb 20, 2012
  4. 3/5 xdiff: introduce XDF_INEXACT_MATCHJunio C Hamano, Feb 20, 2012
  5. 4/5 xdiff: introduce XDF_IGNORE_CASEJunio C Hamano, Feb 20, 2012
  6. Jakub NarebskiFeb 22, 2012
  7. 5/5 diff: --ignore-caseJunio C Hamano, Feb 20, 2012
  8. 6/5 diff -iJunio C Hamano, Feb 20, 2012
  9. Johannes SixtFeb 20, 2012
  10. Junio C HamanoFeb 20, 2012
  11. Thomas RastFeb 20, 2012
  12. Junio C HamanoFeb 20, 2012
  13. Chris LeongFeb 20, 2012
  14. Re* [PATCH 0/5] diff --ignore-caseJunio C Hamano, Feb 21, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.