@matheusbsbs / matheus-bagliano / commits / 095e914281
Fork 0

gitweb: Simplify snapshot format detection logic in evaluate_path_info

This issue was caught by perlcritic in harsh severity level noticing that catch variable was used outside conditional thanks to the Perl::Critic::Policy::RegularExpressions::ProhibitCaptureWithoutTest policy. See "Perl Best Practices", chapter 12. Regular Expressions, section 12.15. Captured Values: Pattern matches that fail never assign anything to $1, $2, etc., nor do they leave those variables undefined. After an unsuccessful pattern match, the numeric capture variables remain exactly as they were before the match was attempted. New version is in my opinion much easier to understand; previous version worked correctly due to the fact that we returned from loop on first found match. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Acked-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed May 11, 2009 at 19:42 UTC 095e914281395f6c0529ce39939d804eb2ccec02
1 file changed +4 -3
gitweb/gitweb.perl
+4 -3
@@ -690,9 +690,10 @@ sub evaluate_path_info {
690 # format key itself, with a prepended dot
691 while (my ($fmt, $opt) = each %known_snapshot_formats) {
692 my $hash = $refname;
693 - my $sfx;
694 - $hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//;
695 - next unless $sfx = $1;
693 + unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
694 + next;
695 + }
696 + my $sfx = $1;
697 # a valid suffix was found, so set the snapshot format
698 # and reset the hash parameter
699 $input_params{'snapshot_format'} = $fmt;