Skip to content

Commit 256b7b4

Browse files
jnarebgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1cae3ee commit 256b7b4

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

gitweb/gitweb.perl

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,22 +3938,21 @@ sub git_print_section {
39383938
print $cgi->end_div;
39393939
}
39403940

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'};
39443944

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)';
39543950
}
3951+
$strtime .= ' ' .
3952+
sprintf($localtime_format,
3953+
$date->{'hour_local'}, $date->{'minute_local'}, $date->{'tz_local'});
39553954

3956-
return $localtime;
3955+
return $strtime;
39573956
}
39583957

39593958
# Outputs the author name and date in long form
@@ -3966,10 +3965,9 @@ sub git_print_authorship {
39663965
my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
39673966
print "<$tag class=\"author_date\">" .
39683967
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";
39733971
}
39743972

39753973
# Outputs table rows containing the full author or committer information,
@@ -3986,16 +3984,16 @@ sub git_print_authorship_rows {
39863984
my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"});
39873985
print "<tr><td>$who</td><td>" .
39883986
format_search_author($co->{"${who}_name"}, $who,
3989-
esc_html($co->{"${who}_name"})) . " " .
3987+
esc_html($co->{"${who}_name"})) . " " .
39903988
format_search_author($co->{"${who}_email"}, $who,
3991-
esc_html("<" . $co->{"${who}_email"} . ">")) .
3989+
esc_html("<" . $co->{"${who}_email"} . ">")) .
39923990
"</td><td rowspan=\"2\">" .
39933991
git_get_avatar($co->{"${who}_email"}, -size => 'double') .
39943992
"</td></tr>\n" .
39953993
"<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>" .
39993997
"</tr>\n";
40003998
}
40013999
}
@@ -5410,7 +5408,8 @@ sub git_summary {
54105408
"<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
54115409
"<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
54125410
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";
54145413
}
54155414

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

0 commit comments

Comments
 (0)