Skip to content

Commit 9d6f220

Browse files
joshtriplettgitster
authored andcommitted
Remove useless uses of cat, and replace with filename arguments
Replace uses of cat that do nothing but writing the contents of a single file to another command via pipe. [jc: Original patch from Josh was somewhat buggy and rewrote "cat $file | wc -l" to "wc -l $file", but this one should be Ok.] Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent bdecd9d commit 9d6f220

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

git-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ then
593593
tree=$(GIT_INDEX_FILE="$TMP_INDEX" git write-tree) &&
594594
rm -f "$TMP_INDEX"
595595
fi &&
596-
commit=$(cat "$GIT_DIR"/COMMIT_MSG | git commit-tree $tree $PARENTS) &&
596+
commit=$(git commit-tree $tree $PARENTS <"$GIT_DIR/COMMIT_MSG") &&
597597
rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
598598
git update-ref -m "$GIT_REFLOG_ACTION: $rlogm" HEAD $commit "$current" &&
599599
rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" &&

git-filter-branch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ case "$filter_subdir" in
171171
git rev-list --reverse --topo-order --default HEAD \
172172
--parents --full-history "$@" -- "$filter_subdir"
173173
esac > ../revs
174-
commits=$(cat ../revs | wc -l | tr -d " ")
174+
commits=$(wc -l <../revs | tr -d " ")
175175

176176
test $commits -eq 0 && die "Found nothing to rewrite"
177177

@@ -241,7 +241,7 @@ case "$target_head" in
241241
;;
242242
*)
243243
git update-ref refs/heads/"$dstbranch" $target_head
244-
if [ $(cat ../map/$src_head | wc -l) -gt 1 ]; then
244+
if [ $(wc -l <../map/$src_head) -gt 1 ]; then
245245
echo "WARNING: Your commit filter caused the head commit to expand to several rewritten commits. Only the first such commit was recorded as the current $dstbranch head but you will need to resolve the situation now (probably by manually merging the other commits). These are all the commits:" >&2
246246
sed 's/^/ /' ../map/$src_head >&2
247247
ret=1

git-ls-remote.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ rsync://* )
8282
(cd $tmpdir && find refs -type f) |
8383
while read path
8484
do
85-
cat "$tmpdir/$path" | tr -d '\012'
85+
tr -d '\012' <"$tmpdir/$path"
8686
echo " $path"
8787
done &&
8888
rm -fr $tmpdir

git-quiltimport.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ tmp_info="$tmp_dir/info"
7070
commit=$(git rev-parse HEAD)
7171

7272
mkdir $tmp_dir || exit 2
73-
for patch_name in $(cat "$QUILT_PATCHES/series" | grep -v '^#'); do
73+
for patch_name in $(grep -v '^#' < "$QUILT_PATCHES/series" ); do
7474
echo $patch_name
75-
(cat $QUILT_PATCHES/$patch_name | git mailinfo "$tmp_msg" "$tmp_patch" > "$tmp_info") || exit 3
76-
test -s .dotest/patch || {
75+
git mailinfo "$tmp_msg" "$tmp_patch" \
76+
<"$QUILT_PATCHES/$patch_name" >"$tmp_info" || exit 3
77+
test -s "$tmp_patch" || {
7778
echo "Patch is empty. Was it split wrong?"
7879
exit 1
7980
}

0 commit comments

Comments
 (0)