git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/5] grep: remove global variable builtin_grep

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
May 7, 2009, 19:46 UTC
Message-ID
<1241725577.4772.10.camel@ubuntu.ubuntu-domain>
In-Reply-To
<1241725380.4772.6.camel@ubuntu.ubuntu-domain>

Replace the only global variable in builtin-grep.c, builtin_grep, by a local one and a function parameter with reversed meaning.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 builtin-grep.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/builtin-grep.c b/builtin-grep.c
index f88a912..620399f 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -20,8 +20,6 @@
 #endif
 #endif
 
-static int builtin_grep;
-
 static int grep_config(const char *var, const char *value, void *cb)
 {
 	struct grep_opt *opt = cb;
@@ -432,7 +430,8 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
 }
 #endif
 
-static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
+static int grep_cache(struct grep_opt *opt, const char **paths, int cached,
+		      int external_grep_allowed)
 {
 	int hit = 0;
 	int nr;
@@ -444,7 +443,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 && !builtin_grep) {
+	if (!cached && external_grep_allowed) {
 		hit = external_grep(opt, paths, cached);
 		if (hit >= 0)
 			return hit;
@@ -574,6 +573,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 {
 	int hit = 0;
 	int cached = 0;
+	int external_grep_allowed = 1;
 	int seen_dashdash = 0;
 	struct grep_opt opt;
 	struct object_array list = { 0, 0, NULL };
@@ -612,7 +612,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 		if (!strcmp("--no-ext-grep", arg)) {
-			builtin_grep = 1;
+			external_grep_allowed = 0;
 			continue;
 		}
 		if (!strcmp("-a", arg) ||
@@ -823,7 +823,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	}
 
 	if (opt.color && !opt.color_external)
-		builtin_grep = 1;
+		external_grep_allowed = 0;
 	if (!opt.pattern_list)
 		die("no pattern given.");
 	if ((opt.regflags != REG_NEWLINE) && opt.fixed)
@@ -874,7 +874,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	if (!list.nr) {
 		if (!cached)
 			setup_work_tree();
-		return !grep_cache(&opt, paths, cached);
+		return !grep_cache(&opt, paths, cached, external_grep_allowed);
 	}
 
 	if (cached)
-- 
1.6.3
Previous: René ScharfeNext: René Scharfe
Message 6 of 10 in “grep parseopt conversion”
  1. 0/5 grep parseopt conversionRené Scharfe, May 7, 2009
  2. 1/5 parseopt: add OPT_NEGBITRené Scharfe, May 7, 2009
  3. Jeff KingMay 8, 2009
  4. 2/5 parseopt: add OPT_NUMBER_CALLBACKRené Scharfe, May 7, 2009
  5. 3/5 parseopt: add PARSE_OPT_NODASHRené Scharfe, May 7, 2009
  6. 4/5 grep: remove global variable builtin_grepRené Scharfe, May 7, 2009
  7. 5/5 grep: use parseoptRené Scharfe, May 7, 2009
  8. Stephen BoydMay 16, 2009
  9. René ScharfeMay 17, 2009
  10. grep: make callback functions staticRené Scharfe, May 20, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.