Skip to content

Commit

Permalink
Merge branch 'jk/portable'
Browse files Browse the repository at this point in the history
* jk/portable:
  t6000lib: re-fix tr portability
  t7505: use SHELL_PATH in hook
  t9112: add missing #!/bin/sh header
  filter-branch: use $SHELL_PATH instead of 'sh'
  filter-branch: don't use xargs -0
  add NO_EXTERNAL_GREP build option
  t6000lib: tr portability fix
  t4020: don't use grep -a
  add test_cmp function for test scripts
  remove use of "tail -n 1" and "tail -1"
  grep portability fix: don't use "-e" or "-q"
  more tr portability test script fixes
  t0050: perl portability fix
  tr portability fixes
  • Loading branch information
gitster committed Mar 15, 2008
2 parents 37bd6c5 + aab0abf commit 1f17868
Show file tree
Hide file tree
Showing 70 changed files with 247 additions and 202 deletions.
7 changes: 7 additions & 0 deletions Makefile
Expand Up @@ -148,6 +148,9 @@ all::
# is a simplified version of the merge sort used in glibc. This is
# recommended if Git triggers O(n^2) behavior in your platform's qsort().
#
# Define NO_EXTERNAL_GREP if you don't want "git grep" to ever call
# your external grep (e.g., if your system lacks grep, if its grep is
# broken, or spawning external process is slower than built-in grep git has).

GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
@$(SHELL_PATH) ./GIT-VERSION-GEN
Expand Down Expand Up @@ -760,6 +763,9 @@ endif
ifdef DIR_HAS_BSD_GROUP_SEMANTICS
COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS
endif
ifdef NO_EXTERNAL_GREP
BASIC_CFLAGS += -DNO_EXTERNAL_GREP
endif

ifeq ($(TCLTK_PATH),)
NO_TCLTK=NoThanks
Expand Down Expand Up @@ -867,6 +873,7 @@ common-cmds.h: $(wildcard Documentation/git-*.txt)
$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
$(QUIET_GEN)$(RM) $@ $@+ && \
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
-e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
Expand Down
12 changes: 10 additions & 2 deletions builtin-grep.c
Expand Up @@ -12,6 +12,14 @@
#include "builtin.h"
#include "grep.h"

#ifndef NO_EXTERNAL_GREP
#ifdef __unix__
#define NO_EXTERNAL_GREP 0
#else
#define NO_EXTERNAL_GREP 1
#endif
#endif

