Skip to content

Commit 4a54370

Browse files
chriscoolgitster
authored andcommitted
Git/Packet.pm: use 'if' instead of 'unless'
The code is more understandable with 'if' instead of 'unless'. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb1c64b commit 4a54370

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

perl/Git/Packet.pm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ sub packet_bin_read {
6868

6969
sub remove_final_lf_or_die {
7070
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;
7473
}
75-
return $buf;
74+
die "A non-binary line MUST be terminated by an LF.\n"
75+
. "Received: '$buf'";
7676
}
7777

7878
sub packet_txt_read {
7979
my ( $res, $buf ) = packet_bin_read();
80-
unless ( $res == -1 or $buf eq '' ) {
80+
if ( $res != -1 and $buf ne '' ) {
8181
$buf = remove_final_lf_or_die($buf);
8282
}
8383
return ( $res, $buf );
@@ -91,10 +91,10 @@ sub packet_txt_read {
9191
sub packet_key_val_read {
9292
my ( $key ) = @_;
9393
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 );
9696
}
97-
return ( $res, $buf );
97+
die "bad $key: '$buf'";
9898
}
9999

100100
sub packet_bin_write {

0 commit comments

Comments
 (0)