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

Re: [PATCH] run-command.c: print env vars when GIT_TRACE is set

From
Duy Nguyen <pclouds@gmail.com>
Date
Jan 11, 2018, 11:13 UTC
Message-ID
<CACsJy8Beq2gx8K8Hk7NMVj_1Cgn5v-tuN9eZtDRCuOxB_urcWw@mail.gmail.com>
In-Reply-To
<20180111100734.GA17274@sigill.intra.peff.net>
On Thu, Jan 11, 2018 at 5:07 PM, Jeff King <peff@peff.net> wrote:
Show 34 quoted lines
> On Wed, Jan 10, 2018 at 05:48:35PM +0700, Nguyễn Thái Ngọc Duy wrote:
>
>> Occasionally submodule code could execute new commands with GIT_DIR set
>> to some submodule. GIT_TRACE prints just the command line which makes it
>> hard to tell that it's not really executed on this repository.
>>
>> Print env variables in this case. Note that the code deliberately ignore
>> variables unsetting because there are so many of them (to keep git
>> environment clean for the next process) and really hard to read.
>
> I like this, and I'm pretty sure it would have helped me debug at least
> once in the past. I did notice one funny thing, though I think it was
> largely there before.
>
> The output for a single command is pretty shell-like due to the quoting:
>
>   $ GIT_TRACE=1 ./git upload-pack . >/dev/null
>   [...]run_command: 'git-upload-pack' '.'
>
> You could copy and paste that to a shell if you wanted.  And with
> environment variables, that remains so:
>
>   $ GIT_TRACE=1 ./git ls-remote https://github.com/git/git >/dev/null
>   [...]run_command: 'GIT_DIR=.git' 'git-remote-https' 'https://[...]'
>
> But if we're actually running a command via the shell, it all gets
> quoted as one argument:
>
>   $ GIT_TRACE=1 GIT_PAGER='foo | bar' ./git log
>   [...]run_command: 'LV=-c' 'foo | bar'
>
> which is kind of weird, as that's not something that can be run in a
> shell. This isn't introduced by your patch at all, but I noticed it more
> because of the shell-like environment variable output.

I think you just found an argument to change my "meh" with regards to quoting to "need to fix" because I also often copy/paste these commands. I thought about it and assumed shells would still recognize 'name=value' assignments without actually testing it.

