Skip to content

Commit 1b5fb44

Browse files
René Scharfegitster
authored andcommitted
grep: remove global variable builtin_grep
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 51a9949 commit 1b5fb44

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

builtin-grep.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#endif
2121
#endif
2222

23-
static int builtin_grep;
24-
2523
static 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

Comments
 (0)