diff options
author | Junio C Hamano <gitster@pobox.com> | 2024-01-13 01:09:56 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-01-13 01:09:56 +0100 |
commit | 15df15fe07ef66b51302bb77e393f3c5502629de (patch) | |
tree | b7e3119769b730bff3351fc17e16ff46df022700 /pkt-line.c | |
parent | Merge branch 'tb/multi-pack-verbatim-reuse' (diff) | |
parent | pkt-line: do not chomp newlines for sideband messages (diff) | |
download | git-15df15fe07ef66b51302bb77e393f3c5502629de.tar.xz git-15df15fe07ef66b51302bb77e393f3c5502629de.zip |
Merge branch 'jx/sideband-chomp-newline-fix'
Sideband demultiplexer fixes.
* jx/sideband-chomp-newline-fix:
pkt-line: do not chomp newlines for sideband messages
pkt-line: memorize sideband fragment in reader
test-pkt-line: add option parser for unpack-sideband
Diffstat (limited to 'pkt-line.c')
-rw-r--r-- | pkt-line.c | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/pkt-line.c b/pkt-line.c index 236dd3a3ee..24479eae4d 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -463,8 +463,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 && @@ -593,17 +617,19 @@ void packet_reader_init(struct packet_reader *reader, int fd, reader->options = options; reader->me = "git"; reader->hash_algo = &hash_algos[GIT_HASH_SHA1]; + strbuf_init(&reader->scratch, 0); } enum packet_read_status packet_reader_read(struct packet_reader *reader) { - struct strbuf scratch = STRBUF_INIT; - if (reader->line_peeked) { reader->line_peeked = 0; return reader->status; } + if (reader->use_sideband) + reader->options |= PACKET_READ_USE_SIDEBAND; + /* * Consume all progress packets until a primary payload packet is * received @@ -621,7 +647,7 @@ enum packet_read_status packet_reader_read(struct packet_reader *reader) break; if (demultiplex_sideband(reader->me, reader->status, reader->buffer, reader->pktlen, 1, - &scratch, &sideband_type)) + &reader->scratch, &sideband_type)) break; } |