/*
* git grep pathspecs are somewhat different from diff-tree pathspecs;
* pathname wildcards are allowed.
Expand Down Expand Up @@ -153,7 +161,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
return i;
}

#ifdef __unix__
#if !NO_EXTERNAL_GREP
static int exec_grep(int argc, const char **argv)
{
pid_t pid;
Expand Down Expand Up @@ -372,7 +380,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
int nr;
read_cache();

#ifdef __unix__
#if !NO_EXTERNAL_GREP
/*
* Use the external "grep" command for the case where
* we grep through the checked-out files. It tends to
Expand Down
2 changes: 1 addition & 1 deletion git-am.sh
Expand Up @@ -357,7 +357,7 @@ do
LAST_SIGNED_OFF_BY=`
sed -ne '/^Signed-off-by: /p' \
"$dotest/msg-clean" |
tail -n 1
sed -ne '$p'
`
ADD_SIGNOFF=`
test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || {
Expand Down
4 changes: 2 additions & 2 deletions git-bisect.sh
Expand Up @@ -293,14 +293,14 @@ bisect_next() {
bisect_next_check good

skip=$(git for-each-ref --format='%(objectname)' \
"refs/bisect/skip-*" | tr '[\012]' ' ') || exit
"refs/bisect/skip-*" | tr '\012' ' ') || exit

BISECT_OPT=''
test -n "$skip" && BISECT_OPT='--bisect-all'

bad=$(git rev-parse --verify refs/bisect/bad) &&
good=$(git for-each-ref --format='^%(objectname)' \
"refs/bisect/good-*" | tr '[\012]' ' ') &&
"refs/bisect/good-*" | tr '\012' ' ') &&
eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
eval="$eval $(cat "$GIT_DIR/BISECT_NAMES")" &&
eval=$(filter_skipped "$eval" "$skip") &&
Expand Down
8 changes: 4 additions & 4 deletions git-filter-branch.sh
Expand Up @@ -58,8 +58,8 @@ eval "$functions"
# "author" or "committer

set_ident () {
lid="$(echo "$1" | tr "A-Z" "a-z")"
uid="$(echo "$1" | tr "a-z" "A-Z")"
lid="$(echo "$1" | tr "[A-Z]" "[a-z]")"
uid="$(echo "$1" | tr "[a-z]" "[A-Z]")"
pick_id_script='
/^'$lid' /{
s/'\''/'\''\\'\'\''/g
Expand Down Expand Up @@ -281,7 +281,7 @@ while read commit parents; do
die "Could not checkout the index"
# files that $commit removed are now still in the working tree;
# remove them, else they would be added again
git ls-files -z --others | xargs -0 rm -f
git clean -q -f -x
eval "$filter_tree" < /dev/null ||
die "tree filter failed: $filter_tree"

Expand Down Expand Up @@ -309,7 +309,7 @@ while read commit parents; do
sed -e '1,/^$/d' <../commit | \
eval "$filter_msg" > ../message ||
die "msg filter failed: $filter_msg"
sh -c "$filter_commit" "git commit-tree" \
@SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
$(git write-tree) $parentstr < ../message > ../map/$commit
done <../revs

Expand Down
8 changes: 4 additions & 4 deletions git-rebase--interactive.sh
Expand Up @@ -78,8 +78,8 @@ mark_action_done () {
sed -e 1q < "$TODO" >> "$DONE"
sed -e 1d < "$TODO" >> "$TODO".new
mv -f "$TODO".new "$TODO"
count=$(($(grep -ve '^$' -e '^#' < "$DONE" | wc -l)))
total=$(($count+$(grep -ve '^$' -e '^#' < "$TODO" | wc -l)))
count=$(grep -c '^[^#]' < "$DONE")
total=$(($count+$(grep -c '^[^#]' < "$TODO")))
if test "$last_count" != "$count"
then
last_count=$count
Expand Down Expand Up @@ -110,7 +110,7 @@ die_abort () {
}

has_action () {
grep -vqe '^$' -e '^#' "$1"
grep '^[^#]' "$1" >/dev/null
}

pick_one () {
Expand Down Expand Up @@ -218,7 +218,7 @@ nth_string () {
make_squash_message () {
if test -f "$SQUASH_MSG"; then
COUNT=$(($(sed -n "s/^# This is [^0-9]*\([1-9][0-9]*\).*/\1/p" \
< "$SQUASH_MSG" | tail -n 1)+1))
< "$SQUASH_MSG" | sed -ne '$p')+1))
echo "# This is a combination of $COUNT commits."
sed -e 1d -e '2,/^./{
/^$/d
Expand Down
6 changes: 3 additions & 3 deletions git-submodule.sh
Expand Up @@ -232,7 +232,7 @@ cmd_init()
shift
done

git ls-files --stage -- "$@" | grep -e '^160000 ' |
git ls-files --stage -- "$@" | grep '^160000 ' |
while read mode sha1 stage path
do
# Skip already registered paths
Expand Down Expand Up @@ -286,7 +286,7 @@ cmd_update()
shift
done

git ls-files --stage -- "$@" | grep -e '^160000 ' |
git ls-files --stage -- "$@" | grep '^160000 ' |
while read mode sha1 stage path
do
name=$(module_name "$path") || exit
Expand Down Expand Up @@ -537,7 +537,7 @@ cmd_status()
shift
done

git ls-files --stage -- "$@" | grep -e '^160000 ' |
git ls-files --stage -- "$@" | grep '^160000 ' |
while read mode sha1 stage path
do
name=$(module_name "$path") || exit
Expand Down
4 changes: 2 additions & 2 deletions t/diff-lib.sh
Expand Up @@ -21,8 +21,8 @@ compare_diff_raw_z () {
# Also we do not check SHA1 hash generation in this test, which
# is a job for t0000-basic.sh

tr '\000' '\012' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
tr '\000' '\012' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
perl -pe 'y/\000/\012/' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
perl -pe 'y/\000/\012/' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
git diff .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
}

