git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] pkt-line: do not chomp EOL for sideband progress info

From
Jiang Xin <worldhello.net@gmail.com>
Date
Sep 19, 2023, 07:19 UTC
Message-ID
<20230919071956.14015-1-worldhello.net@gmail.com>
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
Next: Junio C Hamano
Message 1 of 19 in “pkt-line: do not chomp EOL for sideband progress info”
  1. pkt-line: do not chomp EOL for sideband progress infoJiang Xin, Sep 19, 2023
  2. Junio C HamanoSep 19, 2023
  3. Jonathan TanSep 20, 2023
  4. Jiang XinSep 25, 2023
  5. 1/3 test-pkt-line: add option parser for unpack-sidebandJiang Xin, Sep 25, 2023
  6. 2/3 pkt-line: memorize sideband fragment in readerJiang Xin, Sep 25, 2023
  7. 3/3 pkt-line: do not chomp newlines for sideband messagesJiang Xin, Sep 25, 2023
  8. Junio C HamanoSep 25, 2023
  9. Oswald BuddenhagenSep 26, 2023
  10. Jiang XinOct 4, 2023
  11. Junio C HamanoOct 4, 2023
  12. 0/3 Sideband demultiplexer fixesJiang Xin, Oct 4, 2023
  13. 2/3 pkt-line: memorize sideband fragment in readerJiang Xin, Oct 4, 2023
  14. 1/3 test-pkt-line: add option parser for unpack-sidebandJiang Xin, Oct 4, 2023
  15. 3/3 pkt-line: do not chomp newlines for sideband messagesJiang Xin, Oct 4, 2023
  16. 0/3 Sideband-all demultiplexer fixesJiang Xin, Dec 17, 2023
  17. 1/3 test-pkt-line: add option parser for unpack-sidebandJiang Xin, Dec 17, 2023
  18. 2/3 pkt-line: memorize sideband fragment in readerJiang Xin, Dec 17, 2023
  19. 3/3 pkt-line: do not chomp newlines for sideband messagesJiang Xin, Dec 17, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.