summaryrefslogtreecommitdiff
path: root/pkt-line.c
diff options
context:
space:
mode:
authorJiang Xin <zhiyou.jx@alibaba-inc.com>2023-12-17 14:41:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2023-12-18 21:24:38 (GMT)
commit7033d5479b8a7b8e7c33892f23d106c33c938ff4 (patch)
tree8811ec4e4e82bc73dee4a5af02109a0a5ff21573 /pkt-line.c
parent64220dc5f7450d8eca471fa484965b1dcddc2827 (diff)
downloadgit-7033d5479b8a7b8e7c33892f23d106c33c938ff4.zip
git-7033d5479b8a7b8e7c33892f23d106c33c938ff4.tar.gz
git-7033d5479b8a7b8e7c33892f23d106c33c938ff4.tar.bz2
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 <jonathantanmy@google.com> Helped-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pkt-line.c')
-rw-r--r--pkt-line.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/pkt-line.c b/pkt-line.c
index 5943777..e9061e6 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -462,8 +462,32 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
}
if ((options & PACKET_READ_CHOMP_NEWLINE) &&
- len && buffer[len-1] == '\n')
- len--;
+ len && buffer[len-1] == '\n') {
+ if (options & PACKET_READ_USE_SIDEBAND) {
+ int band = *buffer & 0xff;
+ switch (band) {
+ case 1:
+ /* Chomp newline for payload */
+ len--;
+ break;
+ case 2:
+ case 3:
+ /*
+ * Do not chomp newline for progress and error
+ * message.
+ */
+ break;
+ default:
+ /*
+ * Bad sideband, let's leave it to
+ * demultiplex_sideband() to catch this error.
+ */
+ break;
+ }
+ } else {
+ len--;
+ }
+ }
buffer[len] = 0;
if (options & PACKET_READ_REDACT_URI_PATH &&
@@ -602,6 +626,9 @@ enum packet_read_status packet_reader_read(struct packet_reader *reader)
return reader->status;
}
+ if (reader->use_sideband)
+ reader->options |= PACKET_READ_USE_SIDEBAND;
+
/*
* Consume all progress packets until a primary payload packet is
* received