From: Junio C Hamano <gitster@pobox.com>
To: Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] gitweb: Teach "a=blob" action to be more lenient about blob/file mime type
Date: Sat, 08 Dec 2007 19:34:34 -0800 [thread overview]
Message-ID: <7vk5notub9.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <1197114913-15626-1-git-send-email-jnareb@gmail.com> (Jakub Narebski's message of "Sat, 8 Dec 2007 12:55:13 +0100")
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
next prev parent reply other threads:[~2007-12-09 3:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vk5notub9.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).