Skip to content

Commit 785cdea

Browse files
jnarebJunio C Hamano
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 43d151a commit 785cdea

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

gitweb/gitweb.perl

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,9 @@ sub chop_str {
728728
sub age_class {
729729
my $age = shift;
730730

731-
if ($age < 60*60*2) {
731+
if (!defined $age) {
732+
return "noage";
733+
} elsif ($age < 60*60*2) {
732734
return "age0";
733735
} elsif ($age < 60*60*24*2) {
734736
return "age1";
@@ -1258,7 +1260,8 @@ sub git_get_last_activity {
12581260
'refs/heads') or return;
12591261
my $most_recent = <$fd>;
12601262
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$/) {
12621265
my $timestamp = $1;
12631266
my $age = time - $timestamp;
12641267
return ($age, age_string($age));
@@ -2983,7 +2986,7 @@ sub git_project_list_body {
29832986
esc_html($pr->{'descr'})) . "</td>\n" .
29842987
"<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
29852988
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" .
29872990
"<td class=\"link\">" .
29882991
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
29892992
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
@@ -3335,7 +3338,7 @@ sub git_project_index {
33353338
sub git_summary {
33363339
my $descr = git_get_project_description($project) || "none";
33373340
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'}) : ();
33393342
my $head = $co{'id'};
33403343

33413344
my $owner = git_get_project_owner($project);
@@ -3358,8 +3361,11 @@ sub git_summary {
33583361
print "<div class=\"title\">&nbsp;</div>\n";
33593362
print "<table cellspacing=\"0\">\n" .
33603363
"<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+
33633369
# use per project git URL list in $projectroot/$project/cloneurl
33643370
# or make project git URL from git base URL and project name
33653371
my $url_tag = "URL";
@@ -3382,11 +3388,13 @@ sub git_summary {
33823388

33833389
# we need to request one more than 16 (0..15) to check if
33843390
# 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+
}
33903398

33913399
if (@taglist) {
33923400
git_print_header_div('tags');

0 commit comments

Comments
 (0)