If the user has exported the GREP_OPTIONS environment variable, the output
from "grep" and "egrep" in scripted Porcelains may be different from what
they expect. For example, we may want to count number of matching lines,
by "grep" piped to "wc -l", and GREP_OPTIONS=-C3 will break such use.
The approach taken by this change to address this issue is to protect only
our own use of grep/egrep. Because we do not unset it at the beginning of
our scripts, hook scripts run from the scripted Porcelains are exposed to
the same insanity this environment variable causes when grep/egrep is used
to implement logic (e.g. "grep | wc -l"), and it is entirely up to the
hook scripts to protect themselves.
On the other hand, applypatch-msg hook may want to show offending words in
the proposed commit log message using grep to the end user, and the user
might want to set GREP_OPTIONS=--color to paint the match more visibly.
The approach to protect only our own use without unsetting the environment
variable globally will allow this use case.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
raw | patch | inline | side by side (parent: 7b10422 )
# and see if it looks like that they all begin with the
# header field names...
sed -n -e '/^$/q' -e '/^[ ]/d' -e p "$1" |
# and see if it looks like that they all begin with the
# header field names...
sed -n -e '/^$/q' -e '/^[ ]/d' -e p "$1" |
- LC_ALL=C egrep -v '^[!-9;-~]+:' >/dev/null ||
+ sane_ egrep -v '^[!-9;-~]+:' >/dev/null ||
patch_format=mbox
fi
} < "$1" || clean_abort
patch_format=mbox
fi
} < "$1" || clean_abort
stop_here $this
# skip pine's internal folder data
stop_here $this
# skip pine's internal folder data
- grep '^Author: Mail System Internal Data$' \
+ sane_ grep '^Author: Mail System Internal Data$' \
<"$dotest"/info >/dev/null &&
go_next && continue
<"$dotest"/info >/dev/null &&
go_next && continue
cat "$GIT_DIR/BISECT_RUN"
cat "$GIT_DIR/BISECT_RUN"
- if grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
+ if sane_ grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
> /dev/null; then
echo >&2 "bisect run cannot continue any more"
exit $res
> /dev/null; then
echo >&2 "bisect run cannot continue any more"
exit $res
- if grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then
+ if sane_ grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then
echo "bisect run success"
exit 0;
fi
echo "bisect run success"
exit 0;
fi
git mktag) ||
die "Could not create new tag object for $ref"
if git cat-file tag "$ref" | \
git mktag) ||
die "Could not create new tag object for $ref"
if git cat-file tag "$ref" | \
- grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
+ sane_ grep '^-----BEGIN PGP SIGNATURE-----' >/dev/null 2>&1
then
warn "gpg signature stripped from tag object $sha1t"
fi
then
warn "gpg signature stripped from tag object $sha1t"
fi
case "$httpd" in
*apache2*|*lighttpd*)
# ensure that the apache2/lighttpd command ends with "-f"
case "$httpd" in
*apache2*|*lighttpd*)
# ensure that the apache2/lighttpd command ends with "-f"
- if ! echo "$httpd" | grep -- '-f *$' >/dev/null 2>&1
+ if ! echo "$httpd" | sane_ grep -- '-f *$' >/dev/null 2>&1
then
httpd="$httpd -f"
fi
then
httpd="$httpd -f"
fi
# check to see if Dennis Stosberg's mod_perl compatibility patch
# (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
# check to see if Dennis Stosberg's mod_perl compatibility patch
# (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
- if test -f "$module_path/mod_perl.so" && grep 'MOD_PERL' \
- "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null
+ if test -f "$module_path/mod_perl.so" &&
+ sane_grep 'MOD_PERL' "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null
then
# favor mod_perl if available
cat >> "$conf" <<EOF
then
# favor mod_perl if available
cat >> "$conf" <<EOF
# plain-old CGI
resolve_full_httpd
list_mods=$(echo "$full_httpd" | sed "s/-f$/-l/")
# plain-old CGI
resolve_full_httpd
list_mods=$(echo "$full_httpd" | sed "s/-f$/-l/")
- $list_mods | grep 'mod_cgi\.c' >/dev/null 2>&1 || \
+ $list_mods | sane_ grep 'mod_cgi\.c' >/dev/null 2>&1 || \
echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
cat >> "$conf" <<EOF
AddHandler cgi-script .cgi
echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
cat >> "$conf" <<EOF
AddHandler cgi-script .cgi
sed -e 1q < "$TODO" >> "$DONE"
sed -e 1d < "$TODO" >> "$TODO".new
mv -f "$TODO".new "$TODO"
sed -e 1q < "$TODO" >> "$DONE"
sed -e 1d < "$TODO" >> "$TODO".new
mv -f "$TODO".new "$TODO"
- count=$(grep -c '^[^#]' < "$DONE")
- total=$(($count+$(grep -c '^[^#]' < "$TODO")))
+ count=$(sane_ grep -c '^[^#]' < "$DONE")
+ total=$(($count+$(sane_ grep -c '^[^#]' < "$TODO")))
if test "$last_count" != "$count"
then
last_count=$count
if test "$last_count" != "$count"
then
last_count=$count
- grep '^[^#]' "$1" >/dev/null
+ sane_ grep '^[^#]' "$1" >/dev/null
git rev-list $REVISIONS |
while read rev
do
git rev-list $REVISIONS |
while read rev
do
- if test -f "$REWRITTEN"/$rev -a "$(grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
+ if test -f "$REWRITTEN"/$rev -a "$(sane_ grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
then
# Use -f2 because if rev-list is telling us this commit is
# not worthwhile, we don't want to track its multiple heads,
then
# Use -f2 because if rev-list is telling us this commit is
# not worthwhile, we don't want to track its multiple heads,
# be rebasing on top of it
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
# be rebasing on top of it
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
- grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
+ sane_ grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
rm "$REWRITTEN"/$rev
fi
done
rm "$REWRITTEN"/$rev
fi
done
mb=$(git merge-base "$onto" "$branch")
if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
# linear history?
mb=$(git merge-base "$onto" "$branch")
if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
# linear history?
- ! (git rev-list --parents "$onto".."$branch" | grep " .* ") > /dev/null
+ ! (git rev-list --parents "$onto".."$branch" | sane_ grep " .* ") > /dev/null
then
if test -z "$force_rebase"
then
then
if test -z "$force_rebase"
then
eval "${GIT_EDITOR:=vi}" '"$@"'
}
eval "${GIT_EDITOR:=vi}" '"$@"'
}
+sane_grep () {
+ GREP_OPTIONS= LC_ALL=C grep "$@"
+}
+
+sane_egrep () {
+ GREP_OPTIONS= LC_ALL=C egrep "$@"
+}
+
is_bare_repository () {
git rev-parse --is-bare-repository
}
is_bare_repository () {
git rev-parse --is-bare-repository
}
- git ls-files --error-unmatch --stage -- "$@" | grep '^160000 '
+ git ls-files --error-unmatch --stage -- "$@" | sane_ grep '^160000 '
cd_to_toplevel
# Get modified modules cared by user
modules=$(git $diff_cmd $cached --raw $head -- "$@" |
cd_to_toplevel
# Get modified modules cared by user
modules=$(git $diff_cmd $cached --raw $head -- "$@" |
- egrep '^:([0-7]* )?160000' |
+ sane_ egrep '^:([0-7]* )?160000' |
while read mod_src mod_dst sha1_src sha1_dst status name
do
# Always show modules deleted or type-changed (blob<->module)
while read mod_src mod_dst sha1_src sha1_dst status name
do
# Always show modules deleted or type-changed (blob<->module)
test -z "$modules" && return
git $diff_cmd $cached --raw $head -- $modules |
test -z "$modules" && return
git $diff_cmd $cached --raw $head -- $modules |
- egrep '^:([0-7]* )?160000' |
+ sane_ egrep '^:([0-7]* )?160000' |
cut -c2- |
while read mod_src mod_dst sha1_src sha1_dst status name
do
cut -c2- |
while read mod_src mod_dst sha1_src sha1_dst status name
do