From: Junio C Hamano Date: Wed, 4 Jul 2007 05:10:42 +0000 (-0700) Subject: gitweb: make repeated calls to git_get_project_owner() bearable X-Git-Tag: v1.5.3-rc1~53 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=478524508e2f49af8cc76f2d7294a3b33facf121;p=git.git 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 --- diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index dbfb0441a..d5b8812a1 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -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"); }