* [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection
@ 2007-06-06 1:34 Josh Triplett
2007-06-06 3:39 ` Stephen Rothwell
0 siblings, 1 reply; 6+ messages in thread
From: Josh Triplett @ 2007-06-06 1:34 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 3447 bytes --]
Replace all uses of cat that do nothing other than read a single file.
Signed-off-by: Josh Triplett <josh@freedesktop.org>
---
git-commit.sh | 2 +-
git-filter-branch.sh | 4 ++--
git-ls-remote.sh | 2 +-
git-quiltimport.sh | 4 ++--
git-verify-tag.sh | 3 +--
5 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/git-commit.sh b/git-commit.sh
index e8b60f7..06b6cd7 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -617,7 +617,7 @@ then
tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) &&
rm -f "$TMP_INDEX"
fi &&
- commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
+ commit=$(git-commit-tree $tree $PARENTS < "$GIT_DIR"/COMMIT_MSG) &&
rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
git-update-ref -m "$GIT_REFLOG_ACTION: $rlogm" HEAD $commit "$current" &&
rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" &&
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 0c8a7df..bfac6f2 100644
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -333,7 +333,7 @@ for commit in $unchanged; do
done
git-rev-list --reverse --topo-order $srcbranch --not $unchanged >../revs
-commits=$(cat ../revs | wc -l | tr -d " ")
+commits=$(wc -l ../revs | tr -d " ")
test $commits -eq 0 && die "Found nothing to rewrite"
@@ -386,7 +386,7 @@ while read commit; do
done <../revs
git-update-ref refs/heads/"$dstbranch" $(head -n 1 ../map/$(tail -n 1 ../revs))
-if [ "$(cat ../map/$(tail -n 1 ../revs) | wc -l)" -gt 1 ]; then
+if [ "$(wc -l ../map/$(tail -n 1 ../revs))" -gt 1 ]; then
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
sed 's/^/ /' ../map/$(tail -n 1 ../revs) >&2
ret=1
diff --git a/git-ls-remote.sh b/git-ls-remote.sh
index a6ed99a..f5b2e77 100755
--- a/git-ls-remote.sh
+++ b/git-ls-remote.sh
@@ -82,7 +82,7 @@ rsync://* )
(cd $tmpdir && find refs -type f) |
while read path
do
- cat "$tmpdir/$path" | tr -d '\012'
+ tr -d '\012' < "$tmpdir/$path"
echo " $path"
done &&
rm -fr $tmpdir
diff --git a/git-quiltimport.sh b/git-quiltimport.sh
index a7a6757..bd540cd 100755
--- a/git-quiltimport.sh
+++ b/git-quiltimport.sh
@@ -70,9 +70,9 @@ tmp_info="$tmp_dir/info"
commit=$(git-rev-parse HEAD)
mkdir $tmp_dir || exit 2
-for patch_name in $(cat "$QUILT_PATCHES/series" | grep -v '^#'); do
+for patch_name in $(grep -v '^#' "$QUILT_PATCHES/series"); do
echo $patch_name
- (cat $QUILT_PATCHES/$patch_name | git-mailinfo "$tmp_msg" "$tmp_patch" > "$tmp_info") || exit 3
+ git-mailinfo "$tmp_msg" "$tmp_patch" < "$QUILT_PATCHES/$patch_name" > "$tmp_info" || exit 3
test -s .dotest/patch || {
echo "Patch is empty. Was it split wrong?"
exit 1
diff --git a/git-verify-tag.sh b/git-verify-tag.sh
index 8db7dd0..11ce947 100755
--- a/git-verify-tag.sh
+++ b/git-verify-tag.sh
@@ -38,8 +38,7 @@ trap 'rm -f "$GIT_DIR/.tmp-vtag"' 0
git-cat-file tag "$1" >"$GIT_DIR/.tmp-vtag" || exit 1
-cat "$GIT_DIR/.tmp-vtag" |
-sed '/-----BEGIN PGP/Q' |
+sed '/-----BEGIN PGP/Q' "$GIT_DIR/.tmp-vtag" |
gpg --verify "$GIT_DIR/.tmp-vtag" - || exit 1
rm -f "$GIT_DIR/.tmp-vtag"
--
1.5.2.1
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection
2007-06-06 1:34 [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection Josh Triplett
@ 2007-06-06 3:39 ` Stephen Rothwell
2007-06-06 3:51 ` Michael Poole
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Rothwell @ 2007-06-06 3:39 UTC (permalink / raw)
To: Josh Triplett; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 289 bytes --]
On Tue, 05 Jun 2007 18:34:59 -0700 Josh Triplett <josh@freedesktop.org> wrote:
>
> -commits=$(cat ../revs | wc -l | tr -d " ")
> +commits=$(wc -l ../revs | tr -d " ")
This is not equivalent, you probably wanted:
commits=$(wc -l <../revs | tr -d " ")
Cheers,
Stephen Rothwell
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection
2007-06-06 3:39 ` Stephen Rothwell
@ 2007-06-06 3:51 ` Michael Poole
2007-06-06 3:58 ` Martin Langhoff
0 siblings, 1 reply; 6+ messages in thread
From: Michael Poole @ 2007-06-06 3:51 UTC (permalink / raw)
To: Stephen Rothwell; +Cc: Josh Triplett, git
Stephen Rothwell writes:
> On Tue, 05 Jun 2007 18:34:59 -0700 Josh Triplett <josh@freedesktop.org> wrote:
>>
>> -commits=$(cat ../revs | wc -l | tr -d " ")
>> +commits=$(wc -l ../revs | tr -d " ")
>
> This is not equivalent, you probably wanted:
>
> commits=$(wc -l <../revs | tr -d " ")
Which relevant version(s) of wc do not accept filename arguments?
POSIX[1] seems to specify it. Or do you mean that there is some
subtle difference in its processing of stdin vs specified files?
[1]- http://www.opengroup.org/onlinepubs/000095399/utilities/wc.html
Michael Poole
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection
2007-06-06 3:51 ` Michael Poole
@ 2007-06-06 3:58 ` Martin Langhoff
2007-06-06 4:54 ` Stephen Rothwell
0 siblings, 1 reply; 6+ messages in thread
From: Martin Langhoff @ 2007-06-06 3:58 UTC (permalink / raw)
To: Michael Poole; +Cc: Stephen Rothwell, Josh Triplett, git
On 6/6/07, Michael Poole <mdpoole@troilus.org> wrote:
> Stephen Rothwell writes:
>
> > On Tue, 05 Jun 2007 18:34:59 -0700 Josh Triplett <josh@freedesktop.org> wrote:
> >>
> >> -commits=$(cat ../revs | wc -l | tr -d " ")
> >> +commits=$(wc -l ../revs | tr -d " ")
> >
> > This is not equivalent, you probably wanted:
> >
> > commits=$(wc -l <../revs | tr -d " ")
>
> Which relevant version(s) of wc do not accept filename arguments?
> POSIX[1] seems to specify it. Or do you mean that there is some
> subtle difference in its processing of stdin vs specified files?
Josh is right. The output *is* different because it contains the
filename as well. See
$ wc < .gitk | tr -d " "
2177551
$ wc .gitk | tr -d " "
2177551.gitk
cheers
m
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection
2007-06-06 3:58 ` Martin Langhoff
@ 2007-06-06 4:54 ` Stephen Rothwell
2007-06-06 6:38 ` Martin Langhoff
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Rothwell @ 2007-06-06 4:54 UTC (permalink / raw)
To: Martin Langhoff; +Cc: Michael Poole, Stephen Rothwell, Josh Triplett, git
[-- Attachment #1: Type: text/plain, Size: 254 bytes --]
On Wed, 6 Jun 2007 15:58:09 +1200 "Martin Langhoff" <martin.langhoff@gmail.com> wrote:
>
> Josh is right. The output *is* different because it contains the
^^^^
My name is Stephen :-) and that is indeed what I meant.
Cheers,
Stephen Rothwell
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection
2007-06-06 4:54 ` Stephen Rothwell
@ 2007-06-06 6:38 ` Martin Langhoff
0 siblings, 0 replies; 6+ messages in thread
From: Martin Langhoff @ 2007-06-06 6:38 UTC (permalink / raw)
To: Stephen Rothwell; +Cc: Michael Poole, Josh Triplett, git
On 6/6/07, Stephen Rothwell <git@ozlabs.org> wrote:
> On Wed, 6 Jun 2007 15:58:09 +1200 "Martin Langhoff" <martin.langhoff@gmail.com> wrote:
> >
> > Josh is right. The output *is* different because it contains the
> ^^^^
> My name is Stephen :-) and that is indeed what I meant.
Sorry! Cross-eyed over the email thread, but not over posix behaviour ;-)
...cleans those glasses now
martin
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-06-06 6:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-06 1:34 [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection Josh Triplett
2007-06-06 3:39 ` Stephen Rothwell
2007-06-06 3:51 ` Michael Poole
2007-06-06 3:58 ` Martin Langhoff
2007-06-06 4:54 ` Stephen Rothwell
2007-06-06 6:38 ` Martin Langhoff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).