gitweb: Allow PNG, GIF, JPEG images to be displayed in "blob" view
Allow images in one of web formats (PNG, GIF, JPEG) - actually files with mimetype of image/png, image/git, image/jpeg - to be displayed in "blob" view using <img /> element, instead of using "blob_plain" view for them, like for all other files except also text/* mimetype files. This makes possible to easily go to file history, to HEAD version of the file, to appropriate commit etc; all of those are not available in "blob_plain" (raw) view. Only text files can have "blame" view link in the formats part of navbar. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
211e6eb513
commit
5a4cf3346d
@ -3229,10 +3229,13 @@ sub git_blob {
|
|||||||
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
|
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
|
||||||
or die_error(undef, "Couldn't cat $file_name, $hash");
|
or die_error(undef, "Couldn't cat $file_name, $hash");
|
||||||
my $mimetype = blob_mimetype($fd, $file_name);
|
my $mimetype = blob_mimetype($fd, $file_name);
|
||||||
if ($mimetype !~ m/^text\//) {
|
if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
|
||||||
close $fd;
|
close $fd;
|
||||||
return git_blob_plain($mimetype);
|
return git_blob_plain($mimetype);
|
||||||
}
|
}
|
||||||
|
# we can have blame only for text/* mimetype
|
||||||
|
$have_blame &&= ($mimetype =~ m!^text/!);
|
||||||
|
|
||||||
git_header_html(undef, $expires);
|
git_header_html(undef, $expires);
|
||||||
my $formats_nav = '';
|
my $formats_nav = '';
|
||||||
if (defined $hash_base && (my %co = parse_commit($hash_base))) {
|
if (defined $hash_base && (my %co = parse_commit($hash_base))) {
|
||||||
@ -3269,6 +3272,7 @@ sub git_blob {
|
|||||||
}
|
}
|
||||||
git_print_page_path($file_name, "blob", $hash_base);
|
git_print_page_path($file_name, "blob", $hash_base);
|
||||||
print "<div class=\"page_body\">\n";
|
print "<div class=\"page_body\">\n";
|
||||||
|
if ($mimetype =~ m!^text/!) {
|
||||||
my $nr;
|
my $nr;
|
||||||
while (my $line = <$fd>) {
|
while (my $line = <$fd>) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
@ -3277,6 +3281,16 @@ sub git_blob {
|
|||||||
printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
|
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);
|
$nr, $nr, $nr, esc_html($line, -nbsp=>1);
|
||||||
}
|
}
|
||||||
|
} elsif ($mimetype =~ m!^image/!) {
|
||||||
|
print qq!<img type="$mimetype"!;
|
||||||
|
if ($file_name) {
|
||||||
|
print qq! alt="$file_name" title="$file_name"!;
|
||||||
|
}
|
||||||
|
print qq! src="! .
|
||||||
|
href(action=>"blob_plain", hash=>$hash,
|
||||||
|
hash_base=>$hash_base, file_name=>$file_name) .
|
||||||
|
qq!" />\n!;
|
||||||
|
}
|
||||||
close $fd
|
close $fd
|
||||||
or print "Reading blob failed.\n";
|
or print "Reading blob failed.\n";
|
||||||
print "</div>";
|
print "</div>";
|
||||||
|
Loading…
Reference in New Issue
Block a user