From 64220dc5f7450d8eca471fa484965b1dcddc2827 Mon Sep 17 00:00:00 2001 From: Jiang Xin Date: Sun, 17 Dec 2023 22:41:37 +0800 Subject: pkt-line: memorize sideband fragment in reader When we turn on the "use_sideband" field of the packet_reader, "packet_reader_read()" will call the function "demultiplex_sideband()" to parse and consume sideband messages. Sideband fragment which does not end with "\r" or "\n" will be saved in the sixth parameter "scratch" and it can be reused and be concatenated when parsing another sideband message. In "packet_reader_read()" function, the local variable "scratch" can only be reused by subsequent sideband messages. But if there is a payload message between two sideband fragments, the first fragment which is saved in the local variable "scratch" will be lost. To solve this problem, we can add a new field "scratch" in packet_reader to memorize the sideband fragment across different calls of "packet_reader_read()". Signed-off-by: Jiang Xin Signed-off-by: Junio C Hamano --- pkt-line.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'pkt-line.h') diff --git a/pkt-line.h b/pkt-line.h index 954eec8719..be1010d34e 100644 --- a/pkt-line.h +++ b/pkt-line.h @@ -194,6 +194,9 @@ struct packet_reader { /* hash algorithm in use */ const struct git_hash_algo *hash_algo; + + /* hold temporary sideband message */ + struct strbuf scratch; }; /* -- cgit v1.2.3 From 7033d5479b8a7b8e7c33892f23d106c33c938ff4 Mon Sep 17 00:00:00 2001 From: Jiang Xin Date: Sun, 17 Dec 2023 22:41:38 +0800 Subject: pkt-line: do not chomp newlines for sideband messages When calling "packet_read_with_status()" to parse pkt-line encoded packets, we can turn on the flag "PACKET_READ_CHOMP_NEWLINE" to chomp newline character for each packet for better line matching. But when receiving data and progress information using sideband, we should turn off the flag "PACKET_READ_CHOMP_NEWLINE" to prevent mangling newline characters from data and progress information. When both the server and the client support "sideband-all" capability, we have a dilemma that newline characters in negotiation packets should be removed, but the newline characters in the progress information should be left intact. Add new flag "PACKET_READ_USE_SIDEBAND" for "packet_read_with_status()" to prevent mangling newline characters in sideband messages. Helped-by: Jonathan Tan Helped-by: Oswald Buddenhagen Signed-off-by: Jiang Xin Signed-off-by: Junio C Hamano --- pkt-line.h | 1 + 1 file changed, 1 insertion(+) (limited to 'pkt-line.h') diff --git a/pkt-line.h b/pkt-line.h index be1010d34e..a7ff2e2f18 100644 --- a/pkt-line.h +++ b/pkt-line.h @@ -85,6 +85,7 @@ void packet_fflush(FILE *f); #define PACKET_READ_DIE_ON_ERR_PACKET (1u<<2) #define PACKET_READ_GENTLE_ON_READ_ERROR (1u<<3) #define PACKET_READ_REDACT_URI_PATH (1u<<4) +#define PACKET_READ_USE_SIDEBAND (1u<<5) int packet_read(int fd, char *buffer, unsigned size, int options); /* -- cgit v1.2.3