git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix use of wc in t0000-basic
@ 2005-05-21  0:49 Daniel Barkalow
  2005-05-21  1:08 ` Sean
  2005-05-21 10:37 ` Herbert Xu
  0 siblings, 2 replies; 10+ messages in thread
From: Daniel Barkalow @ 2005-05-21  0:49 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

The version of wc I have (GNU textutils-2.1) puts spaces at the beginning
of lines. This patch should work for any version of wc.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Acked-by: Junio C Hamano <junkio@cox.net>
Index: t/t0000-basic.sh
===================================================================
--- 58741c69570705801db4b785681790d636475695/t/t0000-basic.sh  (mode:100755 sha1:9a557129d98b499bcd601903d6646de29ba4bfc5)
+++ uncommitted/t/t0000-basic.sh  (mode:100755)
@@ -32,7 +32,7 @@
 find .git/objects -type d -print >full-of-directories
 test_expect_success \
     '.git/objects should have 256 subdirectories.' \
-    'test "$(wc -l full-of-directories | sed -e "s/ .*//")" = 257'
+    'test $(cat full-of-directories | wc -l) = 257'
 
 ################################################################
 # Basics of the basics



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix use of wc in t0000-basic
  2005-05-21  0:49 [PATCH] Fix use of wc in t0000-basic Daniel Barkalow
@ 2005-05-21  1:08 ` Sean
  2005-05-21  1:10   ` Daniel Barkalow
  2005-05-21 10:37 ` Herbert Xu
  1 sibling, 1 reply; 10+ messages in thread
From: Sean @ 2005-05-21  1:08 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: Linus Torvalds, git

On Fri, May 20, 2005 8:49 pm, Daniel Barkalow said:
> The version of wc I have (GNU textutils-2.1) puts spaces at the beginning
> of lines. This patch should work for any version of wc.
>
> Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
> Acked-by: Junio C Hamano <junkio@cox.net>
> Index: t/t0000-basic.sh
> ===================================================================
> --- 58741c69570705801db4b785681790d636475695/t/t0000-basic.sh
> (mode:100755 sha1:9a557129d98b499bcd601903d6646de29ba4bfc5)
> +++ uncommitted/t/t0000-basic.sh  (mode:100755)
> @@ -32,7 +32,7 @@
>  find .git/objects -type d -print >full-of-directories
>  test_expect_success \
>      '.git/objects should have 256 subdirectories.' \
> -    'test "$(wc -l full-of-directories | sed -e "s/ .*//")" = 257'
> +    'test $(cat full-of-directories | wc -l) = 257'
>
>  ################################################################
>  # Basics of the basics
>


You can't do "wc -l filename" because some versionso of "wc" then include
the filename in their output and confuse things.   That was the reason to
use "cat" in the first place.  If you're going to use sed, just do away
with wc altogether:

sed -ne '$=' full-of-directories

And that should work everywhere to get a line count.

Cheers,
Sean



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix use of wc in t0000-basic
  2005-05-21  1:08 ` Sean
@ 2005-05-21  1:10   ` Daniel Barkalow
  2005-05-21  1:13     ` Sean
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Barkalow @ 2005-05-21  1:10 UTC (permalink / raw)
  To: Sean; +Cc: Linus Torvalds, git

On Fri, 20 May 2005, Sean wrote:

> You can't do "wc -l filename" because some versionso of "wc" then include
> the filename in their output and confuse things.   That was the reason to
> use "cat" in the first place.

You're reading my patch backwards.

	-Daniel
*This .sig left intentionally blank*


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix use of wc in t0000-basic
  2005-05-21  1:10   ` Daniel Barkalow
@ 2005-05-21  1:13     ` Sean
  2005-05-21  1:16       ` Daniel Barkalow
  0 siblings, 1 reply; 10+ messages in thread
From: Sean @ 2005-05-21  1:13 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: Linus Torvalds, git

On Fri, May 20, 2005 9:10 pm, Daniel Barkalow said:
> On Fri, 20 May 2005, Sean wrote:
>
>> You can't do "wc -l filename" because some versionso of "wc" then
>> include
>> the filename in their output and confuse things.   That was the reason
>> to
>> use "cat" in the first place.
>
> You're reading my patch backwards.
>

Yes, i was.   But presumably someone was stripping the whitespace from wc
for a reason?   Either way the sed-only solution seems a little cleaner.

Sean



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix use of wc in t0000-basic
  2005-05-21  1:13     ` Sean
@ 2005-05-21  1:16       ` Daniel Barkalow
  2005-05-21  1:43         ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Barkalow @ 2005-05-21  1:16 UTC (permalink / raw)
  To: Sean; +Cc: Linus Torvalds, git

On Fri, 20 May 2005, Sean wrote:

> Yes, i was.   But presumably someone was stripping the whitespace from wc
> for a reason?   Either way the sed-only solution seems a little cleaner.

Junio was stripping the filename (not whitespace) from wc, not knowing
that it could be suppressed by using stdin. This didn't work with versions
of wc that put whitespace at the beginning. I think the sed-only solution
is far more obscure and no cleaner than cat and wc.

	-Daniel
*This .sig left intentionally blank*


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix use of wc in t0000-basic
  2005-05-21  1:16       ` Daniel Barkalow
