t0021/rot13-filter: improve 'if .. elsif .. else' style
Before further refactoring the "t0021/rot13-filter.pl" script, let's modernize the style of its 'if .. elsif .. else' clauses to improve its readability by making it more similar to our other perl scripts. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
2c9ea595a7
commit
ed17d26245
@ -75,23 +75,20 @@ sub packet_bin_read {
|
|||||||
if ( $bytes_read == 0 ) {
|
if ( $bytes_read == 0 ) {
|
||||||
# EOF - Git stopped talking to us!
|
# EOF - Git stopped talking to us!
|
||||||
return ( -1, "" );
|
return ( -1, "" );
|
||||||
}
|
} elsif ( $bytes_read != 4 ) {
|
||||||
elsif ( $bytes_read != 4 ) {
|
|
||||||
die "invalid packet: '$buffer'";
|
die "invalid packet: '$buffer'";
|
||||||
}
|
}
|
||||||
my $pkt_size = hex($buffer);
|
my $pkt_size = hex($buffer);
|
||||||
if ( $pkt_size == 0 ) {
|
if ( $pkt_size == 0 ) {
|
||||||
return ( 1, "" );
|
return ( 1, "" );
|
||||||
}
|
} elsif ( $pkt_size > 4 ) {
|
||||||
elsif ( $pkt_size > 4 ) {
|
|
||||||
my $content_size = $pkt_size - 4;
|
my $content_size = $pkt_size - 4;
|
||||||
$bytes_read = read STDIN, $buffer, $content_size;
|
$bytes_read = read STDIN, $buffer, $content_size;
|
||||||
if ( $bytes_read != $content_size ) {
|
if ( $bytes_read != $content_size ) {
|
||||||
die "invalid packet ($content_size bytes expected; $bytes_read bytes read)";
|
die "invalid packet ($content_size bytes expected; $bytes_read bytes read)";
|
||||||
}
|
}
|
||||||
return ( 0, $buffer );
|
return ( 0, $buffer );
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
die "invalid packet size: $pkt_size";
|
die "invalid packet size: $pkt_size";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,8 +192,7 @@ while (1) {
|
|||||||
$debug->flush();
|
$debug->flush();
|
||||||
packet_txt_write("status=success");
|
packet_txt_write("status=success");
|
||||||
packet_flush();
|
packet_flush();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
my ( $res, $pathname ) = packet_required_key_val_read("pathname");
|
my ( $res, $pathname ) = packet_required_key_val_read("pathname");
|
||||||
if ( $res == -1 ) {
|
if ( $res == -1 ) {
|
||||||
die "unexpected EOF while expecting pathname";
|
die "unexpected EOF while expecting pathname";
|
||||||
@ -240,17 +236,13 @@ while (1) {
|
|||||||
my $output;
|
my $output;
|
||||||
if ( exists $DELAY{$pathname} and exists $DELAY{$pathname}{"output"} ) {
|
if ( exists $DELAY{$pathname} and exists $DELAY{$pathname}{"output"} ) {
|
||||||
$output = $DELAY{$pathname}{"output"}
|
$output = $DELAY{$pathname}{"output"}
|
||||||
}
|
} elsif ( $pathname eq "error.r" or $pathname eq "abort.r" ) {
|
||||||
elsif ( $pathname eq "error.r" or $pathname eq "abort.r" ) {
|
|
||||||
$output = "";
|
$output = "";
|
||||||
}
|
} elsif ( $command eq "clean" and grep( /^clean$/, @capabilities ) ) {
|
||||||
elsif ( $command eq "clean" and grep( /^clean$/, @capabilities ) ) {
|
|
||||||
$output = rot13($input);
|
$output = rot13($input);
|
||||||
}
|
} elsif ( $command eq "smudge" and grep( /^smudge$/, @capabilities ) ) {
|
||||||
elsif ( $command eq "smudge" and grep( /^smudge$/, @capabilities ) ) {
|
|
||||||
$output = rot13($input);
|
$output = rot13($input);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
die "bad command '$command'";
|
die "bad command '$command'";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,25 +251,21 @@ while (1) {
|
|||||||
$debug->flush();
|
$debug->flush();
|
||||||
packet_txt_write("status=error");
|
packet_txt_write("status=error");
|
||||||
packet_flush();
|
packet_flush();
|
||||||
}
|
} elsif ( $pathname eq "abort.r" ) {
|
||||||
elsif ( $pathname eq "abort.r" ) {
|
|
||||||
print $debug "[ABORT]\n";
|
print $debug "[ABORT]\n";
|
||||||
$debug->flush();
|
$debug->flush();
|
||||||
packet_txt_write("status=abort");
|
packet_txt_write("status=abort");
|
||||||
packet_flush();
|
packet_flush();
|
||||||
}
|
} elsif ( $command eq "smudge" and
|
||||||
elsif ( $command eq "smudge" and
|
|
||||||
exists $DELAY{$pathname} and
|
exists $DELAY{$pathname} and
|
||||||
$DELAY{$pathname}{"requested"} == 1
|
$DELAY{$pathname}{"requested"} == 1 ) {
|
||||||
) {
|
|
||||||
print $debug "[DELAYED]\n";
|
print $debug "[DELAYED]\n";
|
||||||
$debug->flush();
|
$debug->flush();
|
||||||
packet_txt_write("status=delayed");
|
packet_txt_write("status=delayed");
|
||||||
packet_flush();
|
packet_flush();
|
||||||
$DELAY{$pathname}{"requested"} = 2;
|
$DELAY{$pathname}{"requested"} = 2;
|
||||||
$DELAY{$pathname}{"output"} = $output;
|
$DELAY{$pathname}{"output"} = $output;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
packet_txt_write("status=success");
|
packet_txt_write("status=success");
|
||||||
packet_flush();
|
packet_flush();
|
||||||
|
|
||||||
@ -297,8 +285,7 @@ while (1) {
|
|||||||
print $debug ".";
|
print $debug ".";
|
||||||
if ( length($output) > $MAX_PACKET_CONTENT_SIZE ) {
|
if ( length($output) > $MAX_PACKET_CONTENT_SIZE ) {
|
||||||
$output = substr( $output, $MAX_PACKET_CONTENT_SIZE );
|
$output = substr( $output, $MAX_PACKET_CONTENT_SIZE );
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$output = "";
|
$output = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user