]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.perl
gitweb: Make git_search_* subroutines render whole pages
[Gitweb] / gitweb.perl
index 9e4ab21587137887fc13540ca67889f736bd9f4fb3411eb4d739e9376befa77e..bd240107b052af107a5e5f311b8f34a2840f08eda82f450cb48471c5a04f72b3 100755 (executable)
@@ -5527,16 +5527,13 @@ sub git_search_message {
        my $paging_nav = '';
        if ($page > 0) {
                $paging_nav .=
-                       $cgi->a({-href => href(action=>"search", hash=>$hash,
-                                              searchtext=>$searchtext,
-                                              searchtype=>$searchtype)},
-                               "first");
-               $paging_nav .= " ⋅ " .
+                       $cgi->a({-href => href(-replay=>1, page=>undef)},
+                               "first") .
+                       " ⋅ " .
                        $cgi->a({-href => href(-replay=>1, page=>$page-1),
                                 -accesskey => "p", -title => "Alt-p"}, "prev");
        } else {
-               $paging_nav .= "first";
-               $paging_nav .= " ⋅ prev";
+               $paging_nav .= "first ⋅ prev";
        }
        my $next_link = '';
        if ($#commitlist >= 100) {
@@ -5548,6 +5545,8 @@ sub git_search_message {
                $paging_nav .= " ⋅ next";
        }
 
+       git_header_html();
+
        git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
        git_print_header_div('commit', esc_html($co{'title'}), $hash);
        if ($page == 0 && !@commitlist) {
@@ -5555,20 +5554,26 @@ sub git_search_message {
        } else {
                git_search_grep_body(\@commitlist, 0, 99, $next_link);
        }
+
+       git_footer_html();
 }
 
 sub git_search_changes {
        my %co = @_;
 
+       local $/ = "\n";
+       open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
+               '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
+               ($search_use_regexp ? '--pickaxe-regex' : ())
+                       or die_error(500, "Open git-log failed");
+
+       git_header_html();
+
        git_print_page_nav('','', $hash,$co{'tree'},$hash);
        git_print_header_div('commit', esc_html($co{'title'}), $hash);
 
        print "<table class=\"pickaxe search\">\n";
        my $alternate = 1;
-       local $/ = "\n";
-       open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
-               '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
-               ($search_use_regexp ? '--pickaxe-regex' : ());
        undef %co;
        my @files;
        while (my $line = <$fd>) {
@@ -5581,10 +5586,13 @@ sub git_search_changes {
                        if (%co) {
                                print "</td>\n" .
                                      "<td class=\"link\">" .
-                                     $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
+                                     $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},
+                                             "commit") .
                                      " | " .
-                                     $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
-                               print "</td>\n" .
+                                     $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},
+                                                            hash_base=>$co{'id'})},
+                                             "tree") .
+                                     "</td>\n" .
                                      "</tr>\n";
                        }
 
@@ -5618,29 +5626,38 @@ sub git_search_changes {
        if (%co) {
                print "</td>\n" .
                      "<td class=\"link\">" .
-                     $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
+                     $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})},
+                             "commit") .
                      " | " .
-                     $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
-               print "</td>\n" .
+                     $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'},
+                                            hash_base=>$co{'id'})},
+                             "tree") .
+                     "</td>\n" .
                      "</tr>\n";
        }
 
        print "</table>\n";
+
+       git_footer_html();
 }
 
 sub git_search_files {
        my %co = @_;
 
+       local $/ = "\n";
+       open my $fd, "-|", git_cmd(), 'grep', '-n',
+               $search_use_regexp ? ('-E', '-i') : '-F',
+               $searchtext, $co{'tree'}
+                       or die_error(500, "Open git-grep failed");
+
+       git_header_html();
+
        git_print_page_nav('','', $hash,$co{'tree'},$hash);
        git_print_header_div('commit', esc_html($co{'title'}), $hash);
 
        print "<table class=\"grep_search\">\n";
        my $alternate = 1;
        my $matches = 0;
-       local $/ = "\n";
-       open my $fd, "-|", git_cmd(), 'grep', '-n',
-               $search_use_regexp ? ('-E', '-i') : '-F',
-               $searchtext, $co{'tree'};
        my $lastfile = '';
        while (my $line = <$fd>) {
                chomp $line;
@@ -5697,6 +5714,8 @@ sub git_search_files {
        close $fd;
 
        print "</table>\n";
+
+       git_footer_html();
 }
 
 sub git_search_grep_body {
@@ -7276,8 +7295,6 @@ sub git_search {
                $page = 0;
        }
 
-       git_header_html();
-
        if ($searchtype eq 'commit' ||
            $searchtype eq 'author' ||
            $searchtype eq 'committer') {
@@ -7286,9 +7303,9 @@ sub git_search {
                git_search_changes(%co);
        } elsif ($searchtype eq 'grep') {
                git_search_files(%co);
+       } else {
+               die_error(400, "Unknown search type");
        }
-
-       git_footer_html();
 }
 
 sub git_search_help {
This page took 0.40895 seconds and 4 git commands to generate.