@matheusbsbs / matheus-bagliano / commits / 8be683520e
Fork 0

gitweb: Paginate history output

git_history output is now divided into pages, like git_shortlog, git_tags and git_heads output. As whole git-rev-list output is now read into array before writing anything, it allows for better signaling of errors. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Sep 11, 2006 at 00:36 UTC 8be683520e5a00cb7bd67acfd71d9346c33305b2
1 file changed +54 -10
gitweb/gitweb.perl
+54 -10
@@ -1933,12 +1933,15 @@ sub git_shortlog_body {
1933
1934 sub git_history_body {
1935 # Warning: assumes constant type (blob or tree) during history
1936 - my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1936 + my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
1937 +
1938 + $from = 0 unless defined $from;
1939 + $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
1940
1941 print "<table class=\"history\" cellspacing=\"0\">\n";
1942 my $alternate = 0;
1940 - while (my $line = <$fd>) {
1941 - if ($line !~ m/^([0-9a-fA-F]{40})/) {
1943 + for (my $i = $from; $i <= $to; $i++) {
1944 + if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
1945 next;
1946 }
1947
@@ -3114,29 +3117,70 @@ sub git_history {
3117 if (!defined $hash_base) {
3118 $hash_base = git_get_head_hash($project);
3119 }
3120 + if (!defined $page) {
3121 + $page = 0;
3122 + }
3123 my $ftype;
3124 my %co = parse_commit($hash_base);
3125 if (!%co) {
3126 die_error(undef, "Unknown commit object");
3127 }
3128 +
3129 my $refs = git_get_references();
3123 - git_header_html();
3124 - git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);
3125 - git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3130 + my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3131 +
3132 if (!defined $hash && defined $file_name) {
3133 $hash = git_get_hash_by_path($hash_base, $file_name);
3134 }
3135 if (defined $hash) {
3136 $ftype = git_get_type($hash);
3137 }
3132 - git_print_page_path($file_name, $ftype, $hash_base);
3138
3139 open my $fd, "-|",
3135 - git_cmd(), "rev-list", "--full-history", $hash_base, "--", $file_name;
3140 + git_cmd(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3141 + or die_error(undef, "Open git-rev-list-failed");
3142 + my @revlist = map { chomp; $_ } <$fd>;
3143 + close $fd
3144 + or die_error(undef, "Reading git-rev-list failed");
3145 +
3146 + my $paging_nav = '';
3147 + if ($page > 0) {
3148 + $paging_nav .=
3149 + $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3150 + file_name=>$file_name)},
3151 + "first");
3152 + $paging_nav .= " &sdot; " .
3153 + $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3154 + file_name=>$file_name, page=>$page-1),
3155 + -accesskey => "p", -title => "Alt-p"}, "prev");
3156 + } else {
3157 + $paging_nav .= "first";
3158 + $paging_nav .= " &sdot; prev";
3159 + }
3160 + if ($#revlist >= (100 * ($page+1)-1)) {
3161 + $paging_nav .= " &sdot; " .
3162 + $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3163 + file_name=>$file_name, page=>$page+1),
3164 + -accesskey => "n", -title => "Alt-n"}, "next");
3165 + } else {
3166 + $paging_nav .= " &sdot; next";
3167 + }
3168 + my $next_link = '';
3169 + if ($#revlist >= (100 * ($page+1)-1)) {
3170 + $next_link =
3171 + $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
3172 + file_name=>$file_name, page=>$page+1),
3173 + -title => "Alt-n"}, "next");
3174 + }
3175
3137 - git_history_body($fd, $refs, $hash_base, $ftype);
3176 + git_header_html();
3177 + git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3178 + git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
3179 + git_print_page_path($file_name, $ftype, $hash_base);
3180 +
3181 + git_history_body(\@revlist, ($page * 100), $#revlist,
3182 + $refs, $hash_base, $ftype, $next_link);
3183
3139 - close $fd;
3184 git_footer_html();
3185 }
3186