Expand Down
2 changes: 1 addition & 1 deletion t/t0003-attributes.sh
Expand Up @@ -11,7 +11,7 @@ attr_check () {

git check-attr test -- "$path" >actual &&
echo "$path: test: $2" >expect &&
diff -u expect actual
test_cmp expect actual

}

Expand Down
2 changes: 1 addition & 1 deletion t/t0020-crlf.sh
Expand Up @@ -5,7 +5,7 @@ test_description='CRLF conversion'
. ./test-lib.sh

q_to_nul () {
tr Q '\000'
perl -pe 'y/Q/\000/'
}

q_to_cr () {
Expand Down
2 changes: 1 addition & 1 deletion t/t0022-crlf-rename.sh
Expand Up @@ -26,7 +26,7 @@ test_expect_success 'diff -M' '
git diff-tree -M -r --name-status HEAD^ HEAD |
sed -e "s/R[0-9]*/RNUM/" >actual &&
echo "RNUM sample elpmas" >expect &&
diff -u expect actual
test_cmp expect actual
'

Expand Down
34 changes: 17 additions & 17 deletions t/t0030-stripspace.sh
Expand Up @@ -245,12 +245,12 @@ test_expect_success \

test_expect_success \
'text plus spaces without newline at end should not show spaces' '
! (printf "$ttt$sss" | git stripspace | grep -q " ") &&
! (printf "$ttt$ttt$sss" | git stripspace | grep -q " ") &&
! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep -q " ") &&
! (printf "$ttt$sss$sss" | git stripspace | grep -q " ") &&
! (printf "$ttt$ttt$sss$sss" | git stripspace | grep -q " ") &&
! (printf "$ttt$sss$sss$sss" | git stripspace | grep -q " ")
! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
'

test_expect_success \
Expand Down Expand Up @@ -282,12 +282,12 @@ test_expect_success \

test_expect_success \
'text plus spaces at end should not show spaces' '
! (echo "$ttt$sss" | git stripspace | grep -q " ") &&
! (echo "$ttt$ttt$sss" | git stripspace | grep -q " ") &&
! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep -q " ") &&
! (echo "$ttt$sss$sss" | git stripspace | grep -q " ") &&
! (echo "$ttt$ttt$sss$sss" | git stripspace | grep -q " ") &&
! (echo "$ttt$sss$sss$sss" | git stripspace | grep -q " ")
! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
'

test_expect_success \
Expand Down Expand Up @@ -341,11 +341,11 @@ test_expect_success \

test_expect_success \
'spaces without newline at end should not show spaces' '
! (printf "" | git stripspace | grep -q " ") &&
! (printf "$sss" | git stripspace | grep -q " ") &&
! (printf "$sss$sss" | git stripspace | grep -q " ") &&
! (printf "$sss$sss$sss" | git stripspace | grep -q " ") &&
! (printf "$sss$sss$sss$sss" | git stripspace | grep -q " ")
! (printf "" | git stripspace | grep " " >/dev/null) &&
! (printf "$sss" | git stripspace | grep " " >/dev/null) &&
! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) &&
! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) &&
! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null)
'

test_expect_success \
Expand Down
4 changes: 2 additions & 2 deletions t/t0050-filesystem.sh
Expand Up @@ -4,8 +4,8 @@ test_description='Various filesystem issues'

. ./test-lib.sh

auml=`perl -CO -e 'print pack("U",0x00E4)'`
aumlcdiar=`perl -CO -e 'print pack("U",0x0061).pack("U",0x0308)'`
auml=`printf '\xc3\xa4'`
aumlcdiar=`printf '\x61\xcc\x88'`

test_expect_success 'see if we expect ' '
Expand Down
2 changes: 1 addition & 1 deletion t/t1005-read-tree-reset.sh
Expand Up @@ -24,7 +24,7 @@ test_expect_success 'setup' '
test_expect_success 'reset should work' '
git read-tree -u --reset HEAD^ &&
git ls-files >actual &&
diff -u expect actual
test_cmp expect actual
'

