Skip to content

Commit 957f5db

Browse files
committed
Merge branch 'rs/work-around-grep-opt-insanity' into maint
* rs/work-around-grep-opt-insanity: Protect scripted Porcelains from GREP_OPTIONS insanity mergetool--lib: simplify guess_merge_tool()
2 parents af742b9 + e1622bf commit 957f5db

9 files changed

+32
-25
lines changed

git-am.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ check_patch_format () {
205205
# and see if it looks like that they all begin with the
206206
# header field names...
207207
sed -n -e '/^$/q' -e '/^[ ]/d' -e p "$1" |
208-
LC_ALL=C egrep -v '^[!-9;-~]+:' >/dev/null ||
208+
sane_egrep -v '^[!-9;-~]+:' >/dev/null ||
209209
patch_format=mbox
210210
fi
211211
} < "$1" || clean_abort
@@ -561,7 +561,7 @@ do
561561
stop_here $this
562562

563563
# skip pine's internal folder data
564-
grep '^Author: Mail System Internal Data$' \
564+
sane_grep '^Author: Mail System Internal Data$' \
565565
<"$dotest"/info >/dev/null &&
566566
go_next && continue
567567

git-bisect.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ bisect_run () {
393393

394394
cat "$GIT_DIR/BISECT_RUN"
395395

396-
if grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
396+
if sane_grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
397397
> /dev/null; then
398398
echo >&2 "bisect run cannot continue any more"
399399
exit $res
@@ -405,7 +405,7 @@ bisect_run () {
405405
exit $res
406406
fi
407407

408-
if grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then
408+
if sane_grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then
409409
echo "bisect run success"
410410
exit 0;
411411
fi

git-filter-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ if [ "$filter_tag_name" ]; then
457457
git mktag) ||
458458
die "Could not create new tag object for $ref"
459459
if git cat-file tag "$ref" | \
460-
grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
460+
sane_grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
461461
then
462462
warn "gpg signature stripped from tag object $sha1t"
463463
fi

git-instaweb.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ resolve_full_httpd () {
4141
case "$httpd" in
4242
*apache2*|*lighttpd*)
4343
# ensure that the apache2/lighttpd command ends with "-f"
44-
if ! echo "$httpd" | grep -- '-f *$' >/dev/null 2>&1
44+
if ! echo "$httpd" | sane_grep -- '-f *$' >/dev/null 2>&1
4545
then
4646
httpd="$httpd -f"
4747
fi
@@ -302,8 +302,8 @@ EOF
302302

303303
# check to see if Dennis Stosberg's mod_perl compatibility patch
304304
# (<[email protected]>) has been applied
305-
if test -f "$module_path/mod_perl.so" && grep 'MOD_PERL' \
306-
"$GIT_DIR/gitweb/gitweb.cgi" >/dev/null
305+
if test -f "$module_path/mod_perl.so" &&
306+
sane_grep 'MOD_PERL' "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null
307307
then
308308
# favor mod_perl if available
309309
cat >> "$conf" <<EOF
@@ -321,7 +321,7 @@ EOF
321321
# plain-old CGI
322322
resolve_full_httpd
323323
list_mods=$(echo "$full_httpd" | sed "s/-f$/-l/")
324-
$list_mods | grep 'mod_cgi\.c' >/dev/null 2>&1 || \
324+
$list_mods | sane_grep 'mod_cgi\.c' >/dev/null 2>&1 || \
325325
echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
326326
cat >> "$conf" <<EOF
327327
AddHandler cgi-script .cgi

git-mergetool--lib.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,14 @@ guess_merge_tool () {
325325
fi
326326
tools="$tools gvimdiff diffuse ecmerge araxis"
327327
fi
328-
if echo "${VISUAL:-$EDITOR}" | grep emacs > /dev/null 2>&1; then
329-
# $EDITOR is emacs so add emerge as a candidate
330-
tools="$tools emerge vimdiff"
331-
elif echo "${VISUAL:-$EDITOR}" | grep vim > /dev/null 2>&1; then
332-
# $EDITOR is vim so add vimdiff as a candidate
328+
case "${VISUAL:-$EDITOR}" in
329+
*vim*)
333330
tools="$tools vimdiff emerge"
334-
else
331+
;;
332+
*)
335333
tools="$tools emerge vimdiff"
336-
fi
334+
;;
335+
esac
337336
echo >&2 "merge tool candidates: $tools"
338337

