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

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

 



Christian Couder <christian.couder@xxxxxxxxx> 于2021年3月23日周二 上午5:34写道:
>
> On Mon, Mar 22, 2021 at 11:23 AM ZheNing Hu <adlternative@xxxxxxxxx> wrote:
> >
> > Christian Couder <christian.couder@xxxxxxxxx> 于2021年3月22日周一 下午3:43写道:
>
> > > Nice that you have added such a test!
> >
> > Thanks.
> >
> > But at the same time I have two little doubt.
> >
> > 1.
> > If we have your config:
> >
> > $ git config trailer.sign.key "Signed-off-by: "
> > $ git config trailer.sign.ifexists replace
> > $ git config trailer.sign.command "git log --author='\$ARG' -1
> > --format='format:%aN <%aE>'"
> >
> > Then I touch a test.c and use:
> >
> > $ git interpret-trailers --in-place test.c
> >
> > without `--trailer`, See what is happen:
> >
> > It seem like your local repo last commit "name <email>" pair
> > have been record in `test.c`.
> >
> > Could this be considered a bug?
>
> First it seems strange to use `git interpret-trailers` on a "test.c"
> file. It's supposed to be used on commit messages.
>
> Then, as the doc says, every command specified by any
> "trailer.<token>.command" config option is run at least once when `git
> interpret-trailers` is run. This is because users might want to
> automatically add some trailers all the time.
>

Well, I understand it now.

> 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:

this is because `$ARG` is replaced in "trailer.c" by "strbuf_replace" which
only replcae the specified string for only one time,
I think `strbuf_replace()` can be changed like:

@@ -110,8 +110,9 @@ static inline int is_blank_line(const char *str)

 static inline void strbuf_replace(struct strbuf *sb, const char *a,
const char *b)
 {
-       const char *ptr = strstr(sb->buf, a);
-       if (ptr)
+       char *ptr = sb->buf;
+
+       while ((ptr = strstr(ptr, a)))
                strbuf_splice(sb, ptr - sb->buf, strlen(a), b, strlen(b));
 }

>
> git config trailer.sign.command "test -n '\$ARG' && git log
> --author='\$ARG' -1 --format='format:%aN <%aE>' || true")
>
> Then you can run `git interpret-trailers` with the --trim-empty option
> like this:
>
> ------
> $ git interpret-trailers --trim-empty --trailer sign=Linus<<EOF
> EOF
>
> Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> ------
>
> or like:
>
> ------
> $ git interpret-trailers --trim-empty<<EOF
> > EOF
>
> ------

Thanks for effective solution.
Maybe I should also correct this part of the test.




[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