diff options
Diffstat (limited to 'builtin-grep.c')
-rw-r--r-- | builtin-grep.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/builtin-grep.c b/builtin-grep.c index d3cc75e3a4..3f12ba3826 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -20,6 +20,8 @@ #endif #endif +static int builtin_grep; + /* * git grep pathspecs are somewhat different from diff-tree pathspecs; * pathname wildcards are allowed. @@ -297,6 +299,9 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) 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) { @@ -388,7 +393,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached) * 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; @@ -401,7 +406,12 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached) 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); @@ -544,6 +554,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix) 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; @@ -601,6 +615,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix) 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; |