gitweb: Refactor 'log' action generation, adding git_log_body()
Put the main part of 'log' view generation into git_log_body, similarly how it is done for 'shortlog' and 'history' views (and also for 'tags' and 'heads' views). This is preparation for extracting common code between 'log', 'shortlog' and 'history' actions. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jakub Narebski committed
Nov 13, 2009 at 02:02 UTC
42671caa7d619da9d490e77c438845c1e638c54c
1 file changed
+48
-33
gitweb/gitweb.perl
+48
-33
@@ -4361,6 +4361,46 @@ sub git_project_list_body {
4361
print "</table>\n";
4362
}
4363
4364
+sub git_log_body {
4365
+ # uses global variable $project
4366
+ my ($commitlist, $from, $to, $refs, $extra) = @_;
4367
+
4368
+ $from = 0 unless defined $from;
4369
+ $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4370
+
4371
+ for (my $i = 0; $i <= $to; $i++) {
4372
+ my %co = %{$commitlist->[$i]};
4373
+ next if !%co;
4374
+ my $commit = $co{'id'};
4375
+ my $ref = format_ref_marker($refs, $commit);
4376
+ my %ad = parse_date($co{'author_epoch'});
4377
+ git_print_header_div('commit',
4378
+ "<span class=\"age\">$co{'age_string'}</span>" .
4379
+ esc_html($co{'title'}) . $ref,
4380
+ $commit);
4381
+ print "<div class=\"title_text\">\n" .
4382
+ "<div class=\"log_link\">\n" .
4383
+ $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
4384
+ " | " .
4385
+ $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
4386
+ " | " .
4387
+ $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
4388
+ "<br/>\n" .
4389
+ "</div>\n";
4390
+ git_print_authorship(\%co, -tag => 'span');
4391
+ print "<br/>\n</div>\n";
4392
+
4393
+ print "<div class=\"log_body\">\n";
4394
+ git_print_log($co{'comment'}, -final_empty_line=> 1);
4395
+ print "</div>\n";
4396
+ }
4397
+ if ($extra) {
4398
+ print "<div class=\"page_nav\">\n";
4399
+ print "$extra\n";
4400
+ print "</div>\n";
4401
+ }
4402
+}
4403
+
4404
sub git_shortlog_body {
4405
# uses global variable $project
4406
my ($commitlist, $from, $to, $refs, $extra) = @_;
@@ -5310,7 +5350,12 @@ sub git_log {
5350
my @commitlist = parse_commits($hash, 101, (100 * $page));
5351
5352
my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);
5313
-
5353
+ my $next_link;
5354
+ if ($#commitlist >= 100) {
5355
+ $next_link =
5356
+ $cgi->a({-href => href(-replay=>1, page=>$page+1),
5357
+ -accesskey => "n", -title => "Alt-n"}, "next");
5358
+ }
5359
my ($patch_max) = gitweb_get_feature('patches');
5360
if ($patch_max) {
5361
if ($patch_max < 0 || @commitlist <= $patch_max) {
@@ -5329,39 +5374,9 @@ sub git_log {
5374
git_print_header_div('summary', $project);
5375
print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5376
}
5332
- my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5333
- for (my $i = 0; $i <= $to; $i++) {
5334
- my %co = %{$commitlist[$i]};
5335
- next if !%co;
5336
- my $commit = $co{'id'};
5337
- my $ref = format_ref_marker($refs, $commit);
5338
- my %ad = parse_date($co{'author_epoch'});
5339
- git_print_header_div('commit',
5340
- "<span class=\"age\">$co{'age_string'}</span>" .
5341
- esc_html($co{'title'}) . $ref,
5342
- $commit);
5343
- print "<div class=\"title_text\">\n" .
5344
- "<div class=\"log_link\">\n" .
5345
- $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
5346
- " | " .
5347
- $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
5348
- " | " .
5349
- $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
5350
- "<br/>\n" .
5351
- "</div>\n";
5352
- git_print_authorship(\%co, -tag => 'span');
5353
- print "<br/>\n</div>\n";
5377
5355
- print "<div class=\"log_body\">\n";
5356
- git_print_log($co{'comment'}, -final_empty_line=> 1);
5357
- print "</div>\n";
5358
- }
5359
- if ($#commitlist >= 100) {
5360
- print "<div class=\"page_nav\">\n";
5361
- print $cgi->a({-href => href(-replay=>1, page=>$page+1),
5362
- -accesskey => "n", -title => "Alt-n"}, "next");
5363
- print "</div>\n";
5364
- }
5378
+ git_log_body(\@commitlist, 0, 99, $refs, $next_link);
5379
+
5380
git_footer_html();
5381
}
5382