git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Sixt <j6t@kdbg.org>
To: Lars Schneider <larsxschneider@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, jnareb@gmail.com,
	peff@peff.net, ramsay@ramsayjones.plus.com, tboegi@web.de
Subject: [PATCH (optional)] t0021: use arithmetic expansion to trim whitespace from wc -c output
Date: Thu, 3 Nov 2016 21:22:26 +0100	[thread overview]
Message-ID: <3b58b90d-5435-1503-d052-413a947a5ab5@kdbg.org> (raw)
In-Reply-To: <fb4d62de-fbb5-a2b4-8eba-b135125dafa9@kdbg.org>

Instead of a pipeline with sed and a useless use of cat, return the
unmodified text of wc -c from function file_size, but substitute the
result with arithmetic expansion to get rid of the leading whitespace
that some version of wc -c print.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
This is a pure optimization that reduces the number of forks, which
helps a bit on Windows.

There would be a solution with perl that does not require trimming
of whitespace, but perl startup times are unbearable on Windows.
wc -c is better.

 t/t0021-conversion.sh | 50 +++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh
index db71acacb3..42b529f615 100755
--- a/t/t0021-conversion.sh
+++ b/t/t0021-conversion.sh
@@ -22,7 +22,7 @@ generate_random_characters () {
 }
 
 file_size () {
-	cat "$1" | wc -c | sed "s/^[ ]*//"
+	wc -c <"$1"
 }
 
 filter_git () {
@@ -369,10 +369,10 @@ test_expect_success PERL 'required process filter should filter data' '
 		cat >expected.log <<-EOF &&
 			START
 			init handshake complete
-			IN: clean test.r $S [OK] -- OUT: $S . [OK]
-			IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
+			IN: clean test.r $(($S)) [OK] -- OUT: $(($S)) . [OK]
+			IN: clean test2.r $(($S2)) [OK] -- OUT: $(($S2)) . [OK]
 			IN: clean test4-empty.r 0 [OK] -- OUT: 0  [OK]
-			IN: clean testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
+			IN: clean testsubdir/test3 '\''sq'\'',\$x.r $(($S3)) [OK] -- OUT: $(($S3)) . [OK]
 			STOP
 		EOF
 		test_cmp_count expected.log rot13-filter.log &&
@@ -381,14 +381,14 @@ test_expect_success PERL 'required process filter should filter data' '
 		cat >expected.log <<-EOF &&
 			START
 			init handshake complete
-			IN: clean test.r $S [OK] -- OUT: $S . [OK]
-			IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
+			IN: clean test.r $(($S)) [OK] -- OUT: $(($S)) . [OK]
+			IN: clean test2.r $(($S2)) [OK] -- OUT: $(($S2)) . [OK]
 			IN: clean test4-empty.r 0 [OK] -- OUT: 0  [OK]
-			IN: clean testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
-			IN: clean test.r $S [OK] -- OUT: $S . [OK]
-			IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
+			IN: clean testsubdir/test3 '\''sq'\'',\$x.r $(($S3)) [OK] -- OUT: $(($S3)) . [OK]
+			IN: clean test.r $(($S)) [OK] -- OUT: $(($S)) . [OK]
+			IN: clean test2.r $(($S2)) [OK] -- OUT: $(($S2)) . [OK]
 			IN: clean test4-empty.r 0 [OK] -- OUT: 0  [OK]
-			IN: clean testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
+			IN: clean testsubdir/test3 '\''sq'\'',\$x.r $(($S3)) [OK] -- OUT: $(($S3)) . [OK]
 			STOP
 		EOF
 		test_cmp_count expected.log rot13-filter.log &&
@@ -399,8 +399,8 @@ test_expect_success PERL 'required process filter should filter data' '
 		cat >expected.log <<-EOF &&
 			START
 			init handshake complete
-			IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
-			IN: smudge testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
+			IN: smudge test2.r $(($S2)) [OK] -- OUT: $(($S2)) . [OK]
+			IN: smudge testsubdir/test3 '\''sq'\'',\$x.r $(($S3)) [OK] -- OUT: $(($S3)) . [OK]
 			STOP
 		EOF
 		test_cmp_exclude_clean expected.log rot13-filter.log &&
@@ -409,7 +409,7 @@ test_expect_success PERL 'required process filter should filter data' '
 		cat >expected.log <<-EOF &&
 			START
 			init handshake complete
-			IN: clean test.r $S [OK] -- OUT: $S . [OK]
+			IN: clean test.r $(($S)) [OK] -- OUT: $(($S)) . [OK]
 			STOP
 		EOF
 		test_cmp_exclude_clean expected.log rot13-filter.log &&
@@ -418,10 +418,10 @@ test_expect_success PERL 'required process filter should filter data' '
 		cat >expected.log <<-EOF &&
 			START
 			init handshake complete
-			IN: smudge test.r $S [OK] -- OUT: $S . [OK]
-			IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
+			IN: smudge test.r $(($S)) [OK] -- OUT: $(($S)) . [OK]
+			IN: smudge test2.r $(($S2)) [OK] -- OUT: $(($S2)) . [OK]
 			IN: smudge test4-empty.r 0 [OK] -- OUT: 0  [OK]
-			IN: smudge testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
+			IN: smudge testsubdir/test3 '\''sq'\'',\$x.r $(($S3)) [OK] -- OUT: $(($S3)) . [OK]
 			STOP
 		EOF
 		test_cmp_exclude_clean expected.log rot13-filter.log &&
@@ -451,7 +451,7 @@ test_expect_success PERL 'required process filter takes precedence' '
 		cat >expected.log <<-EOF &&
 			START
 			init handshake complete
-			IN: clean test.r $S [OK] -- OUT: $S . [OK]
+			IN: clean test.r $(($S)) [OK] -- OUT: $(($S)) . [OK]
 			STOP
 		EOF
 		test_cmp_count expected.log rot13-filter.log
@@ -474,7 +474,7 @@ test_expect_success PERL 'required process filter should be used only for "clean
 		cat >expected.log <<-EOF &&
 			START
 			init handshake complete
-			IN: clean test.r $S [OK] -- OUT: $S . [OK]
+			IN: clean test.r $(($S)) [OK] -- OUT: $(($S)) . [OK]
 			STOP
 		EOF
 		test_cmp_count expected.log rot13-filter.log &&
@@ -603,11 +603,11 @@ test_expect_success PERL 'process filter should restart after unexpected write f
 		cat >expected.log <<-EOF &&
 			START
 			init handshake complete
-			IN: smudge smudge-write-fail.r $SF [OK] -- OUT: $SF [WRITE FAIL]
+			IN: smudge smudge-write-fail.r $(($SF)) [OK] -- OUT: $(($SF)) [WRITE FAIL]
 			START
 			init handshake complete
-			IN: smudge test.r $S [OK] -- OUT: $S . [OK]
-			IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
+			IN: smudge test.r $(($S)) [OK] -- OUT: $(($S)) . [OK]
+			IN: smudge test2.r $(($S2)) [OK] -- OUT: $(($S2)) . [OK]
 			STOP
 		EOF
 		test_cmp_exclude_clean expected.log rot13-filter.log &&
@@ -649,9 +649,9 @@ test_expect_success PERL 'process filter should not be restarted if it signals a
 		cat >expected.log <<-EOF &&
 			START
 			init handshake complete
-			IN: smudge error.r $SE [OK] -- OUT: 0 [ERROR]
-			IN: smudge test.r $S [OK] -- OUT: $S . [OK]
-			IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
+			IN: smudge error.r $(($SE)) [OK] -- OUT: 0 [ERROR]
+			IN: smudge test.r $(($S)) [OK] -- OUT: $(($S)) . [OK]
+			IN: smudge test2.r $(($S2)) [OK] -- OUT: $(($S2)) . [OK]
 			STOP
 		EOF
 		test_cmp_exclude_clean expected.log rot13-filter.log &&
@@ -688,7 +688,7 @@ test_expect_success PERL 'process filter abort stops processing of all further f
 		cat >expected.log <<-EOF &&
 			START
 			init handshake complete
-			IN: smudge abort.r $SA [OK] -- OUT: 0 [ABORT]
+			IN: smudge abort.r $(($SA)) [OK] -- OUT: 0 [ABORT]
 			STOP
 		EOF
 		test_cmp_exclude_clean expected.log rot13-filter.log &&
-- 
2.11.0.rc0.55.gd967357


  reply	other threads:[~2016-11-03 20:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-16 23:20 [PATCH v11 00/14] Git filter protocol larsxschneider
2016-10-16 23:20 ` [PATCH v11 01/14] convert: quote filter names in error messages larsxschneider
2016-10-16 23:20 ` [PATCH v11 02/14] convert: modernize tests larsxschneider
2016-10-16 23:20 ` [PATCH v11 03/14] run-command: move check_pipe() from write_or_die to run_command larsxschneider
2016-10-16 23:20 ` [PATCH v11 04/14] run-command: add clean_on_exit_handler larsxschneider
2016-10-16 23:20 ` [PATCH v11 05/14] pkt-line: rename packet_write() to packet_write_fmt() larsxschneider
2016-10-16 23:20 ` [PATCH v11 06/14] pkt-line: extract set_packet_header() larsxschneider
2016-10-16 23:20 ` [PATCH v11 07/14] pkt-line: add packet_write_fmt_gently() larsxschneider
2016-10-16 23:20 ` [PATCH v11 08/14] pkt-line: add packet_flush_gently() larsxschneider
2016-10-16 23:20 ` [PATCH v11 09/14] pkt-line: add packet_write_gently() larsxschneider
2016-10-16 23:20 ` [PATCH v11 10/14] pkt-line: add functions to read/write flush terminated packet streams larsxschneider
2016-10-16 23:20 ` [PATCH v11 11/14] convert: make apply_filter() adhere to standard Git error handling larsxschneider
2016-10-16 23:20 ` [PATCH v11 12/14] convert: prepare filter.<driver>.process option larsxschneider
2016-10-16 23:20 ` [PATCH v11 13/14] convert: add " larsxschneider
2016-11-02 18:03   ` Johannes Sixt
2016-11-03  0:41     ` Lars Schneider
2016-11-03 20:12       ` [PATCH] t0021: expect more variations in the output of uniq -c Johannes Sixt
2016-11-03 20:22         ` Johannes Sixt [this message]
2016-11-06 15:45           ` [PATCH (optional)] t0021: use arithmetic expansion to trim whitespace from wc -c output Lars Schneider
2016-11-06 19:31             ` Johannes Sixt
2016-11-06 19:43               ` Lars Schneider
2016-11-06 15:31         ` [PATCH] t0021: expect more variations in the output of uniq -c Lars Schneider
2016-11-06 21:40           ` Johannes Sixt
2016-10-16 23:20 ` [PATCH v11 14/14] contrib/long-running-filter: add long running filter example larsxschneider
2016-10-17 18:47 ` [PATCH v11 00/14] Git filter protocol Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3b58b90d-5435-1503-d052-413a947a5ab5@kdbg.org \
    --to=j6t@kdbg.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    --cc=larsxschneider@gmail.com \
    --cc=peff@peff.net \
    --cc=ramsay@ramsayjones.plus.com \
    --cc=tboegi@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).