git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gitweb.cgi: Teach tree->raw to not require the hash of the blob
@ 2006-07-12  3:43 Luben Tuikov
  2006-07-12  6:16 ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Luben Tuikov @ 2006-07-12  3:43 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 503 bytes --]

Teach tree->raw to not require the hash of the blob, but to
figure it out from the file name.  This allows to externally
link to files into the repository, such that the hash is not
required.  I.e. the file obtained would be as of the HEAD
commit.

In contrast tree->blob for binary files passes the hash, as
does tree->blob->plain for "text/*" files.

Signed-off-by: Luben Tuikov <ltuikov@yahoo.com>
---
 gitweb/gitweb.cgi |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

[-- Attachment #2: pat1827152979 --]
[-- Type: application/octet-stream, Size: 2055 bytes --]

diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi
index 2e87de4..e904eb7 100755
--- a/gitweb/gitweb.cgi
+++ b/gitweb/gitweb.cgi
@@ -1521,6 +1521,14 @@ sub git_blob_plain_mimetype {
 }
 
 sub git_blob_plain {
+	if (!defined $hash) {
+		if (defined $file_name) {
+			my $base = $hash_base || git_read_head($project);
+			$hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
+		} else {
+			die_error(undef, "No file name defined.");
+		}
+	}
 	my $type = shift;
 	open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash");
 
@@ -1544,9 +1552,13 @@ sub git_blob_plain {
 }
 
 sub git_blob {
-	if (!defined $hash && defined $file_name) {
-		my $base = $hash_base || git_read_head($project);
-		$hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
+	if (!defined $hash) {
+		if (defined $file_name) {
+			my $base = $hash_base || git_read_head($project);
+			$hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
+		} else {
+			die_error(undef, "No file name defined.");
+		}
 	}
 	my $have_blame = git_get_project_config_bool ('blame');
 	open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
@@ -1678,8 +1690,7 @@ sub git_tree {
 			      $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
 #			      " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
 			      " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
-			      " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
+			      " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$base$t_name")}, "raw") .
 			      "</td>\n";
 		} elsif ($t_type eq "tree") {
 			print "<td class=\"list\">" .
-- 
1.4.1.g9ca3


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH] gitweb.cgi: Teach tree->raw to not require the hash of the blob
@ 2006-07-13  3:31 Luben Tuikov
  0 siblings, 0 replies; 8+ messages in thread
From: Luben Tuikov @ 2006-07-13  3:31 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 502 bytes --]

Teach tree->raw to not require the hash of the blob, but to
figure it out from the file name.  This allows to externally
link to files into the repository, such that the hash is not
required.  I.e. the file obtained would be as of the HEAD
commit.

In contrast tree->blob for binary files passes the hash, as
does tree->blob->plain for "text/*" files.

Signed-off-by: Luben Tuikov <ltuikov@yahoo.com>
---
 gitweb/gitweb.cgi |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

[-- Attachment #2: pat867582916 --]
[-- Type: application/octet-stream, Size: 2055 bytes --]

diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi
index 2e87de4..e904eb7 100755
--- a/gitweb/gitweb.cgi
+++ b/gitweb/gitweb.cgi
@@ -1521,6 +1521,14 @@ sub git_blob_plain_mimetype {
 }
 
 sub git_blob_plain {
+	if (!defined $hash) {
+		if (defined $file_name) {
+			my $base = $hash_base || git_read_head($project);
+			$hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
+		} else {
+			die_error(undef, "No file name defined.");
+		}
+	}
 	my $type = shift;
 	open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash");
 
@@ -1544,9 +1552,13 @@ sub git_blob_plain {
 }
 
 sub git_blob {
-	if (!defined $hash && defined $file_name) {
-		my $base = $hash_base || git_read_head($project);
-		$hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
+	if (!defined $hash) {
+		if (defined $file_name) {
+			my $base = $hash_base || git_read_head($project);
+			$hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
+		} else {
+			die_error(undef, "No file name defined.");
+		}
 	}
 	my $have_blame = git_get_project_config_bool ('blame');
 	open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
@@ -1678,8 +1690,7 @@ sub git_tree {
 			      $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
 #			      " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
 			      " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
-			      " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
+			      " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$base$t_name")}, "raw") .
 			      "</td>\n";
 		} elsif ($t_type eq "tree") {
 			print "<td class=\"list\">" .
-- 
1.4.1.g9ca3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-07-14  5:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-12  3:43 [PATCH] gitweb.cgi: Teach tree->raw to not require the hash of the blob Luben Tuikov
2006-07-12  6:16 ` Junio C Hamano
2006-07-12  8:32   ` Jakub Narebski
2006-07-12 18:02     ` Luben Tuikov
2006-07-12 18:12       ` Jakub Narebski
2006-07-12 17:52   ` Luben Tuikov
2006-07-14  5:49     ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2006-07-13  3:31 Luben Tuikov

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).