@ 2005-05-21  1:43         ` Junio C Hamano
  0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2005-05-21  1:43 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: Sean, Linus Torvalds, git

>>>>> "DB" == Daniel Barkalow <barkalow@iabervon.org> writes:

DB> Junio was stripping the filename (not whitespace) from wc, not knowing
DB> that it could be suppressed by using stdin.

Actually the reason I did so initially was because I recalled
seeing a wc that said "-" instead of omitting the filename.  I
do not have access to those obscure Unixen so I cannot these
things easily anymore, though.

DB> of wc that put whitespace at the beginning. I think the
DB> sed-only solution is far more obscure and no cleaner than
DB> cat and wc.

This I tend to agree, but that is probably one of the most
portable.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix use of wc in t0000-basic
  2005-05-21  0:49 [PATCH] Fix use of wc in t0000-basic Daniel Barkalow
  2005-05-21  1:08 ` Sean
@ 2005-05-21 10:37 ` Herbert Xu
  2005-05-21 10:53   ` Junio C Hamano
  1 sibling, 1 reply; 10+ messages in thread
From: Herbert Xu @ 2005-05-21 10:37 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: torvalds, git

Daniel Barkalow <barkalow@iabervon.org> wrote:
>
> -    'test "$(wc -l full-of-directories | sed -e "s/ .*//")" = 257'
> +    'test $(cat full-of-directories | wc -l) = 257'

You don't need the cat:

wc -l < full-of-directories

will do the same thing.

It's also better to use -eq instead of = since you are comparing
numbers, not strings.  If you do that you can keep the double
quotes since the spaces will be removed automatically.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix use of wc in t0000-basic
  2005-05-21 10:37 ` Herbert Xu
@ 2005-05-21 10:53   ` Junio C Hamano
  2005-05-21 11:01     ` Herbert Xu
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2005-05-21 10:53 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Daniel Barkalow, torvalds, git

>>>>> "HX" == Herbert Xu <herbert@gondor.apana.org.au> writes:

HX> It's also better to use -eq instead of = since you are comparing
HX> numbers, not strings.  If you do that you can keep the double
HX> quotes since the spaces will be removed automatically.

I remember being burned by busybox "test" which did not ignore
spaces.  I do not know if the latest one is fixed, though.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix use of wc in t0000-basic
  2005-05-21 10:53   ` Junio C Hamano
@ 2005-05-21 11:01     ` Herbert Xu
  2005-05-21 17:24       ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Herbert Xu @ 2005-05-21 11:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Daniel Barkalow, torvalds, git

On Sat, May 21, 2005 at 03:53:30AM -0700, Junio C Hamano wrote:
> >>>>> "HX" == Herbert Xu <herbert@gondor.apana.org.au> writes:
> 
> HX> It's also better to use -eq instead of = since you are comparing
> HX> numbers, not strings.  If you do that you can keep the double
> HX> quotes since the spaces will be removed automatically.
> 
> I remember being burned by busybox "test" which did not ignore
> spaces.  I do not know if the latest one is fixed, though.

Are you sure that it didn't ignore the leading spaces with -eq?
The code in question just calls strtol.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix use of wc in t0000-basic
  2005-05-21 11:01     ` Herbert Xu
@ 2005-05-21 17:24       ` Junio C Hamano
  0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2005-05-21 17:24 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Daniel Barkalow, torvalds, git

>>>>> "HX" == Herbert Xu <herbert@gondor.apana.org.au> writes:

HX> Are you sure that it didn't ignore the leading spaces with -eq?
HX> The code in question just calls strtol.

Sorry, I am not sure whose fault it was, and the recollection
comes from my distant past.  It could have been that the
smallish shell in that semi-embedded environment had an
incompatible built-in "test" command which was burning me, but
I distinctively remember changing many of the vendor supplied
shell script that had:

    if test " $number" -eq 3
    then
        ...

either stripping dq around it or simply removing the space from
there, depending on how that $number was generated.

Since I assume we are only talking about portability across
POSIXy world I do not think this is a big issue.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-05-21 17:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-21  0:49 [PATCH] Fix use of wc in t0000-basic Daniel Barkalow
2005-05-21  1:08 ` Sean
2005-05-21  1:10   ` Daniel Barkalow
2005-05-21  1:13     ` Sean
2005-05-21  1:16       ` Daniel Barkalow
2005-05-21  1:43         ` Junio C Hamano
2005-05-21 10:37 ` Herbert Xu
2005-05-21 10:53   ` Junio C Hamano
2005-05-21 11:01     ` Herbert Xu
2005-05-21 17:24       ` Junio C Hamano

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).