@matheusbsbs / matheus-bagliano / commits / cff0771bfb
Fork 0

gitweb.cgi: Include direct link to "raw" files from "history"

In "history" view, the "page_path" is now also a URL link to the "raw" format of the file, which will always give you the latest version in the repository. This is helpful for externally linking files, such that the latest version is always referenced and in "raw" format. Signed-off-by: Luben Tuikov <ltuikov@yahoo.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Luben Tuikov committed Jul 23, 2006 at 13:28 UTC cff0771bfbc8a8c1a432a99bc297a52a5ba94304
1 file changed +29 -6
gitweb/gitweb.cgi
+29 -6
@@ -1531,6 +1531,14 @@ sub git_blob_plain_mimetype {
1531 }
1532
1533 sub git_blob_plain {
1534 + if (!defined $hash) {
1535 + if (defined $file_name) {
1536 + my $base = $hash_base || git_read_head($project);
1537 + $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
1538 + } else {
1539 + die_error(undef, "No file name defined.");
1540 + }
1541 + }
1542 my $type = shift;
1543 open my $fd, "-|", "$GIT cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash");
1544
@@ -1554,10 +1562,14 @@ sub git_blob_plain {
1562 }
1563
1564 sub git_blob {
1557 - if (!defined $hash && defined $file_name) {
1558 - my $base = $hash_base || git_read_head($project);
1559 - $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
1560 - }
1565 + if (!defined $hash) {
1566 + if (defined $file_name) {
1567 + my $base = $hash_base || git_read_head($project);
1568 + $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
1569 + } else {
1570 + die_error(undef, "No file name defined.");
1571 + }
1572 + }
1573 my $have_blame = git_get_project_config_bool ('blame');
1574 open my $fd, "-|", "$GIT cat-file blob $hash" or die_error(undef, "Open failed.");
1575 my $mimetype = git_blob_plain_mimetype($fd, $file_name);
@@ -1687,7 +1699,7 @@ sub git_tree {
1699 "<td class=\"link\">" .
1700 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1701 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1690 - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1702 + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1703 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1704 "</td>\n";
1705 } elsif ($t_type eq "tree") {
@@ -2314,7 +2326,18 @@ sub git_history {
2326 print "<div>\n" .
2327 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2328 "</div>\n";
2317 - print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n";
2329 + if (defined $hash) {
2330 + my $ftype = git_get_type($hash);
2331 +
2332 + if ($ftype =~ "blob") {
2333 + print "<div class=\"page_path\"><b>/" .
2334 + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$file_name")}, esc_html($file_name)) . "</b><br/></div>\n";
2335 + } else {
2336 + print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n";
2337 + }
2338 + } else {
2339 + print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n";
2340 + }
2341
2342 open my $fd, "-|",
2343 "$GIT rev-list --full-history $hash_base -- \'$file_name\'";