]> asedeno.scripts.mit.edu Git - git.git/commitdiff
Merge branch 'bc/grep-i-F' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 3 Dec 2009 21:51:26 +0000 (13:51 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Dec 2009 21:51:26 +0000 (13:51 -0800)
* bc/grep-i-F:
  grep: Allow case insensitive search of fixed-strings

1  2 
builtin-grep.c
t/t7002-grep.sh

diff --combined builtin-grep.c
index 1df25b07b573301bba7fdcb3b13d1af9050f513e,b41ad1e43a1e4bc4bec8d4d6b8c0fd68aa6aa92f..d79a6260a4b6f9a467356de117e100cd1a457b23
@@@ -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,
                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 ae5290ab43e8b51b32331768371e2a67d700064d,35a1e7a5d430a8b8565f3b767e31810df4463485..3a103fec96407e0311bb8724660096548ae6923e
@@@ -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 <<EOF
 +file:foo mmap bar
 +file:foo_mmap bar
 +file:foo_mmap bar mmap
 +file:foo mmap bar_mmap
 +file:foo_mmap bar mmap baz
 +EOF
 +
 +cat >pattern <<EOF
 +mmap
 +EOF
 +
 +test_expect_success 'grep -f, one pattern' '
 +      git grep -f pattern >actual &&
 +      test_cmp expected actual
 +'
 +
 +cat >expected <<EOF
 +file:foo mmap bar
 +file:foo_mmap bar
 +file:foo_mmap bar mmap
 +file:foo mmap bar_mmap
 +file:foo_mmap bar mmap baz
 +t/a/v:vvv
 +t/v:vvv
 +v:vvv
 +EOF
 +
 +cat >patterns <<EOF
 +mmap
 +vvv
 +EOF
 +
 +test_expect_success 'grep -f, multiple patterns' '
 +      git grep -f patterns >actual &&
 +      test_cmp expected actual
 +'
 +
 +cat >expected <<EOF
 +file:foo mmap bar
 +file:foo_mmap bar
 +file:foo_mmap bar mmap
 +file:foo mmap bar_mmap
 +file:foo_mmap bar mmap baz
 +t/a/v:vvv
 +t/v:vvv
 +v:vvv
 +EOF
 +
 +cat >patterns <<EOF
 +
 +mmap
 +
 +vvv
 +
 +EOF
 +
 +test_expect_success 'grep -f, ignore empty lines' '
 +      git grep -f patterns >actual &&
 +      test_cmp expected actual
 +'
 +
  cat >expected <<EOF
  y:y yy
  --
@@@ -411,4 -346,13 +412,13 @@@ test_expect_success 'grep from a subdir
        )
  '
  
+ cat >expected <<EOF
+ hello.c:int main(int argc, const char **argv)
+ EOF
+ test_expect_success 'grep -Fi' '
+       git grep -Fi "CHAR *" >actual &&
+       test_cmp expected actual
+ '
  test_done