Re: [PATCH v6] [GSOC] trailer: add new trailer.<token>.cmd config option
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Apr 4, 2021, 08:52 UTC
- Message-ID
- <CAP8UFD1=v_dfjKT2zY2=DFhZO1RWh9-++m5gAOn5WmwuV2pJXg@mail.gmail.com>
- In-Reply-To
- <CAOLTT8QvPPJ4jYXjch+RhdHDnvDT6Woh2oQoX2LcoiVX_t7jZQ@mail.gmail.com>
On Sun, Apr 4, 2021 at 7:44 AM ZheNing Hu <adlternative@gmail.com> wrote:
Show 8 quoted lines
> This may be an off-topic question: > I wanted to use `shortlog -s` instead of the document example, > But I found a very strange place: > Here we have two shell scripts: > > $ cat ~/bin/gcount > #!/bin/sh > if test "$1" != ""
It's better to use `test -n "$1"` instead of `test "$1" != ""`.
Show 37 quoted lines
> then > git log -1 --author="$1" > else > echo "hello there" > fi > > cat ~/bin/gcount2 > #!/bin/sh > if test "$1" != "" > then > git shortlog -1 --author="$1" > else > echo "hello there" > fi > > If I use them in the terminal, there is no problem with them, > > $ ~/bin/gcount gitster > commit 142430338477d9d1bb25be66267225fb58498d92 > (interpret-trailers-command-arg, abc5b) > Author: Junio C Hamano <gitster@pobox.com> > Date: Mon Mar 22 14:00:00 2021 -0700 > > The second batch > > Signed-off-by: Junio C Hamano <gitster@pobox.com> > > $ ~/bin/gcount2 gitster > Junio C Hamano (1): > The second batch > > if I use .cmd to run these scripts, the situation is totally different: > > $ git config -l | grep trailer > trailer.cnt.ifexists=add > trailer.cnt.key=Cnt: > trailer.cnt.cmd=~/bin/gcount
The script/command used in ".cmd" or ".command" should really return a short string with no newline or line feed char in it. Here your script can return multiple lines which could mess things up and be difficult to understand.
Show 21 quoted lines
> $ git interpret-trailers --trailer="cnt:gitster" <<EOF > EOF > > Cnt: hello there > Cnt: commit 142430338477d9d1bb25be66267225fb58498d92 > Author: Junio C Hamano <gitster@pobox.com> > Date: Mon Mar 22 14:00:00 2021 -0700 > > The second batch > > Signed-off-by: Junio C Hamano <gitster@pobox.com> > > And if I turn to use gcount2: > $ git config trailer.cnt.cmd "~/bin/gcount2" > $ git interpret-trailers --trailer="cnt:gitster" <<EOF > EOF > > Cnt: hello there > Cnt: > > It looks like `shortlog` does not write to standard output.
In shortlog's doc there is:
"If no revisions are passed on the command line and either standard input is not a terminal or there is no current branch, git shortlog will output a summary of the log read from standard input, without reference to the current repository."
I guess that's what's happening here.
> Note that in `short_log.c`, log will be output to `log->file`. > Does it make the above behavior different? > Is there a good solution?
I would try to pass a revision on the command line.