Re: [PATCH v6] [GSOC] trailer: add new trailer.<token>.cmd config option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Apr 4, 2021 at 7:44 AM ZheNing Hu <adlternative@xxxxxxxxx> wrote:

> 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" != ""`.

> 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@xxxxxxxxx>
> Date:   Mon Mar 22 14:00:00 2021 -0700
>
>     The second batch
>
>     Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
>
> $ ~/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.

> $ git interpret-trailers --trailer="cnt:gitster" <<EOF
> EOF
>
> Cnt: hello there
> Cnt: commit 142430338477d9d1bb25be66267225fb58498d92
> Author: Junio C Hamano <gitster@xxxxxxxxx>
> Date:   Mon Mar 22 14:00:00 2021 -0700
>
>     The second batch
>
>     Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
>
> 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.



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux