) {
+ open(my $mh, '<', $mimemap) or return undef;
+ while (<$mh>) {
next if m/^#/; # skip comments
- my ($mime, $exts) = split(/\t+/);
+ my ($mimetype, $exts) = split(/\t+/);
if (defined $exts) {
my @exts = split(/\s+/, $exts);
foreach my $ext (@exts) {
- $mimemap{$ext} = $mime;
+ $mimemap{$ext} = $mimetype;
}
}
}
- close(MIME);
+ close($mh);
$filename =~ /\.([^.]*)$/;
return $mimemap{$1};
@@ -3216,22 +3304,54 @@ sub git_print_header_div {
"\n\n";
}
-#sub git_print_authorship (\%) {
+sub print_local_time {
+ my %date = @_;
+ if ($date{'hour_local'} < 6) {
+ printf(" (%02d:%02d %s)",
+ $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
+ } else {
+ printf(" (%02d:%02d %s)",
+ $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
+ }
+}
+
+# Outputs the author name and date in long form
sub git_print_authorship {
my $co = shift;
+ my %opts = @_;
+ my $tag = $opts{-tag} || 'div';
my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
- print "" .
+ print "<$tag class=\"author_date\">" .
esc_html($co->{'author_name'}) .
" [$ad{'rfc2822'}";
- if ($ad{'hour_local'} < 6) {
- printf(" (%02d:%02d %s)",
- $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
- } else {
- printf(" (%02d:%02d %s)",
- $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
+ print_local_time(%ad) if ($opts{-localtime});
+ print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
+ . "$tag>\n";
+}
+
+# Outputs table rows containing the full author or committer information,
+# in the format expected for 'commit' view (& similia).
+# Parameters are a commit hash reference, followed by the list of people
+# to output information for. If the list is empty it defalts to both
+# author and committer.
+sub git_print_authorship_rows {
+ my $co = shift;
+ # too bad we can't use @people = @_ || ('author', 'committer')
+ my @people = @_;
+ @people = ('author', 'committer') unless @people;
+ foreach my $who (@people) {
+ my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"});
+ print "
| $who | " . esc_html($co->{$who}) . " | " .
+ "" .
+ git_get_avatar($co->{"${who}_email"}, -size => 'double') .
+ " |
\n" .
+ "" .
+ " | $wd{'rfc2822'}";
+ print_local_time(%wd);
+ print " | " .
+ "
\n";
}
- print "]\n";
}
sub git_print_page_path {
@@ -3272,8 +3392,7 @@ sub git_print_page_path {
print "
\n";
}
-# sub git_print_log (\@;%) {
-sub git_print_log ($;%) {
+sub git_print_log {
my $log = shift;
my %opts = @_;
@@ -3331,7 +3450,7 @@ sub git_get_link_target {
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
or return;
{
- local $/;
+ local $/ = undef;
$link_target = <$fd>;
}
close $fd
@@ -3344,10 +3463,7 @@ sub git_get_link_target {
# return target of link relative to top directory (top tree);
# return undef if it is not possible (including absolute links).
sub normalize_link_target {
- my ($link_target, $basedir, $hash_base) = @_;
-
- # we can normalize symlink target only if $hash_base is provided
- return unless $hash_base;
+ my ($link_target, $basedir) = @_;
# absolute symlinks (beginning with '/') cannot be normalized
return if (substr($link_target, 0, 1) eq '/');
@@ -3403,7 +3519,7 @@ sub git_print_tree_entry {
if (S_ISLNK(oct $t->{'mode'})) {
my $link_target = git_get_link_target($t->{'hash'});
if ($link_target) {
- my $norm_target = normalize_link_target($link_target, $basedir, $hash_base);
+ my $norm_target = normalize_link_target($link_target, $basedir);
if (defined $norm_target) {
print " -> " .
$cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
@@ -3996,7 +4112,7 @@ sub fill_project_list_info {
($pname !~ /\/$/) &&
(-d "$projectroot/$pname")) {
$pr->{'forks'} = "-d $projectroot/$pname";
- } else {
+ } else {
$pr->{'forks'} = 0;
}
}
@@ -4149,11 +4265,9 @@ sub git_shortlog_body {
print "\n";
}
$alternate ^= 1;
- my $author = chop_and_escape_str($co{'author_name'}, 10);
# git_summary() used print "| $co{'age_string'} | \n" .
print "$co{'age_string_date'} | \n" .
- "" . $author . " | \n" .
- "";
+ format_author_html('td', \%co, 10) . " | ";
print format_subject_html($co{'title'}, $co{'title_short'},
href(action=>"commit", hash=>$commit), $ref);
print " | \n" .
@@ -4200,11 +4314,9 @@ sub git_history_body {
print "
\n";
}
$alternate ^= 1;
- # shortlog uses chop_str($co{'author_name'}, 10)
- my $author = chop_and_escape_str($co{'author_name'}, 15, 3);
print "| $co{'age_string_date'} | \n" .
- "" . $author . " | \n" .
- "";
+ # shortlog: format_author_html('td', \%co, 10)
+ format_author_html('td', \%co, 15, 3) . " | ";
# originally git_history used chop_str($co{'title'}, 50)
print format_subject_html($co{'title'}, $co{'title_short'},
href(action=>"commit", hash=>$commit), $ref);
@@ -4357,9 +4469,8 @@ sub git_search_grep_body {
print " |
\n";
}
$alternate ^= 1;
- my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
print "| $co{'age_string_date'} | \n" .
- "" . $author . " | \n" .
+ format_author_html('td', \%co, 15, 5) .
"" .
$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
-class => "list subject"},
@@ -4593,11 +4704,7 @@ sub git_tag {
$tag{'type'}) . " | \n" .
"
\n";
if (defined($tag{'author'})) {
- my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
- print "| author | " . esc_html($tag{'author'}) . " |
\n";
- print " | " . $ad{'rfc2822'} .
- sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
- " |
\n";
+ git_print_authorship_rows(\%tag, 'author');
}
print "\n\n" .
"\n";
@@ -4806,11 +4913,10 @@ sub git_blob_plain {
-content_disposition =>
($sandbox ? 'attachment' : 'inline')
. '; filename="' . $save_as . '"');
- undef $/;
+ local $/ = undef;
binmode STDOUT, ':raw';
print <$fd>;
binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
- $/ = "\n";
close $fd;
}
@@ -4912,12 +5018,16 @@ sub git_tree {
}
}
die_error(404, "No such tree") unless defined($hash);
- $/ = "\0";
- open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
- or die_error(500, "Open git-ls-tree failed");
- my @entries = map { chomp; $_ } <$fd>;
- close $fd or die_error(404, "Reading tree failed");
- $/ = "\n";
+
+ my @entries = ();
+ {
+ local $/ = "\0";
+ open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
+ or die_error(500, "Open git-ls-tree failed");
+ @entries = map { chomp; $_ } <$fd>;
+ close $fd
+ or die_error(404, "Reading tree failed");
+ }
my $refs = git_get_references();
my $ref = format_ref_marker($refs, $hash_base);
@@ -5098,9 +5208,9 @@ sub git_log {
" | " .
$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
"
\n" .
- "\n" .
- "" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]
\n" .
"\n";
+ git_print_authorship(\%co, -tag => 'span');
+ print "
\n\n";
print "\n";
git_print_log($co{'comment'}, -final_empty_line=> 1);
@@ -5119,8 +5229,6 @@ sub git_commit {
$hash ||= $hash_base || "HEAD";
my %co = parse_commit($hash)
or die_error(404, "Unknown commit object");
- my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
- my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
my $parent = $co{'parent'};
my $parents = $co{'parents'}; # listref
@@ -5187,22 +5295,7 @@ sub git_commit {
}
print "
\n" .
"