{"thread":{"id":"29164","subject":"t0090-cache-tree fails due to wc whitespace","startedAt":"2011-12-14T14:35:55Z","lastAt":"2011-12-20T09:17:41Z","messageCount":8,"participants":["Brian Gernhardt","Stefano Lattarini","Hallvard Breien Furuseth","Johannes Sixt","Thomas Rast","Andreas Schwab"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"181140","messageId":"7F1792D2-8ED4-4546-8ED4-52B95E0AE9FC@silverinsanity.com","threadId":"29164","inReplyTo":null,"subject":"t0090-cache-tree fails due to wc whitespace","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2011-12-14T14:35:55Z","receivedAt":"2011-12-14T14:35:55Z","isPatch":false,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"It's time for my periodic complaint:  People assuming `wc -l` outputs just a number.  wc on OS X (and perhaps other BSD-like systems) always aligns the output in columns, even with the -l flag.  Generally this results in a quick patch from me to remove some unneeded quotes.  However, this time it's used in a more complex manner:\n\n\techo \"SHA \" \\\n\t    \"($(git ls-files|wc -l) entries, 0 subtrees)\" >expect &&\n\tcmp_cache_tree expect\n\nThis results in errors like:\n\n--- expect\t2011-12-14 14:26:26.000000000 +0000\n+++ filtered\t2011-12-14 14:26:26.000000000 +0000\n@@ -1 +1 @@\n-SHA  (       1 entries, 0 subtrees)\n+SHA  (1 entries, 0 subtrees)\n\nI was able to fix this by adding a sed command to remove leading spaces:\n\n-           \"($(git ls-files|wc -l) entries, 0 subtrees)\" >expect &&\n+           \"($(git ls-files|wc -l|sed -e 's/^ *//') entries, 0 subtrees)\" >expect &&\n\nBut I'm not sure if this is the best way to solve the issue.\n\n~~ Brian Gernhardt\n"},{"id":"181142","messageId":"201112141557.26794.stefano.lattarini@gmail.com","threadId":"29164","inReplyTo":"7F1792D2-8ED4-4546-8ED4-52B95E0AE9FC@silverinsanity.com","subject":"Re: t0090-cache-tree fails due to wc whitespace","fromName":"Stefano Lattarini","fromEmail":"stefano.lattarini@gmail.com","sentAt":"2011-12-14T14:57:26Z","receivedAt":"2011-12-14T14:57:26Z","isPatch":false,"sender":{"key":"stefano.lattarini@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1429199?v=4"},"body":"On Wednesday 14 December 2011, Brian Gernhardt wrote:\n> It's time for my periodic complaint:  People assuming `wc -l`\n> outputs just a number.  wc on OS X (and perhaps other BSD-like\n> systems) always aligns the output in columns, even with the -l\n> flag.\n>\nIt surely does so on Solaris 10 as well:\n\n$ echo x | wc -l\n       1\n$ for i in {1..1000}; do echo x; done | wc -l\n    1000\n\nRegards,\n  Stefano\n"},{"id":"181143","messageId":"hbf.20111214ogjn@bombur.uio.no","threadId":"29164","inReplyTo":"7F1792D2-8ED4-4546-8ED4-52B95E0AE9FC@silverinsanity.com","subject":"Re: t0090-cache-tree fails due to wc whitespace","fromName":"Hallvard Breien Furuseth","fromEmail":"h.b.furuseth@usit.uio.no","sentAt":"2011-12-14T15:09:47Z","receivedAt":"2011-12-14T15:09:47Z","isPatch":false,"sender":{"key":"h.b.furuseth@usit.uio.no","avatar":null},"body":"Brian Gernhardt writes:\n> I was able to fix this by adding a sed command to remove leading spaces:\n> \n> -           \"($(git ls-files|wc -l) entries, 0 subtrees)\" >expect &&\n> +           \"($(git ls-files|wc -l|sed -e 's/^ *//') entries, 0 subtrees)\" >expect &&\n> \n> But I'm not sure if this is the best way to solve the issue.\n\nWell,  tr -d ' '  saves all of 7 characters from  sed -e 's/^ *//'.\n\n-- \nHallvard\n"},{"id":"181150","messageId":"4EE8C3AD.9050605@viscovery.net","threadId":"29164","inReplyTo":"7F1792D2-8ED4-4546-8ED4-52B95E0AE9FC@silverinsanity.com","subject":"Re: t0090-cache-tree fails due to wc whitespace","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2011-12-14T15:41:33Z","receivedAt":"2011-12-14T15:41:33Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 12/14/2011 15:35, schrieb Brian Gernhardt:\n> It's time for my periodic complaint:  People assuming `wc -l` outputs\n> just a number.  wc on OS X (and perhaps other BSD-like systems) always\n> aligns the output in columns, even with the -l flag.  Generally this\n> results in a quick patch from me to remove some unneeded quotes.\n> However, this time it's used in a more complex manner:\n> \n> \techo \"SHA \" \\\n> \t    \"($(git ls-files|wc -l) entries, 0 subtrees)\" >expect &&\n> \tcmp_cache_tree expect\n\nI'd solve it by moving the command substitution outside the quoted string:\n\n \tprintf \"SHA (%d entries, 0 subtrees)\\n\" \\\n\t\t$(git ls-files | wc -l) >expect &&\n\nOther proposed solutions add another process. I don't like that on Windows ;)\n\n-- Hannes\n"},{"id":"181151","messageId":"201112141643.06656.trast@student.ethz.ch","threadId":"29164","inReplyTo":"7F1792D2-8ED4-4546-8ED4-52B95E0AE9FC@silverinsanity.com","subject":"Re: t0090-cache-tree fails due to wc whitespace","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2011-12-14T15:43:06Z","receivedAt":"2011-12-14T15:43:06Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Brian Gernhardt wrote:\n> \n> It's time for my periodic complaint: People assuming `wc -l` outputs\n> just a number.  wc on OS X (and perhaps other BSD-like systems)\n> always aligns the output in columns, even with the -l flag.\n\nOops.\n\n> Generally this results in a quick patch from me to remove some\n> unneeded quotes.  However, this time it's used in a more complex\n> manner:\n[...]\n> -           \"($(git ls-files|wc -l) entries, 0 subtrees)\" >expect &&\n> +           \"($(git ls-files|wc -l|sed -e 's/^ *//') entries, 0 subtrees)\" >expect &&\n\nI'm tempted to say we should define\n\ntest_wc_l () {\n\ttest $# = 0 || error \"bug in test script: passing arguments to wc -l is not portable\"\n\twc -l | tr -d -c 0-9\n}\n\njust to avoid issues if any wc comes across and prints a tab for\npadding or says \"hi, the number of lines you wanted to know is: 42\".\n\n\n\n(Oddly, according to 'man 1p wc' here, the POSIXly correct format in\nthe absence of options is\n\n  \"%d %d %d %s\\n\", <newlines>, <words>, <bytes>, <file>\n\nTaking it literally would mean no padding/alignment whatsoever.\nNeither GNU wc on my Linux exactly conforms to this.)\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"181153","messageId":"m2ehw7jgis.fsf@igel.home","threadId":"29164","inReplyTo":"201112141643.06656.trast@student.ethz.ch","subject":"Re: t0090-cache-tree fails due to wc whitespace","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2011-12-14T15:54:03Z","receivedAt":"2011-12-14T15:54:03Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Thomas Rast <trast@student.ethz.ch> writes:\n\n> (Oddly, according to 'man 1p wc' here, the POSIXly correct format in\n> the absence of options is\n>\n>   \"%d %d %d %s\\n\", <newlines>, <words>, <bytes>, <file>\n>\n> Taking it literally would mean no padding/alignment whatsoever.\n> Neither GNU wc on my Linux exactly conforms to this.)\n\nA space in the format string stands for one or more <blank>s.  If only a\nsingle <space> is allowed the standard uses 𝚫.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"181515","messageId":"4EF04635.6020406@viscovery.net","threadId":"29164","inReplyTo":"4EE8C3AD.9050605@viscovery.net","subject":"[PATCH] t0090: be prepared that 'wc -l' writes leading blanks","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2011-12-20T08:24:21Z","receivedAt":"2011-12-20T08:24:21Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"From: Johannes Sixt <j6t@kdbg.org>\n\nUse 'printf %d $(whatever|wc -l)' so that the shell removes the blanks\nfor us.\n\nSigned-off-by: Johannes Sixt <j6t@kdbg.org>\n---\nAm 12/14/2011 16:41, schrieb Johannes Sixt:\n> I'd solve it by moving the command substitution outside the quoted string:\n> \n>  \tprintf \"SHA (%d entries, 0 subtrees)\\n\" \\\n> \t\t$(git ls-files | wc -l) >expect &&\n> \n> Other proposed solutions add another process. I don't like that on Windows ;)\n\nAnd here is a proper patch to that effect.\n\n-- Hannes\n\n t/t0090-cache-tree.sh |    6 ++----\n 1 files changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh\nindex f972562..6c33e28 100755\n--- a/t/t0090-cache-tree.sh\n+++ b/t/t0090-cache-tree.sh\n@@ -17,15 +17,13 @@ cmp_cache_tree () {\n # test-dump-cache-tree already verifies that all existing data is\n # correct.\n test_shallow_cache_tree () {\n-\techo \"SHA \" \\\n-\t    \"($(git ls-files|wc -l) entries, 0 subtrees)\" >expect &&\n+\tprintf \"SHA  (%d entries, 0 subtrees)\\n\" $(git ls-files|wc -l) >expect &&\n \tcmp_cache_tree expect\n }\n \n test_invalid_cache_tree () {\n \techo \"invalid                                   (0 subtrees)\" >expect &&\n-\techo \"SHA #(ref) \" \\\n-\t    \"($(git ls-files|wc -l) entries, 0 subtrees)\" >>expect &&\n+\tprintf \"SHA #(ref)  (%d entries, 0 subtrees)\\n\" $(git ls-files|wc -l) >>expect &&\n \tcmp_cache_tree expect\n }\n \n-- \n1.7.8.1499.g39f909\n"},{"id":"181519","messageId":"87d3bjlhze.fsf@thomas.inf.ethz.ch","threadId":"29164","inReplyTo":"4EF04635.6020406@viscovery.net","subject":"Re: [PATCH] t0090: be prepared that 'wc -l' writes leading blanks","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2011-12-20T09:17:41Z","receivedAt":"2011-12-20T09:17:41Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Sorry for slacking off on replying to this thread...\n\nJohannes Sixt <j.sixt@viscovery.net> writes:\n> Use 'printf %d $(whatever|wc -l)' so that the shell removes the blanks\n> for us.\n>\n> Signed-off-by: Johannes Sixt <j6t@kdbg.org>\n> ---\n> Am 12/14/2011 16:41, schrieb Johannes Sixt:\n>> I'd solve it by moving the command substitution outside the quoted string:\n>> \n>>  \tprintf \"SHA (%d entries, 0 subtrees)\\n\" \\\n>> \t\t$(git ls-files | wc -l) >expect &&\n>> \n>> Other proposed solutions add another process. I don't like that on Windows ;)\n>\n> And here is a proper patch to that effect.\n\nAcked-by: Thomas Rast <trast@student.ethz.ch>\n\nThis is the best solution also because it the formatting more (instead\nof less) readable.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"}]}