git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH (optional)] t0021: use arithmetic expansion to trim whitespace from wc -c output

From
Lars Schneider <larsxschneider@gmail.com>
Date
Nov 6, 2016, 19:43 UTC
Message-ID
<283FAD19-35C3-4167-8946-A0F2A9CEDC57@gmail.com>
In-Reply-To
<b87ddffd-3de1-4481-b484-9f03a73b6ad1@kdbg.org>
Show 52 quoted lines
> On 06 Nov 2016, at 20:31, Johannes Sixt <j6t@kdbg.org> wrote:
> 
> Am 06.11.2016 um 16:45 schrieb Lars Schneider:
>> 
>>> On 03 Nov 2016, at 21:22, Johannes Sixt <j6t@kdbg.org> wrote:
>>> 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.
> 
> I was wrong here. I had looked at the perl invocations due to
> git-sendemail, and they are awfully slow. A do-almost-nothing perl
> invocation is in the same ballpark as wc. Therefore I changed my mind
> and suggest the patch below instead.
> 
>> Since the file size function became very simple with your patch,
>> shouldn't we get rid of it? If you agree, then we could squash the 
>> patch below into your patch.
> 
> In the new patch, the function is not that trivial (it uses perl), and
> the call sites can remain as they are (simple shell variables and
> substitutions).
> 
> ---- 8< ----
> [PATCH] t0021: compute file size with a single process instead of a pipeline
> 
> Avoid unwanted coding patterns (prodigal use of pipelines), and in
> particular a useless use of cat.
> 
> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> ---
> t/t0021-conversion.sh | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh
> index db71acacb3..cb72fa49de 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/^[ ]*//"
> +	perl -e 'print -s $ARGV[0]' "$1"
> }
> 
> filter_git () {
> -- 
> 2.11.0.rc0.55.gd967357
> 
I like this better, too. Looks good to me and works on macOS.

Thanks, Lars

Previous: Johannes SixtNext: Lars Schneider
Message 21 of 25 in “Git filter protocol”
  1. 00/14 Git filter protocollarsxschneider@gmail.com, Oct 16, 2016
  2. 01/14 convert: quote filter names in error messageslarsxschneider@gmail.com, Oct 16, 2016
  3. 02/14 convert: modernize testslarsxschneider@gmail.com, Oct 16, 2016
  4. 03/14 run-command: move check_pipe() from write_or_die to run_commandlarsxschneider@gmail.com, Oct 16, 2016
  5. 04/14 run-command: add clean_on_exit_handlerlarsxschneider@gmail.com, Oct 16, 2016
  6. 05/14 pkt-line: rename packet_write() to packet_write_fmt()larsxschneider@gmail.com, Oct 16, 2016
  7. 08/14 pkt-line: add packet_flush_gently()larsxschneider@gmail.com, Oct 16, 2016
  8. 07/14 pkt-line: add packet_write_fmt_gently()larsxschneider@gmail.com, Oct 16, 2016
  9. 06/14 pkt-line: extract set_packet_header()larsxschneider@gmail.com, Oct 16, 2016
  10. 09/14 pkt-line: add packet_write_gently()larsxschneider@gmail.com, Oct 16, 2016
  11. 10/14 pkt-line: add functions to read/write flush terminated packet streamslarsxschneider@gmail.com, Oct 16, 2016
  12. 11/14 convert: make apply_filter() adhere to standard Git error handlinglarsxschneider@gmail.com, Oct 16, 2016
  13. 12/14 convert: prepare filter.<driver>.process optionlarsxschneider@gmail.com, Oct 16, 2016
  14. 13/14 convert: add filter.<driver>.process optionlarsxschneider@gmail.com, Oct 16, 2016
  15. Johannes SixtNov 2, 2016
  16. Lars SchneiderNov 3, 2016
  17. t0021: expect more variations in the output of uniq -cJohannes Sixt, Nov 3, 2016
  18. t0021: use arithmetic expansion to trim whitespace from wc -c outputJohannes Sixt, Nov 3, 2016
  19. Lars SchneiderNov 6, 2016
  20. Johannes SixtNov 6, 2016
  21. Lars SchneiderNov 6, 2016
  22. Lars SchneiderNov 6, 2016
  23. Johannes SixtNov 6, 2016
  24. 14/14 contrib/long-running-filter: add long running filter examplelarsxschneider@gmail.com, Oct 16, 2016
  25. Junio C HamanoOct 17, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.