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>
Jakub Narebski committed
Apr 28, 2011 at 21:04 UTC
256b7b4883231ae9c7f24f2cb4170f61e00704e1
1 file changed
+22
-23
gitweb/gitweb.perl
+22
-23
@@ -3938,22 +3938,21 @@ sub git_print_section {
3938
print $cgi->end_div;
3939
}
3940
3941
-sub print_local_time {
3942
- print format_local_time(@_);
3943
-}
3941
+sub format_timestamp_html {
3942
+ my ($date, %opts) = @_;
3943
+ my $strtime = $date->{'rfc2822'};
3944
3945
-sub format_local_time {
3946
- my $localtime = '';
3947
- my %date = @_;
3948
- if ($date{'hour_local'} < 6) {
3949
- $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3950
- $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3951
- } else {
3952
- $localtime .= sprintf(" (%02d:%02d %s)",
3953
- $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3945
+ return $strtime unless $opts{'-localtime'};
3946
+
3947
+ my $localtime_format = '(%02d:%02d %s)';
3948
+ if ($date->{'hour_local'} < 6) {
3949
+ $localtime_format = '(<span class="atnight">%02d:%02d</span> %s)';
3950
}
3951
+ $strtime .= ' ' .
3952
+ sprintf($localtime_format,
3953
+ $date->{'hour_local'}, $date->{'minute_local'}, $date->{'tz_local'});
3954
3956
- return $localtime;
3955
+ return $strtime;
3956
}
3957
3958
# Outputs the author name and date in long form
@@ -3966,10 +3965,9 @@ sub git_print_authorship {
3965
my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
3966
print "<$tag class=\"author_date\">" .
3967
format_search_author($author, "author", esc_html($author)) .
3969
- " [$ad{'rfc2822'}";
3970
- print_local_time(%ad) if ($opts{-localtime});
3971
- print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
3972
- . "</$tag>\n";
3968
+ " [".format_timestamp_html(\%ad, %opts)."]".
3969
+ git_get_avatar($co->{'author_email'}, -pad_before => 1) .
3970
+ "</$tag>\n";
3971
}
3972
3973
# Outputs table rows containing the full author or committer information,
@@ -3986,16 +3984,16 @@ sub git_print_authorship_rows {
3984
my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3985
print "<tr><td>$who</td><td>" .
3986
format_search_author($co->{"${who}_name"}, $who,
3989
- esc_html($co->{"${who}_name"})) . " " .
3987
+ esc_html($co->{"${who}_name"})) . " " .
3988
format_search_author($co->{"${who}_email"}, $who,
3991
- esc_html("<" . $co->{"${who}_email"} . ">")) .
3989
+ esc_html("<" . $co->{"${who}_email"} . ">")) .
3990
"</td><td rowspan=\"2\">" .
3991
git_get_avatar($co->{"${who}_email"}, -size => 'double') .
3992
"</td></tr>\n" .
3993
"<tr>" .
3996
- "<td></td><td> $wd{'rfc2822'}";
3997
- print_local_time(%wd);
3998
- print "</td>" .
3994
+ "<td></td><td>" .
3995
+ format_timestamp_html(\%wd, -localtime=>1) .
3996
+ "</td>" .
3997
"</tr>\n";
3998
}
3999
}
@@ -5410,7 +5408,8 @@ sub git_summary {
5408
"<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
5409
"<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
5410
if (defined $cd{'rfc2822'}) {
5413
- print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
5411
+ print "<tr id=\"metadata_lchange\"><td>last change</td>" .
5412
+ "<td>".format_timestamp_html(\%cd)."</td></tr>\n";
5413
}
5414
5415
# use per project git URL list in $projectroot/$project/cloneurl