{"thread":{"id":"4868","subject":"[PATCH] gitweb.cgi: Teach tree->raw to not require the hash of the blob","startedAt":"2006-07-13T03:31:45Z","lastAt":"2006-07-13T03:31:45Z","messageCount":1,"participants":["Luben Tuikov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"23732","messageId":"20060713033145.62912.qmail@web31808.mail.mud.yahoo.com","threadId":"4868","inReplyTo":null,"subject":"[PATCH] gitweb.cgi: Teach tree->raw to not require the hash of the blob","fromName":"Luben Tuikov","fromEmail":"ltuikov@yahoo.com","sentAt":"2006-07-13T03:31:45Z","receivedAt":"2006-07-13T03:31:45Z","isPatch":true,"sender":{"key":"ltuikov@yahoo.com","avatar":null},"body":"Teach tree->raw to not require the hash of the blob, but to\nfigure it out from the file name.  This allows to externally\nlink to files into the repository, such that the hash is not\nrequired.  I.e. the file obtained would be as of the HEAD\ncommit.\n\nIn contrast tree->blob for binary files passes the hash, as\ndoes tree->blob->plain for \"text/*\" files.\n\nSigned-off-by: Luben Tuikov <ltuikov@yahoo.com>\n---\n gitweb/gitweb.cgi |   20 ++++++++++++++++----\n 1 files changed, 16 insertions(+), 4 deletions(-)\n\ndiff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi\nindex 2e87de4..e904eb7 100755\n--- a/gitweb/gitweb.cgi\n+++ b/gitweb/gitweb.cgi\n@@ -1521,6 +1521,14 @@ sub git_blob_plain_mimetype {\n }\n \n sub git_blob_plain {\n+\tif (!defined $hash) {\n+\t\tif (defined $file_name) {\n+\t\t\tmy $base = $hash_base || git_read_head($project);\n+\t\t\t$hash = git_get_hash_by_path($base, $file_name, \"blob\") || die_error(undef, \"Error lookup file.\");\n+\t\t} else {\n+\t\t\tdie_error(undef, \"No file name defined.\");\n+\t\t}\n+\t}\n \tmy $type = shift;\n \topen my $fd, \"-|\", \"$gitbin/git-cat-file blob $hash\" or die_error(\"Couldn't cat $file_name, $hash\");\n \n@@ -1544,9 +1552,13 @@ sub git_blob_plain {\n }\n \n sub git_blob {\n-\tif (!defined $hash && defined $file_name) {\n-\t\tmy $base = $hash_base || git_read_head($project);\n-\t\t$hash = git_get_hash_by_path($base, $file_name, \"blob\") || die_error(undef, \"Error lookup file.\");\n+\tif (!defined $hash) {\n+\t\tif (defined $file_name) {\n+\t\t\tmy $base = $hash_base || git_read_head($project);\n+\t\t\t$hash = git_get_hash_by_path($base, $file_name, \"blob\") || die_error(undef, \"Error lookup file.\");\n+\t\t} else {\n+\t\t\tdie_error(undef, \"No file name defined.\");\n+\t\t}\n \t}\n \tmy $have_blame = git_get_project_config_bool ('blame');\n \topen my $fd, \"-|\", \"$gitbin/git-cat-file blob $hash\" or die_error(undef, \"Open failed.\");\n@@ -1678,8 +1690,7 @@ sub git_tree {\n \t\t\t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name\")}, \"blob\") .\n #\t\t\t      \" | \" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name\")}, \"blame\") .\n \t\t\t      \" | \" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=history;h=$hash_base;f=$base$t_name\")}, \"history\") .\n-\t\t\t      \" | \" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob_plain;h=$t_hash;f=$base$t_name\")}, \"raw\") .\n+\t\t\t      \" | \" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob_plain;f=$base$t_name\")}, \"raw\") .\n \t\t\t      \"</td>\\n\";\n \t\t} elsif ($t_type eq \"tree\") {\n \t\t\tprint \"<td class=\\\"list\\\">\" .\n-- \n1.4.1.g9ca3\n\n"}]}