Skip to content

Commit 5f7c643

Browse files
peffgitster
authored andcommitted
add NO_EXTERNAL_GREP build option
Previously, we just chose whether to allow external grep based on the __unix__ define. However, there are systems which define this macro but which have an inferior group (e.g., one that does not support all options used by t7002). This allows users to accept the potential speed penalty to get a more consistent grep experience (and to pass the testsuite). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent cde2ed2 commit 5f7c643

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ all::
148148
# is a simplified version of the merge sort used in glibc. This is
149149
# recommended if Git triggers O(n^2) behavior in your platform's qsort().
150150
#
151+
# Define NO_EXTERNAL_GREP if you don't want "git grep" to ever call
152+
# your external grep (e.g., if your system lacks grep, if its grep is
153+
# broken, or spawning external process is slower than built-in grep git has).
151154

152155
GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
153156
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -760,6 +763,9 @@ endif
760763
ifdef DIR_HAS_BSD_GROUP_SEMANTICS
761764
COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS
762765
endif
766+
ifdef NO_EXTERNAL_GREP
767+
BASIC_CFLAGS += -DNO_EXTERNAL_GREP
768+
endif
763769

764770
ifeq ($(TCLTK_PATH),)
765771
NO_TCLTK=NoThanks

builtin-grep.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
#include "builtin.h"
1313
#include "grep.h"
1414

15+
#ifndef NO_EXTERNAL_GREP
16+
#ifdef __unix__
17+
#define NO_EXTERNAL_GREP 0
18+
#else
19+
#define NO_EXTERNAL_GREP 1
20+
#endif
21+
#endif
22+
1523
/*
1624
* git grep pathspecs are somewhat different from diff-tree pathspecs;
1725
* pathname wildcards are allowed.
@@ -153,7 +161,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
153161
return i;
154162
}
155163

156-
#ifdef __unix__
164+
#if !NO_EXTERNAL_GREP
157165
static int exec_grep(int argc, const char **argv)
158166
{
159167
pid_t pid;
@@ -372,7 +380,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
372380
int nr;
373381
read_cache();
374382

375-
#ifdef __unix__
383+
#if !NO_EXTERNAL_GREP
376384
/*
377385
* Use the external "grep" command for the case where
378386
* we grep through the checked-out files. It tends to

0 commit comments

Comments
 (0)