From: Junio C Hamano Date: Mon, 23 Nov 2009 00:28:29 +0000 (-0800) Subject: Merge branch 'bc/grep-i-F' X-Git-Tag: v1.6.6-rc0~11 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/3fa384d27e79d4731a9188716f566fa423a8ff50?ds=inline;hp=-c Merge branch 'bc/grep-i-F' * bc/grep-i-F: grep: Allow case insensitive search of fixed-strings --- 3fa384d27e79d4731a9188716f566fa423a8ff50 diff --combined builtin-grep.c index 9a9e3fccd5,b41ad1e43a..a5b6719a1a --- a/builtin-grep.c +++ b/builtin-grep.c @@@ -367,7 -367,7 +367,7 @@@ static int external_grep(struct grep_op push_arg("-h"); if (opt->regflags & REG_EXTENDED) push_arg("-E"); - if (opt->regflags & REG_ICASE) + if (opt->ignore_case) push_arg("-i"); if (opt->binary == GREP_BINARY_NOMATCH) push_arg("-I"); @@@ -433,11 -433,7 +433,11 @@@ if (opt->color_external && strlen(opt->color_external) > 0) push_arg(opt->color_external); + } else { + unsetenv("GREP_COLOR"); + unsetenv("GREP_COLORS"); } + unsetenv("GREP_OPTIONS"); hit = 0; argc = nr; @@@ -635,7 -631,7 +635,7 @@@ static int file_callback(const struct o struct grep_opt *grep_opt = opt->value; FILE *patterns; int lno = 0; - struct strbuf sb; + struct strbuf sb = STRBUF_INIT; patterns = fopen(arg, "r"); if (!patterns) @@@ -710,8 -706,8 +710,8 @@@ int cmd_grep(int argc, const char **arg OPT_GROUP(""), OPT_BOOLEAN('v', "invert-match", &opt.invert, "show non-matching lines"), - OPT_BIT('i', "ignore-case", &opt.regflags, - "case insensitive matching", REG_ICASE), + OPT_BOOLEAN('i', "ignore-case", &opt.ignore_case, + "case insensitive matching"), OPT_BOOLEAN('w', "word-regexp", &opt.word_regexp, "match patterns only at word boundaries"), OPT_SET_INT('a', "text", &opt.binary, @@@ -792,13 -788,6 +792,13 @@@ OPT_END() }; + /* + * 'git grep -h', unlike 'git grep -h ', is a request + * to show usage information and exit. + */ + if (argc == 2 && !strcmp(argv[1], "-h")) + usage_with_options(grep_usage, options); + memset(&opt, 0, sizeof(opt)); opt.prefix = prefix; opt.prefix_length = (prefix && *prefix) ? strlen(prefix) : 0; @@@ -841,6 -830,8 +841,8 @@@ external_grep_allowed = 0; if (!opt.pattern_list) die("no pattern given."); + if (!opt.fixed && opt.ignore_case) + opt.regflags |= REG_ICASE; if ((opt.regflags != REG_NEWLINE) && opt.fixed) die("cannot mix --fixed-strings and regexp"); compile_grep_patterns(&opt); diff --combined t/t7002-grep.sh index dd0da6c0bf,35a1e7a5d4..abd14bf819 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@@ -14,6 -14,7 +14,7 @@@ int main(int argc, const char **argv { printf("Hello world.\n"); return 0; + /* char ?? */ } EOF @@@ -213,77 -214,6 +214,77 @@@ test_expect_success 'grep -e A --and -- test_cmp expected actual ' +test_expect_success 'grep should ignore GREP_OPTIONS' ' + GREP_OPTIONS=-v git grep " mmap bar\$" >actual && + test_cmp expected actual +' + +test_expect_success 'grep -f, non-existent file' ' + test_must_fail git grep -f patterns +' + +cat >expected <pattern <actual && + test_cmp expected actual +' + +cat >expected <patterns <actual && + test_cmp expected actual +' + +cat >expected <patterns <actual && + test_cmp expected actual +' + cat >expected <expected <actual && + test_cmp expected actual + ' + test_done