Re: [PATCH v2 1/4] revision: improve commit_rewrite_person()
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Jul 9, 2022, 05:04 UTC
- Message-ID
- <CAP8UFD0p+Ty1Fx-vBoX6N0Ahg+Z_JCYe_Jypk7Mag=yY2yzbqg@mail.gmail.com>
- In-Reply-To
- <YsjTif0TjYBzBXfh@danh.dev>
On Sat, Jul 9, 2022 at 3:02 AM Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:
> > Add list back to cc
Sorry for not keeping the list in Cc by mistake.
Show 31 quoted lines
> On 2022-07-08 23:23:07+0200, Christian Couder <christian.couder@gmail.com> wrote:
> > On Fri, Jul 8, 2022 at 4:50 PM Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:
> > >
> > > On 2022-07-07 21:45:51+0530, Siddharth Asthana <siddharthasthana31@gmail.com> wrote:
> >
> > > > By simplyfying the interface of the commit_rewrite_person(), we also
> > >
> > > s/simplyfying/simplifying/
> >
> > Thanks for noticing the typos!
> >
> > > > +static void commit_rewrite_person(struct strbuf *buf, const char **headers, struct string_list *mailmap)
> > > > +{
> > > > + size_t buf_offset = 0;
> > > > +
> > > > + if (!mailmap)
> > > > + return;
> > > > +
> > > > + for (;;) {
> > > > + const char *person, *line = buf->buf + buf_offset;
> > > > + int i, linelen = strchrnul(line, '\n') - line + 1;
> > >
> > > Would you mind to change those lines to avoid mixed of declaration and
> > > expression.
> >
> > I am not sure we have some clear guidelines on this.
>
> Yes, we don't have a clear guidelines on this, but this would sure
> matches into mixed declaration and expression. And some variables are
> initialized and some aren't in the same line. I was confused in my
> first glance.Yeah, it might be clearer to avoid having some variables both declared and initialized while others are only declared on the same line.
Show 22 quoted lines
> > > Also, I think i and linelen should be ssize_t instead. > > > > Could you explain why? > > > > I think 'i' is changed only in: > > > > for (i = 0; headers[i]; i++) > > > > and therefore cannot be négative. > > > > While linelen is set only in: > > > > linelen = strchrnul(line, '\n') - line + 1; > > > > and therefore cannot be négative either. > > Yes, both of them can't be negative. As I explained in the part you > removed. However, I choose ssize_t in my reply because it's > a ptrdiff_t. > > So, size_t is an obviously a better choice. > Either size_t and ssize_t could be used in this case, but not int.
I am Ok with size_t. Thanks for the explanations!
Show 8 quoted lines
> >>> + > >>> + if (!linelen || linelen == 1) > >>> + /* End of header */ > >>> + return; > >> > >>And I think linelen will never be 0 or negative, > >>even if linelen could be 0, I think we want "linelen != 0" > >>for integer comparision.
maybe `if (linelen <=1)` is just a simpler check.