git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Petr Baudis <pasky@suse.cz>
Date
Jun 6, 2006, 20:57 UTC
Message-ID
<20060606205737.GX10488@pasky.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.
Next: Jakub Narebski
Message 1 of 5 in “[gitweb] Make it possible to retrieve HEAD plain blob”
  1. [gitweb] Make it possible to retrieve HEAD plain blobPetr Baudis, Jun 6, 2006
  2. Jakub NarebskiJun 6, 2006
  3. Bertrand JacquinJun 6, 2006
  4. Junio C HamanoJun 6, 2006
  5. Bertrand JacquinJun 6, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.