# [PATCH][gitweb] Make it possible to retrieve HEAD plain blob

5 messages from 2006-06-06 to 2006-06-06. Participants: Petr Baudis, Jakub Narebski, Bertrand Jacquin, Junio C Hamano.
Thread: https://gitlist.dev/t/4413

## Petr Baudis, 2006-06-06 20:57

Subject: [PATCH][gitweb] Make it possible to retrieve HEAD plain blob
Message-ID: <20060606205737.GX10488@pasky.or.cz>
URL: https://gitlist.dev/e/20060606205737.GX10488%40pasky.or.cz

```
Sometimes, it is useful to be able to link directly to the blob plain
version in the latest tree. This patch implements that.

Signed-off-by: Petr Baudis <pasky@suse.cz>

diff --git a/gitweb.cgi b/gitweb.cgi
index ea21fbe..abaf6ce 100755
--- a/gitweb.cgi
+++ b/gitweb.cgi
@@ -1376,7 +1376,8 @@ sub git_blob {
 		      " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
 		if (defined $file_name) {
 			print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
-			" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
+			" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") .
+			" (" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;hb=HEAD;f=$file_name")}, "plain") . ")<br/>\n";
 		} else {
 			print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
 		}
@@ -1414,6 +1415,10 @@ sub git_blob_plain {
 	my $save_as = "$hash.txt";
 	if (defined $file_name) {
 		$save_as = $file_name;
+		if (!defined $hash) {
+			my $base = $hash_base || git_read_head($project);
+			$hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
+		}
 	}
 	print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\"");
 	open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
A person is just about as big as the things that make them angry.

```

## Jakub Narebski, 2006-06-06 21:20

Subject: Re: [PATCH][gitweb] Make it possible to retrieve HEAD plain blob
Message-ID: <e64rhu$i7n$1@sea.gmane.org>
URL: https://gitlist.dev/e/e64rhu%24i7n%241%40sea.gmane.org
In-Reply-To: <20060606205737.GX10488@pasky.or.cz>

```
Petr Baudis wrote:

> Sometimes, it is useful to be able to link directly to the blob plain
> version in the latest tree. This patch implements that.

By the way, how to download binary file, like for example image, via gitweb?
blob_plain doesn't give correct file after Save As (in the case of image,
it is not recognized as such)...

-- 
Jakub Narebski
Warsaw, Poland

```

## Bertrand Jacquin, 2006-06-06 21:31

Subject: Re: [PATCH][gitweb] Make it possible to retrieve HEAD plain blob
Message-ID: <4fb292fa0606061431g2fcc8cdet93685b5a4977c29f@mail.gmail.com>
URL: https://gitlist.dev/e/4fb292fa0606061431g2fcc8cdet93685b5a4977c29f%40mail.gmail.com
In-Reply-To: <e64rhu$i7n$1@sea.gmane.org>

```
On 6/6/06, Jakub Narebski <jnareb@gmail.com> wrote:
> Petr Baudis wrote:
>
> > Sometimes, it is useful to be able to link directly to the blob plain
> > version in the latest tree. This patch implements that.
>
> By the way, how to download binary file, like for example image, via gitweb?
> blob_plain doesn't give correct file after Save As (in the case of image,
> it is not recognized as such)...

This is also a gitweb fault which always define document as plain-text
instead of correct MIME.

-- 
# Beber : beber@gna.org
# IM : beber@jabber.fr
# http://guybrush.ath.cx, irc://irc.freenode.net/#{e.fr,gentoofr}

```

## Junio C Hamano, 2006-06-06 22:05

Subject: Re: [PATCH][gitweb] Make it possible to retrieve HEAD plain blob
Message-ID: <7vwtbulz32.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vwtbulz32.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <4fb292fa0606061431g2fcc8cdet93685b5a4977c29f@mail.gmail.com>

```
"Bertrand Jacquin" <beber.mailing@gmail.com> writes:

> This is also a gitweb fault which always define document as plain-text
> instead of correct MIME.

But that is somewhat unfair to blame it for -- we do not store
what the correct mime-type is for each blob, so gitweb has to
choose between guessing and getting it wrong, or not guessing
and havign the browser deal with it.  It chose the latter, which
is understandably sensible.

Having said that, I would agree it would be very nice if I can
see t/test4012.png blob in gitweb automagically ;-).

```

## Bertrand Jacquin, 2006-06-06 22:10

Subject: Re: [PATCH][gitweb] Make it possible to retrieve HEAD plain blob
Message-ID: <4fb292fa0606061510s73fa6f3ag6e12766370749c77@mail.gmail.com>
URL: https://gitlist.dev/e/4fb292fa0606061510s73fa6f3ag6e12766370749c77%40mail.gmail.com
In-Reply-To: <7vwtbulz32.fsf@assigned-by-dhcp.cox.net>

```
On 6/7/06, Junio C Hamano <junkio@cox.net> wrote:
> "Bertrand Jacquin" <beber.mailing@gmail.com> writes:
>
> > This is also a gitweb fault which always define document as plain-text
> > instead of correct MIME.
>
> But that is somewhat unfair to blame it for -- we do not store
> what the correct mime-type is for each blob, so gitweb has to
> choose between guessing and getting it wrong, or not guessing
> and havign the browser deal with it.  It chose the latter, which
> is understandably sensible.

I'm ok with that. Browser can deal with if serveur do pass to it a
type=text/plain. And it's case for now :('

-- 
# Beber : beber@gna.org
# IM : beber@jabber.fr
# http://guybrush.ath.cx, irc://irc.freenode.net/#{e.fr,gentoofr}

```