test_done
4 changes: 2 additions & 2 deletions t/t1300-repo-config.sh
Expand Up @@ -657,12 +657,12 @@ Qsection.sub=section.val4
Qsection.sub=section.val5Q
EOF

git config --null --list | tr '\000' 'Q' > result
git config --null --list | perl -pe 'y/\000/Q/' > result
echo >>result

test_expect_success '--null --list' 'cmp result expect'

git config --null --get-regexp 'val[0-9]' | tr '\000' 'Q' > result
git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result
echo >>result

test_expect_success '--null --get-regexp' 'cmp result expect'
Expand Down
2 changes: 1 addition & 1 deletion t/t2200-add-update.sh
Expand Up @@ -62,7 +62,7 @@ test_expect_success 'cache tree has not been corrupted' '
sed -e "s/ 0 / /" >expect &&
git ls-tree -r $(git write-tree) |
sed -e "s/ blob / /" >current &&
diff -u expect current
test_cmp expect current
'

Expand Down
2 changes: 1 addition & 1 deletion t/t3001-ls-files-others-exclude.sh
Expand Up @@ -97,7 +97,7 @@ cat > expect << EOF
EOF

test_expect_success 'git-status honours core.excludesfile' \
'diff -u expect output'
'test_cmp expect output'

test_expect_success 'trailing slash in exclude allows directory match(1)' '
Expand Down
4 changes: 2 additions & 2 deletions t/t3050-subprojects-fetch.sh
Expand Up @@ -26,7 +26,7 @@ test_expect_success clone '
cd cloned &&
(git rev-parse HEAD; git ls-files -s) >../actual
) &&
diff -u expected actual
test_cmp expected actual
'

test_expect_success advance '
Expand All @@ -46,7 +46,7 @@ test_expect_success fetch '
git pull &&
(git rev-parse HEAD; git ls-files -s) >../actual
) &&
diff -u expected actual
test_cmp expected actual
'

test_done
2 changes: 1 addition & 1 deletion t/t3060-ls-files-with-tree.sh
Expand Up @@ -66,6 +66,6 @@ test_expect_success 'git -ls-files --with-tree should succeed from subdir' '
cd ..
test_expect_success \
'git -ls-files --with-tree should add entries from named tree.' \
'diff -u expected output'
'test_cmp expected output'

test_done
6 changes: 3 additions & 3 deletions t/t3201-branch-contains.sh
Expand Up @@ -31,7 +31,7 @@ test_expect_success 'branch --contains=master' '
{
echo " master" && echo "* side"
} >expect &&
diff -u expect actual
test_cmp expect actual
'

Expand All @@ -41,7 +41,7 @@ test_expect_success 'branch --contains master' '
{
echo " master" && echo "* side"
} >expect &&
diff -u expect actual
test_cmp expect actual
'

Expand All @@ -51,7 +51,7 @@ test_expect_success 'branch --contains=side' '
{
echo "* side"
} >expect &&
diff -u expect actual
test_cmp expect actual
'

Expand Down
6 changes: 3 additions & 3 deletions t/t3300-funny-names.sh
Expand Up @@ -54,7 +54,7 @@ echo 'just space
no-funny
tabs ," (dq) and spaces' >expected
test_expect_success 'git ls-files -z with-funny' \
'git ls-files -z | tr \\000 \\012 >current &&
'git ls-files -z | perl -pe y/\\000/\\012/ >current &&
git diff expected current'

t1=`git write-tree`
Expand Down Expand Up @@ -83,11 +83,11 @@ test_expect_success 'git diff-tree with-funny' \
echo 'A
tabs ," (dq) and spaces' >expected
test_expect_success 'git diff-index -z with-funny' \
'git diff-index -z --name-status $t0 | tr \\000 \\012 >current &&
'git diff-index -z --name-status $t0 | perl -pe y/\\000/\\012/ >current &&
git diff expected current'

test_expect_success 'git diff-tree -z with-funny' \
'git diff-tree -z --name-status $t0 $t1 | tr \\000 \\012 >current &&
'git diff-tree -z --name-status $t0 $t1 | perl -pe y/\\000/\\012/ >current &&
git diff expected current'

cat > expected <<\EOF
Expand Down

0 comments on commit 1f17868

Please sign in to comment.