gitweb: make repeated calls to git_get_project_owner() bearable

If repeated calls to git_get_project_owner() are made, we would have read the
same file over and over again.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano 2007-07-03 22:10:42 -07:00
parent 6abe0f0383
commit 478524508e

View File

@ -1465,12 +1465,12 @@ sub git_get_projects_list {
return @list;
}
sub git_get_project_owner {
my $project = shift;
my $owner;
our $gitweb_project_owner = undef;
sub git_get_project_list_from_file {
return undef unless $project;
return if (defined $gitweb_project_owner);
$gitweb_project_owner = {};
# read from file (url-encoded):
# 'git%2Fgit.git Linus+Torvalds'
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
@ -1482,13 +1482,25 @@ sub git_get_project_owner {
my ($pr, $ow) = split ' ', $line;
$pr = unescape($pr);
$ow = unescape($ow);
if ($pr eq $project) {
$owner = to_utf8($ow);
last;
}
$gitweb_project_owner->{$pr} = to_utf8($ow);
}
close $fd;
}
}
sub git_get_project_owner {
my $project = shift;
my $owner;
return undef unless $project;
if (!defined $gitweb_project_owner) {
git_get_project_list_from_file();
}
if (exists $gitweb_project_owner->{$project}) {
$owner = $gitweb_project_owner->{$project};
}
if (!defined $owner) {
$owner = get_file_owner("$projectroot/$project");
}