Skip to content

Commit 64220dc

Browse files
jiangxingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eaa82f8 commit 64220dc

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

pkt-line.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,12 +592,11 @@ void packet_reader_init(struct packet_reader *reader, int fd,
592592
reader->options = options;
593593
reader->me = "git";
594594
reader->hash_algo = &hash_algos[GIT_HASH_SHA1];
595+
strbuf_init(&reader->scratch, 0);
595596
}
596597

597598
enum packet_read_status packet_reader_read(struct packet_reader *reader)
598599
{
599-
struct strbuf scratch = STRBUF_INIT;
600-
601600
if (reader->line_peeked) {
602601
reader->line_peeked = 0;
603602
return reader->status;
@@ -620,7 +619,7 @@ enum packet_read_status packet_reader_read(struct packet_reader *reader)
620619
break;
621620
if (demultiplex_sideband(reader->me, reader->status,
622621
reader->buffer, reader->pktlen, 1,
623-
&scratch, &sideband_type))
622+
&reader->scratch, &sideband_type))
624623
break;
625624
}
626625

pkt-line.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ struct packet_reader {
194194

195195
/* hash algorithm in use */
196196
const struct git_hash_algo *hash_algo;
197+
198+
/* hold temporary sideband message */
199+
struct strbuf scratch;
197200
};
198201

199202
/*

t/t0070-fundamental.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ test_expect_success 'unpack-sideband: --chomp-newline (default)' '
8181
test_cmp expect-err err
8282
'
8383

84-
test_expect_failure 'unpack-sideband: packet_reader_read() consumes sideband, no chomp payload' '
84+
test_expect_success 'unpack-sideband: packet_reader_read() consumes sideband, no chomp payload' '
8585
test_when_finished "rm -f expect-out expect-err" &&
8686
test-tool pkt-line send-split-sideband >split-sideband &&
8787
test-tool pkt-line unpack-sideband \

0 commit comments

Comments
 (0)