gitweb: Make the `blame' interface in gitweb optional.
Since `git-annotate' is an expensive operation to run it may be desirable to deactivate this functionality. This patch introduces the `gitweb.blame' option to git-repo-config and disables the blame support by default. Signed-off-by: Florian Forster <octo@verplant.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Florian Forster committed
Jun 12, 2006 at 10:31 UTC
5996ca0836e21ab4e6be0a16a615eff965f18b8b
1 file changed
+25
-2
gitweb/gitweb.cgi
+25
-2
@@ -837,6 +837,25 @@ sub git_read_projects {
837
return @list;
838
}
839
840
+sub git_get_project_config {
841
+ my $key = shift;
842
+
843
+ return unless ($key);
844
+ $key =~ s/^gitweb\.//;
845
+ return if ($key =~ m/\W/);
846
+
847
+ my $val = qx(git-repo-config --get gitweb.$key);
848
+ return ($val);
849
+}
850
+
851
+sub git_get_project_config_bool {
852
+ my $val = git_get_project_config (@_);
853
+ if ($val and $val =~ m/true|yes|on/) {
854
+ return (1);
855
+ }
856
+ return; # implicit false
857
+}
858
+
859
sub git_project_list {
860
my @list = git_read_projects();
861
my @projects;
@@ -1233,6 +1252,7 @@ sub git_tag {
1252
1253
sub git_blame {
1254
my $fd;
1255
+ die_error('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool ('blame'));
1256
die_error('404 Not Found', "What file will it be, master?") if (!$file_name);
1257
$hash_base ||= git_read_head($project);
1258
die_error(undef, "Reading commit failed.") unless ($hash_base);
@@ -1468,6 +1488,7 @@ sub git_blob {
1488
my $base = $hash_base || git_read_head($project);
1489
$hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
1490
}
1491
+ my $have_blame = git_get_project_config_bool ('blame');
1492
open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1493
git_header_html();
1494
if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
@@ -1479,8 +1500,10 @@ sub git_blob {
1500
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1501
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1502
if (defined $file_name) {
1482
- print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") .
1483
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1503
+ if ($have_blame) {
1504
+ print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1505
+ }
1506
+ print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1507
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1508
} else {
1509
print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";