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>
Jakub Narebski committed
Dec 4, 2006 at 23:47 UTC
5a4cf3346d6c37007a7f5f94697868a5b2f2fa29
1 file changed
+22
-8
gitweb/gitweb.perl
+22
-8
@@ -3229,10 +3229,13 @@ sub git_blob {
3229
open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
3230
or die_error(undef, "Couldn't cat $file_name, $hash");
3231
my $mimetype = blob_mimetype($fd, $file_name);
3232
- if ($mimetype !~ m/^text\//) {
3232
+ if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3233
close $fd;
3234
return git_blob_plain($mimetype);
3235
}
3236
+ # we can have blame only for text/* mimetype
3237
+ $have_blame &&= ($mimetype =~ m!^text/!);
3238
+
3239
git_header_html(undef, $expires);
3240
my $formats_nav = '';
3241
if (defined $hash_base && (my %co = parse_commit($hash_base))) {
@@ -3269,13 +3272,24 @@ sub git_blob {
3272
}
3273
git_print_page_path($file_name, "blob", $hash_base);
3274
print "<div class=\"page_body\">\n";
3272
- my $nr;
3273
- while (my $line = <$fd>) {
3274
- chomp $line;
3275
- $nr++;
3276
- $line = untabify($line);
3277
- printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3278
- $nr, $nr, $nr, esc_html($line, -nbsp=>1);
3275
+ if ($mimetype =~ m!^text/!) {
3276
+ my $nr;
3277
+ while (my $line = <$fd>) {
3278
+ chomp $line;
3279
+ $nr++;
3280
+ $line = untabify($line);
3281
+ printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3282
+ $nr, $nr, $nr, esc_html($line, -nbsp=>1);
3283
+ }
3284
+ } elsif ($mimetype =~ m!^image/!) {
3285
+ print qq!<img type="$mimetype"!;
3286
+ if ($file_name) {
3287
+ print qq! alt="$file_name" title="$file_name"!;
3288
+ }
3289
+ print qq! src="! .
3290
+ href(action=>"blob_plain", hash=>$hash,
3291
+ hash_base=>$hash_base, file_name=>$file_name) .
3292
+ qq!" />\n!;
3293
}
3294
close $fd
3295
or print "Reading blob failed.\n";