339338
# Loop over each candidate and stop when a valid merge tool is found.

git-rebase--interactive.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ mark_action_done () {
106106
sed -e 1q < "$TODO" >> "$DONE"
107107
sed -e 1d < "$TODO" >> "$TODO".new
108108
mv -f "$TODO".new "$TODO"
109-
count=$(grep -c '^[^#]' < "$DONE")
110-
total=$(($count+$(grep -c '^[^#]' < "$TODO")))
109+
count=$(sane_grep -c '^[^#]' < "$DONE")
110+
total=$(($count+$(sane_grep -c '^[^#]' < "$TODO")))
111111
if test "$last_count" != "$count"
112112
then
113113
last_count=$count
@@ -147,7 +147,7 @@ die_abort () {
147147
}
148148

149149
has_action () {
150-
grep '^[^#]' "$1" >/dev/null
150+
sane_grep '^[^#]' "$1" >/dev/null
151151
}
152152

153153
pick_one () {
@@ -736,15 +736,15 @@ first and then run 'git rebase --continue' again."
736736
git rev-list $REVISIONS |
737737
while read rev
738738
do
739-
if test -f "$REWRITTEN"/$rev -a "$(grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
739+
if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
740740
then
741741
# Use -f2 because if rev-list is telling us this commit is
742742
# not worthwhile, we don't want to track its multiple heads,
743743
# just the history of its first-parent for others that will
744744
# be rebasing on top of it
745745
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
746746
short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
747-
grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
747+
sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
748748
rm "$REWRITTEN"/$rev
749749
fi
750750
done

git-rebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ orig_head=$branch
467467
mb=$(git merge-base "$onto" "$branch")
468468
if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
469469
# linear history?
470-
! (git rev-list --parents "$onto".."$branch" | grep " .* ") > /dev/null
470+
! (git rev-list --parents "$onto".."$branch" | sane_grep " .* ") > /dev/null
471471
then
472472
if test -z "$force_rebase"
473473
then

git-sh-setup.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ git_editor() {
114114
eval "${GIT_EDITOR:=vi}" '"$@"'
115115
}
116116
117+
sane_grep () {
118+
GREP_OPTIONS= LC_ALL=C grep "$@"
119+
}
120+
121+
sane_egrep () {
122+
GREP_OPTIONS= LC_ALL=C egrep "$@"
123+
}
124+
117125
is_bare_repository () {
118126
git rev-parse --is-bare-repository
119127
}

git-submodule.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ resolve_relative_url ()
5757
#
5858
module_list()
5959
{
60-
git ls-files --error-unmatch --stage -- "$@" | grep '^160000 '
60+
git ls-files --error-unmatch --stage -- "$@" | sane_grep '^160000 '
6161
}
6262

6363
#
@@ -567,7 +567,7 @@ cmd_summary() {
567567
cd_to_toplevel
568568
# Get modified modules cared by user
569569
modules=$(git $diff_cmd $cached --raw $head -- "$@" |
570-
egrep '^:([0-7]* )?160000' |
570+
sane_egrep '^:([0-7]* )?160000' |
571571
while read mod_src mod_dst sha1_src sha1_dst status name
572572
do
573573
# Always show modules deleted or type-changed (blob<->module)
@@ -581,7 +581,7 @@ cmd_summary() {
581581
test -z "$modules" && return
582582

583583
git $diff_cmd $cached --raw $head -- $modules |
584-
egrep '^:([0-7]* )?160000' |
584+
sane_egrep '^:([0-7]* )?160000' |
585585
cut -c2- |
586586
while read mod_src mod_dst sha1_src sha1_dst status name
587587
do

0 commit comments

Comments
 (0)