gitweb: Refactor generating of long dates into format_timestamp_html

It is pure refactoring and doesn't change gitweb output, though this
could potentially affect 'summary', 'log', and 'commit'-like views
('commit', 'commitdiff', 'tag').

Remove print_local_time and format_local_time, as their use is now
replaced (indirectly) by using format_timestamp_html.

While at it improve whitespace formatting.

Inspired-by-code-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Jakub Narebski 2011-04-28 21:04:07 +02:00 committed by Junio C Hamano
parent 1cae3ee70d
commit 256b7b4883
1 changed files with 22 additions and 23 deletions

View File

@ -3938,22 +3938,21 @@ sub git_print_section {
print $cgi->end_div; print $cgi->end_div;
} }


sub print_local_time { sub format_timestamp_html {
print format_local_time(@_); my ($date, %opts) = @_;
} my $strtime = $date->{'rfc2822'};


sub format_local_time { return $strtime unless $opts{'-localtime'};
my $localtime = '';
my %date = @_; my $localtime_format = '(%02d:%02d %s)';
if ($date{'hour_local'} < 6) { if ($date->{'hour_local'} < 6) {
$localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $localtime_format = '(<span class="atnight">%02d:%02d</span> %s)';
$date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
} else {
$localtime .= sprintf(" (%02d:%02d %s)",
$date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
} }
$strtime .= ' ' .
sprintf($localtime_format,
$date->{'hour_local'}, $date->{'minute_local'}, $date->{'tz_local'});


return $localtime; return $strtime;
} }


# Outputs the author name and date in long form # Outputs the author name and date in long form
@ -3966,10 +3965,9 @@ sub git_print_authorship {
my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
print "<$tag class=\"author_date\">" . print "<$tag class=\"author_date\">" .
format_search_author($author, "author", esc_html($author)) . format_search_author($author, "author", esc_html($author)) .
" [$ad{'rfc2822'}"; " [".format_timestamp_html(\%ad, %opts)."]".
print_local_time(%ad) if ($opts{-localtime}); git_get_avatar($co->{'author_email'}, -pad_before => 1) .
print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1) "</$tag>\n";
. "</$tag>\n";
} }


# Outputs table rows containing the full author or committer information, # Outputs table rows containing the full author or committer information,
@ -3993,9 +3991,9 @@ sub git_print_authorship_rows {
git_get_avatar($co->{"${who}_email"}, -size => 'double') . git_get_avatar($co->{"${who}_email"}, -size => 'double') .
"</td></tr>\n" . "</td></tr>\n" .
"<tr>" . "<tr>" .
"<td></td><td> $wd{'rfc2822'}"; "<td></td><td>" .
print_local_time(%wd); format_timestamp_html(\%wd, -localtime=>1) .
print "</td>" . "</td>" .
"</tr>\n"; "</tr>\n";
} }
} }
@ -5410,7 +5408,8 @@ sub git_summary {
"<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" . "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
"<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n"; "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
if (defined $cd{'rfc2822'}) { if (defined $cd{'rfc2822'}) {
print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n"; print "<tr id=\"metadata_lchange\"><td>last change</td>" .
"<td>".format_timestamp_html(\%cd)."</td></tr>\n";
} }


# use per project git URL list in $projectroot/$project/cloneurl # use per project git URL list in $projectroot/$project/cloneurl