Show 16 quoted lines
> We actually used to print a separate:
>
>   exec: /bin/sh -c 'foo | bar'
>
> line when we invoked a shell, which would arguably be the right place to
> show the env variables for such a case. But that went away with
> 3967e25be1 (run-command: prepare command before forking, 2017-04-19).
>
> I think it might be helpful if we added back in "/bin/sh -c" to the
> run_command line when "use_shell" is in effect (and when we're not doing
> our "skip the shell" trickery).  But that's totally orthogonal to your
> patch.
>
> And anyway, it's just tracing output, so I don't think it's incredibly
> important either way. It was just something I noticed while looking at
> your patch's output.
Noted. I might do it if it's not super complex.
-- 
Duy
Previous: Jeff KingNext: Johannes Sixt
Message 73 of 74 in “run-command.c: print env vars when GIT_TRACE is set”
  1. run-command.c: print env vars when GIT_TRACE is setNguyễn Thái Ngọc Duy, Jan 10, 2018
  2. Brandon WilliamsJan 10, 2018
  3. Stefan BellerJan 10, 2018
  4. Brandon WilliamsJan 10, 2018
  5. Stefan BellerJan 10, 2018
  6. run-command.c: print env vars when GIT_TRACE is setNguyễn Thái Ngọc Duy, Jan 11, 2018
  7. Duy NguyenJan 11, 2018
  8. Brandon WilliamsJan 11, 2018
  9. Stefan BellerJan 11, 2018
  10. Junio C HamanoJan 11, 2018
  11. Duy NguyenJan 12, 2018
  12. 0/4 run-command.c: print env vars when GIT_TRACE is setNguyễn Thái Ngọc Duy, Jan 12, 2018
  13. 1/4 trace.c: introduce trace_run_command()Nguyễn Thái Ngọc Duy, Jan 12, 2018
  14. Jeff KingJan 12, 2018
  15. Jeff KingJan 12, 2018
  16. 2/4 trace.c: print program 'git' when child_process.git_cmd is setNguyễn Thái Ngọc Duy, Jan 12, 2018
  17. Jeff KingJan 12, 2018
  18. 3/4 trace.c: print env vars in trace_run_command()Nguyễn Thái Ngọc Duy, Jan 12, 2018
  19. Jeff KingJan 12, 2018
  20. 4/4 trace.c: be smart about what env to print in trace_run_command()Nguyễn Thái Ngọc Duy, Jan 12, 2018
  21. Jeff KingJan 12, 2018
  22. Junio C HamanoJan 12, 2018
  23. Jeff KingJan 12, 2018
  24. Junio C HamanoJan 12, 2018
  25. Jeff KingJan 12, 2018
  26. Brandon WilliamsJan 12, 2018
  27. Junio C HamanoJan 12, 2018
  28. Duy NguyenJan 13, 2018
  29. Duy NguyenJan 13, 2018
  30. Jeff KingJan 12, 2018
  31. 5/4 sq_quote_argv: drop maxlen parameterJeff King, Jan 12, 2018
  32. Junio C HamanoJan 12, 2018
  33. 6/4 trace: avoid unnecessary quotingJeff King, Jan 12, 2018
  34. Stefan BellerJan 12, 2018
  35. Stefan BellerJan 12, 2018
  36. Duy NguyenJan 13, 2018
  37. 0/7 Trace env variables in run_command()Nguyễn Thái Ngọc Duy, Jan 13, 2018
  38. 1/7 sq_quote_argv: drop maxlen parameterNguyễn Thái Ngọc Duy, Jan 13, 2018
  39. 2/7 trace: avoid unnecessary quotingNguyễn Thái Ngọc Duy, Jan 13, 2018
  40. 3/7 trace.c: move strbuf_release() out of print_trace_line()Nguyễn Thái Ngọc Duy, Jan 13, 2018
  41. Jeff KingJan 13, 2018
  42. 4/7 trace.c: introduce trace_run_command()Nguyễn Thái Ngọc Duy, Jan 13, 2018
  43. 5/7 trace.c: print program 'git' when child_process.git_cmd is setNguyễn Thái Ngọc Duy, Jan 13, 2018
  44. 6/7 trace.c: print env vars in trace_run_command()Nguyễn Thái Ngọc Duy, Jan 13, 2018
  45. Jeff KingJan 13, 2018
  46. Junio C HamanoJan 16, 2018
  47. Stefan BellerJan 16, 2018
  48. Junio C HamanoJan 17, 2018
  49. 7/7 trace.c: print new cwd in trace_run_command()Nguyễn Thái Ngọc Duy, Jan 13, 2018
  50. Jeff KingJan 13, 2018
  51. 0/7 Trace env variables in run_command()Nguyễn Thái Ngọc Duy, Jan 15, 2018
  52. 1/7 sq_quote_argv: drop maxlen parameterNguyễn Thái Ngọc Duy, Jan 15, 2018
  53. 2/7 trace: avoid unnecessary quotingNguyễn Thái Ngọc Duy, Jan 15, 2018
  54. 3/7 trace.c: move strbuf_release() out of print_trace_line()Nguyễn Thái Ngọc Duy, Jan 15, 2018
  55. Brandon WilliamsJan 16, 2018
  56. 4/7 trace.c: introduce trace_run_command()Nguyễn Thái Ngọc Duy, Jan 15, 2018
  57. Jeff KingJan 17, 2018
  58. Junio C HamanoJan 17, 2018
  59. 5/7 trace.c: print program 'git' when child_process.git_cmd is setNguyễn Thái Ngọc Duy, Jan 15, 2018
  60. 6/7 trace.c: print env vars in trace_run_command()Nguyễn Thái Ngọc Duy, Jan 15, 2018
  61. Brandon WilliamsJan 16, 2018
  62. 7/7 trace.c: print new cwd in trace_run_command()Nguyễn Thái Ngọc Duy, Jan 15, 2018
  63. 0/7 Trace env variables in run_command()Nguyễn Thái Ngọc Duy, Jan 18, 2018
  64. 1/7 sq_quote_argv: drop maxlen parameterNguyễn Thái Ngọc Duy, Jan 18, 2018
  65. 2/7 trace: avoid unnecessary quotingNguyễn Thái Ngọc Duy, Jan 18, 2018
  66. 3/7 trace.c: move strbuf_release() out of print_trace_line()Nguyễn Thái Ngọc Duy, Jan 18, 2018
  67. 4/7 run-command.c: introduce trace_run_command()Nguyễn Thái Ngọc Duy, Jan 18, 2018
  68. 5/7 run-command.c: print program 'git' when tracing git_cmd modeNguyễn Thái Ngọc Duy, Jan 18, 2018
  69. 6/7 run-command.c: print env vars in trace_run_command()Nguyễn Thái Ngọc Duy, Jan 18, 2018
  70. 7/7 run-command.c: print new cwd in trace_run_command()Nguyễn Thái Ngọc Duy, Jan 18, 2018
  71. Jeff KingJan 19, 2018
  72. Jeff KingJan 11, 2018
  73. Duy NguyenJan 11, 2018
  74. Johannes SixtJan 11, 2018

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.