gitweb: Refactor common parts of 'log' and 'shortlog' views
Put the common parts of git_log and git_shortlog into git_log_generic subroutine: git_log and git_shortlog are now thin wrappers calling git_log_generic with appropriate arguments. The unification of code responsible for 'log' and 'shorlog' actions lead to the following changes in gitweb output * 'tree' link in page_nav now uses $hash parameter, as was the case for 'shortlog' but not for 'log' * 'log' view now respect $hash_parent limiting, like 'shortlog' did * 'log' view doesn't have special case for empty list anymore, and it always uses page_header linking to summary view, like 'shortlog' did. 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
15f0b112d86001b0ae4be2555513c45b3cf65844
1 file changed
+20
-52
gitweb/gitweb.perl
+20
-52
@@ -5337,7 +5337,9 @@ sub git_snapshot {
5337
close $fd;
5338
}
5339
5340
-sub git_log {
5340
+sub git_log_generic {
5341
+ my ($fmt_name, $body_subr) = @_;
5342
+
5343
my $head = git_get_head_hash($project);
5344
if (!defined $hash) {
5345
$hash = $head;
@@ -5347,16 +5349,21 @@ sub git_log {
5349
}
5350
my $refs = git_get_references();
5351
5350
- my @commitlist = parse_commits($hash, 101, (100 * $page));
5352
+ my $commit_hash = $hash;
5353
+ if (defined $hash_parent) {
5354
+ $commit_hash = "$hash_parent..$hash";
5355
+ }
5356
+ my @commitlist = parse_commits($commit_hash, 101, (100 * $page));
5357
5352
- my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);
5353
- my $next_link;
5358
+ my $paging_nav = format_paging_nav($fmt_name, $hash, $head,
5359
+ $page, $#commitlist >= 100);
5360
+ my $next_link = '';
5361
if ($#commitlist >= 100) {
5362
$next_link =
5363
$cgi->a({-href => href(-replay=>1, page=>$page+1),
5364
-accesskey => "n", -title => "Alt-n"}, "next");
5365
}
5359
- my ($patch_max) = gitweb_get_feature('patches');
5366
+ my $patch_max = gitweb_get_feature('patches');
5367
if ($patch_max) {
5368
if ($patch_max < 0 || @commitlist <= $patch_max) {
5369
$paging_nav .= " ⋅ " .
@@ -5366,20 +5373,18 @@ sub git_log {
5373
}
5374
5375
git_header_html();
5369
- git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
5370
-
5371
- if (!@commitlist) {
5372
- my %co = parse_commit($hash);
5373
-
5374
- git_print_header_div('summary', $project);
5375
- print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5376
- }
5376
+ git_print_page_nav($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5377
+ git_print_header_div('summary', $project);
5378
5378
- git_log_body(\@commitlist, 0, 99, $refs, $next_link);
5379
+ $body_subr->(\@commitlist, 0, 99, $refs, $next_link);
5380
5381
git_footer_html();
5382
}
5383
5384
+sub git_log {
5385
+ git_log_generic('log', \&git_log_body);
5386
+}
5387
+
5388
sub git_commit {
5389
$hash ||= $hash_base || "HEAD";
5390
my %co = parse_commit($hash)
@@ -6243,44 +6248,7 @@ EOT
6248
}
6249
6250
sub git_shortlog {
6246
- my $head = git_get_head_hash($project);
6247
- if (!defined $hash) {
6248
- $hash = $head;
6249
- }
6250
- if (!defined $page) {
6251
- $page = 0;
6252
- }
6253
- my $refs = git_get_references();
6254
-
6255
- my $commit_hash = $hash;
6256
- if (defined $hash_parent) {
6257
- $commit_hash = "$hash_parent..$hash";
6258
- }
6259
- my @commitlist = parse_commits($commit_hash, 101, (100 * $page));
6260
-
6261
- my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#commitlist >= 100);
6262
- my $next_link = '';
6263
- if ($#commitlist >= 100) {
6264
- $next_link =
6265
- $cgi->a({-href => href(-replay=>1, page=>$page+1),
6266
- -accesskey => "n", -title => "Alt-n"}, "next");
6267
- }
6268
- my $patch_max = gitweb_check_feature('patches');
6269
- if ($patch_max) {
6270
- if ($patch_max < 0 || @commitlist <= $patch_max) {
6271
- $paging_nav .= " ⋅ " .
6272
- $cgi->a({-href => href(action=>"patches", -replay=>1)},
6273
- "patches");
6274
- }
6275
- }
6276
-
6277
- git_header_html();
6278
- git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
6279
- git_print_header_div('summary', $project);
6280
-
6281
- git_shortlog_body(\@commitlist, 0, 99, $refs, $next_link);
6282
-
6283
- git_footer_html();
6251
+ git_log_generic('shortlog', \&git_shortlog_body);
6252
}
6253
6254
## ......................................................................