Re: [GSOC PATCH v3] commit: avoid scanning trailing comments when 'core.commentChar' is "auto"
- From
Ayush Chandekar <ayu.chandekar@gmail.com>
- Date
- Jul 2, 2025, 23:46 UTC
- Message-ID
- <CAE7as+abNzqbGSCWsuYe8D_c5dBUuRdDEbHL0pVW5j3kTMER4Q@mail.gmail.com>
- In-Reply-To
- <9e96aaab-79a2-4632-94cd-d016d4a63b30@gmail.com>
Hi Phillip,
On Wed, Jul 2, 2025 at 1:02 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 57 quoted lines
>
> Hi Ayush
>
> On 01/07/2025 19:33, Ayush Chandekar wrote:
> > On Tue, Jul 1, 2025 at 6:47 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
> >>
> >> The changes here look good but I think we want to update the config
> >> parsing as well so that comment_line_str is reset to '#' when
> >> core.commentString=auto. We probably want to do that in its own commit.
> >
> > maybe something like this?
> >
> > --- a/builtin/commit.c
> > +++ b/builtin/commit.c
> > @@ -912,8 +912,10 @@ static int prepare_to_commit(const char
> > *index_file, const char *prefix,
> > if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
> > die_errno(_("could not write commit template"));
> >
> > - if (auto_comment_line_char)
> > + if (auto_comment_line_char){
> > + comment_line_str = "#";
> > adjust_comment_line_char(&sb);
> > + }
> > strbuf_release(&sb);
> >
> > or we can do it inside the `adjust_comment_line()` function.
>
> We need to do it when we parse the config so that
> append_conflicts_comment() uses '#' as the comment char. See the
> (whitespace damaged) diff below
>
> Thanks
>
> Phillip
>
> diff --git a/config.c b/config.c
> index eb60c293ab3..bb75bdc65d3 100644
> --- a/config.c
> +++ b/config.c
> @@ -1537,9 +1537,11 @@ static int git_default_core_config(const char
> *var, const char *value,
> !strcmp(var, "core.commentstring")) {
> if (!value)
> return config_error_nonbool(var);
> - else if (!strcasecmp(value, "auto"))
> + else if (!strcasecmp(value, "auto")) {
> auto_comment_line_char = 1;
> - else if (value[0]) {
> + FREE_AND_NULL(comment_line_str_to_free);
> + comment_line_str = "#";
> + } else if (value[0]) {
> if (strchr(value, '\n'))
> return error(_("%s cannot contain
> newline"), var);
> comment_line_str = value;
>Thanks, I understood it.
What if we simply return the function `adjust_comment_line_char()` if we get a non-zero value from `ignored_log_message_bytes()`, i.e we won't scan the commit message in case conflict message exists, and we let the old code exist as it is?
+ if(ignored_log_message_bytes(sb->buf, sb->len)) + return;