* [PATCH] gitweb: Teach "a=blob" action to be more lenient about blob/file mime type
@ 2007-12-08 11:55 Jakub Narebski
2007-12-09 3:34 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Narebski @ 2007-12-08 11:55 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jakub Narebski
Since 930cf7dd7cc6b87d173f182230763e1f1913d319 '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>
---
The patch I've send earlier
"[RFC/PATCH] gitweb: Try to sanitize mimetype for 'blob_plain' view"
Message-Id: <1195484054-18164-1-git-send-email-jnareb@gmail.com>
should also do what this patch is about. This one however IMHO
is much less invasive, and much less controversial.
P.S. BTW is there some plumbing for scripts to help with
gitattributes, for example showing all gitattributes (or status of
selected attributes) for given path?
gitweb/gitweb.perl | 24 ++++++++++++------------
1 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index eac7e16..b833327 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4302,7 +4302,7 @@ sub git_blob {
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
or die_error(undef, "Couldn't cat $file_name, $hash");
my $mimetype = blob_mimetype($fd, $file_name);
- if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
+ if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
close $fd;
return git_blob_plain($mimetype);
}
@@ -4343,16 +4343,7 @@ sub git_blob {
}
git_print_page_path($file_name, "blob", $hash_base);
print "<div class=\"page_body\">\n";
- if ($mimetype =~ m!^text/!) {
- my $nr;
- while (my $line = <$fd>) {
- chomp $line;
- $nr++;
- $line = untabify($line);
- printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
- $nr, $nr, $nr, esc_html($line, -nbsp=>1);
- }
- } elsif ($mimetype =~ m!^image/!) {
+ if ($mimetype =~ m!^image/!) {
print qq!<img type="$mimetype"!;
if ($file_name) {
print qq! alt="$file_name" title="$file_name"!;
@@ -4361,7 +4352,16 @@ sub git_blob {
href(action=>"blob_plain", hash=>$hash,
hash_base=>$hash_base, file_name=>$file_name) .
qq!" />\n!;
- }
+ } else {
+ my $nr;
+ while (my $line = <$fd>) {
+ chomp $line;
+ $nr++;
+ $line = untabify($line);
+ printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
+ $nr, $nr, $nr, esc_html($line, -nbsp=>1);
+ }
+ } els
close $fd
or print "Reading blob failed.\n";
print "</div>";
--
1.5.3.7
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] gitweb: Teach "a=blob" action to be more lenient about blob/file mime type
2007-12-08 11:55 [PATCH] gitweb: Teach "a=blob" action to be more lenient about blob/file mime type Jakub Narebski
@ 2007-12-09 3:34 ` Junio C Hamano
2007-12-09 10:06 ` Jakub Narebski
0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2007-12-09 3:34 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
Jakub Narebski <jnareb@gmail.com> writes:
> Since 930cf7dd7cc6b87d173f182230763e1f1913d319 '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).
Ok, the intent sounds sane. Let's see if the implementation is also
sane.
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index eac7e16..b833327 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -4302,7 +4302,7 @@ sub git_blob {
> open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
> or die_error(undef, "Couldn't cat $file_name, $hash");
> my $mimetype = blob_mimetype($fd, $file_name);
> - if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
> + if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
> close $fd;
> return git_blob_plain($mimetype);
> }
"If not text or image and binary go blob_plain" -- Ok.
> @@ -4343,16 +4343,7 @@ sub git_blob {
> }
> git_print_page_path($file_name, "blob", $hash_base);
> print "<div class=\"page_body\">\n";
> + if ($mimetype =~ m!^image/!) {
> print qq!<img type="$mimetype"!;
> if ($file_name) {
> print qq! alt="$file_name" title="$file_name"!;
> @@ -4361,7 +4352,16 @@ sub git_blob {
> href(action=>"blob_plain", hash=>$hash,
> hash_base=>$hash_base, file_name=>$file_name) .
> qq!" />\n!;
> + } else {
> + my $nr;
> + while (my $line = <$fd>) {
> + chomp $line;
> + $nr++;
> + $line = untabify($line);
> + printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
> + $nr, $nr, $nr, esc_html($line, -nbsp=>1);
> + }
> + } els
"If image, do image, but otherwise show line-by-line" -- Ok.
There is a "Huh?" on the last line, though.
> P.S. BTW is there some plumbing for scripts to help with
> gitattributes, for example showing all gitattributes (or status of
> selected attributes) for given path?
$ git grep gitattributes Documentation | grep -i display
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gitweb: Teach "a=blob" action to be more lenient about blob/file mime type
2007-12-09 3:34 ` Junio C Hamano
@ 2007-12-09 10:06 ` Jakub Narebski
0 siblings, 0 replies; 4+ messages in thread
From: Jakub Narebski @ 2007-12-09 10:06 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Junio C Hamano wrote:
> Jakub Narebski <jnareb@gmail.com> writes:
>> + }
>> + } els
> There is a "Huh?" on the last line, though.
I'm sorry for this wart. Can you correct this, or should I send
amended patch?
>> P.S. BTW is there some plumbing for scripts to help with
>> gitattributes, for example showing all gitattributes (or status of
>> selected attributes) for given path?
>
> $ git grep gitattributes Documentation | grep -i display
Thanks.
But as far as I can see you cannot specify _revision_,
i.e. git-check-attr operates _only_ on working directory, and
can be run only in a work tree. For gitweb I'd like it to run
in bare repository, and check $GIT_DIR/info/attributes and
<revision>:[*/].gitattributes
--
Jakub Narebski
Poland
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] gitweb: Teach "a=blob" action to be more lenient about blob/file mime type
2007-12-15 14:34 [PATCH 0/3 (resend)] gitweb: Miscelanous fixes Jakub Narebski
@ 2007-12-15 14:41 ` Jakub Narebski
0 siblings, 0 replies; 4+ messages in thread
From: Jakub Narebski @ 2007-12-15 14:41 UTC (permalink / raw)
To: git; +Cc: Junio Hamano
Since 930cf7dd7cc6b87d173f182230763e1f1913d319 '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>
---
Original version of the patch has a simple bug.
gitweb/gitweb.perl | 22 +++++++++++-----------
1 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 448dca7..6256641 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4290,7 +4290,7 @@ sub git_blob {
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
or die_error(undef, "Couldn't cat $file_name, $hash");
my $mimetype = blob_mimetype($fd, $file_name);
- if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
+ if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
close $fd;
return git_blob_plain($mimetype);
}
@@ -4331,16 +4331,7 @@ sub git_blob {
}
git_print_page_path($file_name, "blob", $hash_base);
print "<div class=\"page_body\">\n";
- if ($mimetype =~ m!^text/!) {
- my $nr;
- while (my $line = <$fd>) {
- chomp $line;
- $nr++;
- $line = untabify($line);
- printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
- $nr, $nr, $nr, esc_html($line, -nbsp=>1);
- }
- } elsif ($mimetype =~ m!^image/!) {
+ if ($mimetype =~ m!^image/!) {
print qq!<img type="$mimetype"!;
if ($file_name) {
print qq! alt="$file_name" title="$file_name"!;
@@ -4349,6 +4340,15 @@ sub git_blob {
href(action=>"blob_plain", hash=>$hash,
hash_base=>$hash_base, file_name=>$file_name) .
qq!" />\n!;
+ } else {
+ my $nr;
+ while (my $line = <$fd>) {
+ chomp $line;
+ $nr++;
+ $line = untabify($line);
+ printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
+ $nr, $nr, $nr, esc_html($line, -nbsp=>1);
+ }
}
close $fd
or print "Reading blob failed.\n";
--
1.5.3.7
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-12-15 14:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-08 11:55 [PATCH] gitweb: Teach "a=blob" action to be more lenient about blob/file mime type Jakub Narebski
2007-12-09 3:34 ` Junio C Hamano
2007-12-09 10:06 ` Jakub Narebski
-- strict thread matches above, loose matches on Subject: below --
2007-12-15 14:34 [PATCH 0/3 (resend)] gitweb: Miscelanous fixes Jakub Narebski
2007-12-15 14:41 ` [PATCH] gitweb: Teach "a=blob" action to be more lenient about blob/file mime type Jakub Narebski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).