gitweb: Fix "Use of unitialized value" warnings in empty repository
Fix it so gitweb doesn't write "Use of unitialized value..." warnings (which gets written in web server logs) for empty (no commits) repository. In empty repository "last change" (last activity) doesn't make sense; also there is no sense in parsing commits which aren't there. In projects list for empty repositories gitweb now writes "No commits" using "noage" class, instead of leaving cell empty, in the last change column. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jakub Narebski committed
May 13, 2007 at 12:39 UTC
785cdea9befecc63b2b576c8042c5482fbf7bceb
1 file changed
+19
-11
gitweb/gitweb.perl
+19
-11
@@ -728,7 +728,9 @@ sub chop_str {
728
sub age_class {
729
my $age = shift;
730
731
- if ($age < 60*60*2) {
731
+ if (!defined $age) {
732
+ return "noage";
733
+ } elsif ($age < 60*60*2) {
734
return "age0";
735
} elsif ($age < 60*60*24*2) {
736
return "age1";
@@ -1258,7 +1260,8 @@ sub git_get_last_activity {
1260
'refs/heads') or return;
1261
my $most_recent = <$fd>;
1262
close $fd or return;
1261
- if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1263
+ if (defined $most_recent &&
1264
+ $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1265
my $timestamp = $1;
1266
my $age = time - $timestamp;
1267
return ($age, age_string($age));
@@ -2983,7 +2986,7 @@ sub git_project_list_body {
2986
esc_html($pr->{'descr'})) . "</td>\n" .
2987
"<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2988
print "<td class=\"". age_class($pr->{'age'}) . "\">" .
2986
- $pr->{'age_string'} . "</td>\n" .
2989
+ (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
2990
"<td class=\"link\">" .
2991
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2992
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
@@ -3335,7 +3338,7 @@ sub git_project_index {
3338
sub git_summary {
3339
my $descr = git_get_project_description($project) || "none";
3340
my %co = parse_commit("HEAD");
3338
- my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
3341
+ my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3342
my $head = $co{'id'};
3343
3344
my $owner = git_get_project_owner($project);
@@ -3358,8 +3361,11 @@ sub git_summary {
3361
print "<div class=\"title\"> </div>\n";
3362
print "<table cellspacing=\"0\">\n" .
3363
"<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
3361
- "<tr><td>owner</td><td>$owner</td></tr>\n" .
3362
- "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3364
+ "<tr><td>owner</td><td>$owner</td></tr>\n";
3365
+ if (defined $cd{'rfc2822'}) {
3366
+ print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3367
+ }
3368
+
3369
# use per project git URL list in $projectroot/$project/cloneurl
3370
# or make project git URL from git base URL and project name
3371
my $url_tag = "URL";
@@ -3382,11 +3388,13 @@ sub git_summary {
3388
3389
# we need to request one more than 16 (0..15) to check if
3390
# those 16 are all
3385
- my @commitlist = parse_commits($head, 17);
3386
- git_print_header_div('shortlog');
3387
- git_shortlog_body(\@commitlist, 0, 15, $refs,
3388
- $#commitlist <= 15 ? undef :
3389
- $cgi->a({-href => href(action=>"shortlog")}, "..."));
3391
+ my @commitlist = $head ? parse_commits($head, 17) : ();
3392
+ if (@commitlist) {
3393
+ git_print_header_div('shortlog');
3394
+ git_shortlog_body(\@commitlist, 0, 15, $refs,
3395
+ $#commitlist <= 15 ? undef :
3396
+ $cgi->a({-href => href(action=>"shortlog")}, "..."));
3397
+ }
3398
3399
if (@taglist) {
3400
git_print_header_div('tags');