gitweb: Paginate commit/author/committer search output
Paginate commit/author/committer search output to only show 100 commits at a time, added appropriate nav links. Signed-off-by: Robert Fitzsimons <robfitz@273k.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Robert Fitzsimons committed
Dec 23, 2006 at 14:57 UTC
8dbc0fcef4912f7814b7822324b3c1943e55865b
1 file changed
+103
-45
gitweb/gitweb.perl
+103
-45
@@ -2852,6 +2852,58 @@ sub git_heads_body {
2852
print "</table>\n";
2853
}
2854
2855
+sub git_search_grep_body {
2856
+ my ($greplist, $from, $to, $extra) = @_;
2857
+ $from = 0 unless defined $from;
2858
+ $to = $#{$greplist} if (!defined $to || $#{$greplist} < $to);
2859
+
2860
+ print "<table class=\"grep\" cellspacing=\"0\">\n";
2861
+ my $alternate = 1;
2862
+ for (my $i = $from; $i <= $to; $i++) {
2863
+ my $commit = $greplist->[$i];
2864
+ my %co = parse_commit($commit);
2865
+ if (!%co) {
2866
+ next;
2867
+ }
2868
+ if ($alternate) {
2869
+ print "<tr class=\"dark\">\n";
2870
+ } else {
2871
+ print "<tr class=\"light\">\n";
2872
+ }
2873
+ $alternate ^= 1;
2874
+ print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2875
+ "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2876
+ "<td>" .
2877
+ $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
2878
+ esc_html(chop_str($co{'title'}, 50)) . "<br/>");
2879
+ my $comment = $co{'comment'};
2880
+ foreach my $line (@$comment) {
2881
+ if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2882
+ my $lead = esc_html($1) || "";
2883
+ $lead = chop_str($lead, 30, 10);
2884
+ my $match = esc_html($2) || "";
2885
+ my $trail = esc_html($3) || "";
2886
+ $trail = chop_str($trail, 30, 10);
2887
+ my $text = "$lead<span class=\"match\">$match</span>$trail";
2888
+ print chop_str($text, 80, 5) . "<br/>\n";
2889
+ }
2890
+ }
2891
+ print "</td>\n" .
2892
+ "<td class=\"link\">" .
2893
+ $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
2894
+ " | " .
2895
+ $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
2896
+ print "</td>\n" .
2897
+ "</tr>\n";
2898
+ }
2899
+ if (defined $extra) {
2900
+ print "<tr>\n" .
2901
+ "<td colspan=\"3\">$extra</td>\n" .
2902
+ "</tr>\n";
2903
+ }
2904
+ print "</table>\n";
2905
+}
2906
+
2907
## ======================================================================
2908
## ======================================================================
2909
## actions
@@ -4174,6 +4226,9 @@ sub git_search {
4226
if (!%co) {
4227
die_error(undef, "Unknown commit object");
4228
}
4229
+ if (!defined $page) {
4230
+ $page = 0;
4231
+ }
4232
4233
$searchtype ||= 'commit';
4234
if ($searchtype eq 'pickaxe') {
@@ -4186,11 +4241,7 @@ sub git_search {
4241
}
4242
4243
git_header_html();
4189
- git_print_page_nav('','', $hash,$co{'tree'},$hash);
4190
- git_print_header_div('commit', esc_html($co{'title'}), $hash);
4244
4192
- print "<table cellspacing=\"0\">\n";
4193
- my $alternate = 1;
4245
if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4246
my $greptype;
4247
if ($searchtype eq 'commit') {
@@ -4200,52 +4251,58 @@ sub git_search {
4251
} elsif ($searchtype eq 'committer') {
4252
$greptype = "--committer=";
4253
}
4203
- $/ = "\0";
4254
open my $fd, "-|", git_cmd(), "rev-list",
4205
- "--header", "--parents", ($greptype . $searchtext),
4206
- $hash, "--"
4255
+ ("--max-count=" . (100 * ($page+1))),
4256
+ ($greptype . $searchtext),
4257
+ $hash, "--"
4258
or next;
4208
- while (my $commit_text = <$fd>) {
4209
- my @commit_lines = split "\n", $commit_text;
4210
- my %co = parse_commit(undef, \@commit_lines);
4211
- if (!%co) {
4212
- next;
4213
- }
4214
- if ($alternate) {
4215
- print "<tr class=\"dark\">\n";
4216
- } else {
4217
- print "<tr class=\"light\">\n";
4218
- }
4219
- $alternate ^= 1;
4220
- print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4221
- "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4222
- "<td>" .
4223
- $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
4224
- esc_html(chop_str($co{'title'}, 50)) . "<br/>");
4225
- my $comment = $co{'comment'};
4226
- foreach my $line (@$comment) {
4227
- if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
4228
- my $lead = esc_html($1) || "";
4229
- $lead = chop_str($lead, 30, 10);
4230
- my $match = esc_html($2) || "";
4231
- my $trail = esc_html($3) || "";
4232
- $trail = chop_str($trail, 30, 10);
4233
- my $text = "$lead<span class=\"match\">$match</span>$trail";
4234
- print chop_str($text, 80, 5) . "<br/>\n";
4235
- }
4236
- }
4237
- print "</td>\n" .
4238
- "<td class=\"link\">" .
4239
- $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
4240
- " | " .
4241
- $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
4242
- print "</td>\n" .
4243
- "</tr>\n";
4244
- }
4259
+ my @revlist = map { chomp; $_ } <$fd>;
4260
close $fd;
4261
+
4262
+ my $paging_nav = '';
4263
+ if ($page > 0) {
4264
+ $paging_nav .=
4265
+ $cgi->a({-href => href(action=>"search", hash=>$hash,
4266
+ searchtext=>$searchtext, searchtype=>$searchtype)},
4267
+ "first");
4268
+ $paging_nav .= " ⋅ " .
4269
+ $cgi->a({-href => href(action=>"search", hash=>$hash,
4270
+ searchtext=>$searchtext, searchtype=>$searchtype,
4271
+ page=>$page-1),
4272
+ -accesskey => "p", -title => "Alt-p"}, "prev");
4273
+ } else {
4274
+ $paging_nav .= "first";
4275
+ $paging_nav .= " ⋅ prev";
4276
+ }
4277
+ if ($#revlist >= (100 * ($page+1)-1)) {
4278
+ $paging_nav .= " ⋅ " .
4279
+ $cgi->a({-href => href(action=>"search", hash=>$hash,
4280
+ searchtext=>$searchtext, searchtype=>$searchtype,
4281
+ page=>$page+1),
4282
+ -accesskey => "n", -title => "Alt-n"}, "next");
4283
+ } else {
4284
+ $paging_nav .= " ⋅ next";
4285
+ }
4286
+ my $next_link = '';
4287
+ if ($#revlist >= (100 * ($page+1)-1)) {
4288
+ $next_link =
4289
+ $cgi->a({-href => href(action=>"search", hash=>$hash,
4290
+ searchtext=>$searchtext, searchtype=>$searchtype,
4291
+ page=>$page+1),
4292
+ -accesskey => "n", -title => "Alt-n"}, "next");
4293
+ }
4294
+
4295
+ git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
4296
+ git_print_header_div('commit', esc_html($co{'title'}), $hash);
4297
+ git_search_grep_body(\@revlist, ($page * 100), $#revlist, $next_link);
4298
}
4299
4300
if ($searchtype eq 'pickaxe') {
4301
+ git_print_page_nav('','', $hash,$co{'tree'},$hash);
4302
+ git_print_header_div('commit', esc_html($co{'title'}), $hash);
4303
+
4304
+ print "<table cellspacing=\"0\">\n";
4305
+ my $alternate = 1;
4306
$/ = "\n";
4307
my $git_command = git_cmd_str();
4308
open my $fd, "-|", "$git_command rev-list $hash | " .
@@ -4300,8 +4357,9 @@ sub git_search {
4357
}
4358
}
4359
close $fd;
4360
+
4361
+ print "</table>\n";
4362
}
4304
- print "</table>\n";
4363
git_footer_html();
4364
}
4365