Browse Source

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
maint
Junio C Hamano 16 years ago
parent
commit
6a15416a89
  1. 15
      builtin-grep.c
  2. 7
      t/t7002-grep.sh

15
builtin-grep.c

@ -20,6 +20,8 @@
#endif #endif
#endif #endif


static int builtin_grep;

/* /*
* git grep pathspecs are somewhat different from diff-tree pathspecs; * git grep pathspecs are somewhat different from diff-tree pathspecs;
* pathname wildcards are allowed. * 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 * we grep through the checked-out files. It tends to
* be a lot more optimized * be a lot more optimized
*/ */
if (!cached) { if (!cached && !builtin_grep) {
hit = external_grep(opt, paths, cached); hit = external_grep(opt, paths, cached);
if (hit >= 0) if (hit >= 0)
return hit; return hit;
@ -402,7 +404,12 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
continue; continue;
if (!pathspec_matches(paths, ce->name)) if (!pathspec_matches(paths, ce->name))
continue; 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)) if (ce_stage(ce))
continue; continue;
hit |= grep_sha1(opt, ce->sha1, ce->name, 0); 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; cached = 1;
continue; continue;
} }
if (!strcmp("--no-ext-grep", arg)) {
builtin_grep = 1;
continue;
}
if (!strcmp("-a", arg) || if (!strcmp("-a", arg) ||
!strcmp("--text", arg)) { !strcmp("--text", arg)) {
opt.binary = GREP_BINARY_TEXT; opt.binary = GREP_BINARY_TEXT;

7
t/t7002-grep.sh

@ -161,7 +161,14 @@ test_expect_success 'log grep (6)' '
git log --author=-0700 --pretty=tformat:%s >actual && git log --author=-0700 --pretty=tformat:%s >actual &&
>expect && >expect &&
test_cmp expect actual test_cmp expect actual
'


test_expect_success 'grep with CE_VALID file' '
git update-index --assume-unchanged t/t &&
rm t/t &&
test "$(git grep --no-ext-grep t)" = "t/t:test" &&
git update-index --no-assume-unchanged t/t &&
git checkout t/t
' '


test_done test_done

Loading…
Cancel
Save