Skip to content

Commit

Permalink
add NO_EXTERNAL_GREP build option
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Mar 13, 2008
1 parent cde2ed2 commit 5f7c643
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ all::
# is a simplified version of the merge sort used in glibc. This is
# recommended if Git triggers O(n^2) behavior in your platform's qsort().
#
# Define NO_EXTERNAL_GREP if you don't want "git grep" to ever call
# your external grep (e.g., if your system lacks grep, if its grep is
# broken, or spawning external process is slower than built-in grep git has).

GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
@$(SHELL_PATH) ./GIT-VERSION-GEN
Expand Down Expand Up @@ -760,6 +763,9 @@ endif
ifdef DIR_HAS_BSD_GROUP_SEMANTICS
COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS
endif
ifdef NO_EXTERNAL_GREP
BASIC_CFLAGS += -DNO_EXTERNAL_GREP
endif

ifeq ($(TCLTK_PATH),)
NO_TCLTK=NoThanks
Expand Down
12 changes: 10 additions & 2 deletions builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
#include "builtin.h"
#include "grep.h"

#ifndef NO_EXTERNAL_GREP
#ifdef __unix__
#define NO_EXTERNAL_GREP 0
#else
#define NO_EXTERNAL_GREP 1
#endif
#endif

/*
* git grep pathspecs are somewhat different from diff-tree pathspecs;
* pathname wildcards are allowed.
Expand Down Expand Up @@ -153,7 +161,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
return i;
}

#ifdef __unix__
#if !NO_EXTERNAL_GREP
static int exec_grep(int argc, const char **argv)
{
pid_t pid;
Expand Down Expand Up @@ -372,7 +380,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
int nr;
read_cache();

#ifdef __unix__
#if !NO_EXTERNAL_GREP
/*
* Use the external "grep" command for the case where
* we grep through the checked-out files. It tends to
Expand Down

0 comments on commit 5f7c643

Please sign in to comment.