sane_grep: pass "-a" if grep accepts it
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 Mar 2016 23:47:57 +0000 (15:47 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Mar 2016 23:35:43 +0000 (15:35 -0800)
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>
Makefile
config.mak.uname
configure.ac
git-sh-setup.sh
index 37e2d9e1861295361d08b3f2cc0f3dcc584acdc9..59bbb1e6a9af55aba6d4b2b765c2ea429e0a19ef 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -266,6 +266,9 @@ all::
 #
 # Define NO_TCLTK if you do not want Tcl/Tk GUI.
 #
+# Define SANE_TEXT_GREP to "-a" if you use recent versions of GNU grep
+# and egrep that are pickier when their input contains non-ASCII data.
+#
 # The TCL_PATH variable governs the location of the Tcl interpreter
 # used to optimize git-gui for your system.  Only used if NO_TCLTK
 # is not set.  Defaults to the bare 'tclsh'.
@@ -1728,7 +1731,7 @@ common-cmds.h: $(wildcard Documentation/git-*.txt)
 
 SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
        $(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
-       $(gitwebdir_SQ):$(PERL_PATH_SQ)
+       $(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP)
 define cmd_munge_script
 $(RM) $@ $@+ && \
 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
@@ -1740,6 +1743,7 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
     -e $(BROKEN_PATH_FIX) \
     -e 's|@@GITWEBDIR@@|$(gitwebdir_SQ)|g' \
     -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
+    -e 's|@@SANE_TEXT_GREP@@|$(SANE_TEXT_GREP)|g' \
     $@.sh >$@+
 endef
 
index 943c43965e68fe39fa6e0ea266c3ac376f6e0125..a7064749fc82617199c26ca27a6715fa51552f61 100644 (file)
@@ -37,6 +37,7 @@ ifeq ($(uname_S),Linux)
        HAVE_CLOCK_GETTIME = YesPlease
        HAVE_CLOCK_MONOTONIC = YesPlease
        HAVE_GETDELIM = YesPlease
+       SANE_TEXT_GREP=-a
 endif
 ifeq ($(uname_S),GNU/kFreeBSD)
        HAVE_ALLOCA_H = YesPlease
index 1f55009bba756322dca30cd945d2695666422a71..6fd7b8edce348ec5cacd2fb8f1d8b1f5c7490ae0 100644 (file)
@@ -471,6 +471,13 @@ if test -n "$ASCIIDOC"; then
        esac
 fi
 
+if grep -a ascii configure.ac >/dev/null; then
+  AC_MSG_RESULT([Using 'grep -a' for sane_grep])
+  SANE_TEXT_GREP=-a
+else
+  SANE_TEXT_GREP=
+fi
+GIT_CONF_SUBST([SANE_TEXT_GREP])
 
 ## Checks for libraries.
 AC_MSG_NOTICE([CHECKS for libraries])
index 4691fbcb64fe7ecbc58930bb96d4e6b28e2b87a7..c48139a49420ea2318e23d8667eb20bae9772463 100644 (file)
@@ -168,11 +168,11 @@ git_pager() {
 }
 
 sane_grep () {
-       GREP_OPTIONS= LC_ALL=C grep "$@"
+       GREP_OPTIONS= LC_ALL=C grep @@SANE_TEXT_GREP@@ "$@"
 }
 
 sane_egrep () {
-       GREP_OPTIONS= LC_ALL=C egrep "$@"
+       GREP_OPTIONS= LC_ALL=C egrep @@SANE_TEXT_GREP@@ "$@"
 }
 
 is_bare_repository () {