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>maint
parent
04f7a94f65
commit
8be683520e
|
|
@ -1933,12 +1933,15 @@ sub git_shortlog_body {
|
||||||
|
|
||||||
sub git_history_body {
|
sub git_history_body {
|
||||||
# Warning: assumes constant type (blob or tree) during history
|
# Warning: assumes constant type (blob or tree) during history
|
||||||
my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
|
my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
|
||||||
|
|
||||||
|
$from = 0 unless defined $from;
|
||||||
|
$to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
|
||||||
|
|
||||||
print "<table class=\"history\" cellspacing=\"0\">\n";
|
print "<table class=\"history\" cellspacing=\"0\">\n";
|
||||||
my $alternate = 0;
|
my $alternate = 0;
|
||||||
while (my $line = <$fd>) {
|
for (my $i = $from; $i <= $to; $i++) {
|
||||||
if ($line !~ m/^([0-9a-fA-F]{40})/) {
|
if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3114,29 +3117,70 @@ sub git_history {
|
||||||
if (!defined $hash_base) {
|
if (!defined $hash_base) {
|
||||||
$hash_base = git_get_head_hash($project);
|
$hash_base = git_get_head_hash($project);
|
||||||
}
|
}
|
||||||
|
if (!defined $page) {
|
||||||
|
$page = 0;
|
||||||
|
}
|
||||||
my $ftype;
|
my $ftype;
|
||||||
my %co = parse_commit($hash_base);
|
my %co = parse_commit($hash_base);
|
||||||
if (!%co) {
|
if (!%co) {
|
||||||
die_error(undef, "Unknown commit object");
|
die_error(undef, "Unknown commit object");
|
||||||
}
|
}
|
||||||
|
|
||||||
my $refs = git_get_references();
|
my $refs = git_get_references();
|
||||||
git_header_html();
|
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
|
||||||
git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);
|
|
||||||
git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
|
|
||||||
if (!defined $hash && defined $file_name) {
|
if (!defined $hash && defined $file_name) {
|
||||||
$hash = git_get_hash_by_path($hash_base, $file_name);
|
$hash = git_get_hash_by_path($hash_base, $file_name);
|
||||||
}
|
}
|
||||||
if (defined $hash) {
|
if (defined $hash) {
|
||||||
$ftype = git_get_type($hash);
|
$ftype = git_get_type($hash);
|
||||||
}
|
}
|
||||||
git_print_page_path($file_name, $ftype, $hash_base);
|
|
||||||
|
|
||||||
open my $fd, "-|",
|
open my $fd, "-|",
|
||||||
git_cmd(), "rev-list", "--full-history", $hash_base, "--", $file_name;
|
git_cmd(), "rev-list", $limit, "--full-history", $hash_base, "--", $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");
|
||||||
|
|
||||||
git_history_body($fd, $refs, $hash_base, $ftype);
|
my $paging_nav = '';
|
||||||
|
if ($page > 0) {
|
||||||
|
$paging_nav .=
|
||||||
|
$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
|
||||||
|
file_name=>$file_name)},
|
||||||
|
"first");
|
||||||
|
$paging_nav .= " ⋅ " .
|
||||||
|
$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
|
||||||
|
file_name=>$file_name, page=>$page-1),
|
||||||
|
-accesskey => "p", -title => "Alt-p"}, "prev");
|
||||||
|
} else {
|
||||||
|
$paging_nav .= "first";
|
||||||
|
$paging_nav .= " ⋅ prev";
|
||||||
|
}
|
||||||
|
if ($#revlist >= (100 * ($page+1)-1)) {
|
||||||
|
$paging_nav .= " ⋅ " .
|
||||||
|
$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
|
||||||
|
file_name=>$file_name, page=>$page+1),
|
||||||
|
-accesskey => "n", -title => "Alt-n"}, "next");
|
||||||
|
} else {
|
||||||
|
$paging_nav .= " ⋅ next";
|
||||||
|
}
|
||||||
|
my $next_link = '';
|
||||||
|
if ($#revlist >= (100 * ($page+1)-1)) {
|
||||||
|
$next_link =
|
||||||
|
$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
|
||||||
|
file_name=>$file_name, page=>$page+1),
|
||||||
|
-title => "Alt-n"}, "next");
|
||||||
|
}
|
||||||
|
|
||||||
|
git_header_html();
|
||||||
|
git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
|
||||||
|
git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
|
||||||
|
git_print_page_path($file_name, $ftype, $hash_base);
|
||||||
|
|
||||||
|
git_history_body(\@revlist, ($page * 100), $#revlist,
|
||||||
|
$refs, $hash_base, $ftype, $next_link);
|
||||||
|
|
||||||
close $fd;
|
|
||||||
git_footer_html();
|
git_footer_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue