Skip to content

Commit ed17d26

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

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

t/t0021/rot13-filter.pl

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,20 @@ sub packet_bin_read {
7575
if ( $bytes_read == 0 ) {
7676
# EOF - Git stopped talking to us!
7777
return ( -1, "" );
78-
}
79-
elsif ( $bytes_read != 4 ) {
78+
} elsif ( $bytes_read != 4 ) {
8079
die "invalid packet: '$buffer'";
8180
}
8281
my $pkt_size = hex($buffer);
8382
if ( $pkt_size == 0 ) {
8483
return ( 1, "" );
85-
}
86-
elsif ( $pkt_size > 4 ) {
84+
} elsif ( $pkt_size > 4 ) {
8785
my $content_size = $pkt_size - 4;
8886
$bytes_read = read STDIN, $buffer, $content_size;
8987
if ( $bytes_read != $content_size ) {
9088
die "invalid packet ($content_size bytes expected; $bytes_read bytes read)";
9189
}
9290
return ( 0, $buffer );
93-
}
94-
else {
91+
} else {
9592
die "invalid packet size: $pkt_size";
9693
}
9794
}
@@ -195,8 +192,7 @@ sub packet_flush {
195192
$debug->flush();
196193
packet_txt_write("status=success");
197194
packet_flush();
198-
}
199-
else {
195+
} else {
200196
my ( $res, $pathname ) = packet_required_key_val_read("pathname");
201197
if ( $res == -1 ) {
202198
die "unexpected EOF while expecting pathname";
@@ -240,17 +236,13 @@ sub packet_flush {
240236
my $output;
241237
if ( exists $DELAY{$pathname} and exists $DELAY{$pathname}{"output"} ) {
242238
$output = $DELAY{$pathname}{"output"}
243-
}
244-
elsif ( $pathname eq "error.r" or $pathname eq "abort.r" ) {
239+
} elsif ( $pathname eq "error.r" or $pathname eq "abort.r" ) {
245240
$output = "";
246-
}
247-
elsif ( $command eq "clean" and grep( /^clean$/, @capabilities ) ) {
241+
} elsif ( $command eq "clean" and grep( /^clean$/, @capabilities ) ) {
248242
$output = rot13($input);
249-
}
250-
elsif ( $command eq "smudge" and grep( /^smudge$/, @capabilities ) ) {
243+
} elsif ( $command eq "smudge" and grep( /^smudge$/, @capabilities ) ) {
251244
$output = rot13($input);
252-
}
253-
else {
245+
} else {
254246
die "bad command '$command'";
255247
}
256248

@@ -259,25 +251,21 @@ sub packet_flush {
259251
$debug->flush();
260252
packet_txt_write("status=error");
261253
packet_flush();
262-
}
263-
elsif ( $pathname eq "abort.r" ) {
254+
} elsif ( $pathname eq "abort.r" ) {
264255
print $debug "[ABORT]\n";
265256
$debug->flush();
266257
packet_txt_write("status=abort");
267258
packet_flush();
268-
}
269-
elsif ( $command eq "smudge" and
259+
} elsif ( $command eq "smudge" and
270260
exists $DELAY{$pathname} and
271-
$DELAY{$pathname}{"requested"} == 1
272-
) {
261+
$DELAY{$pathname}{"requested"} == 1 ) {
273262
print $debug "[DELAYED]\n";
274263
$debug->flush();
275264
packet_txt_write("status=delayed");
276265
packet_flush();
277266
$DELAY{$pathname}{"requested"} = 2;
278267
$DELAY{$pathname}{"output"} = $output;
279-
}
280-
else {
268+
} else {
281269
packet_txt_write("status=success");
282270
packet_flush();
283271

@@ -297,8 +285,7 @@ sub packet_flush {
297285
print $debug ".";
298286
if ( length($output) > $MAX_PACKET_CONTENT_SIZE ) {
299287
$output = substr( $output, $MAX_PACKET_CONTENT_SIZE );
300-
}
301-
else {
288+
} else {
302289
$output = "";
303290
}
304291
}

0 commit comments

Comments
 (0)