20
20
#endif
21
21
#endif
22
22
23
+ static int builtin_grep ;
24
+
23
25
/*
24
26
* git grep pathspecs are somewhat different from diff-tree pathspecs;
25
27
* pathname wildcards are allowed.
@@ -389,7 +391,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
389
391
* we grep through the checked-out files. It tends to
390
392
* be a lot more optimized
391
393
*/
392
- if (!cached ) {
394
+ if (!cached && ! builtin_grep ) {
393
395
hit = external_grep (opt , paths , cached );
394
396
if (hit >= 0 )
395
397
return hit ;
@@ -402,7 +404,12 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
402
404
continue ;
403
405
if (!pathspec_matches (paths , ce -> name ))
404
406
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 )) {
406
413
if (ce_stage (ce ))
407
414
continue ;
408
415
hit |= grep_sha1 (opt , ce -> sha1 , ce -> name , 0 );
@@ -545,6 +552,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
545
552
cached = 1 ;
546
553
continue ;
547
554
}
555
+ if (!strcmp ("--no-ext-grep" , arg )) {
556
+ builtin_grep = 1 ;
557
+ continue ;
558
+ }
548
559
if (!strcmp ("-a" , arg ) ||
549
560
!strcmp ("--text" , arg )) {
550
561
opt .binary = GREP_BINARY_TEXT ;
0 commit comments