From: Junio C Hamano Date: Thu, 3 Dec 2009 21:51:26 +0000 (-0800) Subject: Merge branch 'bc/grep-i-F' into maint X-Git-Tag: v1.6.5.5~21 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f2c0ca4fae299c2515c1554dbeec2080af5c6792?hp=-c Merge branch 'bc/grep-i-F' into maint * bc/grep-i-F: grep: Allow case insensitive search of fixed-strings --- f2c0ca4fae299c2515c1554dbeec2080af5c6792 diff --combined builtin-grep.c index 1df25b07b5,b41ad1e43a..d79a6260a4 --- 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"); @@@ -631,7 -631,7 +631,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) @@@ -706,8 -706,8 +706,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, @@@ -830,6 -830,8 +830,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 ae5290ab43,35a1e7a5d4..3a103fec96 --- 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,72 -214,6 +214,72 @@@ test_expect_success 'grep -e A --and -- 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