Skip to content

Commit 2df1363

Browse files
committed
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
2 parents 9e68980 + 214123c commit 2df1363

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ all::
264264
#
265265
# Define NO_TCLTK if you do not want Tcl/Tk GUI.
266266
#
267+
# Define SANE_TEXT_GREP to "-a" if you use recent versions of GNU grep
268+
# and egrep that are pickier when their input contains non-ASCII data.
269+
#
267270
# The TCL_PATH variable governs the location of the Tcl interpreter
268271
# used to optimize git-gui for your system. Only used if NO_TCLTK
269272
# is not set. Defaults to the bare 'tclsh'.
@@ -1740,7 +1743,7 @@ common-cmds.h: $(wildcard Documentation/git-*.txt)
17401743

17411744
SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
17421745
$(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
1743-
$(gitwebdir_SQ):$(PERL_PATH_SQ)
1746+
$(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP)
17441747
define cmd_munge_script
17451748
$(RM) $@ $@+ && \
17461749
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
@@ -1752,6 +1755,7 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
17521755
-e $(BROKEN_PATH_FIX) \
17531756
-e 's|@@GITWEBDIR@@|$(gitwebdir_SQ)|g' \
17541757
-e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
1758+
-e 's|@@SANE_TEXT_GREP@@|$(SANE_TEXT_GREP)|g' \
17551759
17561760
endef
17571761

config.mak.uname

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ifeq ($(uname_S),Linux)
3737
HAVE_CLOCK_GETTIME = YesPlease
3838
HAVE_CLOCK_MONOTONIC = YesPlease
3939
HAVE_GETDELIM = YesPlease
40+
SANE_TEXT_GREP=-a
4041
endif
4142
ifeq ($(uname_S),GNU/kFreeBSD)
4243
HAVE_ALLOCA_H = YesPlease

configure.ac

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ if test -n "$ASCIIDOC"; then
471471
esac
472472
fi
473473

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])
474481

475482
## Checks for libraries.
476483
AC_MSG_NOTICE([CHECKS for libraries])

git-rebase--interactive.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,8 @@ then
12331233
git rev-list $revisions |
12341234
while read rev
12351235
do
1236-
if test -f "$rewritten"/$rev && test "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
1236+
if test -f "$rewritten"/$rev &&
1237+
! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
12371238
then
12381239
# Use -f2 because if rev-list is telling us this commit is
12391240
# not worthwhile, we don't want to track its multiple heads,

git-sh-setup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ git_pager() {
168168
}
169169
170170
sane_grep () {
171-
GREP_OPTIONS= LC_ALL=C grep "$@"
171+
GREP_OPTIONS= LC_ALL=C grep @@SANE_TEXT_GREP@@ "$@"
172172
}
173173
174174
sane_egrep () {
175-
GREP_OPTIONS= LC_ALL=C egrep "$@"
175+
GREP_OPTIONS= LC_ALL=C egrep @@SANE_TEXT_GREP@@ "$@"
176176
}
177177
178178
is_bare_repository () {

0 commit comments

Comments
 (0)