{"thread":{"id":"8458","subject":"[PATCH] Remove useless uses of cat, and replace with filename arguments or redirection","startedAt":"2007-06-06T01:34:59Z","lastAt":"2007-06-06T06:38:09Z","messageCount":6,"participants":["Josh Triplett","Stephen Rothwell","Michael Poole","Martin Langhoff"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"44111","messageId":"46660F43.4060402@freedesktop.org","threadId":"8458","inReplyTo":null,"subject":"[PATCH] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Josh Triplett","fromEmail":"josh@freedesktop.org","sentAt":"2007-06-06T01:34:59Z","receivedAt":"2007-06-06T01:34:59Z","isPatch":true,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"Replace all uses of cat that do nothing other than read a single file.\n\nSigned-off-by: Josh Triplett <josh@freedesktop.org>\n---\n git-commit.sh        |    2 +-\n git-filter-branch.sh |    4 ++--\n git-ls-remote.sh     |    2 +-\n git-quiltimport.sh   |    4 ++--\n git-verify-tag.sh    |    3 +--\n 5 files changed, 7 insertions(+), 8 deletions(-)\n\ndiff --git a/git-commit.sh b/git-commit.sh\nindex e8b60f7..06b6cd7 100755\n--- a/git-commit.sh\n+++ b/git-commit.sh\n@@ -617,7 +617,7 @@ then\n \t\ttree=$(GIT_INDEX_FILE=\"$TMP_INDEX\" git-write-tree) &&\n \t\trm -f \"$TMP_INDEX\"\n \tfi &&\n-\tcommit=$(cat \"$GIT_DIR\"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&\n+\tcommit=$(git-commit-tree $tree $PARENTS < \"$GIT_DIR\"/COMMIT_MSG) &&\n \trlogm=$(sed -e 1q \"$GIT_DIR\"/COMMIT_MSG) &&\n \tgit-update-ref -m \"$GIT_REFLOG_ACTION: $rlogm\" HEAD $commit \"$current\" &&\n \trm -f -- \"$GIT_DIR/MERGE_HEAD\" \"$GIT_DIR/MERGE_MSG\" &&\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 0c8a7df..bfac6f2 100644\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -333,7 +333,7 @@ for commit in $unchanged; do\n done\n \n git-rev-list --reverse --topo-order $srcbranch --not $unchanged >../revs\n-commits=$(cat ../revs | wc -l | tr -d \" \")\n+commits=$(wc -l ../revs | tr -d \" \")\n \n test $commits -eq 0 && die \"Found nothing to rewrite\"\n \n@@ -386,7 +386,7 @@ while read commit; do\n done <../revs\n \n git-update-ref refs/heads/\"$dstbranch\" $(head -n 1 ../map/$(tail -n 1 ../revs))\n-if [ \"$(cat ../map/$(tail -n 1 ../revs) | wc -l)\" -gt 1 ]; then\n+if [ \"$(wc -l ../map/$(tail -n 1 ../revs))\" -gt 1 ]; then\n \techo \"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\n \tsed 's/^/\t/' ../map/$(tail -n 1 ../revs) >&2\n \tret=1\ndiff --git a/git-ls-remote.sh b/git-ls-remote.sh\nindex a6ed99a..f5b2e77 100755\n--- a/git-ls-remote.sh\n+++ b/git-ls-remote.sh\n@@ -82,7 +82,7 @@ rsync://* )\n \t(cd $tmpdir && find refs -type f) |\n \twhile read path\n \tdo\n-\t\tcat \"$tmpdir/$path\" | tr -d '\\012'\n+\t\ttr -d '\\012' < \"$tmpdir/$path\"\n \t\techo \"\t$path\"\n \tdone &&\n \trm -fr $tmpdir\ndiff --git a/git-quiltimport.sh b/git-quiltimport.sh\nindex a7a6757..bd540cd 100755\n--- a/git-quiltimport.sh\n+++ b/git-quiltimport.sh\n@@ -70,9 +70,9 @@ tmp_info=\"$tmp_dir/info\"\n commit=$(git-rev-parse HEAD)\n \n mkdir $tmp_dir || exit 2\n-for patch_name in $(cat \"$QUILT_PATCHES/series\" | grep -v '^#'); do\n+for patch_name in $(grep -v '^#' \"$QUILT_PATCHES/series\"); do\n \techo $patch_name\n-\t(cat $QUILT_PATCHES/$patch_name | git-mailinfo \"$tmp_msg\" \"$tmp_patch\" > \"$tmp_info\") || exit 3\n+\tgit-mailinfo \"$tmp_msg\" \"$tmp_patch\" < \"$QUILT_PATCHES/$patch_name\" > \"$tmp_info\" || exit 3\n \ttest -s .dotest/patch || {\n \t\techo \"Patch is empty.  Was it split wrong?\"\n \t\texit 1\ndiff --git a/git-verify-tag.sh b/git-verify-tag.sh\nindex 8db7dd0..11ce947 100755\n--- a/git-verify-tag.sh\n+++ b/git-verify-tag.sh\n@@ -38,8 +38,7 @@ trap 'rm -f \"$GIT_DIR/.tmp-vtag\"' 0\n \n git-cat-file tag \"$1\" >\"$GIT_DIR/.tmp-vtag\" || exit 1\n \n-cat \"$GIT_DIR/.tmp-vtag\" |\n-sed '/-----BEGIN PGP/Q' |\n+sed '/-----BEGIN PGP/Q' \"$GIT_DIR/.tmp-vtag\" |\n gpg --verify \"$GIT_DIR/.tmp-vtag\" - || exit 1\n rm -f \"$GIT_DIR/.tmp-vtag\"\n \n-- \n1.5.2.1\n\n\n"},{"id":"44114","messageId":"20070606133915.d72e4afe.git@ozlabs.org","threadId":"8458","inReplyTo":"46660F43.4060402@freedesktop.org","subject":"Re: [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Stephen Rothwell","fromEmail":"git@ozlabs.org","sentAt":"2007-06-06T03:39:15Z","receivedAt":"2007-06-06T03:39:15Z","isPatch":true,"sender":{"key":"git@ozlabs.org","avatar":null},"body":"On Tue, 05 Jun 2007 18:34:59 -0700 Josh Triplett <josh@freedesktop.org> wrote:\n>\n> -commits=$(cat ../revs | wc -l | tr -d \" \")\n> +commits=$(wc -l ../revs | tr -d \" \")\n\nThis is not equivalent, you probably wanted:\n\ncommits=$(wc -l <../revs | tr -d \" \")\n\nCheers,\nStephen Rothwell\n"},{"id":"44115","messageId":"87sl957naf.fsf@graviton.dyn.troilus.org","threadId":"8458","inReplyTo":"20070606133915.d72e4afe.git@ozlabs.org","subject":"Re: [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Michael Poole","fromEmail":"mdpoole@troilus.org","sentAt":"2007-06-06T03:51:52Z","receivedAt":"2007-06-06T03:51:52Z","isPatch":true,"sender":{"key":"mdpoole@troilus.org","avatar":null},"body":"Stephen Rothwell writes:\n\n> On Tue, 05 Jun 2007 18:34:59 -0700 Josh Triplett <josh@freedesktop.org> wrote:\n>>\n>> -commits=$(cat ../revs | wc -l | tr -d \" \")\n>> +commits=$(wc -l ../revs | tr -d \" \")\n>\n> This is not equivalent, you probably wanted:\n>\n> commits=$(wc -l <../revs | tr -d \" \")\n\nWhich relevant version(s) of wc do not accept filename arguments?\nPOSIX[1] seems to specify it.  Or do you mean that there is some\nsubtle difference in its processing of stdin vs specified files?\n\n[1]- http://www.opengroup.org/onlinepubs/000095399/utilities/wc.html\n\nMichael Poole\n"},{"id":"44116","messageId":"46a038f90706052058h1c823278o78ce0d8edce3caab@mail.gmail.com","threadId":"8458","inReplyTo":"87sl957naf.fsf@graviton.dyn.troilus.org","subject":"Re: [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2007-06-06T03:58:09Z","receivedAt":"2007-06-06T03:58:09Z","isPatch":true,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On 6/6/07, Michael Poole <mdpoole@troilus.org> wrote:\n> Stephen Rothwell writes:\n>\n> > On Tue, 05 Jun 2007 18:34:59 -0700 Josh Triplett <josh@freedesktop.org> wrote:\n> >>\n> >> -commits=$(cat ../revs | wc -l | tr -d \" \")\n> >> +commits=$(wc -l ../revs | tr -d \" \")\n> >\n> > This is not equivalent, you probably wanted:\n> >\n> > commits=$(wc -l <../revs | tr -d \" \")\n>\n> Which relevant version(s) of wc do not accept filename arguments?\n> POSIX[1] seems to specify it.  Or do you mean that there is some\n> subtle difference in its processing of stdin vs specified files?\n\nJosh is right. The output *is* different because it contains the\nfilename as well. See\n\n  $ wc < .gitk | tr -d \" \"\n  2177551\n  $ wc .gitk | tr -d \" \"\n  2177551.gitk\n\ncheers\n\n\nm\n"},{"id":"44120","messageId":"20070606145436.b8907cf0.git@ozlabs.org","threadId":"8458","inReplyTo":"46a038f90706052058h1c823278o78ce0d8edce3caab@mail.gmail.com","subject":"Re: [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Stephen Rothwell","fromEmail":"git@ozlabs.org","sentAt":"2007-06-06T04:54:36Z","receivedAt":"2007-06-06T04:54:36Z","isPatch":true,"sender":{"key":"git@ozlabs.org","avatar":null},"body":"On Wed, 6 Jun 2007 15:58:09 +1200 \"Martin Langhoff\" <martin.langhoff@gmail.com> wrote:\n>\n> Josh is right. The output *is* different because it contains the\n  ^^^^\nMy name is Stephen  :-) and that is indeed what I meant.\n\nCheers,\nStephen Rothwell\n"},{"id":"44123","messageId":"46a038f90706052338x775b18e1h2bdf0d8d120dd799@mail.gmail.com","threadId":"8458","inReplyTo":"20070606145436.b8907cf0.git@ozlabs.org","subject":"Re: [PATCH] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2007-06-06T06:38:09Z","receivedAt":"2007-06-06T06:38:09Z","isPatch":true,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On 6/6/07, Stephen Rothwell <git@ozlabs.org> wrote:\n> On Wed, 6 Jun 2007 15:58:09 +1200 \"Martin Langhoff\" <martin.langhoff@gmail.com> wrote:\n> >\n> > Josh is right. The output *is* different because it contains the\n>   ^^^^\n> My name is Stephen  :-) and that is indeed what I meant.\n\nSorry! Cross-eyed over the email thread, but not over posix behaviour ;-)\n\n...cleans those glasses now\n\n\nmartin\n"}]}