1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-29 07:26:10 +02:00

Merge branch 'jc/sane-grep'

Recent versions of GNU grep is pickier than before to decide if a
file is "binary" and refuse to give line-oriented hits when we
expect it to, unless explicitly told with "-a" option.  As our
scripted Porcelains use sane_grep wrapper for line-oriented data,
even when the line may contain non-ASCII payload we took from
end-user data, use "grep -a" to implement sane_grep wrapper when
using an implementation of "grep" that takes the "-a" option.

* jc/sane-grep:
  rebase-i: clarify "is this commit relevant?" test
  sane_grep: pass "-a" if grep accepts it
This commit is contained in:
Junio C Hamano 2016-03-16 13:16:54 -07:00
commit 2df13639e7
5 changed files with 17 additions and 4 deletions

View File

@ -264,6 +264,9 @@ all::
# #
# Define NO_TCLTK if you do not want Tcl/Tk GUI. # 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 # The TCL_PATH variable governs the location of the Tcl interpreter
# used to optimize git-gui for your system. Only used if NO_TCLTK # used to optimize git-gui for your system. Only used if NO_TCLTK
# is not set. Defaults to the bare 'tclsh'. # is not set. Defaults to the bare 'tclsh'.
@ -1740,7 +1743,7 @@ common-cmds.h: $(wildcard Documentation/git-*.txt)
SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\ SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
$(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\ $(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 define cmd_munge_script
$(RM) $@ $@+ && \ $(RM) $@ $@+ && \
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
@ -1752,6 +1755,7 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
-e $(BROKEN_PATH_FIX) \ -e $(BROKEN_PATH_FIX) \
-e 's|@@GITWEBDIR@@|$(gitwebdir_SQ)|g' \ -e 's|@@GITWEBDIR@@|$(gitwebdir_SQ)|g' \
-e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \ -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
-e 's|@@SANE_TEXT_GREP@@|$(SANE_TEXT_GREP)|g' \
$@.sh >$@+ $@.sh >$@+
endef endef

View File

@ -37,6 +37,7 @@ ifeq ($(uname_S),Linux)
HAVE_CLOCK_GETTIME = YesPlease HAVE_CLOCK_GETTIME = YesPlease
HAVE_CLOCK_MONOTONIC = YesPlease HAVE_CLOCK_MONOTONIC = YesPlease
HAVE_GETDELIM = YesPlease HAVE_GETDELIM = YesPlease
SANE_TEXT_GREP=-a
endif endif
ifeq ($(uname_S),GNU/kFreeBSD) ifeq ($(uname_S),GNU/kFreeBSD)
HAVE_ALLOCA_H = YesPlease HAVE_ALLOCA_H = YesPlease

View File

@ -471,6 +471,13 @@ if test -n "$ASCIIDOC"; then
esac esac
fi 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. ## Checks for libraries.
AC_MSG_NOTICE([CHECKS for libraries]) AC_MSG_NOTICE([CHECKS for libraries])

View File

@ -1233,7 +1233,8 @@ then
git rev-list $revisions | git rev-list $revisions |
while read rev while read rev
do do
if test -f "$rewritten"/$rev && test "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = "" if test -f "$rewritten"/$rev &&
! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
then then
# Use -f2 because if rev-list is telling us this commit is # Use -f2 because if rev-list is telling us this commit is
# not worthwhile, we don't want to track its multiple heads, # not worthwhile, we don't want to track its multiple heads,

View File

@ -168,11 +168,11 @@ git_pager() {
} }
sane_grep () { sane_grep () {
GREP_OPTIONS= LC_ALL=C grep "$@" GREP_OPTIONS= LC_ALL=C grep @@SANE_TEXT_GREP@@ "$@"
} }
sane_egrep () { sane_egrep () {
GREP_OPTIONS= LC_ALL=C egrep "$@" GREP_OPTIONS= LC_ALL=C egrep @@SANE_TEXT_GREP@@ "$@"
} }
is_bare_repository () { is_bare_repository () {