Skip to content

Commit dfa7c7d

Browse files
jnarebgitster
authored andcommitted
gitweb: Teach "a=blob" action to be more lenient about blob/file mime type
Since 930cf7d 'blob' action knows the file type; if the file type is not "text/*" or one of common network image formats/mimetypes (gif, png, jpeg) then the action "blob" defaulted to "blob_plain". This caused the problem if mimetypes file was not well suited for web, for example returning "application/x-sh" for "*.sh" shell scripts, instead of "text/plain" (or other "text/*"). Now "blob" action defaults to "blob_plain" ('raw' view) only if file is of type which is neither "text/*" nor "image/{gif,png,jpeg}" AND it is binary file. Otherwise it assumes that it can be displayed either in <img> tag ("image/*" mimetype), or can be displayed line by line (otherwise). Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent bf901f8 commit dfa7c7d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

gitweb/gitweb.perl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,7 +4290,7 @@ sub git_blob {
42904290
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
42914291
or die_error(undef, "Couldn't cat $file_name, $hash");
42924292
my $mimetype = blob_mimetype($fd, $file_name);
4293-
if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4293+
if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
42944294
close $fd;
42954295
return git_blob_plain($mimetype);
42964296
}
@@ -4331,16 +4331,7 @@ sub git_blob {
43314331
}
43324332
git_print_page_path($file_name, "blob", $hash_base);
43334333
print "<div class=\"page_body\">\n";
4334-
if ($mimetype =~ m!^text/!) {
4335-
my $nr;
4336-
while (my $line = <$fd>) {
4337-
chomp $line;
4338-
$nr++;
4339-
$line = untabify($line);
4340-
printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4341-
$nr, $nr, $nr, esc_html($line, -nbsp=>1);
4342-
}
4343-
} elsif ($mimetype =~ m!^image/!) {
4334+
if ($mimetype =~ m!^image/!) {
43444335
print qq!<img type="$mimetype"!;
43454336
if ($file_name) {
43464337
print qq! alt="$file_name" title="$file_name"!;
@@ -4349,6 +4340,15 @@ sub git_blob {
43494340
href(action=>"blob_plain", hash=>$hash,
43504341
hash_base=>$hash_base, file_name=>$file_name) .
43514342
qq!" />\n!;
4343+
} else {
4344+
my $nr;
4345+
while (my $line = <$fd>) {
4346+
chomp $line;
4347+
$nr++;
4348+
$line = untabify($line);
4349+
printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4350+
$nr, $nr, $nr, esc_html($line, -nbsp=>1);
4351+
}
43524352
}
43534353
close $fd
43544354
or print "Reading blob failed.\n";

0 commit comments

Comments
 (0)