{"thread":{"id":"5534","subject":"[PATCH] gitweb: Paginate history output","startedAt":"2006-09-10T22:36:04Z","lastAt":"2006-09-10T22:36:04Z","messageCount":1,"participants":["Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"26703","messageId":"200609110036.04827.jnareb@gmail.com","threadId":"5534","inReplyTo":null,"subject":"[PATCH] gitweb: Paginate history output","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-09-10T22:36:04Z","receivedAt":"2006-09-10T22:36:04Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"git_history output is now divided into pages, like git_shortlog,\ngit_tags and git_heads output. As whole git-rev-list output is now\nread into array before writing anything, it allows for better\nsignaling of errors.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis can be seen as the part of series consolidating log-like\nview (shortlog, log, history, perhaps tags and heads) generation.\n\n gitweb/gitweb.perl |   64 ++++++++++++++++++++++++++++++++++++++++++++--------\n 1 files changed, 54 insertions(+), 10 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 53e3478..c3544dd 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1933,12 +1933,15 @@ sub git_shortlog_body {\n \n sub git_history_body {\n \t# Warning: assumes constant type (blob or tree) during history\n-\tmy ($fd, $refs, $hash_base, $ftype, $extra) = @_;\n+\tmy ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;\n+\n+\t$from = 0 unless defined $from;\n+\t$to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});\n \n \tprint \"<table class=\\\"history\\\" cellspacing=\\\"0\\\">\\n\";\n \tmy $alternate = 0;\n-\twhile (my $line = <$fd>) {\n-\t\tif ($line !~ m/^([0-9a-fA-F]{40})/) {\n+\tfor (my $i = $from; $i <= $to; $i++) {\n+\t\tif ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {\n \t\t\tnext;\n \t\t}\n \n@@ -3114,29 +3117,70 @@ sub git_history {\n \tif (!defined $hash_base) {\n \t\t$hash_base = git_get_head_hash($project);\n \t}\n+\tif (!defined $page) {\n+\t\t$page = 0;\n+\t}\n \tmy $ftype;\n \tmy %co = parse_commit($hash_base);\n \tif (!%co) {\n \t\tdie_error(undef, \"Unknown commit object\");\n \t}\n+\n \tmy $refs = git_get_references();\n-\tgit_header_html();\n-\tgit_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);\n-\tgit_print_header_div('commit', esc_html($co{'title'}), $hash_base);\n+\tmy $limit = sprintf(\"--max-count=%i\", (100 * ($page+1)));\n+\n \tif (!defined $hash && defined $file_name) {\n \t\t$hash = git_get_hash_by_path($hash_base, $file_name);\n \t}\n \tif (defined $hash) {\n \t\t$ftype = git_get_type($hash);\n \t}\n-\tgit_print_page_path($file_name, $ftype, $hash_base);\n \n \topen my $fd, \"-|\",\n-\t\tgit_cmd(), \"rev-list\", \"--full-history\", $hash_base, \"--\", $file_name;\n+\t\tgit_cmd(), \"rev-list\", $limit, \"--full-history\", $hash_base, \"--\", $file_name\n+\t\t\tor die_error(undef, \"Open git-rev-list-failed\");\n+\tmy @revlist = map { chomp; $_ } <$fd>;\n+\tclose $fd\n+\t\tor die_error(undef, \"Reading git-rev-list failed\");\n+\n+\tmy $paging_nav = '';\n+\tif ($page > 0) {\n+\t\t$paging_nav .=\n+\t\t\t$cgi->a({-href => href(action=>\"history\", hash=>$hash, hash_base=>$hash_base,\n+\t\t\t                       file_name=>$file_name)},\n+\t\t\t        \"first\");\n+\t\t$paging_nav .= \" &sdot; \" .\n+\t\t\t$cgi->a({-href => href(action=>\"history\", hash=>$hash, hash_base=>$hash_base,\n+\t\t\t                       file_name=>$file_name, page=>$page-1),\n+\t\t\t         -accesskey => \"p\", -title => \"Alt-p\"}, \"prev\");\n+\t} else {\n+\t\t$paging_nav .= \"first\";\n+\t\t$paging_nav .= \" &sdot; prev\";\n+\t}\n+\tif ($#revlist >= (100 * ($page+1)-1)) {\n+\t\t$paging_nav .= \" &sdot; \" .\n+\t\t\t$cgi->a({-href => href(action=>\"history\", hash=>$hash, hash_base=>$hash_base,\n+\t\t\t                       file_name=>$file_name, page=>$page+1),\n+\t\t\t         -accesskey => \"n\", -title => \"Alt-n\"}, \"next\");\n+\t} else {\n+\t\t$paging_nav .= \" &sdot; next\";\n+\t}\n+\tmy $next_link = '';\n+\tif ($#revlist >= (100 * ($page+1)-1)) {\n+\t\t$next_link =\n+\t\t\t$cgi->a({-href => href(action=>\"history\", hash=>$hash, hash_base=>$hash_base,\n+\t\t\t                       file_name=>$file_name, page=>$page+1),\n+\t\t\t         -title => \"Alt-n\"}, \"next\");\n+\t}\n \n-\tgit_history_body($fd, $refs, $hash_base, $ftype);\n+\tgit_header_html();\n+\tgit_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);\n+\tgit_print_header_div('commit', esc_html($co{'title'}), $hash_base);\n+\tgit_print_page_path($file_name, $ftype, $hash_base);\n+\n+\tgit_history_body(\\@revlist, ($page * 100), $#revlist,\n+\t                 $refs, $hash_base, $ftype, $next_link);\n \n-\tclose $fd;\n \tgit_footer_html();\n }\n \n-- \n1.4.2\n"}]}