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
This commit is contained in:
@ -458,8 +458,8 @@ sub filter_snapshot_fmts {
|
|||||||
@fmts = map {
|
@fmts = map {
|
||||||
exists $known_snapshot_format_aliases{$_} ?
|
exists $known_snapshot_format_aliases{$_} ?
|
||||||
$known_snapshot_format_aliases{$_} : $_} @fmts;
|
$known_snapshot_format_aliases{$_} : $_} @fmts;
|
||||||
@fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
|
@fmts = grep {
|
||||||
|
exists $known_snapshot_formats{$_} } @fmts;
|
||||||
}
|
}
|
||||||
|
|
||||||
our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
|
our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
|
||||||
@ -690,9 +690,10 @@ sub evaluate_path_info {
|
|||||||
# format key itself, with a prepended dot
|
# format key itself, with a prepended dot
|
||||||
while (my ($fmt, $opt) = each %known_snapshot_formats) {
|
while (my ($fmt, $opt) = each %known_snapshot_formats) {
|
||||||
my $hash = $refname;
|
my $hash = $refname;
|
||||||
my $sfx;
|
unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
|
||||||
$hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//;
|
next;
|
||||||
next unless $sfx = $1;
|
}
|
||||||
|
my $sfx = $1;
|
||||||
# a valid suffix was found, so set the snapshot format
|
# a valid suffix was found, so set the snapshot format
|
||||||
# and reset the hash parameter
|
# and reset the hash parameter
|
||||||
$input_params{'snapshot_format'} = $fmt;
|
$input_params{'snapshot_format'} = $fmt;
|
||||||
@ -828,7 +829,7 @@ if (!defined $action) {
|
|||||||
if (!defined($actions{$action})) {
|
if (!defined($actions{$action})) {
|
||||||
die_error(400, "Unknown action");
|
die_error(400, "Unknown action");
|
||||||
}
|
}
|
||||||
if ($action !~ m/^(opml|project_list|project_index)$/ &&
|
if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
|
||||||
!$project) {
|
!$project) {
|
||||||
die_error(400, "Project needed");
|
die_error(400, "Project needed");
|
||||||
}
|
}
|
||||||
@ -1839,7 +1840,7 @@ sub git_cmd {
|
|||||||
# Try to avoid using this function wherever possible.
|
# Try to avoid using this function wherever possible.
|
||||||
sub quote_command {
|
sub quote_command {
|
||||||
return join(' ',
|
return join(' ',
|
||||||
map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
|
map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
# get HEAD ref of given project as hash
|
# get HEAD ref of given project as hash
|
||||||
@ -2051,7 +2052,7 @@ sub git_get_project_description {
|
|||||||
my $path = shift;
|
my $path = shift;
|
||||||
|
|
||||||
$git_dir = "$projectroot/$path";
|
$git_dir = "$projectroot/$path";
|
||||||
open my $fd, "$git_dir/description"
|
open my $fd, '<', "$git_dir/description"
|
||||||
or return git_get_project_config('description');
|
or return git_get_project_config('description');
|
||||||
my $descr = <$fd>;
|
my $descr = <$fd>;
|
||||||
close $fd;
|
close $fd;
|
||||||
@ -2066,18 +2067,17 @@ sub git_get_project_ctags {
|
|||||||
my $ctags = {};
|
my $ctags = {};
|
||||||
|
|
||||||
$git_dir = "$projectroot/$path";
|
$git_dir = "$projectroot/$path";
|
||||||
unless (opendir D, "$git_dir/ctags") {
|
opendir my $dh, "$git_dir/ctags"
|
||||||
return $ctags;
|
or return $ctags;
|
||||||
}
|
foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
|
||||||
foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir(D)) {
|
open my $ct, '<', $_ or next;
|
||||||
open CT, $_ or next;
|
my $val = <$ct>;
|
||||||
my $val = <CT>;
|
|
||||||
chomp $val;
|
chomp $val;
|
||||||
close CT;
|
close $ct;
|
||||||
my $ctag = $_; $ctag =~ s#.*/##;
|
my $ctag = $_; $ctag =~ s#.*/##;
|
||||||
$ctags->{$ctag} = $val;
|
$ctags->{$ctag} = $val;
|
||||||
}
|
}
|
||||||
closedir D;
|
closedir $dh;
|
||||||
$ctags;
|
$ctags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2130,7 +2130,7 @@ sub git_get_project_url_list {
|
|||||||
my $path = shift;
|
my $path = shift;
|
||||||
|
|
||||||
$git_dir = "$projectroot/$path";
|
$git_dir = "$projectroot/$path";
|
||||||
open my $fd, "$git_dir/cloneurl"
|
open my $fd, '<', "$git_dir/cloneurl"
|
||||||
or return wantarray ?
|
or return wantarray ?
|
||||||
@{ config_to_multi(git_get_project_config('url')) } :
|
@{ config_to_multi(git_get_project_config('url')) } :
|
||||||
config_to_multi(git_get_project_config('url'));
|
config_to_multi(git_get_project_config('url'));
|
||||||
@ -2188,7 +2188,7 @@ sub git_get_projects_list {
|
|||||||
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
|
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
|
||||||
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
|
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
|
||||||
my %paths;
|
my %paths;
|
||||||
open my ($fd), $projects_list or return;
|
open my $fd, '<', $projects_list or return;
|
||||||
PROJECT:
|
PROJECT:
|
||||||
while (my $line = <$fd>) {
|
while (my $line = <$fd>) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
@ -2251,7 +2251,7 @@ sub git_get_project_list_from_file {
|
|||||||
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
|
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
|
||||||
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
|
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
|
||||||
if (-f $projects_list) {
|
if (-f $projects_list) {
|
||||||
open (my $fd , $projects_list);
|
open(my $fd, '<', $projects_list);
|
||||||
while (my $line = <$fd>) {
|
while (my $line = <$fd>) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
my ($pr, $ow) = split ' ', $line;
|
my ($pr, $ow) = split ' ', $line;
|
||||||
@ -2805,18 +2805,18 @@ sub mimetype_guess_file {
|
|||||||
-r $mimemap or return undef;
|
-r $mimemap or return undef;
|
||||||
|
|
||||||
my %mimemap;
|
my %mimemap;
|
||||||
open(MIME, $mimemap) or return undef;
|
open(my $mh, '<', $mimemap) or return undef;
|
||||||
while (<MIME>) {
|
while (<$mh>) {
|
||||||
next if m/^#/; # skip comments
|
next if m/^#/; # skip comments
|
||||||
my ($mime, $exts) = split(/\t+/);
|
my ($mimetype, $exts) = split(/\t+/);
|
||||||
if (defined $exts) {
|
if (defined $exts) {
|
||||||
my @exts = split(/\s+/, $exts);
|
my @exts = split(/\s+/, $exts);
|
||||||
foreach my $ext (@exts) {
|
foreach my $ext (@exts) {
|
||||||
$mimemap{$ext} = $mime;
|
$mimemap{$ext} = $mimetype;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(MIME);
|
close($mh);
|
||||||
|
|
||||||
$filename =~ /\.([^.]*)$/;
|
$filename =~ /\.([^.]*)$/;
|
||||||
return $mimemap{$1};
|
return $mimemap{$1};
|
||||||
@ -3327,7 +3327,7 @@ sub git_get_link_target {
|
|||||||
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
|
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
|
||||||
or return;
|
or return;
|
||||||
{
|
{
|
||||||
local $/;
|
local $/ = undef;
|
||||||
$link_target = <$fd>;
|
$link_target = <$fd>;
|
||||||
}
|
}
|
||||||
close $fd
|
close $fd
|
||||||
@ -3340,10 +3340,7 @@ sub git_get_link_target {
|
|||||||
# return target of link relative to top directory (top tree);
|
# return target of link relative to top directory (top tree);
|
||||||
# return undef if it is not possible (including absolute links).
|
# return undef if it is not possible (including absolute links).
|
||||||
sub normalize_link_target {
|
sub normalize_link_target {
|
||||||
my ($link_target, $basedir, $hash_base) = @_;
|
my ($link_target, $basedir) = @_;
|
||||||
|
|
||||||
# we can normalize symlink target only if $hash_base is provided
|
|
||||||
return unless $hash_base;
|
|
||||||
|
|
||||||
# absolute symlinks (beginning with '/') cannot be normalized
|
# absolute symlinks (beginning with '/') cannot be normalized
|
||||||
return if (substr($link_target, 0, 1) eq '/');
|
return if (substr($link_target, 0, 1) eq '/');
|
||||||
@ -3399,7 +3396,7 @@ sub git_print_tree_entry {
|
|||||||
if (S_ISLNK(oct $t->{'mode'})) {
|
if (S_ISLNK(oct $t->{'mode'})) {
|
||||||
my $link_target = git_get_link_target($t->{'hash'});
|
my $link_target = git_get_link_target($t->{'hash'});
|
||||||
if ($link_target) {
|
if ($link_target) {
|
||||||
my $norm_target = normalize_link_target($link_target, $basedir, $hash_base);
|
my $norm_target = normalize_link_target($link_target, $basedir);
|
||||||
if (defined $norm_target) {
|
if (defined $norm_target) {
|
||||||
print " -> " .
|
print " -> " .
|
||||||
$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
|
$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
|
||||||
@ -3992,7 +3989,7 @@ sub fill_project_list_info {
|
|||||||
($pname !~ /\/$/) &&
|
($pname !~ /\/$/) &&
|
||||||
(-d "$projectroot/$pname")) {
|
(-d "$projectroot/$pname")) {
|
||||||
$pr->{'forks'} = "-d $projectroot/$pname";
|
$pr->{'forks'} = "-d $projectroot/$pname";
|
||||||
} else {
|
} else {
|
||||||
$pr->{'forks'} = 0;
|
$pr->{'forks'} = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4802,11 +4799,10 @@ sub git_blob_plain {
|
|||||||
-content_disposition =>
|
-content_disposition =>
|
||||||
($sandbox ? 'attachment' : 'inline')
|
($sandbox ? 'attachment' : 'inline')
|
||||||
. '; filename="' . $save_as . '"');
|
. '; filename="' . $save_as . '"');
|
||||||
undef $/;
|
local $/ = undef;
|
||||||
binmode STDOUT, ':raw';
|
binmode STDOUT, ':raw';
|
||||||
print <$fd>;
|
print <$fd>;
|
||||||
binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
|
binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
|
||||||
$/ = "\n";
|
|
||||||
close $fd;
|
close $fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4908,12 +4904,16 @@ sub git_tree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
die_error(404, "No such tree") unless defined($hash);
|
die_error(404, "No such tree") unless defined($hash);
|
||||||
$/ = "\0";
|
|
||||||
open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
|
my @entries = ();
|
||||||
or die_error(500, "Open git-ls-tree failed");
|
{
|
||||||
my @entries = map { chomp; $_ } <$fd>;
|
local $/ = "\0";
|
||||||
close $fd or die_error(404, "Reading tree failed");
|
open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
|
||||||
$/ = "\n";
|
or die_error(500, "Open git-ls-tree failed");
|
||||||
|
@entries = map { chomp; $_ } <$fd>;
|
||||||
|
close $fd
|
||||||
|
or die_error(404, "Reading tree failed");
|
||||||
|
}
|
||||||
|
|
||||||
my $refs = git_get_references();
|
my $refs = git_get_references();
|
||||||
my $ref = format_ref_marker($refs, $hash_base);
|
my $ref = format_ref_marker($refs, $hash_base);
|
||||||
@ -5808,7 +5808,7 @@ sub git_search {
|
|||||||
|
|
||||||
print "<table class=\"pickaxe search\">\n";
|
print "<table class=\"pickaxe search\">\n";
|
||||||
my $alternate = 1;
|
my $alternate = 1;
|
||||||
$/ = "\n";
|
local $/ = "\n";
|
||||||
open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
|
open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
|
||||||
'--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
|
'--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
|
||||||
($search_use_regexp ? '--pickaxe-regex' : ());
|
($search_use_regexp ? '--pickaxe-regex' : ());
|
||||||
@ -5878,7 +5878,7 @@ sub git_search {
|
|||||||
print "<table class=\"grep_search\">\n";
|
print "<table class=\"grep_search\">\n";
|
||||||
my $alternate = 1;
|
my $alternate = 1;
|
||||||
my $matches = 0;
|
my $matches = 0;
|
||||||
$/ = "\n";
|
local $/ = "\n";
|
||||||
open my $fd, "-|", git_cmd(), 'grep', '-n',
|
open my $fd, "-|", git_cmd(), 'grep', '-n',
|
||||||
$search_use_regexp ? ('-E', '-i') : '-F',
|
$search_use_regexp ? ('-E', '-i') : '-F',
|
||||||
$searchtext, $co{'tree'};
|
$searchtext, $co{'tree'};
|
||||||
@ -6281,7 +6281,7 @@ XML
|
|||||||
# end of feed
|
# end of feed
|
||||||
if ($format eq 'rss') {
|
if ($format eq 'rss') {
|
||||||
print "</channel>\n</rss>\n";
|
print "</channel>\n</rss>\n";
|
||||||
} elsif ($format eq 'atom') {
|
} elsif ($format eq 'atom') {
|
||||||
print "</feed>\n";
|
print "</feed>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user