All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] gpg-interface: trim only CR characters that precede LF
Date: Thu, 16 Oct 2025 11:52:05 -0700	[thread overview]
Message-ID: <xmqq4iry4r3e.fsf@gitster.g> (raw)
In-Reply-To: <20251016184420.78268-1-okhuomonajayi54@gmail.com> (Okhuomon Ajayi's message of "Thu, 16 Oct 2025 19:44:20 +0100")

Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

>  /*
> - * Strip CR from the line endings, in case we are on Windows.
> - * NEEDSWORK: make it trim only CRs before LFs and rename
> + * Trim CR characters only when they appear before LF (\r\n) line endings.
> + * This avoids removing legitimate lone CRs from teh content.

"teh" -> "the".  I know, I myself often make teh same typo.

>   */
> -static void remove_cr_after(struct strbuf *buffer, size_t offset)
> +static void trim_cr_before_lf(struct strbuf *buffer, size_t offset)

In other words, this normalizes crlf to lf line ending.

>  {
>  	size_t i, j;
>  
>  	for (i = j = offset; i < buffer->len; i++) {
> -		if (buffer->buf[i] != '\r') {
> +	     /* skip CR only if it comes right before LF */
> +		if (buffer->buf[i] == '\r' && i + 1 < buffer->len && buffer->buf[i+1] == '\n')

Are two different mixture of tabs and spaces used in the above two
lines?  I think they wanted to begin at the same column.

Also, the second line is overly long that it does not even fit on my
92-column wide terminal (yes, 80 is the limit, but this will let a
line in the patches quoted a few times to still fit, as long as the
patch honors the 80-column limit).

> +		    continue;

>  			if (i != j)
>  				buffer->buf[j] = buffer->buf[i];
>  			j++;
> -		}
> +		

Do we need a blank line here?  I dunno.

>  	}
>  	strbuf_setlen(buffer, j);
>  }
> @@ -1023,8 +1026,10 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
>  	}
>  	strbuf_release(&gpg_status);
>  
> -	/* Strip CR from the line endings, in case we are on Windows. */
> -	remove_cr_after(signature, bottom);
> +	/* Trim carriage returns (CR) only when they appear before line feeds (LF),.
> +	*  mainly for handling Windows-style line endings
> + 	*/

	/* Convert CRLF to LF, in case we are on Windows */

> +	trim_cr_before_lf(signature, bottom);
>  
>  	return 0;
>  }
> @@ -1110,8 +1115,10 @@ static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf *signature,
>  			ssh_signature_filename.buf);
>  		goto out;
>  	}
> -	/* Strip CR from the line endings, in case we are on Windows. */
> -	remove_cr_after(signature, bottom);
> +	/* Trim carriage returns (CR) only when they appear before line feeds (LF),
> +	*  mainly for handling Windows-style line endings.
> +	*/
> +	trim_cr_before_lf(signature, bottom);

Ditto.

>  
>  out:
>  	if (key_file)

  reply	other threads:[~2025-10-16 18:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-16 18:44 [PATCH] gpg-interface: trim only CR characters that precede LF Okhuomon Ajayi
2025-10-16 18:52 ` Junio C Hamano [this message]
2025-10-16 19:38   ` Okhuomon Ajayi
2025-10-16 20:50     ` Junio C Hamano
2025-10-16 20:53     ` Kristoffer Haugsbakk
2025-10-16 21:01       ` Okhuomon Ajayi

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=xmqq4iry4r3e.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=okhuomonajayi54@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.