All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pkt-line: do not chomp EOL for sideband progress info
@ 2023-09-19  7:19 Jiang Xin
  2023-09-19 22:38 ` Junio C Hamano
  2023-09-20 21:08 ` Jonathan Tan
  0 siblings, 2 replies; 19+ messages in thread
From: Jiang Xin @ 2023-09-19  7:19 UTC (permalink / raw)
  To: Git List, Junio C Hamano, Jonathan Tan; +Cc: Jiang Xin

From: Jiang Xin <zhiyou.jx@alibaba-inc.com>

In the protocol negotiation stage, we need to turn on the flag
"PACKET_READ_CHOMP_NEWLINE" to chomp EOL for each packet line from
client or server. But when receiving data and progress information
using sideband, we will turn off the flag "PACKET_READ_CHOMP_NEWLINE"
to prevent mangling EOLs from data and progress information.

When both the server and the client support "sideband-all" capability,
we have a dilemma that EOLs in negotiation packets should be trimmed,
but EOLs in progress infomation should be leaved as is.

Move the logic of chomping EOLs from "packet_read_with_status()" to
"packet_reader_read()" can resolve this dilemma.

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
---
 pkt-line.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/pkt-line.c b/pkt-line.c
index af83a19f4d..d6d08b6aa6 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -597,12 +597,18 @@ void packet_reader_init(struct packet_reader *reader, int fd,
 enum packet_read_status packet_reader_read(struct packet_reader *reader)
 {
 	struct strbuf scratch = STRBUF_INIT;
+	int options = reader->options;
 
 	if (reader->line_peeked) {
 		reader->line_peeked = 0;
 		return reader->status;
 	}
 
+	/* Do not chomp newlines for sideband progress and error messages */
+	if (reader->use_sideband && options & PACKET_READ_CHOMP_NEWLINE) {
+		options &= ~PACKET_READ_CHOMP_NEWLINE;
+	}
+
 	/*
 	 * Consume all progress packets until a primary payload packet is
 	 * received
@@ -615,7 +621,7 @@ enum packet_read_status packet_reader_read(struct packet_reader *reader)
 							 reader->buffer,
 							 reader->buffer_size,
 							 &reader->pktlen,
-							 reader->options);
+							 options);
 		if (!reader->use_sideband)
 			break;
 		if (demultiplex_sideband(reader->me, reader->status,
@@ -624,12 +630,19 @@ enum packet_read_status packet_reader_read(struct packet_reader *reader)
 			break;
 	}
 
-	if (reader->status == PACKET_READ_NORMAL)
+	if (reader->status == PACKET_READ_NORMAL) {
 		/* Skip the sideband designator if sideband is used */
 		reader->line = reader->use_sideband ?
 			reader->buffer + 1 : reader->buffer;
-	else
+
+		if ((reader->options & PACKET_READ_CHOMP_NEWLINE) &&
+		    reader->buffer[reader->pktlen - 1] == '\n') {
+			reader->buffer[reader->pktlen - 1] = 0;
+			reader->pktlen--;
+		}
+	} else {
 		reader->line = NULL;
+	}
 
 	return reader->status;
 }
-- 
2.40.1.49.g40e13c3520.dirty


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2023-12-17 14:41 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-19  7:19 [PATCH] pkt-line: do not chomp EOL for sideband progress info Jiang Xin
2023-09-19 22:38 ` Junio C Hamano
2023-09-20 21:08 ` Jonathan Tan
2023-09-25  0:25   ` Jiang Xin
2023-09-25 15:41     ` [PATCH v2 1/3] test-pkt-line: add option parser for unpack-sideband Jiang Xin
2023-09-25 15:41     ` [PATCH v2 2/3] pkt-line: memorize sideband fragment in reader Jiang Xin
2023-09-25 15:41     ` [PATCH v2 3/3] pkt-line: do not chomp newlines for sideband messages Jiang Xin
2023-09-25 21:51       ` Junio C Hamano
2023-09-26  8:48         ` Oswald Buddenhagen
2023-10-04 13:02           ` Jiang Xin
2023-10-04 20:05             ` Junio C Hamano
2023-10-04 13:18           ` [PATCH v3 0/3] Sideband demultiplexer fixes Jiang Xin
2023-10-04 13:18             ` [PATCH v3 1/3] test-pkt-line: add option parser for unpack-sideband Jiang Xin
2023-10-04 13:18             ` [PATCH v3 2/3] pkt-line: memorize sideband fragment in reader Jiang Xin
2023-10-04 13:18             ` [PATCH v3 3/3] pkt-line: do not chomp newlines for sideband messages Jiang Xin
2023-12-17 14:41             ` [PATCH v4 0/3] Sideband-all demultiplexer fixes Jiang Xin
2023-12-17 14:41               ` [PATCH v4 1/3] test-pkt-line: add option parser for unpack-sideband Jiang Xin
2023-12-17 14:41               ` [PATCH v4 2/3] pkt-line: memorize sideband fragment in reader Jiang Xin
2023-12-17 14:41               ` [PATCH v4 3/3] pkt-line: do not chomp newlines for sideband messages Jiang Xin

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.