From: Christian Couder Date: Fri, 09 Apr 2021 20:18:57 GMT Subject: Re: [PATCH v8 2/2] [GSOC] trailer: add new .cmd config option Message-ID: In-Reply-To: <3dc8983a47020fb417bb8c6c3d835e609b13c155.1617975462.git.gitgitgadget@gmail.com> On Fri, Apr 9, 2021 at 3:37 PM ZheNing Hu via GitGitGadget wrote: > > From: ZheNing Hu > > The `trailer..command` configuration variable > specifies a command (run via the shell, so it does not have > to be a single name of or path to the command, but can be a s/of or/or/ > shell script), and the first occurrence of substring $ARG is > replaced with the value given to the `interpret-trailer` > command for the token. This has two downsides: Maybe: s/for the token/for the token in a '--trailer =' argument/ > * The use of $ARG in the mechanism misleads the users that > the value is passed in the shell variable, and tempt them > to use $ARG more than once, but that would not work, as > the second and subsequent $ARG are not replaced. > > * Because $ARG is textually replaced without regard to the > shell language syntax, even '$ARG' (inside a single-quote > pair), which a user would expect to stay intact, would be > replaced, and worse, if the value had an unmatched single > quote (imagine a name like "O'Connor", substituted into > NAME='$ARG' to make it NAME='O'Connor'), it would result in > a broken command that is not syntactically correct (or > worse). > > Introduce a new `trailer..cmd` configuration that > takes higher precedence to deprecate and eventually remove > `trailer..command`, which passes the value as an > argument to the command. Instead of "$ARG", users can > refer to the value as positional argument, $1, in their > scripts. Good! > Helped-by: Junio C Hamano > Helped-by: Christian Couder > Signed-off-by: ZheNing Hu > --- > Documentation/git-interpret-trailers.txt | 90 ++++++++++++++++++++---- > t/t7513-interpret-trailers.sh | 84 ++++++++++++++++++++++ > trailer.c | 37 +++++++--- > 3 files changed, 187 insertions(+), 24 deletions(-) > > diff --git a/Documentation/git-interpret-trailers.txt b/Documentation/git-interpret-trailers.txt > index 3e5aa3a65ae9..1a874a93f49b 100644 > --- a/Documentation/git-interpret-trailers.txt > +++ b/Documentation/git-interpret-trailers.txt > @@ -236,21 +236,38 @@ trailer..command:: > be called to automatically add or modify a trailer with the > specified . > + > -When this option is specified, the behavior is as if a special > -'--trailer =' argument was added at the beginning of > -the "git interpret-trailers" command, where is taken to be the > -standard output of the specified command with any leading and trailing > -whitespace trimmed off. > +When this option is specified, the first occurrence of substring $ARG is > +replaced with the value given to the `interpret-trailer` command for the > +same token. It passes the value through `$ARG`, otherwise this option behaves > +in the same way as 'trailer..cmd'. Actually I think that we should say first that this behaves in the same way as the 'trailer..cmd'. And this should also replace the first paragraph in the description of 'trailer..command', not just the second one. Maybe: "This option behaves in the same way as 'trailer..cmd', except that it doesn't pass anything as argument to the specified command. Instead the first occurrence of substring $ARG is replaced by the value that would be passed as argument." > +The 'trailer..command' option has been deprecated due to the fact s/deprecated/deprecated in favor of 'trailer..cmd'/ > +that $ARG in the user's command can only be replaced once and that the s/can only be/is only/ > +original way of replacing $ARG was not safe. s/was/is/ > Now the preferred option is 'trailer..cmd', which uses a positional argument to pass the value. I think we can remove this sentence especially if we say "deprecated in favor of 'trailer..cmd'" above. > -The first occurrence of substring `$ARG` will be replaced with the > - part of an existing trailer with the same , if any, > -before the command is launched. > +When both 'trailer..cmd' and 'trailer..command' are given > +for the same , 'trailer..cmd' is used and > +'trailer..command' is ignored. Ok. > +trailer..cmd:: I think we should base the description of this option on what I suggest in patch 1/2. So let's agree on patch 1/2 before discussing this.