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

Re: [PATCH v13] [GSOC] commit: add --trailer option

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 23, 2021, 17:11 UTC
Message-ID
<xmqqeeg54wye.fsf@gitster.g>
In-Reply-To
<CAP8UFD0s4Gm3PgDPpsXC-8Gyrnn1JTMUBu60XGV7i8nRDCCJ2Q@mail.gmail.com>
Christian Couder <christian.couder@gmail.com> writes:
Show 22 quoted lines
> On Tue, Mar 23, 2021 at 7:19 AM Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Christian Couder <christian.couder@gmail.com> writes:
>>
>> > If you want nothing to happen when $ARG isn't set, you can change the
>> > config option to something like:
>> >
>> > $ git config trailer.sign.command "NAME='\$ARG'; test -n \"\$NAME\" &&
>> > git log --author=\"\$NAME\" -1 --format='format:%aN <%aE>' || true"
>> >
>> > (This is because it looks like $ARG is replaced only once with the
>> > actual value, which is perhaps a bug. Otherwise something like the
>> > following might work:
>>
>> I do not know the origin of that code in trailers.c but it feels
>> quite confused and error prone to use textual replacement with
>> strbuf_replace().  Why doesn't the code, which knows it will use
>> shell to execute the command line given by the end user in the
>> configuration, to just export ARG as an environment variable and
>> be done with it?  It would also avoid quoting problem etc.
>
> Yeah, I agree that would be better.

It probably would have been better to do so before the feature got unleased to the public, but doing such a change retroactively would introduce regression for those who were using ARG that happens to be safe from shell quoting rules.

For example, if the trailer.*.command were
	echo '$ARG'

and the argument 'h e l l o' were to be given to it, then the current code would have textually expanded $ARG with the argument and caused

	echo 'h e l l o'
to run, which would have been "fine" [*1*].

But exporting the environment ARG would "break" such a setting that has been "working perfectly well" for the user. Because of the single-quotes around $ARG, the command now will give literal four letter string $ARG and not 'h e l l o'.

We should think such potential ramifications of changing it (and also not changing it) through before deciding what to do about it.

Although I have a feeling that not many people would miss '$ARG' inside a pair of single-quotes to be replaced textually and it would be OK to make a backward incompatible bugfix, the safer and better way is not all that difficult, so I am inclined to suggest going the usual "deprecate and replace and then later remove" dance.

The normal sequence of replacing a "sort of works but not recommended" feature with a "better and safer, but can break a setting that has been 'working'" feature is:

 - Announce deprecation of trailer.x.command and add and advertise a
   similar traier.x.cmd that (1) exports environment variable ARG,
   or (2) passes the argument as a positional parameter [*], as a
   replacement.  Explain the reason for deprecation (i.e. unsafe
   substitution that works only once).  When .cmd exists, .command
   is ignored for the corresponding trailer.x
 - Wait for a few releases and then remove trailer.x.command.
and that is the safest way to fix this "bug".
[Footnotes]
*1* If the argument were 
	';rm -rf .;'
    then it wouldn't have been fine, though, and that is how the
    current code solicited "Huh?"  reaction out of me.
*2* If we passed the argument as a positional parameter, the example
    you gave in the quoted part of the message would become
    something like this:
      [trailer "sign"]
        cmd = test -n "$1" && git log --author="$1" -1 --format='%aN <%aE>'
Previous: Christian CouderNext: ZheNing Hu
Message 74 of 84 in “[GSOC] commit: provides multiple common signatures”
  1. [GSOC] commit: provides multiple common signaturesZheNing Hu via GitGitGadget, Mar 11, 2021
  2. Shourya ShuklaMar 11, 2021
  3. ZheNing HuMar 12, 2021
  4. Junio C HamanoMar 11, 2021
  5. ZheNing HuMar 12, 2021
  6. ZheNing HuMar 12, 2021
  7. [GSOC] commit: add trailer commandZheNing Hu via GitGitGadget, Mar 12, 2021
  8. Christian CouderMar 14, 2021
  9. ZheNing HuMar 14, 2021
  10. Junio C HamanoMar 14, 2021
  11. [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 14, 2021
  12. Rafael SilvaMar 14, 2021
  13. ZheNing HuMar 14, 2021
  14. [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 14, 2021
  15. Junio C HamanoMar 14, 2021
  16. ZheNing HuMar 15, 2021
  17. Junio C HamanoMar 15, 2021
  18. ZheNing HuMar 15, 2021
  19. [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 15, 2021
  20. Christian CouderMar 15, 2021
  21. Christian CouderMar 15, 2021
  22. ZheNing HuMar 15, 2021
  23. [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 15, 2021
  24. Christian CouderMar 15, 2021
  25. ZheNing HuMar 15, 2021
  26. [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 15, 2021
  27. Christian CouderMar 15, 2021
  28. Christian CouderMar 15, 2021
  29. ZheNing HuMar 15, 2021
  30. Christian CouderMar 16, 2021
  31. ZheNing HuMar 16, 2021
  32. 0/2 [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 15, 2021
  33. 1/2 [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 15, 2021
  34. Ævar Arnfjörð BjarmasonMar 16, 2021
  35. ZheNing HuMar 17, 2021
  36. Ævar Arnfjörð BjarmasonMar 17, 2021
  37. ZheNing HuMar 17, 2021
  38. 2/2 interpret_trailers: for three options parse add warningZheNing Hu via GitGitGadget, Mar 15, 2021
  39. Christian CouderMar 16, 2021
  40. ZheNing HuMar 16, 2021
  41. [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 16, 2021
  42. Shourya ShuklaMar 17, 2021
  43. ZheNing HuMar 17, 2021
  44. 0/3 [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 18, 2021
  45. 1/3 [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 18, 2021
  46. Đoàn Trần Công DanhMar 18, 2021
  47. ZheNing HuMar 19, 2021
  48. 2/3 interpret-trailers: add own-identity optionZheNing Hu via GitGitGadget, Mar 18, 2021
  49. Đoàn Trần Công DanhMar 18, 2021
  50. ZheNing HuMar 19, 2021
  51. Junio C HamanoMar 18, 2021
  52. ZheNing HuMar 19, 2021
  53. Junio C HamanoMar 19, 2021
  54. ZheNing HuMar 20, 2021
  55. Jeff KingMar 20, 2021
  56. Junio C HamanoMar 20, 2021
  57. ZheNing HuMar 20, 2021
  58. ZheNing HuMar 20, 2021
  59. Junio C HamanoMar 20, 2021
  60. ZheNing HuMar 20, 2021
  61. 3/3 commit: add own-identity optionZheNing Hu via GitGitGadget, Mar 18, 2021
  62. Christian CouderMar 18, 2021
  63. ZheNing HuMar 18, 2021
  64. [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 19, 2021
  65. Junio C HamanoMar 19, 2021
  66. [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 20, 2021
  67. [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 22, 2021
  68. Christian CouderMar 22, 2021
  69. ZheNing HuMar 22, 2021
  70. Christian CouderMar 22, 2021
  71. ZheNing HuMar 23, 2021
  72. Junio C HamanoMar 23, 2021
  73. Christian CouderMar 23, 2021
  74. Junio C HamanoMar 23, 2021
  75. ZheNing HuMar 24, 2021
  76. ZheNing HuMar 23, 2021
  77. Christian CouderMar 23, 2021
  78. Junio C HamanoMar 23, 2021
  79. ZheNing HuMar 24, 2021
  80. Christian CouderMar 22, 2021
  81. ZheNing HuMar 23, 2021
  82. [GSOC] commit: add --trailer optionZheNing Hu via GitGitGadget, Mar 23, 2021
  83. Junio C HamanoMar 15, 2021
  84. ZheNing HuMar 15, 2021

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.