Re: [PATCH v2] Remove useless uses of cat, and replace with filename arguments or redirection
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jun 7, 2007, 04:06 UTC
- Message-ID
- <Pine.LNX.4.64.0706070506230.4046@racer.site>
- In-Reply-To
- <46676C35.60406@freedesktop.org>
Hi,
On Wed, 6 Jun 2007, Josh Triplett wrote:
Show 29 quoted lines
> Junio C Hamano wrote: > > Josh Triplett <josh@freedesktop.org> writes: > >> Replace all uses of cat that do nothing other than read a single file. In the > >> case of git-quilt-import, this occurs once per patch. > >> > >> Signed-off-by: Josh Triplett <josh@freedesktop.org> > >> --- > >> > >> This revised version fixes a bug caught by Stephen Rothwell: the output of wc > >> -l changes when it has a filename on the command line. The same bug occurred > >> in one other place as well. > > > > Hmph... > > > >> diff --git a/git-filter-branch.sh b/git-filter-branch.sh > >> index 0c8a7df..346cf3f 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 -c 0-9) > > > > ... and left unfixed ;-)? > > No, just fixed differently. :) Note the change to the tr invocation: delete > everything other than digits.
Actually, it feels wrong. For example, if some wc some day decides to display the size in kilobyte, even if you say "-l", it would fail badly. That is, it would fail to function properly, but would not tell you that it failed.
Things like that are known to happen, and that's why "wc -l < file" is a better fix than "wc -l file | tr -dc 0-9". In this case, it might not matter for a long time, but why not stop being sloppy here and now?
Ciao, Dscho