From: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
To: git@vger.kernel.org
Cc: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
Subject: [PATCH] [PATCH v2] gpg-interface.c: trim CR only before LF
Date: Thu, 16 Oct 2025 21:03:44 +0100 [thread overview]
Message-ID: <20251016200344.43239-1-okhuomonajayi54@gmail.com> (raw)
Problem:
The function remove_cr_after() stripped CRs blindly. The comment suggested
NEEDSWORK: trim only CRs before LF. This caused potential confusion.
Solution:
Rename remove_cr_after() to trim_cr_before_lf() and update the comment:
"Trim CR characters only when they appear before LF (\r\n) line endings."
This keeps lone CRs intact and documents intent clearly.
Also improved formatting.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
gpg-interface.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/gpg-interface.c b/gpg-interface.c
index c961607444..2d114e05e8 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -964,23 +964,37 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *sig
return use_format->sign_buffer(buffer, signature, signing_key);
}
-/*
- * Trim CR characters only when they appear before LF (\r\n) line endings.
- * This avoids removing legitimate lone CRs from teh content.
- */
+/* Convert CRLF to LF, in case we are on Windows */
static void trim_cr_before_lf(struct strbuf *buffer, size_t offset)
{
size_t i, j;
+ for (i = j = offset; i < buffer->len; i++) {
+ /* Skip CR only if it comes right before LF */
+ if (buffer->buf[i] == '\r' && i + 1 < buffer->len &&
+ buffer->buf[i + 1] == '\n')
+ continue;
+
+ if (i != j)
+ buffer->buf[j] = buffer->buf[i];
+ j++;
+ }
+ strbuf_setlen(buffer, j);
+}
+
+static void trim_cr_before_lf(struct strbuf *buffer, size_t offset)
+{
+ size_t i, j;
+
for (i = j = offset; i < buffer->len; i++) {
/* skip CR only if it comes right before LF */
- if (buffer->buf[i] == '\r' && i + 1 < buffer->len && buffer->buf[i+1] == '\n')
- continue;
+ if (buffer->buf[i] == '\r' && i + 1 < buffer->len &&
+ buffer->buf[i+1] == '\n')
+ continue;
- if (i != j)
- buffer->buf[j] = buffer->buf[i];
- j++;
-
+ if (i != j)
+ buffer->buf[j] = buffer->buf[i];
+ j++;
}
strbuf_setlen(buffer, j);
}
--
2.43.0
next reply other threads:[~2025-10-16 20:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 20:03 Okhuomon Ajayi [this message]
2025-10-17 11:55 ` [PATCH] [PATCH v2] gpg-interface.c: trim CR only before LF Christian Couder
2025-10-17 19:12 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251016200344.43239-1-okhuomonajayi54@gmail.com \
--to=okhuomonajayi54@gmail.com \
--cc=git@vger.kernel.org \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).