Skip to content

Commit ad7ace7

Browse files
committed
Merge branch 'rs/work-around-grep-opt-insanity'
* rs/work-around-grep-opt-insanity: Protect scripted Porcelains from GREP_OPTIONS insanity mergetool--lib: simplify guess_merge_tool() Conflicts: git-instaweb.sh
2 parents b073b7a + e1622bf commit ad7ace7

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
@@ -392,7 +392,7 @@ bisect_run () {
392392

393393
cat "$GIT_DIR/BISECT_RUN"
394394

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

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

git-filter-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ if [ "$filter_tag_name" ]; then
473473
git mktag) ||
474474
die "Could not create new tag object for $ref"
475475
if git cat-file tag "$ref" | \
476-
grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
476+
sane_grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
477477
then
478478
warn "gpg signature stripped from tag object $sha1t"
479479
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
if test -f "$module_path/mod_cgi.so"
326326
then
327327
echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"

git-mergetool--lib.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,14 @@ guess_merge_tool () {
338338
fi
339339
tools="$tools gvimdiff diffuse ecmerge p4merge araxis"
340340
fi
341-
if echo "${VISUAL:-$EDITOR}" | grep emacs > /dev/null 2>&1; then
342-
# $EDITOR is emacs so add emerge as a candidate
343-
tools="$tools emerge vimdiff"
344-
elif echo "${VISUAL:-$EDITOR}" | grep vim > /dev/null 2>&1; then
345-
# $EDITOR is vim so add vimdiff as a candidate
341+
case "${VISUAL:-$EDITOR}" in
342+
*vim*)
346343
tools="$tools vimdiff emerge"
347-
else
344+
;;
345+
*)
348346
tools="$tools emerge vimdiff"
349-
fi
347+
;;
348+
esac
350349
echo >&2 "merge tool candidates: $tools"
351350

352351
# 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 () {
@@ -744,15 +744,15 @@ first and then run 'git rebase --continue' again."
744744
git rev-list $REVISIONS |
745745
while read rev
746746
do
747-
if test -f "$REWRITTEN"/$rev -a "$(grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
747+
if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
748748
then
749749
# Use -f2 because if rev-list is telling us this commit is
750750
# not worthwhile, we don't want to track its multiple heads,
751751
# just the history of its first-parent for others that will
752752
# be rebasing on top of it
753753
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
754754
short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
755-
grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
755+
sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
756756
rm "$REWRITTEN"/$rev
757757
fi
758758
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
@@ -107,6 +107,14 @@ git_editor() {
107107
eval "$GIT_EDITOR" '"$@"'
108108
}
109109
110+
sane_grep () {
111+
GREP_OPTIONS= LC_ALL=C grep "$@"
112+
}
113+
114+
sane_egrep () {
115+
GREP_OPTIONS= LC_ALL=C egrep "$@"
116+
}
117+
110118
is_bare_repository () {
111119
git rev-parse --is-bare-repository
112120
}

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
#
@@ -572,7 +572,7 @@ cmd_summary() {
572572
cd_to_toplevel
573573
# Get modified modules cared by user
574574
modules=$(git $diff_cmd $cached --raw $head -- "$@" |
575-
egrep '^:([0-7]* )?160000' |
575+
sane_egrep '^:([0-7]* )?160000' |
576576
while read mod_src mod_dst sha1_src sha1_dst status name
577577
do
578578
# Always show modules deleted or type-changed (blob<->module)
@@ -586,7 +586,7 @@ cmd_summary() {
586586
test -z "$modules" && return
587587

588588
git $diff_cmd $cached --raw $head -- $modules |
589-
egrep '^:([0-7]* )?160000' |
589+
sane_egrep '^:([0-7]* )?160000' |
590590
cut -c2- |
591591
while read mod_src mod_dst sha1_src sha1_dst status name
592592
do

0 commit comments

Comments
 (0)