Skip to content

Commit

Permalink
Merge branch 'bb/sh-scripts-cleanup'
Browse files Browse the repository at this point in the history
Shell scripts clean-up.

* bb/sh-scripts-cleanup: (22 commits)
  git-quiltimport: avoid an unnecessary subshell
  contrib/coverage-diff: avoid redundant pipelines
  t/t9*: merge "grep | sed" pipelines
  t/t8*: merge "grep | sed" pipelines
  t/t5*: merge a "grep | sed" pipeline
  t/t4*: merge a "grep | sed" pipeline
  t/t3*: merge a "grep | awk" pipeline
  t/t1*: merge a "grep | sed" pipeline
  t/t9*: avoid redundant uses of cat
  t/t8*: avoid redundant use of cat
  t/t7*: avoid redundant use of cat
  t/t6*: avoid redundant uses of cat
  t/t5*: avoid redundant uses of cat
  t/t4*: avoid redundant uses of cat
  t/t3*: avoid redundant uses of cat
  t/t1*: avoid redundant uses of cat
  t/t0*: avoid redundant uses of cat
  t/perf: avoid redundant use of cat
  t/annotate-tests.sh: avoid redundant use of cat
  t/lib-cvs.sh: avoid redundant use of cat
  ...
  • Loading branch information
gitster committed Mar 25, 2024
2 parents 46d8bf3 + c2a7536 commit a7f0fcb
Show file tree
Hide file tree
Showing 37 changed files with 85 additions and 97 deletions.
4 changes: 2 additions & 2 deletions Documentation/howto/update-hook-example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ info "The user is: '$username'"

