Skip to content

Commit cb1c64b

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0fe8d51 commit cb1c64b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

perl/Git/Packet.pm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ our @EXPORT = qw(
1717
packet_compare_lists
1818
packet_bin_read
1919
packet_txt_read
20-
packet_required_key_val_read
20+
packet_key_val_read
2121
packet_bin_write
2222
packet_txt_write
2323
packet_flush
@@ -83,7 +83,12 @@ sub packet_txt_read {
8383
return ( $res, $buf );
8484
}
8585

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 {
8792
my ( $key ) = @_;
8893
my ( $res, $buf ) = packet_txt_read();
8994
unless ( $res == -1 or ( $buf =~ s/^$key=// and $buf ne '' ) ) {

t/t0021/rot13-filter.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ sub rot13 {
7070
$debug->flush();
7171

7272
while (1) {
73-
my ( $res, $command ) = packet_required_key_val_read("command");
73+
my ( $res, $command ) = packet_key_val_read("command");
7474
if ( $res == -1 ) {
7575
print $debug "STOP\n";
7676
exit();
@@ -106,7 +106,7 @@ sub rot13 {
106106
packet_txt_write("status=success");
107107
packet_flush();
108108
} else {
109-
my ( $res, $pathname ) = packet_required_key_val_read("pathname");
109+
my ( $res, $pathname ) = packet_key_val_read("pathname");
110110
if ( $res == -1 ) {
111111
die "unexpected EOF while expecting pathname";
112112
}

0 commit comments

Comments
 (0)