{"thread":{"id":"8462","subject":"[PATCH v2] Remove useless uses of cat, and replace with filename arguments or redirection","startedAt":"2007-06-06T04:36:32Z","lastAt":"2007-06-08T12:52:56Z","messageCount":7,"participants":["Josh Triplett","Junio C Hamano","Johannes Schindelin","Martin Langhoff"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"44119","messageId":"466639D0.1040306@freedesktop.org","threadId":"8462","inReplyTo":null,"subject":"[PATCH v2] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Josh Triplett","fromEmail":"josh@freedesktop.org","sentAt":"2007-06-06T04:36:32Z","receivedAt":"2007-06-06T04:36:32Z","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.  In the\ncase of git-quilt-import, this occurs once per patch.\n\nSigned-off-by: Josh Triplett <josh@freedesktop.org>\n---\n\nThis revised version fixes a bug caught by Stephen Rothwell: the output of wc\n-l changes when it has a filename on the command line.  The same bug occurred\nin one other place as well.\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..346cf3f 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 -c 0-9)\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":"44216","messageId":"7vsl94sego.fsf@assigned-by-dhcp.cox.net","threadId":"8462","inReplyTo":"466639D0.1040306@freedesktop.org","subject":"Re: [PATCH v2] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-06-07T02:09:11Z","receivedAt":"2007-06-07T02:09:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Josh Triplett <josh@freedesktop.org> writes:\n\n> Replace all uses of cat that do nothing other than read a single file.  In the\n> case of git-quilt-import, this occurs once per patch.\n>\n> Signed-off-by: Josh Triplett <josh@freedesktop.org>\n> ---\n>\n> This revised version fixes a bug caught by Stephen Rothwell: the output of wc\n> -l changes when it has a filename on the command line.  The same bug occurred\n> in one other place as well.\n\nHmph...\n\n> diff --git a/git-filter-branch.sh b/git-filter-branch.sh\n> index 0c8a7df..346cf3f 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 -c 0-9)\n\n\n... and left unfixed ;-)?\n"},{"id":"44217","messageId":"46676C35.60406@freedesktop.org","threadId":"8462","inReplyTo":"7vsl94sego.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH v2] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Josh Triplett","fromEmail":"josh@freedesktop.org","sentAt":"2007-06-07T02:23:49Z","receivedAt":"2007-06-07T02:23:49Z","isPatch":true,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"Junio C Hamano wrote:\n> Josh Triplett <josh@freedesktop.org> writes:\n>> Replace all uses of cat that do nothing other than read a single file.  In the\n>> case of git-quilt-import, this occurs once per patch.\n>>\n>> Signed-off-by: Josh Triplett <josh@freedesktop.org>\n>> ---\n>>\n>> This revised version fixes a bug caught by Stephen Rothwell: the output of wc\n>> -l changes when it has a filename on the command line.  The same bug occurred\n>> in one other place as well.\n> \n> Hmph...\n> \n>> diff --git a/git-filter-branch.sh b/git-filter-branch.sh\n>> index 0c8a7df..346cf3f 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 -c 0-9)\n> \n> ... and left unfixed ;-)?\n\nNo, just fixed differently. :) Note the change to the tr invocation: delete\neverything other than digits.\n\n- Josh Triplett\n\n\n"},{"id":"44219","messageId":"7vtztkqxvy.fsf@assigned-by-dhcp.cox.net","threadId":"8462","inReplyTo":"46676C35.60406@freedesktop.org","subject":"Re: [PATCH v2] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-07T02:52:33Z","receivedAt":"2007-06-07T02:52:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Josh Triplett <josh@freedesktop.org> writes:\n\n> No, just fixed differently. :) Note the change to the tr invocation: delete\n> everything other than digits.\n\nAh, silly me.  Sorry for the noise.\n"},{"id":"44222","messageId":"Pine.LNX.4.64.0706070506230.4046@racer.site","threadId":"8462","inReplyTo":"46676C35.60406@freedesktop.org","subject":"Re: [PATCH v2] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-06-07T04:06:32Z","receivedAt":"2007-06-07T04:06:32Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 6 Jun 2007, Josh Triplett wrote:\n\n> Junio C Hamano wrote:\n> > Josh Triplett <josh@freedesktop.org> writes:\n> >> Replace all uses of cat that do nothing other than read a single file.  In the\n> >> case of git-quilt-import, this occurs once per patch.\n> >>\n> >> Signed-off-by: Josh Triplett <josh@freedesktop.org>\n> >> ---\n> >>\n> >> This revised version fixes a bug caught by Stephen Rothwell: the output of wc\n> >> -l changes when it has a filename on the command line.  The same bug occurred\n> >> in one other place as well.\n> > \n> > Hmph...\n> > \n> >> diff --git a/git-filter-branch.sh b/git-filter-branch.sh\n> >> index 0c8a7df..346cf3f 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 -c 0-9)\n> > \n> > ... and left unfixed ;-)?\n> \n> No, just fixed differently. :) Note the change to the tr invocation: delete\n> everything other than digits.\n\nActually, it feels wrong. For example, if some wc some day decides to \ndisplay the size in kilobyte, even if you say \"-l\", it would fail badly. \nThat is, it would fail to function properly, but would not tell you that \nit failed.\n\nThings like that are known to happen, and that's why \"wc -l < file\" is a \nbetter fix than \"wc -l file | tr -dc 0-9\". In this case, it might not \nmatter for a long time, but why not stop being sloppy here and now?\n\nCiao,\nDscho\n"},{"id":"44334","messageId":"46a038f90706080342j3a5bb7abv58c78d7b532e29de@mail.gmail.com","threadId":"8462","inReplyTo":"Pine.LNX.4.64.0706070506230.4046@racer.site","subject":"Re: [PATCH v2] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2007-06-08T10:42:44Z","receivedAt":"2007-06-08T10:42:44Z","isPatch":true,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On 6/7/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> Things like that are known to happen, and that's why \"wc -l < file\" is a\n> better fix than \"wc -l file | tr -dc 0-9\". In this case, it might not\n> matter for a long time, but why not stop being sloppy here and now?\n\nNot sure if I'd call is sloppy, but I also prefer wc -l < file -- it's\ndefinitely safer.\n\ncheers,\n\n\nm\n"},{"id":"44346","messageId":"Pine.LNX.4.64.0706081352260.4059@racer.site","threadId":"8462","inReplyTo":"46a038f90706080342j3a5bb7abv58c78d7b532e29de@mail.gmail.com","subject":"Re: [PATCH v2] Remove useless uses of cat, and replace with filename arguments or redirection","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-06-08T12:52:56Z","receivedAt":"2007-06-08T12:52:56Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 8 Jun 2007, Martin Langhoff wrote:\n\n> On 6/7/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> > Things like that are known to happen, and that's why \"wc -l < file\" is a\n> > better fix than \"wc -l file | tr -dc 0-9\". In this case, it might not\n> > matter for a long time, but why not stop being sloppy here and now?\n> \n> Not sure if I'd call is sloppy, but I also prefer wc -l < file -- it's\n> definitely safer.\n\nOkay, so I sounded harsher than intended.\n\nI should have phrased it like that: I consider \"wc -l < file\" \nsubstantially more future-proof, and it is in general a good practice \nIMVHO not to generate something you throw away just after that, when there \nis a way to avoid generating the unwanted part consistently.\n\nSorry,\nDscho\n"}]}