sane_grep: pass "-a" if grep accepts it

Newer versions of GNU grep is reported to be pickier when we feed a non-ASCII input and break some Porcelain scripts. As we know we do not feed random binary file to our own sane_grep wrapper, allow us to always pass "-a" by setting SANE_TEXT_GREP=-a Makefile variable to work it around. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Mar 8, 2016 at 15:47 UTC 71b401032b9e5b0a71e41d95ae0998858787700c
4 files changed +15 -3
Makefile
+5 -1
@@ -266,6 +266,9 @@ all::
266 #
267 # Define NO_TCLTK if you do not want Tcl/Tk GUI.
268 #
269 +# Define SANE_TEXT_GREP to "-a" if you use recent versions of GNU grep
270 +# and egrep that are pickier when their input contains non-ASCII data.
271 +#
272 # The TCL_PATH variable governs the location of the Tcl interpreter
273 # used to optimize git-gui for your system. Only used if NO_TCLTK
274 # is not set. Defaults to the bare 'tclsh'.
@@ -1728,7 +1731,7 @@ common-cmds.h: $(wildcard Documentation/git-*.txt)
1731
1732 SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
1733 $(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
1731 - $(gitwebdir_SQ):$(PERL_PATH_SQ)
1734 + $(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP)
1735 define cmd_munge_script
1736 $(RM) $@ $@+ && \
1737 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
@@ -1740,6 +1743,7 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
1743 -e $(BROKEN_PATH_FIX) \
1744 -e 's|@@GITWEBDIR@@|$(gitwebdir_SQ)|g' \
1745 -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
1746 + -e 's|@@SANE_TEXT_GREP@@|$(SANE_TEXT_GREP)|g' \
1747 $@.sh >$@+
1748 endef
1749
config.mak.uname
+1
@@ -37,6 +37,7 @@ ifeq ($(uname_S),Linux)
37 HAVE_CLOCK_GETTIME = YesPlease
38 HAVE_CLOCK_MONOTONIC = YesPlease
39 HAVE_GETDELIM = YesPlease
40 + SANE_TEXT_GREP=-a
41 endif
42 ifeq ($(uname_S),GNU/kFreeBSD)
43 HAVE_ALLOCA_H = YesPlease
configure.ac
+7
@@ -471,6 +471,13 @@ if test -n "$ASCIIDOC"; then
471 esac
472 fi
473
474 +if grep -a ascii configure.ac >/dev/null; then
475 + AC_MSG_RESULT([Using 'grep -a' for sane_grep])
476 + SANE_TEXT_GREP=-a
477 +else
478 + SANE_TEXT_GREP=
479 +fi
480 +GIT_CONF_SUBST([SANE_TEXT_GREP])
481
482 ## Checks for libraries.
483 AC_MSG_NOTICE([CHECKS for libraries])
git-sh-setup.sh
+2 -2
@@ -168,11 +168,11 @@ git_pager() {
168 }
169
170 sane_grep () {
171 - GREP_OPTIONS= LC_ALL=C grep "$@"
171 + GREP_OPTIONS= LC_ALL=C grep @@SANE_TEXT_GREP@@ "$@"
172 }
173
174 sane_egrep () {
175 - GREP_OPTIONS= LC_ALL=C egrep "$@"
175 + GREP_OPTIONS= LC_ALL=C egrep @@SANE_TEXT_GREP@@ "$@"
176 }
177
178 is_bare_repository () {