Git/Packet: clarify that packet_required_key_val_read allows EOF

The function calls itself "required", but it does not die when it sees an unexpected EOF. Let's rename it to "packet_key_val_read()". Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Nov 21, 2017 at 17:09 UTC cb1c64b4a8eeda9bc576063c3c9eea34d5693560
2 files changed +9 -4
perl/Git/Packet.pm
+7 -2
@@ -17,7 +17,7 @@ our @EXPORT = qw(
17 packet_compare_lists
18 packet_bin_read
19 packet_txt_read
20 - packet_required_key_val_read
20 + packet_key_val_read
21 packet_bin_write
22 packet_txt_write
23 packet_flush
@@ -83,7 +83,12 @@ sub packet_txt_read {
83 return ( $res, $buf );
84 }
85
86 -sub packet_required_key_val_read {
86 +# Read a text packet, expecting that it is in the form "key=value" for
87 +# the given $key. An EOF does not trigger any error and is reported
88 +# back to the caller (like packet_txt_read() does). Die if the "key"
89 +# part of "key=value" does not match the given $key, or the value part
90 +# is empty.
91 +sub packet_key_val_read {
92 my ( $key ) = @_;
93 my ( $res, $buf ) = packet_txt_read();
94 unless ( $res == -1 or ( $buf =~ s/^$key=// and $buf ne '' ) ) {
t/t0021/rot13-filter.pl
+2 -2
@@ -70,7 +70,7 @@ print $debug "init handshake complete\n";
70 $debug->flush();
71
72 while (1) {
73 - my ( $res, $command ) = packet_required_key_val_read("command");
73 + my ( $res, $command ) = packet_key_val_read("command");
74 if ( $res == -1 ) {
75 print $debug "STOP\n";
76 exit();
@@ -106,7 +106,7 @@ while (1) {
106 packet_txt_write("status=success");
107 packet_flush();
108 } else {
109 - my ( $res, $pathname ) = packet_required_key_val_read("pathname");
109 + my ( $res, $pathname ) = packet_key_val_read("pathname");
110 if ( $res == -1 ) {
111 die "unexpected EOF while expecting pathname";
112 }