@matheusbsbs / matheus-bagliano / commits / efb2d0c5dc
Fork 0

gitweb: Move generating page title to separate subroutine

get_page_title subroutine is currently used only in git_header_html. Nevertheless refactoring title generation allowed to reduce indent level. It would be used in more than one callsite in the patch adding caching activity indicator to gitweb. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Acked-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed Apr 24, 2010 at 16:01 UTC efb2d0c5dcea1069bae2d26c9534e2025ee63e66
1 file changed +19 -13
gitweb/gitweb.perl
+19 -13
@@ -3179,24 +3179,30 @@ sub blob_contenttype {
3179 ## ======================================================================
3180 ## functions printing HTML: header, footer, error page
3181
3182 +sub get_page_title {
3183 + my $title = to_utf8($site_name);
3184 +
3185 + return $title unless (defined $project);
3186 + $title .= " - " . to_utf8($project);
3187 +
3188 + return $title unless (defined $action);
3189 + $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3190 +
3191 + return $title unless (defined $file_name);
3192 + $title .= " - " . esc_path($file_name);
3193 + if ($action eq "tree" && $file_name !~ m|/$|) {
3194 + $title .= "/";
3195 + }
3196 +
3197 + return $title;
3198 +}
3199 +
3200 sub git_header_html {
3201 my $status = shift || "200 OK";
3202 my $expires = shift;
3203 my %opts = @_;
3204
3187 - my $title = "$site_name";
3188 - if (defined $project) {
3189 - $title .= " - " . to_utf8($project);
3190 - if (defined $action) {
3191 - $title .= "/$action";
3192 - if (defined $file_name) {
3193 - $title .= " - " . esc_path($file_name);
3194 - if ($action eq "tree" && $file_name !~ m|/$|) {
3195 - $title .= "/";
3196 - }
3197 - }
3198 - }
3199 - }
3205 + my $title = get_page_title();
3206 my $content_type;
3207 # require explicit support from the UA if we are to send the page as
3208 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.