From: Junio C Hamano Date: Tue, 3 Feb 2009 08:32:29 +0000 (-0800) Subject: Merge branch 'maint-1.6.0' into maint X-Git-Tag: v1.6.1.3~12 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/281907574ca420cc9a800190509adbf89bf9a2d1?ds=inline;hp=-c Merge branch 'maint-1.6.0' into maint * maint-1.6.0: grep: pass -I (ignore binary) down to external grep --- 281907574ca420cc9a800190509adbf89bf9a2d1 diff --combined builtin-grep.c index bebf15cd6f,d3cc75e3a4..3f12ba3826 --- a/builtin-grep.c +++ b/builtin-grep.c @@@ -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; @@@ -404,12 -401,7 +406,12 @@@ 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; @@@ -613,11 -601,6 +615,11 @@@ 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;