diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-01-13 23:10:02 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-01-13 23:10:02 -0800 |
commit | 6a15416a89b8e0095de6dd0d733b4f4545c27d16 (patch) | |
tree | acd7f6112700e2389eae9c2777e5656d0db8ea80 /builtin-grep.c | |
parent | Merge branch 'as/maint-shortlog-cleanup' (diff) | |
parent | grep: grep cache entries if they are "assume unchanged" (diff) | |
download | tgif-6a15416a89b8e0095de6dd0d733b4f4545c27d16.tar.xz |
Merge branch 'nd/grep-assume-unchanged'
* nd/grep-assume-unchanged:
grep: grep cache entries if they are "assume unchanged"
grep: support --no-ext-grep to test builtin grep
Diffstat (limited to 'builtin-grep.c')
-rw-r--r-- | builtin-grep.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/builtin-grep.c b/builtin-grep.c index 624f86e287..bebf15cd6f 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. @@ -389,7 +391,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; @@ -402,7 +404,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); @@ -545,6 +552,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; |