git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] rebase -p: avoid grep on potentailly non-ASCII data

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 9, 2016, 20:26 UTC
Message-ID
<xmqqvb4vgzxs.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<alpine.DEB.2.10.1603082127230.2674@buzzword-bingo.mit.edu>
Anders Kaseorg <andersk@mit.edu> writes:
> The autoconf support you committed as 67f1790a has a small bug (the else 
> cause should omit -a):
Thanks.  To summarize the discussion, here is what I ended up with.
-- >8 --
Subject: [PATCH] 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>
---
 Makefile         | 6 +++++-
 config.mak.uname | 1 +
 configure.ac     | 7 +++++++
 git-sh-setup.sh  | 4 ++--
 4 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 37e2d9e..62d759d 100644
--- 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 picker 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
 
diff --git a/config.mak.uname b/config.mak.uname
index 943c439..a706474 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -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
diff --git a/configure.ac b/configure.ac
index 1f55009..6fd7b8e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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])
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 4691fbc..c48139a 100644
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -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 () {
-- 
2.8.0-rc1-141-gbaa22e3
Previous: Anders KaseorgNext: Torsten Bögershausen
Message 10 of 12 in “rebase -p: avoid grep on potentailly non-ASCII data”
  1. rebase -p: avoid grep on potentailly non-ASCII dataAnders Kaseorg, Mar 8, 2016
  2. Torsten BögershausenMar 8, 2016
  3. Michael J GruberMar 8, 2016
  4. Jeff KingMar 8, 2016
  5. Junio C HamanoMar 8, 2016
  6. Junio C HamanoMar 8, 2016
  7. Jeff KingMar 9, 2016
  8. Jeff KingMar 9, 2016
  9. Anders KaseorgMar 9, 2016
  10. Junio C HamanoMar 9, 2016
  11. Torsten BögershausenMar 10, 2016
  12. Junio C HamanoMar 10, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.