From: Phillip Wood Date: Tue, 01 Jul 2025 19:31:58 GMT Subject: Re: [GSOC PATCH v3] commit: avoid scanning trailing comments when 'core.commentChar' is "auto" Message-ID: <9e96aaab-79a2-4632-94cd-d016d4a63b30@gmail.com> In-Reply-To: Hi Ayush On 01/07/2025 19:33, Ayush Chandekar wrote: > On Tue, Jul 1, 2025 at 6:47 PM Phillip Wood 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;