threads / patch / 14620

patch, 12 partsgit-grep: support --no-external-grep

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

## tl;dr

3 messages between Jul 23, 2008 and Jul 24, 2008. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Nguyễn Thái Ngọc Duy· Jul 23, 2008, 14:55 UTC · lore
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(-)
Show changes to builtin-grep.c +7 −1
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· Jul 24, 2008, 20:26 UTC · re: Nguyễn Thái Ngọc Duy · lore

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

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;
Show 6 quoted lines
> @@ -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) {
Show 8 quoted lines
> @@ -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· Jul 24, 2008, 23:16 UTC · re: Alex Riesen · lore

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

On 7/25/08, Alex Riesen <raa.lkml@gmail.com> wrote:
Show 9 quoted lines
> 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.
Show 6 quoted lines
>  +               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

← back to recent threads