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

[PATCH 6/5] diff -i

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 20, 2012, 07:36 UTC
Message-ID
<7vzkcelzw9.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1329704188-9955-1-git-send-email-gitster@pobox.com>

The previous patch to teach "--ignore-case" option to our "diff" machinery deliberately omitted a short-and-sweet "-i" that GNU diff uses to ask for "--ignore-case". This is because our diff machinery are often used by and shares the command line options with the commands in the "git log" family, where the short option already means something entirely different. Namely, it instructs to use case-insensitive match when looking for commits that match information that appear in the commit object itself, e.g. --author and --grep.

Tweak the option parser so that "-i" means both, so that
	$ git log --grep=frotz -i -p

first picks commits that have string "frotz" in any combination of cases, and then shows patches that ignore case-only changes for the chosen commits, while "--ignore-case" and "--regexp-ignore-case" can be used to mean only one, i.e.

	$ git log --grep=frotz --regexp-ignore-case -p

would pick the same set of commits, but the patches shown by it does not ignore case-only changes while

	$ git log --grep=frotz --ignore-case -p

would pick commits that has "frotz" in all lowercase, but shows patches that ignore case-only changes for the chosen commits.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/diff-options.txt |    1 +
 diff.c                         |    2 +-
 revision.c                     |    6 +++++-
 t/lib-diff-alternative.sh      |    3 ++-
 4 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 791e07f..9ed78c9 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -404,6 +404,7 @@ endif::git-format-patch[]
 	differences even if one line has whitespace where the other
 	line has none.
 
+-i::
 --ignore-case::
 	Ignore changes in case only; only ASCII alphabet is supported for
 	now.
diff --git a/diff.c b/diff.c
index d7604b7..9d1584e 100644
--- a/diff.c
+++ b/diff.c
@@ -3399,7 +3399,7 @@ 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"))
+	else if (!strcmp(arg, "--ignore-case") || !strcmp(arg, "-i"))
 		DIFF_XDL_SET(options, IGNORE_CASE);
 	else if (!strcmp(arg, "--patience"))
 		options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
diff --git a/revision.c b/revision.c
index 8764dde..f1a1354 100644
--- a/revision.c
+++ b/revision.c
@@ -13,6 +13,7 @@
 #include "decorate.h"
 #include "log-tree.h"
 #include "string-list.h"
+#include "xdiff-interface.h"
 
 volatile show_early_output_fn_t show_early_output;
 
@@ -1557,7 +1558,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		return argcount;
 	} else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) {
 		revs->grep_filter.regflags |= REG_EXTENDED;
-	} else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) {
+	} else if (!strcmp(arg, "-i")) {
+		DIFF_XDL_SET(&revs->diffopt, IGNORE_CASE);
+		revs->grep_filter.regflags |= REG_ICASE;
+	} else if (!strcmp(arg, "--regexp-ignore-case")) {
 		revs->grep_filter.regflags |= REG_ICASE;
 	} else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) {
 		revs->grep_filter.fixed = 1;
diff --git a/t/lib-diff-alternative.sh b/t/lib-diff-alternative.sh
index 45c665e..81609f8 100644
--- a/t/lib-diff-alternative.sh
+++ b/t/lib-diff-alternative.sh
@@ -175,9 +175,10 @@ test_diff_ignore () {
 	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-i
 	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"
+	cases="-b -w --ignore-space-at-eol --ignore-case -i"
 
 	if test -z "$STRATEGY"
 	then
Previous: Junio C HamanoNext: Johannes Sixt
Message 8 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.