aboutsummaryrefslogtreecommitdiff
path: root/gitweb
diff options
context:
space:
mode:
authorJakub Narebski <jnareb@gmail.com>2008-06-03 16:47:10 +0200
committerJunio C Hamano <gitster@pobox.com>2008-06-04 15:05:01 -0700
commit7f718e8b46b37a9e1caf58a372938817f04885d9 (patch)
tree4c0461af9b0af0efe78126e958b6621da63a9507 /gitweb
parentdd613e6b8706f31c01aae622345dbaab3f276262 (diff)
downloadgit-7f718e8b46b37a9e1caf58a372938817f04885d9.tar.gz
git-7f718e8b46b37a9e1caf58a372938817f04885d9.tar.xz
gitweb: Add charset info to "raw" output of 'text/plain' blobs
Earlier "blob_plain" view sent "charset=utf-8" only when gitweb guessed the content type to be text by reading from it, and not when the MIME type was obtained from /etc/mime.types, or when gitweb couldn't guess mimetype and used $default_blob_plain_mimetype. This fixes the bug by always add charset info from $default_text_plain_charset (if it is defined) to "raw" (a=blob_plain) output for 'text/plain' blobs. Generating information for Content-Type: header got separated into blob_contenttype() subroutine; adding charset info in a special case was removed from blob_mimetype(), which now should return mimetype only. While at it cleanup code a bit: put subroutine parameter initialization first, make error message more robust (when $file_name is not defined) if more cryptic, remove unnecessary '"' around variable ("$var" -> $var). Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'gitweb')
-rwxr-xr-xgitweb/gitweb.perl29
1 files changed, 20 insertions, 9 deletions
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 55fb10053..198772c21 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2481,8 +2481,7 @@ sub blob_mimetype {
return $default_blob_plain_mimetype unless $fd;
if (-T $fd) {
- return 'text/plain' .
- ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
+ return 'text/plain';
} elsif (! $filename) {
return 'application/octet-stream';
} elsif ($filename =~ m/\.png$/i) {
@@ -2496,6 +2495,17 @@ sub blob_mimetype {
}
}
+sub blob_contenttype {
+ my ($fd, $file_name, $type) = @_;
+
+ $type ||= blob_mimetype($fd, $file_name);
+ if ($type eq 'text/plain' && defined $default_text_plain_charset) {
+ $type .= "; charset=$default_text_plain_charset";
+ }
+
+ return $type;
+}
+
## ======================================================================
## functions printing HTML: header, footer, error page
@@ -4374,6 +4384,7 @@ sub git_heads {
}
sub git_blob_plain {
+ my $type = shift;
my $expires;
if (!defined $hash) {
@@ -4389,13 +4400,13 @@ sub git_blob_plain {
$expires = "+1d";
}
- my $type = shift;
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
- or die_error(undef, "Couldn't cat $file_name, $hash");
+ or die_error(undef, "Open git-cat-file blob '$hash' failed");
- $type ||= blob_mimetype($fd, $file_name);
+ # content-type (can include charset)
+ $type = blob_contenttype($fd, $file_name, $type);
- # save as filename, even when no $file_name is given
+ # "save as" filename, even when no $file_name is given
my $save_as = "$hash";
if (defined $file_name) {
$save_as = $file_name;
@@ -4404,9 +4415,9 @@ sub git_blob_plain {
}
print $cgi->header(
- -type => "$type",
- -expires=>$expires,
- -content_disposition => 'inline; filename="' . "$save_as" . '"');
+ -type => $type,
+ -expires => $expires,
+ -content_disposition => 'inline; filename="' . $save_as . '"');
undef $/;
binmode STDOUT, ':raw';
print <$fd>;