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

Re: [PATCH v3 4/4] trace.c: be smart about what env to print in trace_run_command()

From
Jeff King <peff@peff.net>
Date
Jan 12, 2018, 13:33 UTC
Message-ID
<20180112133355.GE27499@sigill.intra.peff.net>
In-Reply-To
<20180112095607.18293-5-pclouds@gmail.com>
On Fri, Jan 12, 2018 at 04:56:07PM +0700, Nguyễn Thái Ngọc Duy wrote:
Show 8 quoted lines
> The previous concatenate_env() is kinda dumb. It receives a env delta
> in child_process and blindly follows it. If the run_command() user
> "adds" more vars of the same value, or deletes vars that do not exist
> in parent env in the first place (*), then why bother to print them?
> 
> This patch checks child_process.env against parent environment and
> only print the actual differences. The unset syntax (and later on cwd)
> follows closely shell syntax for easy reading/guessing and copy/paste.
I like it.
Show 11 quoted lines
> There is an interesting thing with this change. In the previous patch,
> we unconditionally print new vars. With submodule code we may have
> something like this
> 
>     trace: ... GIT_DIR='.git' git 'status' '--porcelain=2'
> 
> but since parent's GIT_DIR usually has the same value '.git' too, this
> change suppress that, now we can't see that the above command runs in
> a separate repo. This is the run for printing cwd. Now we have
> 
>     trace: ... cd foo; git 'status' '--porcelain=2'
Makes sense (though s/run/reason/ in the last paragraph?).
> Another equally interesting thing is, some caller can do "unset GIT_DIR;
> set GIT_DIR=.git". Since parent env can have the same value '.git', we
> don't re-print GIT_DIR=.git. In that case must NOT print "unset GIT_DIR"
> or the user will be misled to think the new command has no GIT_DIR.

Interesting. I wonder if any callers actually do that. It seems like kind of an odd thing, but maybe a caller sets GIT_DIR on top of the clearing of local_repo_env.

> A note about performance. Yes we're burning a lot more cycles for
> displaying something this nice. But because it's protected by
> $GIT_TRACE, and run_command() should not happen often anyway, it should
> not feel any slower than before.
I'd agree that performance probably doesn't matter much here.
Show 7 quoted lines
> +		/*
> +		 * Do we have a sequence of "unset GIT_DIR; GIT_DIR=foo"?
> +		 * Then don't bother with the unset thing.
> +		 */
> +		if (i + 1 < envs.nr &&
> +		    !strcmp(env, envs.items[i + 1].string))
>  			continue;

Are we guaranteed that "FOO" and "FOO=bar" appear next to each other in the sorted list? I think "FOO123=bar" could come between.

I also think this is a special case of a more general problem. FOO could appear any number of times in the "env" array, as a deletion or with multiple values. Our prep_childenv() would treat that as "last one wins", I think. Could we just do the same here?

-Peff
Previous: Nguyễn Thái Ngọc DuyNext: Junio C Hamano
Message 21 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.