Skip to content

Commit 7f5a68a

Browse files
committed
Merge branch 'jn/gitweb-cleanup'
* jn/gitweb-cleanup: gitweb: Remove unused $hash_base parameter from normalize_link_target gitweb: Simplify snapshot format detection logic in evaluate_path_info gitweb: Use capturing parentheses only when you intend to capture gitweb: Replace wrongly added tabs with spaces gitweb: Use block form of map/grep in a few cases more gitweb: Always use three argument form of open gitweb: Always use three argument form of open gitweb: Do not use bareword filehandles
2 parents c9a88de + 15c54fe commit 7f5a68a

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

gitweb/gitweb.perl

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ sub filter_snapshot_fmts {
458458
@fmts = map {
459459
exists $known_snapshot_format_aliases{$_} ?
460460
$known_snapshot_format_aliases{$_} : $_} @fmts;
461-
@fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
462-
461+
@fmts = grep {
462+
exists $known_snapshot_formats{$_} } @fmts;
463463
}
464464

465465
our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
@@ -690,9 +690,10 @@ sub evaluate_path_info {
690690
# format key itself, with a prepended dot
691691
while (my ($fmt, $opt) = each %known_snapshot_formats) {
692692
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;
696697
# a valid suffix was found, so set the snapshot format
697698
# and reset the hash parameter
698699
$input_params{'snapshot_format'} = $fmt;
@@ -828,7 +829,7 @@ sub evaluate_path_info {
828829
if (!defined($actions{$action})) {
829830
die_error(400, "Unknown action");
830831
}
831-
if ($action !~ m/^(opml|project_list|project_index)$/ &&
832+
if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
832833
!$project) {
833834
die_error(400, "Project needed");
834835
}
@@ -1839,7 +1840,7 @@ sub git_cmd {
18391840
# Try to avoid using this function wherever possible.
18401841
sub quote_command {
18411842
return join(' ',
1842-
map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1843+
map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
18431844
}
18441845

18451846
# get HEAD ref of given project as hash
@@ -2051,7 +2052,7 @@ sub git_get_project_description {
20512052
my $path = shift;
20522053

20532054
$git_dir = "$projectroot/$path";
2054-
open my $fd, "$git_dir/description"
2055+
open my $fd, '<', "$git_dir/description"
20552056
or return git_get_project_config('description');
20562057
my $descr = <$fd>;
20572058
close $fd;
@@ -2066,18 +2067,17 @@ sub git_get_project_ctags {
20662067
my $ctags = {};
20672068

20682069
$git_dir = "$projectroot/$path";
2069-
unless (opendir D, "$git_dir/ctags") {
2070-
return $ctags;
2071-
}
2072-
foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir(D)) {
2073-
open CT, $_ or next;
2074-
my $val = <CT>;
2070+
opendir my $dh, "$git_dir/ctags"
2071+
or return $ctags;
2072+
foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2073+
open my $ct, '<', $_ or next;
2074+
my $val = <$ct>;
20752075
chomp $val;
2076-
close CT;
2076+
close $ct;
20772077
my $ctag = $_; $ctag =~ s#.*/##;
20782078
$ctags->{$ctag} = $val;
20792079
}
2080-
closedir D;
2080+
closedir $dh;
20812081
$ctags;
20822082
}
20832083

@@ -2130,7 +2130,7 @@ sub git_get_project_url_list {
21302130
my $path = shift;
21312131

21322132
$git_dir = "$projectroot/$path";
2133-
open my $fd, "$git_dir/cloneurl"
2133+
open my $fd, '<', "$git_dir/cloneurl"
21342134
or return wantarray ?
21352135
@{ config_to_multi(git_get_project_config('url')) } :
21362136
config_to_multi(git_get_project_config('url'));
@@ -2188,7 +2188,7 @@ sub git_get_projects_list {
21882188
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
21892189
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
21902190
my %paths;
2191-
open my ($fd), $projects_list or return;
2191+
open my $fd, '<', $projects_list or return;
21922192
PROJECT:
21932193
while (my $line = <$fd>) {
21942194
chomp $line;
@@ -2251,7 +2251,7 @@ sub git_get_project_list_from_file {
22512251
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
22522252
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
22532253
if (-f $projects_list) {
2254-
open (my $fd , $projects_list);
2254+
open(my $fd, '<', $projects_list);
22552255
while (my $line = <$fd>) {
22562256
chomp $line;
22572257
my ($pr, $ow) = split ' ', $line;
@@ -2805,18 +2805,18 @@ sub mimetype_guess_file {
28052805
-r $mimemap or return undef;
28062806

28072807
my %mimemap;
2808-
open(MIME, $mimemap) or return undef;
2809-
while (<MIME>) {
2808+
open(my $mh, '<', $mimemap) or return undef;
2809+
while (<$mh>) {
28102810
next if m/^#/; # skip comments
2811-
my ($mime, $exts) = split(/\t+/);
2811+
my ($mimetype, $exts) = split(/\t+/);
28122812
if (defined $exts) {
28132813
my @exts = split(/\s+/, $exts);
28142814
foreach my $ext (@exts) {
2815-
$mimemap{$ext} = $mime;
2815+
$mimemap{$ext} = $mimetype;
28162816
}
28172817
}
28182818
}
2819-
close(MIME);
2819+
close($mh);
28202820

28212821
$filename =~ /\.([^.]*)$/;
28222822
return $mimemap{$1};
@@ -3327,7 +3327,7 @@ sub git_get_link_target {
33273327
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
33283328
or return;
33293329
{
3330-
local $/;
3330+
local $/ = undef;
33313331
$link_target = <$fd>;
33323332
}
33333333
close $fd
@@ -3340,10 +3340,7 @@ sub git_get_link_target {
33403340
# return target of link relative to top directory (top tree);
33413341
# return undef if it is not possible (including absolute links).
33423342
sub normalize_link_target {
3343-
my ($link_target, $basedir, $hash_base) = @_;
3344-
3345-
# we can normalize symlink target only if $hash_base is provided
3346-
return unless $hash_base;
3343+
my ($link_target, $basedir) = @_;
33473344

33483345
# absolute symlinks (beginning with '/') cannot be normalized
33493346
return if (substr($link_target, 0, 1) eq '/');
@@ -3399,7 +3396,7 @@ sub git_print_tree_entry {
33993396
if (S_ISLNK(oct $t->{'mode'})) {
34003397
my $link_target = git_get_link_target($t->{'hash'});
34013398
if ($link_target) {
3402-
my $norm_target = normalize_link_target($link_target, $basedir, $hash_base);
3399+
my $norm_target = normalize_link_target($link_target, $basedir);
34033400
if (defined $norm_target) {
34043401
print " -> " .
34053402
$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
@@ -3992,7 +3989,7 @@ sub fill_project_list_info {
39923989
($pname !~ /\/$/) &&
39933990
(-d "$projectroot/$pname")) {
39943991
$pr->{'forks'} = "-d $projectroot/$pname";
3995-
} else {
3992+
} else {
39963993
$pr->{'forks'} = 0;
39973994
}
39983995
}
@@ -4802,11 +4799,10 @@ sub git_blob_plain {
48024799
-content_disposition =>
48034800
($sandbox ? 'attachment' : 'inline')
48044801
. '; filename="' . $save_as . '"');
4805-
undef $/;
4802+
local $/ = undef;
48064803
binmode STDOUT, ':raw';
48074804
print <$fd>;
48084805
binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
4809-
$/ = "\n";
48104806
close $fd;
48114807
}
48124808

@@ -4908,12 +4904,16 @@ sub git_tree {
49084904
}
49094905
}
49104906
die_error(404, "No such tree") unless defined($hash);
4911-
$/ = "\0";
4912-
open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
4913-
or die_error(500, "Open git-ls-tree failed");
4914-
my @entries = map { chomp; $_ } <$fd>;
4915-
close $fd or die_error(404, "Reading tree failed");
4916-
$/ = "\n";
4907+
4908+
my @entries = ();
4909+
{
4910+
local $/ = "\0";
4911+
open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
4912+
or die_error(500, "Open git-ls-tree failed");
4913+
@entries = map { chomp; $_ } <$fd>;
4914+
close $fd
4915+
or die_error(404, "Reading tree failed");
4916+
}
49174917

49184918
my $refs = git_get_references();
49194919
my $ref = format_ref_marker($refs, $hash_base);
@@ -5808,7 +5808,7 @@ sub git_search {
58085808

58095809
print "<table class=\"pickaxe search\">\n";
58105810
my $alternate = 1;
5811-
$/ = "\n";
5811+
local $/ = "\n";
58125812
open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
58135813
'--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
58145814
($search_use_regexp ? '--pickaxe-regex' : ());
@@ -5878,7 +5878,7 @@ sub git_search {
58785878
print "<table class=\"grep_search\">\n";
58795879
my $alternate = 1;
58805880
my $matches = 0;
5881-
$/ = "\n";
5881+
local $/ = "\n";
58825882
open my $fd, "-|", git_cmd(), 'grep', '-n',
58835883
$search_use_regexp ? ('-E', '-i') : '-F',
58845884
$searchtext, $co{'tree'};
@@ -6281,7 +6281,7 @@ sub git_feed {
62816281
# end of feed
62826282
if ($format eq 'rss') {
62836283
print "</channel>\n</rss>\n";
6284-
} elsif ($format eq 'atom') {
6284+
} elsif ($format eq 'atom') {
62856285
print "</feed>\n";
62866286
}
62876287
}

0 commit comments

Comments
 (0)