public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: "Robert Boyd III via GitGitGadget" <gitgitgadget@gmail•com>
Cc: git@vger•kernel.org, Robert Boyd III <git@robertboyd•dev>
Subject: Re: [PATCH] git-commit: fix cut_line behavior with CRLF
Date: Tue, 11 Apr 2023 16:10:33 -0700	[thread overview]
Message-ID: <xmqq35569frq.fsf@gitster.g> (raw)
In-Reply-To: <pull.1513.git.1681253732794.gitgitgadget@gmail.com> (Robert Boyd III via GitGitGadget's message of "Tue, 11 Apr 2023 22:55:32 +0000")

"Robert Boyd III via GitGitGadget" <gitgitgadget@gmail•com> writes:

> From: Robert Boyd III <git@robertboyd•dev>
>
> On Windows with certain editor (mis)configurations, the cut_line that is
> used when commit.verbose is turned on doesn't work correctly because
> COMMIT_EDITMSG is rewritten with Windows line endings. This used to
> happen on old versions of VSCode, but I can't seem to reproduce it
> anymore without explicitly setting the line-endings to Windows. Even so,
> I think it would be sensible to fix this for good, even in the face of
> bad editor behavior.
>
> This patch moves the \n ending out of the detection string constant, so
> that regardless of the line endings, the cut_line is detected correctly.

The problem description does make sense.

Removing the hardcoded LF from the constant is a good idea, because
we would want to allow CRLF after the cut_line[] constant on Windows
while we usually expect LF there.  The code that inserts cut_line[]
into the output wants to have the LF at the end of the input string,
and your patch correctly compensates for the loss of LF, so that is
good, too.

But wt_status_locate_end() should be taught about our expectation
that cut_line[] we seek is supposed to be followed by either LF or
CRLF.  Otherwise we would mistake any random line that begins with
the cut_line[] constant, followed by arbitrary garbage that is not
end of line.

Thanks.

>  wt-status.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/wt-status.c b/wt-status.c
> index 3162241a570..85904362fe5 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -24,7 +24,7 @@
>  #define UF_DELAY_WARNING_IN_MS (2 * 1000)
>  
>  static const char cut_line[] =
> -"------------------------ >8 ------------------------\n";
> +"------------------------ >8 ------------------------";
>  
>  static char default_wt_status_colors[][COLOR_MAXLEN] = {
>  	GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
> @@ -1090,7 +1090,7 @@ void wt_status_append_cut_line(struct strbuf *buf)
>  {
>  	const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored.");
>  
> -	strbuf_commented_addf(buf, "%s", cut_line);
> +	strbuf_commented_addf(buf, "%s\n", cut_line);
>  	strbuf_add_commented_lines(buf, explanation, strlen(explanation));
>  }
>  
>
> base-commit: 73876f4861cd3d187a4682290ab75c9dccadbc56

      reply	other threads:[~2023-04-11 23:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11 22:55 [PATCH] git-commit: fix cut_line behavior with CRLF Robert Boyd III via GitGitGadget
2023-04-11 23:10 ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq35569frq.fsf@gitster.g \
    --to=gitster@pobox$(echo .)com \
    --cc=git@robertboyd$(echo .)dev \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitgitgadget@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox