Git/Packet.pm: use 'if' instead of 'unless'
The code is more understandable with 'if' instead of 'unless'. 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
4a543708cc1dd9bdc1e359078118a5279a2cfe11
1 file changed
+8
-8
perl/Git/Packet.pm
+8
-8
@@ -68,16 +68,16 @@ sub packet_bin_read {
68
69
sub remove_final_lf_or_die {
70
my $buf = shift;
71
- unless ( $buf =~ s/\n$// ) {
72
- die "A non-binary line MUST be terminated by an LF.\n"
73
- . "Received: '$buf'";
71
+ if ( $buf =~ s/\n$// ) {
72
+ return $buf;
73
}
75
- return $buf;
74
+ die "A non-binary line MUST be terminated by an LF.\n"
75
+ . "Received: '$buf'";
76
}
77
78
sub packet_txt_read {
79
my ( $res, $buf ) = packet_bin_read();
80
- unless ( $res == -1 or $buf eq '' ) {
80
+ if ( $res != -1 and $buf ne '' ) {
81
$buf = remove_final_lf_or_die($buf);
82
}
83
return ( $res, $buf );
@@ -91,10 +91,10 @@ sub packet_txt_read {
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 '' ) ) {
95
- die "bad $key: '$buf'";
94
+ if ( $res == -1 or ( $buf =~ s/^$key=// and $buf ne '' ) ) {
95
+ return ( $res, $buf );
96
}
97
- return ( $res, $buf );
97
+ die "bad $key: '$buf'";
98
}
99
100
sub packet_bin_write {