Skip to content

Commit f9686cd

Browse files
committed
Merge branch 'nd/grep-assume-unchanged' into maint
* nd/grep-assume-unchanged: grep: grep cache entries if they are "assume unchanged" grep: support --no-ext-grep to test builtin grep
2 parents 32fe027 + 57d4346 commit f9686cd

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

builtin-grep.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#endif
2121
#endif
2222

23+
static int builtin_grep;
24+
2325
/*
2426
* git grep pathspecs are somewhat different from diff-tree pathspecs;
2527
* pathname wildcards are allowed.
@@ -389,7 +391,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
389391
* we grep through the checked-out files. It tends to
390392
* be a lot more optimized
391393
*/
392-
if (!cached) {
394+
if (!cached && !builtin_grep) {
393395
hit = external_grep(opt, paths, cached);
394396
if (hit >= 0)
395397
return hit;
@@ -402,7 +404,12 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
402404
continue;
403405
if (!pathspec_matches(paths, ce->name))
404406
continue;
405-
if (cached) {
407+
/*
408+
* If CE_VALID is on, we assume worktree file and its cache entry
409+
* are identical, even if worktree file has been modified, so use
410+
* cache version instead
411+
*/
412+
if (cached || (ce->ce_flags & CE_VALID)) {
406413
if (ce_stage(ce))
407414
continue;
408415
hit |= grep_sha1(opt, ce->sha1, ce->name, 0);
@@ -545,6 +552,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
545552
cached = 1;
546553
continue;
547554
}
555+
if (!strcmp("--no-ext-grep", arg)) {
556+
builtin_grep = 1;
557+
continue;
558+
}
548559
if (!strcmp("-a", arg) ||
549560
!strcmp("--text", arg)) {
550561
opt.binary = GREP_BINARY_TEXT;

t/t7002-grep.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,14 @@ test_expect_success 'log grep (6)' '
161161
git log --author=-0700 --pretty=tformat:%s >actual &&
162162
>expect &&
163163
test_cmp expect actual
164+
'
164165

166+
test_expect_success 'grep with CE_VALID file' '
167+
git update-index --assume-unchanged t/t &&
168+
rm t/t &&
169+
test "$(git grep --no-ext-grep t)" = "t/t:test" &&
170+
git update-index --no-assume-unchanged t/t &&
171+
git checkout t/t
165172
'
166173

167174
test_done

0 commit comments

Comments
 (0)