if test -f "$allowed_users_file"
then
rc=$(cat $allowed_users_file | grep -v '^#' | grep -v '^$' |
rc=$(grep -Ev '^(#|$)' $allowed_users_file |
while read heads user_patterns
do
# does this rule apply to us?
Expand Down Expand Up @@ -138,7 +138,7 @@ info "'$groups'"

if test -f "$allowed_groups_file"
then
rc=$(cat $allowed_groups_file | grep -v '^#' | grep -v '^$' |
rc=$(grep -Ev '^(#|$)' $allowed_groups_file |
while read heads group_patterns
do
# does this rule apply to us?
Expand Down
9 changes: 2 additions & 7 deletions contrib/coverage-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ do
sort >uncovered_lines.txt

comm -12 uncovered_lines.txt new_lines.txt |
sed -e 's/$/\)/' |
sed -e 's/^/ /' >uncovered_new_lines.txt
sed -e 's/$/\)/' -e 's/^/ /' >uncovered_new_lines.txt

grep -q '[^[:space:]]' <uncovered_new_lines.txt &&
echo $file >>coverage-data.txt &&
Expand All @@ -91,11 +90,7 @@ cat coverage-data.txt

echo "Commits introducing uncovered code:"

commit_list=$(cat coverage-data.txt |
grep -E '^[0-9a-f]{7,} ' |
awk '{print $1;}' |
sort |
uniq)
commit_list=$(awk '/^[0-9a-f]{7,}/ { print $1 }' coverage-data.txt | sort -u)

(
for commit in $commit_list
Expand Down
2 changes: 1 addition & 1 deletion contrib/subtree/t/t7900-subtree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test_create_pre2_32_repo () {
git -C "$1" log -1 --format=%B HEAD^2 >msg &&
test_commit -C "$1-sub" --annotate sub2 &&
git clone --no-local "$1" "$1-clone" &&
new_commit=$(cat msg | sed -e "s/$commit/$tag/" | git -C "$1-clone" commit-tree HEAD^2^{tree}) &&
new_commit=$(sed -e "s/$commit/$tag/" msg | git -C "$1-clone" commit-tree HEAD^2^{tree}) &&
git -C "$1-clone" replace HEAD^2 $new_commit
}

Expand Down
2 changes: 1 addition & 1 deletion git-quiltimport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ do
if [ -z "$dry_run" ] ; then
git apply --index -C1 ${level:+"$level"} "$tmp_patch" &&
tree=$(git write-tree) &&
commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) &&
commit=$( { echo "$SUBJECT"; echo; cat "$tmp_msg"; } | git commit-tree $tree -p $commit) &&
git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4
fi
done 3<"$QUILT_SERIES"
Expand Down
2 changes: 1 addition & 1 deletion t/annotate-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ test_expect_success 'blame -L :funcname with userdiff driver' '
"$(cat file.template)" &&
test_commit --author "B <[email protected]>" \
"change" "$fortran_file" \
"$(cat file.template | sed -e s/ChangeMe/IWasChanged/)" &&
"$(sed -e s/ChangeMe/IWasChanged/ file.template)" &&
check_count -f "$fortran_file" -L:RIGHT A 3 B 1
'

Expand Down
4 changes: 2 additions & 2 deletions t/lib-cvs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ test_cmp_branch_tree () {
find . -type d -name .git -prune -o -type f -print
) | sort >module-git-"$1".list &&
test_cmp module-cvs-"$1".list module-git-"$1".list &&
cat module-cvs-"$1".list | while read f
while read f
do
test_cmp_branch_file "$1" "$f" || return 1
done
done <module-cvs-"$1".list
}
2 changes: 1 addition & 1 deletion t/perf/repos/inflate-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ do
done

git ls-tree -r HEAD >GEN_src_list
nr_src_files=$(cat GEN_src_list | wc -l)
nr_src_files=$(wc -l <GEN_src_list)

src_branch=$(git symbolic-ref --short HEAD)

Expand Down
2 changes: 1 addition & 1 deletion t/t0002-gitfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test_expect_success 'final setup + check rev-parse --git-dir' '

test_expect_success 'check hash-object' '
echo "foo" >bar &&
SHA=$(cat bar | git hash-object -w --stdin) &&
SHA=$(git hash-object -w --stdin <bar) &&
test_path_is_file "$REAL/objects/$(objpath $SHA)"
'

Expand Down
2 changes: 1 addition & 1 deletion t/t0011-hashmap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ test_expect_success 'grow / shrink' '
echo value40 >> expect &&
echo size >> in &&
echo 64 39 >> expect &&
cat in | test-tool hashmap > out &&
test-tool hashmap <in >out &&
test_cmp expect out
'
Expand Down
4 changes: 2 additions & 2 deletions t/t0028-working-tree-encoding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ do
test_when_finished "rm -f crlf.utf${i}.raw lf.utf${i}.raw" &&
test_when_finished "git reset --hard HEAD^" &&
cat lf.utf8.raw | write_utf${i} >lf.utf${i}.raw &&
cat crlf.utf8.raw | write_utf${i} >crlf.utf${i}.raw &&
write_utf${i} <lf.utf8.raw >lf.utf${i}.raw &&
write_utf${i} <crlf.utf8.raw >crlf.utf${i}.raw &&
cp crlf.utf${i}.raw eol.utf${i} &&
cat >expectIndexLF <<-EOF &&
Expand Down
2 changes: 1 addition & 1 deletion t/t0204-gettext-reencode-sanity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ test_expect_success GETTEXT_ISO_LOCALE 'gettext.c: git init UTF-8 -> ISO-8859-1'
printf "Bjó til tóma Git lind" >expect &&
LANGUAGE=is LC_ALL="$is_IS_iso_locale" git init repo >actual &&
test_when_finished "rm -rf repo" &&
grep "^$(cat expect | iconv -f UTF-8 -t ISO8859-1) " actual
grep "^$(iconv -f UTF-8 -t ISO8859-1 <expect) " actual
'

test_done
6 changes: 3 additions & 3 deletions t/t1007-hash-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ test_expect_success 'check that appropriate filter is invoke when --path is used
path0_sha=$(git hash-object --path=file0 file1) &&
test "$file0_sha" = "$path0_sha" &&
test "$file1_sha" = "$path1_sha" &&
path1_sha=$(cat file0 | git hash-object --path=file1 --stdin) &&
path0_sha=$(cat file1 | git hash-object --path=file0 --stdin) &&
path1_sha=$(git hash-object --path=file1 --stdin <file0) &&
path0_sha=$(git hash-object --path=file0 --stdin <file1) &&
test "$file0_sha" = "$path0_sha" &&
test "$file1_sha" = "$path1_sha"
'
Expand Down Expand Up @@ -154,7 +154,7 @@ test_expect_success '--path works in a subdirectory' '
test_expect_success 'check that --no-filters option works' '
nofilters_file1=$(git hash-object --no-filters file1) &&
test "$file0_sha" = "$nofilters_file1" &&
nofilters_file1=$(cat file1 | git hash-object --stdin) &&
nofilters_file1=$(git hash-object --stdin <file1) &&
test "$file0_sha" = "$nofilters_file1"
'

Expand Down
2 changes: 1 addition & 1 deletion t/t1091-sparse-checkout-builtin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ test_expect_success 'check-rules non-cone mode' '
git -C bare sparse-checkout check-rules --no-cone --rules-file ../rules\
>check-rules-file <all-files &&
cat rules | git -C repo sparse-checkout set --no-cone --stdin &&
git -C repo sparse-checkout set --no-cone --stdin <rules &&
git -C repo ls-files -t >out &&
sed -n "/^S /!s/^. //p" out >ls-files &&
Expand Down
2 changes: 1 addition & 1 deletion t/t1509/prepare-chroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ rsync --exclude-from t/t1509/excludes -Ha . "$R$(pwd)"
# env might slip through, see test-lib.sh, unset.*PERL_PATH
sed 's|^PERL_PATH=.*|PERL_PATH=/bin/true|' GIT-BUILD-OPTIONS > "$R$(pwd)/GIT-BUILD-OPTIONS"
for cmd in git $BB;do
ldd $cmd | grep '/' | sed 's,.*\s\(/[^ ]*\).*,\1,' | while read i; do
ldd $cmd | sed -n '/\//s,.*\s\(/[^ ]*\).*,\1,p' | while read i; do
mkdir -p "$R$(dirname $i)"
cp "$i" "$R/$i"
done
Expand Down
2 changes: 1 addition & 1 deletion t/t3200-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ EOF
# ...and that the comments for those sections are also
# preserved.
cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
sed "s/\"source\"/\"dest\"/" config.branch >expect &&
sed -n -e "/Note the lack/,\$p" .git/config >actual &&
test_cmp expect actual
'
Expand Down
8 changes: 4 additions & 4 deletions t/t3321-notes-stripspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ test_expect_success 'add note by specifying "-C", "--no-stripspace" is the defau
${LF}
EOF
cat expect | git hash-object -w --stdin >blob &&
git hash-object -w --stdin <expect >blob &&
git notes add -C $(cat blob) &&
git notes show >actual &&
test_cmp expect actual &&
Expand All @@ -468,7 +468,7 @@ test_expect_success 'reuse note by specifying "-C" and "--stripspace"' '
second-line
EOF
cat data | git hash-object -w --stdin >blob &&
git hash-object -w --stdin <data >blob &&
git notes add --stripspace -C $(cat blob) &&
git notes show >actual &&
test_cmp expect actual
Expand All @@ -492,7 +492,7 @@ test_expect_success 'reuse with "-C" and add note with "-m", "-m" will stripspac
third-line
EOF
cat data | git hash-object -w --stdin >blob &&
git hash-object -w --stdin <data >blob &&
git notes add -C $(cat blob) -m "third-line" &&
git notes show >actual &&
test_cmp expect actual
Expand All @@ -511,7 +511,7 @@ test_expect_success 'add note with "-m" and reuse note with "-C", "-C" will not
second-line
EOF
cat data | git hash-object -w --stdin >blob &&
git hash-object -w --stdin <data >blob &&
git notes add -m "first-line" -C $(cat blob) &&
git notes show >actual &&
test_cmp expect actual
Expand Down
4 changes: 2 additions & 2 deletions t/t3920-crlf-messages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LIB_CRLF_BRANCHES=""
create_crlf_ref () {
branch="$1" &&
cat >.crlf-orig-$branch.txt &&
cat .crlf-orig-$branch.txt | append_cr >.crlf-message-$branch.txt &&
append_cr <.crlf-orig-$branch.txt >.crlf-message-$branch.txt &&
grep 'Subject' .crlf-orig-$branch.txt | tr '\n' ' ' | sed 's/[ ]*$//' | tr -d '\n' >.crlf-subject-$branch.txt &&
grep 'Body' .crlf-orig-$branch.txt | append_cr >.crlf-body-$branch.txt &&
LIB_CRLF_BRANCHES="${LIB_CRLF_BRANCHES} ${branch}" &&
Expand Down Expand Up @@ -97,7 +97,7 @@ test_expect_success 'branch: --verbose works with messages using CRLF' '
git branch -v >tmp &&
# Remove first two columns, and the line for the currently checked out branch
current=$(git branch --show-current) &&
grep -v $current <tmp | awk "{\$1=\$2=\"\"}1" >actual &&
awk "/$current/ { next } { \$1 = \$2 = \"\" } 1" <tmp >actual &&
test_cmp expect actual
'

Expand Down
2 changes: 1 addition & 1 deletion t/t4002-diff-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ test_expect_success 'diff-tree -r B A == diff-tree -r -R A B' '

test_expect_success 'diff can read from stdin' '
test_must_fail git diff --no-index -- MN - < NN |
grep -v "^index" | sed "s#/-#/NN#" >.test-a &&
sed "/^index/d; s#/-#/NN#" >.test-a &&
test_must_fail git diff --no-index -- MN NN |
grep -v "^index" >.test-b &&
test_cmp .test-a .test-b
Expand Down
2 changes: 1 addition & 1 deletion t/t4020-diff-external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ keep_only_cr () {
test_expect_success 'external diff with autocrlf = true' '
test_config core.autocrlf true &&
GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
test $(wc -l <crlfed.txt) = $(keep_only_cr <crlfed.txt | wc -c)
'

test_expect_success 'diff --cached' '
Expand Down
2 changes: 1 addition & 1 deletion t/t4205-log-pretty-formats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ test_expect_success 'NUL termination with --reflog --pretty=oneline' '
for r in $revs
do
git show -s --pretty=oneline "$r" >raw &&
cat raw | lf_to_nul || return 1
lf_to_nul <raw || return 1
done >expect &&
# the trailing NUL is already produced so we do not need to
# output another one
Expand Down
8 changes: 4 additions & 4 deletions t/t4301-merge-tree-write-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ test_expect_success 'rename/add handling' '
# First, check that the bar that appears at stage 3 does not
# correspond to an individual blob anywhere in history
#
hash=$(cat out | tr "\0" "\n" | head -n 3 | grep 3.bar | cut -f 2 -d " ") &&
hash=$(tr "\0" "\n" <out | head -n 3 | grep 3.bar | cut -f 2 -d " ") &&
git rev-list --objects --all >all_blobs &&
! grep $hash all_blobs &&
Expand Down Expand Up @@ -380,7 +380,7 @@ test_expect_success SYMLINKS 'rename/add, where add is a mode conflict' '
# First, check that the bar that appears at stage 3 does not
# correspond to an individual blob anywhere in history
#
hash=$(cat out | tr "\0" "\n" | head -n 3 | grep 3.bar | cut -f 2 -d " ") &&
hash=$(tr "\0" "\n" <out | head -n 3 | grep 3.bar | cut -f 2 -d " ") &&
git rev-list --objects --all >all_blobs &&
! grep $hash all_blobs &&
Expand Down Expand Up @@ -630,8 +630,8 @@ test_expect_success 'mod6: chains of rename/rename(1to2) and add/add via collidi
# conflict entries do not appear as individual blobs anywhere
# in history.
#
hash1=$(cat out | tr "\0" "\n" | head | grep 2.four | cut -f 2 -d " ") &&
hash2=$(cat out | tr "\0" "\n" | head | grep 3.two | cut -f 2 -d " ") &&
hash1=$(tr "\0" "\n" <out | head | grep 2.four | cut -f 2 -d " ") &&
hash2=$(tr "\0" "\n" <out | head | grep 3.two | cut -f 2 -d " ") &&
git rev-list --objects --all >all_blobs &&
! grep $hash1 all_blobs &&
! grep $hash2 all_blobs &&
Expand Down
2 changes: 1 addition & 1 deletion t/t5100-mailinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ test_expect_success 'respect NULs' '
git mailsplit -d3 -o. "$DATA/nul-plain" &&
test_cmp "$DATA/nul-plain" 001 &&
(cat 001 | git mailinfo msg patch) &&
git mailinfo msg patch <001 &&
test_line_count = 4 patch
'
Expand Down
2 changes: 1 addition & 1 deletion t/t5317-pack-objects-filter-objects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ test_expect_success 'setup r1 - delete loose blobs' '
test_parse_ls_files_stage_oids <ls_files_result |
sort >expected &&
for id in `cat expected | sed "s|..|&/|"`
for id in `sed "s|..|&/|" expected`
do
rm r1/.git/objects/$id || return 1
done
Expand Down
2 changes: 1 addition & 1 deletion t/t5401-update-hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ remote: STDOUT post-update
remote: STDERR post-update
EOF
test_expect_success 'send-pack stderr contains hook messages' '
grep ^remote: send.err | sed "s/ *\$//" >actual &&
sed -n "/^remote:/s/ *\$//p" send.err >actual &&
test_cmp expect actual
'

Expand Down
2 changes: 1 addition & 1 deletion t/t5534-push-signed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ test_expect_success GPGSM 'fail without key and heed user.signingkey x509' '
EOF
sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert
) >expect.in &&
key=$(cat "${GNUPGHOME}/trustlist.txt" | cut -d" " -f1 | tr -d ":") &&
key=$(cut -d" " -f1 <"${GNUPGHOME}/trustlist.txt" | tr -d ":") &&
sed -e "s/^KEY=/KEY=${key}/" expect.in >expect &&
noop=$(git rev-parse noop) &&
Expand Down
2 changes: 1 addition & 1 deletion t/t6112-rev-list-filters-objects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ test_expect_success 'rev-list W/ --missing=print' '
awk -f print_2.awk ls_files_result |
sort >expected &&
for id in `cat expected | sed "s|..|&/|"`
for id in `sed "s|..|&/|" expected`
do
rm r1/.git/objects/$id || return 1
done &&
Expand Down
4 changes: 2 additions & 2 deletions t/t6413-merge-crlf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ test_expect_success setup '
test_expect_success 'Check "ours" is CRLF' '
git reset --hard initial &&
git merge side -s ours &&
cat file | remove_cr | append_cr >file.temp &&
remove_cr <file | append_cr >file.temp &&
test_cmp file file.temp
'

test_expect_success 'Check that conflict file is CRLF' '
git reset --hard a &&
test_must_fail git merge side &&
cat file | remove_cr | append_cr >file.temp &&
remove_cr <file | append_cr >file.temp &&
test_cmp file file.temp
'

Expand Down
2 changes: 1 addition & 1 deletion t/t7704-repack-cruft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test_expect_success '--expire-to stores pruned objects (now)' '
# ...in other words, the combined contents of this
# repository and expired.git should be the same as the
# set of objects we started with.
cat expired.objects remaining.objects | sort >actual &&
sort expired.objects remaining.objects >actual &&
test_cmp expect actual &&
# The "moved" objects (i.e., those in expired.git)
Expand Down
2 changes: 1 addition & 1 deletion t/t8010-cat-file-filters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test_expect_success 'cat-file --textconv --path=<path> works' '
sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" &&
git cat-file --textconv --path=hello.txt $sha1 >rot13 &&
test uryyb = "$(cat rot13 | remove_cr)"
test uryyb = "$(remove_cr <rot13)"
'

test_expect_success '--path=<path> complains without --textconv/--filters' '
Expand Down
Loading

0 comments on commit a7f0fcb

Please sign in to comment.