Merge branch 'maint-1.6.0' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 3 Feb 2009 08:32:29 +0000 (00:32 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Feb 2009 08:32:29 +0000 (00:32 -0800)
* maint-1.6.0:
grep: pass -I (ignore binary) down to external grep

1  2 
builtin-grep.c
diff --combined builtin-grep.c
index bebf15cd6f7d82b773f985ce238688b4759e3c37,d3cc75e3a47bed0d44d1981a6f609f24558a9e1b..3f12ba382690699d96580c3ddb1a61c79520e694
@@@ -20,8 -20,6 +20,8 @@@
  #endif
  #endif
  
 +static int builtin_grep;
 +
  /*
   * git grep pathspecs are somewhat different from diff-tree pathspecs;
   * pathname wildcards are allowed.
@@@ -291,15 -289,14 +291,17 @@@ static int external_grep(struct grep_op
                push_arg("-E");
        if (opt->regflags & REG_ICASE)
                push_arg("-i");
+       if (opt->binary == GREP_BINARY_NOMATCH)
+               push_arg("-I");
        if (opt->word_regexp)
                push_arg("-w");
        if (opt->name_only)
                push_arg("-l");
        if (opt->unmatch_name_only)
                push_arg("-L");
 +      if (opt->null_following_name)
 +              /* in GNU grep git's "-z" translates to "-Z" */
 +              push_arg("-Z");
        if (opt->count)
                push_arg("-c");
        if (opt->post_context || opt->pre_context) {
@@@ -391,7 -388,7 +393,7 @@@ static int grep_cache(struct grep_opt *
         * we grep through the checked-out files. It tends to
         * be a lot more optimized
         */
 -      if (!cached) {
 +      if (!cached && !builtin_grep) {
                hit = external_grep(opt, paths, cached);
                if (hit >= 0)
                        return hit;
                        continue;
                if (!pathspec_matches(paths, ce->name))
                        continue;
 -              if (cached) {
 +              /*
 +               * If CE_VALID is on, we assume worktree file and its cache entry
 +               * are identical, even if worktree file has been modified, so use
 +               * cache version instead
 +               */
 +              if (cached || (ce->ce_flags & CE_VALID)) {
                        if (ce_stage(ce))
                                continue;
                        hit |= grep_sha1(opt, ce->sha1, ce->name, 0);
@@@ -552,10 -544,6 +554,10 @@@ int cmd_grep(int argc, const char **arg
                        cached = 1;
                        continue;
                }
 +              if (!strcmp("--no-ext-grep", arg)) {
 +                      builtin_grep = 1;
 +                      continue;
 +              }
                if (!strcmp("-a", arg) ||
                    !strcmp("--text", arg)) {
                        opt.binary = GREP_BINARY_TEXT;
                        opt.unmatch_name_only = 1;
                        continue;
                }
 +              if (!strcmp("-z", arg) ||
 +                  !strcmp("--null", arg)) {
 +                      opt.null_following_name = 1;
 +                      continue;
 +              }
                if (!strcmp("-c", arg) ||
                    !strcmp("--count", arg)) {
                        opt.count = 1;