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

Re: [PATCH 2/3] trace2: trim whitespace in start message in perf target format

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 1, 2019, 21:34 UTC
Message-ID
<xmqqef24muxe.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<834ee95cd2fe919c7a5a2d3cc3d647cfdeebe9e6.1564603467.git.gitgitgadget@gmail.com>
"Jeff Hostetler via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 7 quoted lines
> From: Jeff Hostetler <jeffhost@microsoft.com>
>
> Trim leading/trailing whitespace from the command line
> printed in the "start" message in the perf target format.
>
> We use `sq_quote_argv_pretty()` to format the message
> and it adds a leading space to the output.  Trim that.

strbuf_trim() not just drops a single leading space, but removes consecutive spaces from both ends. But the first char after the SP comes from the first arg, and it can never be a whitespace (as a payload that begins with a whitespace will be quoted, so it will be a single quote), and the last char in the buffer would also be either a closing single quote (if the last argument ends with a whitespace) or a non whitespace "safe" character, so it is safe to use strbuf_trim() here.

I wonder if we want to lose the prepending of SP from sq_quote_argv_pretty(), though:

 * run-command.c::trace_run_command() does rely on having SP there,
   so the caller needs adjusting if we did so.
 * trace.c::trace_argv_vprintf_fl() also needs SP there after the
   caller supplied format.
 * trace.c::print_command_performance_atexit() expects command_line
   begins with the extra SP left by the sq_quote_argv_pretty()
   called by the trace_command_performance(); the format string
   given to trace_performance_leave() there needs adjusting.

By the way, use of sq_quote_argv_pretty() in builtin/rebase.c on opts->git_am_opts.argv done in run_specific_rebase() is dubious. The argv array is made into a single string that safely uses sq, appropriate to feed a shell. But that string is passed as the "value" parameter to add_var() helper that expects to receive a raw value (hence it calls sq_quote_buf() on the value), resulting in a string that is doubly quoted. I am not sure if that was intended.

In any case, the patch itself obviously look correct.
Show 17 quoted lines
> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
> ---
>  trace2/tr2_tgt_perf.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
> index 4a9d99218b..ed4e708f28 100644
> --- a/trace2/tr2_tgt_perf.c
> +++ b/trace2/tr2_tgt_perf.c
> @@ -185,6 +185,7 @@ static void fn_start_fl(const char *file, int line,
>  	struct strbuf buf_payload = STRBUF_INIT;
>  
>  	sq_quote_argv_pretty(&buf_payload, argv);
> +	strbuf_trim(&buf_payload);
>  
>  	perf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,
>  			 NULL, NULL, &buf_payload);
Previous: Jeff Hostetler via GitGitGadgetNext: Jeff Hostetler
Message 5 of 33 in “trace2: clean up formatting in perf target format”
  1. 0/3 trace2: clean up formatting in perf target formatJeff Hostetler via GitGitGadget, Jul 31, 2019
  2. 1/3 trace2: cleanup column alignment in perf target formatJeff Hostetler via GitGitGadget, Jul 31, 2019
  3. 3/3 trace2: trim whitespace in region messages in perf target formatJeff Hostetler via GitGitGadget, Jul 31, 2019
  4. 2/3 trace2: trim whitespace in start message in perf target formatJeff Hostetler via GitGitGadget, Jul 31, 2019
  5. Junio C HamanoAug 1, 2019
  6. Jeff HostetlerAug 7, 2019
  7. Junio C HamanoAug 7, 2019
  8. Josh SteadmonAug 1, 2019
  9. 0/7 trace2: clean up formatting in perf target formatJeff Hostetler via GitGitGadget, Aug 8, 2019
  10. 1/7 trace2: cleanup column alignment in perf target formatJeff Hostetler via GitGitGadget, Aug 8, 2019
  11. 3/7 trace2: remove dead code in maybe_add_string_va()Jeff Hostetler via GitGitGadget, Aug 8, 2019
  12. 6/7 trace2: cleanup whitespace in normal formatJeff Hostetler via GitGitGadget, Aug 8, 2019
  13. 5/7 quote: add sq_quote_argv_pretty_ltrimJeff Hostetler via GitGitGadget, Aug 8, 2019
  14. Junio C HamanoAug 8, 2019
  15. Jeff HostetlerAug 8, 2019
  16. Junio C HamanoAug 8, 2019
  17. René ScharfeAug 8, 2019
  18. Jeff HostetlerAug 9, 2019
  19. René ScharfeAug 9, 2019
  20. 7/7 trace2: cleanup whitespace in perf formatJeff Hostetler via GitGitGadget, Aug 8, 2019
  21. 4/7 trace2: trim trailing whitespace in normal format error messageJeff Hostetler via GitGitGadget, Aug 8, 2019
  22. 2/7 trace2: trim whitespace in region messages in perf target formatJeff Hostetler via GitGitGadget, Aug 8, 2019
  23. 0/7 trace2: clean up formatting in perf target formatJeff Hostetler via GitGitGadget, Aug 9, 2019
  24. 1/7 trace2: cleanup column alignment in perf target formatJeff Hostetler via GitGitGadget, Aug 9, 2019
  25. 2/7 trace2: trim whitespace in region messages in perf target formatJeff Hostetler via GitGitGadget, Aug 9, 2019
  26. 4/7 trace2: trim trailing whitespace in normal format error messageJeff Hostetler via GitGitGadget, Aug 9, 2019
  27. 6/7 trace2: cleanup whitespace in normal formatJeff Hostetler via GitGitGadget, Aug 9, 2019
  28. 7/7 trace2: cleanup whitespace in perf formatJeff Hostetler via GitGitGadget, Aug 9, 2019
  29. 3/7 trace2: remove dead code in maybe_add_string_va()Jeff Hostetler via GitGitGadget, Aug 9, 2019
  30. 5/7 quote: add sq_append_quote_argv_pretty()Jeff Hostetler via GitGitGadget, Aug 9, 2019
  31. Junio C HamanoAug 9, 2019
  32. Jeff HostetlerAug 9, 2019
  33. Junio C HamanoAug 9, 2019

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.