]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: Move generating page title to separate subroutine
authorJakub Narebski <redacted>
Sat, 24 Apr 2010 14:01:10 +0000 (16:01 +0200)
committerLady <redacted>
Mon, 6 Apr 2026 04:50:39 +0000 (00:50 -0400)
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 <redacted>
Acked-by: Petr Baudis <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl

index 309660aad3534302a1d0e2e08d20cba206e1375bbc8fe1a60dbac56ae4fd5f08..1d675614b5b6ecfe5df0d5bd3201b1b2fcf4571eeb9d2e61c430605a2b19b6b7 100755 (executable)
@@ -3180,24 +3180,30 @@ sub blob_contenttype {
 ## ======================================================================
 ## functions printing HTML: header, footer, error page
 
 ## ======================================================================
 ## functions printing HTML: header, footer, error page
 
+sub get_page_title {
+       my $title = to_utf8($site_name);
+
+       return $title unless (defined $project);
+       $title .= " - " . to_utf8($project);
+
+       return $title unless (defined $action);
+       $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
+
+       return $title unless (defined $file_name);
+       $title .= " - " . esc_path($file_name);
+       if ($action eq "tree" && $file_name !~ m|/$|) {
+               $title .= "/";
+       }
+
+       return $title;
+}
+
 sub git_header_html {
        my $status = shift || "200 OK";
        my $expires = shift;
        my %opts = @_;
 
 sub git_header_html {
        my $status = shift || "200 OK";
        my $expires = shift;
        my %opts = @_;
 
-       my $title = "$site_name";
-       if (defined $project) {
-               $title .= " - " . to_utf8($project);
-               if (defined $action) {
-                       $title .= "/$action";
-                       if (defined $file_name) {
-                               $title .= " - " . esc_path($file_name);
-                               if ($action eq "tree" && $file_name !~ m|/$|) {
-                                       $title .= "/";
-                               }
-                       }
-               }
-       }
+       my $title = get_page_title();
        my $content_type;
        # require explicit support from the UA if we are to send the page as
        # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
        my $content_type;
        # require explicit support from the UA if we are to send the page as
        # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
This page took 0.207791 seconds and 4 git commands to generate.