gitweb: Change atom, rss actions to use parse_commits.
[gitweb.git] / gitweb / gitweb.perl
index 5f1ace98aaf8a32a1dc8b7784b779d504922bc6d..f752a6f605dcd39fbdac5f2c14b4c3b03383ce00 100755 (executable)
@@ -2910,18 +2910,18 @@ sub git_heads_body {
 }
 
 sub git_search_grep_body {
-       my ($greplist, $from, $to, $extra) = @_;
+       my ($commitlist, $from, $to, $extra) = @_;
        $from = 0 unless defined $from;
-       $to = $#{$greplist} if (!defined $to || $#{$greplist} < $to);
+       $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
 
        print "<table class=\"grep\" cellspacing=\"0\">\n";
        my $alternate = 1;
        for (my $i = $from; $i <= $to; $i++) {
-               my $commit = $greplist->[$i];
-               my %co = parse_commit($commit);
+               my %co = %{$commitlist->[$i]};
                if (!%co) {
                        next;
                }
+               my $commit = $co{'id'};
                if ($alternate) {
                        print "<tr class=\"dark\">\n";
                } else {
@@ -3645,28 +3645,25 @@ sub git_log {
        }
        my $refs = git_get_references();
 
-       my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
-       open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash, "--"
-               or die_error(undef, "Open git-rev-list failed");
-       my @revlist = map { chomp; $_ } <$fd>;
-       close $fd;
+       my @commitlist = parse_commits($hash, 101, (100 * $page));
 
-       my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#revlist);
+       my $paging_nav = format_paging_nav('log', $hash, $head, $page, (100 * ($page+1)));
 
        git_header_html();
        git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
 
-       if (!@revlist) {
+       if (!@commitlist) {
                my %co = parse_commit($hash);
 
                git_print_header_div('summary', $project);
                print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
        }
-       for (my $i = ($page * 100); $i <= $#revlist; $i++) {
-               my $commit = $revlist[$i];
-               my $ref = format_ref_marker($refs, $commit);
-               my %co = parse_commit($commit);
+       my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
+       for (my $i = 0; $i <= $to; $i++) {
+               my %co = %{$commitlist[$i]};
                next if !%co;
+               my $commit = $co{'id'};
+               my $ref = format_ref_marker($refs, $commit);
                my %ad = parse_date($co{'author_epoch'});
                git_print_header_div('commit',
                               "<span class=\"age\">$co{'age_string'}</span>" .
@@ -3688,6 +3685,12 @@ sub git_log {
                git_print_log($co{'comment'}, -final_empty_line=> 1);
                print "</div>\n";
        }
+       if ($#commitlist >= 100) {
+               print "<div class=\"page_nav\">\n";
+               print $cgi->a({-href => href(action=>"log", hash=>$hash, page=>$page+1),
+                              -accesskey => "n", -title => "Alt-n"}, "next");
+               print "</div>\n";
+       }
        git_footer_html();
 }
 
@@ -4304,13 +4307,8 @@ sub git_search {
                } elsif ($searchtype eq 'committer') {
                        $greptype = "--committer=";
                }
-               open my $fd, "-|", git_cmd(), "rev-list",
-                       ("--max-count=" . (100 * ($page+1))),
-                       ($greptype . $searchtext),
-                       $hash, "--"
-                       or next;
-               my @revlist = map { chomp; $_ } <$fd>;
-               close $fd;
+               $greptype .= $searchtext;
+               my @commitlist = parse_commits($hash, 101, (100 * $page), $greptype);
 
                my $paging_nav = '';
                if ($page > 0) {
@@ -4327,7 +4325,7 @@ sub git_search {
                        $paging_nav .= "first";
                        $paging_nav .= " &sdot; prev";
                }
-               if ($#revlist >= (100 * ($page+1)-1)) {
+               if ($#commitlist >= 100) {
                        $paging_nav .= " &sdot; " .
                                $cgi->a({-href => href(action=>"search", hash=>$hash,
                                                       searchtext=>$searchtext, searchtype=>$searchtype,
@@ -4337,7 +4335,7 @@ sub git_search {
                        $paging_nav .= " &sdot; next";
                }
                my $next_link = '';
-               if ($#revlist >= (100 * ($page+1)-1)) {
+               if ($#commitlist >= 100) {
                        $next_link =
                                $cgi->a({-href => href(action=>"search", hash=>$hash,
                                                       searchtext=>$searchtext, searchtype=>$searchtype,
@@ -4347,7 +4345,7 @@ sub git_search {
 
                git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
                git_print_header_div('commit', esc_html($co{'title'}), $hash);
-               git_search_grep_body(\@revlist, ($page * 100), $#revlist, $next_link);
+               git_search_grep_body(\@commitlist, 0, 99, $next_link);
        }
 
        if ($searchtype eq 'pickaxe') {
@@ -4485,11 +4483,7 @@ sub git_feed {
 
        # log/feed of current (HEAD) branch, log of given branch, history of file/directory
        my $head = $hash || 'HEAD';
-       open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150",
-               $head, "--", (defined $file_name ? $file_name : ())
-               or die_error(undef, "Open git-rev-list failed");
-       my @revlist = map { chomp; $_ } <$fd>;
-       close $fd or die_error(undef, "Reading git-rev-list failed");
+       my @commitlist = parse_commits($head, 150);
 
        my %latest_commit;
        my %latest_date;
@@ -4499,8 +4493,8 @@ sub git_feed {
                # browser (feed reader) prefers text/xml
                $content_type = 'text/xml';
        }
-       if (defined($revlist[0])) {
-               %latest_commit = parse_commit($revlist[0]);
+       if (defined($commitlist[0])) {
+               %latest_commit = %{$commitlist[0]};
                %latest_date   = parse_date($latest_commit{'author_epoch'});
                print $cgi->header(
                        -type => $content_type,
@@ -4590,9 +4584,9 @@ sub git_feed {
        }
 
        # contents
-       for (my $i = 0; $i <= $#revlist; $i++) {
-               my $commit = $revlist[$i];
-               my %co = parse_commit($commit);
+       for (my $i = 0; $i <= $#commitlist; $i++) {
+               my %co = %{$commitlist[$i]};
+               my $commit = $co{'id'};
                # we read 150, we always show 30 and the ones more recent than 48 hours
                if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
                        last;
@@ -4600,7 +4594,7 @@ sub git_feed {
                my %cd = parse_date($co{'author_epoch'});
 
                # get list of changed files
-               open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
+               open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
                        $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
                        or next;
                my @difftree = map { chomp; $_ } <$fd>;