2020#endif
2121#endif
2222
23- static int builtin_grep ;
24-
2523static int grep_config (const char * var , const char * value , void * cb )
2624{
2725 struct grep_opt * opt = cb ;
@@ -432,7 +430,8 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
432430}
433431#endif
434432
435- static int grep_cache (struct grep_opt * opt , const char * * paths , int cached )
433+ static int grep_cache (struct grep_opt * opt , const char * * paths , int cached ,
434+ int external_grep_allowed )
436435{
437436 int hit = 0 ;
438437 int nr ;
@@ -444,7 +443,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
444443 * we grep through the checked-out files. It tends to
445444 * be a lot more optimized
446445 */
447- if (!cached && ! builtin_grep ) {
446+ if (!cached && external_grep_allowed ) {
448447 hit = external_grep (opt , paths , cached );
449448 if (hit >= 0 )
450449 return hit ;
@@ -574,6 +573,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
574573{
575574 int hit = 0 ;
576575 int cached = 0 ;
576+ int external_grep_allowed = 1 ;
577577 int seen_dashdash = 0 ;
578578 struct grep_opt opt ;
579579 struct object_array list = { 0 , 0 , NULL };
@@ -612,7 +612,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
612612 continue ;
613613 }
614614 if (!strcmp ("--no-ext-grep" , arg )) {
615- builtin_grep = 1 ;
615+ external_grep_allowed = 0 ;
616616 continue ;
617617 }
618618 if (!strcmp ("-a" , arg ) ||
@@ -823,7 +823,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
823823 }
824824
825825 if (opt .color && !opt .color_external )
826- builtin_grep = 1 ;
826+ external_grep_allowed = 0 ;
827827 if (!opt .pattern_list )
828828 die ("no pattern given." );
829829 if ((opt .regflags != REG_NEWLINE ) && opt .fixed )
@@ -874,7 +874,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
874874 if (!list .nr ) {
875875 if (!cached )
876876 setup_work_tree ();
877- return !grep_cache (& opt , paths , cached );
877+ return !grep_cache (& opt , paths , cached , external_grep_allowed );
878878 }
879879
880880 if (cached )
0 commit comments