# [PATCH 02/12] git-grep: support --no-external-grep

3 messages from 2008-07-23 to 2008-07-24. Participants: Nguyễn Thái Ngọc Duy, Alex Riesen, Nguyen Thai Ngoc Duy.
Thread: https://gitlist.dev/t/14620

## Nguyễn Thái Ngọc Duy, 2008-07-23 14:55

Subject: [PATCH 02/12] git-grep: support --no-external-grep
Message-ID: <20080723145549.GA29067@laptop>
URL: https://gitlist.dev/e/20080723145549.GA29067%40laptop

```
this one is mainly for testing builtin grep

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-grep.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index cc9ba6b..ee96d01 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -20,6 +20,8 @@
 #endif
 #endif
 
+static int no_external_grep;
+
 /*
  * git grep pathspecs are somewhat different from diff-tree pathspecs;
  * pathname wildcards are allowed.
@@ -386,7 +388,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 && !no_external_grep) {
 		hit = external_grep(opt, paths, cached);
 		if (hit >= 0)
 			return hit;
@@ -544,6 +546,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			cached = 1;
 			continue;
 		}
+		if (!strcmp("--no-external-grep", arg)) {
+			no_external_grep = 1;
+			continue;
+		}
 		if (!strcmp("-a", arg) ||
 		    !strcmp("--text", arg)) {
 			opt.binary = GREP_BINARY_TEXT;
-- 
1.5.5.GIT

```

## Alex Riesen, 2008-07-24 20:26

Subject: Re: [PATCH 02/12] git-grep: support --no-external-grep
Message-ID: <20080724202634.GB3760@blimp.local>
URL: https://gitlist.dev/e/20080724202634.GB3760%40blimp.local
In-Reply-To: <20080723145549.GA29067@laptop>

```
Nguyễn Thái Ngọc Duy, Wed, Jul 23, 2008 16:55:49 +0200:
>  
> +static int no_external_grep;
> +

If you have used direct logic instead of negative, your patch would
have been simplier and the code would be easier to understand. I.e.:

+static int external_grep = 1;

> @@ -386,7 +388,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 && !no_external_grep) {

+	if (!cached && external_grep) {

> @@ -544,6 +546,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>  			cached = 1;
>  			continue;
>  		}
> +		if (!strcmp("--no-external-grep", arg)) {
> +			no_external_grep = 1;
> +			continue;
> +		}

+		if (!strcmp("--no-external-grep", arg)) {
+			external_grep = 0;
+			continue;
+		}

BTW, how about a config option for this? And maybe --external-grep={yes|no}

```

## Nguyen Thai Ngoc Duy, 2008-07-24 23:16

Subject: Re: [PATCH 02/12] git-grep: support --no-external-grep
Message-ID: <fcaeb9bf0807241616k787ea8cco75d1a93a3eb516@mail.gmail.com>
URL: https://gitlist.dev/e/fcaeb9bf0807241616k787ea8cco75d1a93a3eb516%40mail.gmail.com
In-Reply-To: <20080724202634.GB3760@blimp.local>

```
On 7/25/08, Alex Riesen <raa.lkml@gmail.com> wrote:
> Nguyen Thai Ngoc Duy, Wed, Jul 23, 2008 16:55:49 +0200:
>
> >
>  > +static int no_external_grep;
>  > +
>
>
> If you have used direct logic instead of negative, your patch would
>  have been simplier and the code would be easier to understand. I.e.:

Point taken.

>  +               if (!strcmp("--no-external-grep", arg)) {
>  +                       external_grep = 0;
>  +                       continue;
>  +               }
>
>  BTW, how about a config option for this? And maybe --external-grep={yes|no}

I don't need --external-grep=yes now, but that would be good for
testing external grep. About config option, is it really needed?
-- 
Duy

```
