Hi, Christian and Junio, Christian Couder <christian.couder@xxxxxxxxx> 于2021年4月13日周二 下午3:33写道: > > On Mon, Apr 12, 2021 at 10:51 PM Junio C Hamano <gitster@xxxxxxxxx> wrote: > > > > "ZheNing Hu via GitGitGadget" <gitgitgadget@xxxxxxxxx> writes: > > > > > +For consistency, the $1 is also passed, this time with the empty string, > > > +in the command when the command is first called to add a trailer with > > > +the specified <token>. > > > > I guess the same question as 1/2 applies to this part. I am not > > sure what "consistency" the behaviour of calling the configured > > command with no argument is trying to achieve. To me, .cmd doing > > this may be for consistency with .command but I am not sure why > > the consistency is even desirable. > > It might be desirable to make it easier for people to migrate from > ".command" to ".cmd". I agree this is debatable, but I don't see a big > downside in it. Maybe, if no argument was passed at all the first time > the command is called instead of the empty string, the command could > then know that it's called for the first time. I am not sure this > would be very helpful in practice though. > If i'm not wrong, Christan meant that this command must run so it's "consistency", and Junio thinks this "consistency" is not needed. It is true that there is not much harm in keeping `.cmd` at the behavior of `.command` now. But I remember the `trailer.<token>.runmode` that Christan said before, perhaps adding it in the subsequent iterations can solve Junio's doubts. Sometimes I also confirm that the behavior of `git interpret-trailers` is very strange too. > > > +$ cat ~/bin/gcount > > > +#!/bin/sh > > > +test -n "$1" && git shortlog -s --author="$1" HEAD || true > > > +$ git config trailer.cnt.key "Commit-count: " > > > +$ git config trailer.cnt.ifExists "replace" > > > +$ git config trailer.cnt.cmd "~/bin/gcount" > > > +$ git interpret-trailers --trailer="cnt:Junio" <<EOF > > > +> subject > > > +> > > > +> message > > > +> > > > +> EOF > > > +subject > > > + > > > +message > > > + > > > +Commit-count: 22484 Junio C Hamano > > > +------------ > > > > This and the other (omitted) example demonstrates how the initial > > "empty" invocation is useless by using "replace". Which also means > > that you cannot add more than one trailer of the same <key> with the > > mechanism (since the older ones are replaced with the latest). > > You can add more than one trailer with the same key if you don't use > "replace" but use "--trim-empty" on the command line, so that an empty > trailer added by the initial invocation is removed. And we can later > add a `trailer.<token>.runMode` to remove the initial invocation. > Yes, something like: trailer.see.command=echo "$ARG" git interpret-trailers --trim-empty --trailer="see = lll" --trailer="see:jj"</dev/null see: lll see: jj > > The code change and the test change are consistent with the design, > > though. > > Yeah, this patch looks good to me now. > > Thanks! So is there anything else should I improve? Thanks. -- ZheNing Hu