{"thread":{"id":"4960","subject":"[PATCH 2/4] gitweb.cgi: Include direct link to \"raw\" files from \"history\"","startedAt":"2006-07-23T20:28:55Z","lastAt":"2006-07-23T20:28:55Z","messageCount":1,"participants":["Luben Tuikov"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"24022","messageId":"20060723202855.54712.qmail@web31811.mail.mud.yahoo.com","threadId":"4960","inReplyTo":null,"subject":"[PATCH 2/4] gitweb.cgi: Include direct link to \"raw\" files from \"history\"","fromName":"Luben Tuikov","fromEmail":"ltuikov@yahoo.com","sentAt":"2006-07-23T20:28:55Z","receivedAt":"2006-07-23T20:28:55Z","isPatch":true,"sender":{"key":"ltuikov@yahoo.com","avatar":null},"body":"In \"history\" view, the \"page_path\" is now also a URL link to\nthe \"raw\" format of the file, which will always give you\nthe latest version in the repository.\n\nThis is helpful for externally linking files, such that\nthe latest version is always referenced and in \"raw\" format.\n\nSigned-off-by: Luben Tuikov <ltuikov@yahoo.com>\n---\n gitweb/gitweb.cgi |   35 +++++++++++++++++++++++++++++------\n 1 files changed, 29 insertions(+), 6 deletions(-)\n\n\ndiff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi\nindex d976d4a..7a61de4 100755\n--- a/gitweb/gitweb.cgi\n+++ b/gitweb/gitweb.cgi\n@@ -1531,6 +1531,14 @@ sub git_blob_plain_mimetype {\n }\n \n sub git_blob_plain {\n+\tif (!defined $hash) {\n+                if (defined $file_name) {\n+                        my $base = $hash_base || git_read_head($project);\n+                        $hash = git_get_hash_by_path($base, $file_name, \"blob\") || die_error(undef, \"Error lookup file.\");\n+                } else {\n+                        die_error(undef, \"No file name defined.\");\n+                }\n+        }\n \tmy $type = shift;\n \topen my $fd, \"-|\", \"$GIT cat-file blob $hash\" or die_error(\"Couldn't cat $file_name, $hash\");\n \n@@ -1554,10 +1562,14 @@ 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-\t}\n+\tif (!defined $hash) {\n+                if (defined $file_name) {\n+                        my $base = $hash_base || git_read_head($project);\n+                        $hash = git_get_hash_by_path($base, $file_name, \"blob\") || die_error(undef, \"Error lookup file.\");\n+                } else {\n+                        die_error(undef, \"No file name defined.\");\n+                }\n+        }\n \tmy $have_blame = git_get_project_config_bool ('blame');\n \topen my $fd, \"-|\", \"$GIT cat-file blob $hash\" or die_error(undef, \"Open failed.\");\n \tmy $mimetype = git_blob_plain_mimetype($fd, $file_name);\n@@ -1687,7 +1699,7 @@ sub git_tree {\n \t\t\t      \"<td class=\\\"link\\\">\" .\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;hb=$hash_base;f=$base$t_name\")}, \"history\") .\n+\t\t\t      \" | \" . $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=history;h=$t_hash;hb=$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      \"</td>\\n\";\n \t\t} elsif ($t_type eq \"tree\") {\n@@ -2314,8 +2326,18 @@ sub git_history {\n \tprint \"<div>\\n\" .\n \t      $cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=commit;h=$hash_base\"), -class => \"title\"}, esc_html($co{'title'})) . \"\\n\" .\n \t      \"</div>\\n\";\n-\tprint \"<div class=\\\"page_path\\\"><b>/\" . esc_html($file_name) . \"</b><br/></div>\\n\";\n+\tif (defined $hash) {\n+\t\tmy $ftype = git_get_type($hash);\n+\n+\t\tif ($ftype =~ \"blob\") {\n+\t\t    print \"<div class=\\\"page_path\\\"><b>/\" .\n+\t\t\t$cgi->a({-href => \"$my_uri?\" . esc_param(\"p=$project;a=blob_plain;f=$file_name\")}, esc_html($file_name)) . \"</b><br/></div>\\n\";\n+\t\t} else {\n+\t\t    print \"<div class=\\\"page_path\\\"><b>/\" . esc_html($file_name) . \"</b><br/></div>\\n\";\n+\t\t}\n+\t} else {\n+\t\tprint \"<div class=\\\"page_path\\\"><b>/\" . esc_html($file_name) . \"</b><br/></div>\\n\";\n+\t}\n \n \topen my $fd, \"-|\",\n \t\t\"$GIT rev-list --full-history $hash_base -- \\'$file_name\\'\";\n-- \n1.4.2.rc1.g9b54\n\n"}]}