@matheusbsbs / matheus-bagliano / commits / 04f7a94f65
Fork 0

gitweb: Make pickaxe search a feature

As pickaxe search (selected using undocumented 'pickaxe:' operator in search query) is resource consuming, allow to turn it on/off using feature meachanism. Turned on by default, for historical reasons. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Sep 11, 2006 at 00:29 UTC 04f7a94f65f40d24607ba9af77756e121b7c8e4f
1 file changed +31 -2
gitweb/gitweb.perl
+31 -2
@@ -90,6 +90,11 @@ our %feature = (
90 'override' => 0,
91 # => [content-encoding, suffix, program]
92 'default' => ['x-gzip', 'gz', 'gzip']},
93 +
94 + 'pickaxe' => {
95 + 'sub' => \&feature_pickaxe,
96 + 'override' => 0,
97 + 'default' => [1]},
98 );
99
100 sub gitweb_check_feature {
@@ -143,6 +148,24 @@ sub feature_snapshot {
148 return ($ctype, $suffix, $command);
149 }
150
151 +# To enable system wide have in $GITWEB_CONFIG
152 +# $feature{'pickaxe'}{'default'} = [1];
153 +# To have project specific config enable override in $GITWEB_CONFIG
154 +# $feature{'pickaxe'}{'override'} = 1;
155 +# and in project config gitweb.pickaxe = 0|1;
156 +
157 +sub feature_pickaxe {
158 + my ($val) = git_get_project_config('pickaxe', '--bool');
159 +
160 + if ($val eq 'true') {
161 + return (1);
162 + } elsif ($val eq 'false') {
163 + return (0);
164 + }
165 +
166 + return ($_[0]);
167 +}
168 +
169 # rename detection options for git-diff and git-diff-tree
170 # - default is '-M', with the cost proportional to
171 # (number of removed files) * (number of new files).
@@ -3128,8 +3151,7 @@ sub git_search {
3151 if (!%co) {
3152 die_error(undef, "Unknown commit object");
3153 }
3131 - # pickaxe may take all resources of your box and run for several minutes
3132 - # with every query - so decide by yourself how public you make this feature :)
3154 +
3155 my $commit_search = 1;
3156 my $author_search = 0;
3157 my $committer_search = 0;
@@ -3141,6 +3163,13 @@ sub git_search {
3163 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3164 $commit_search = 0;
3165 $pickaxe_search = 1;
3166 +
3167 + # pickaxe may take all resources of your box and run for several minutes
3168 + # with every query - so decide by yourself how public you make this feature
3169 + my ($have_pickaxe) = gitweb_check_feature('pickaxe');
3170 + if (!$have_pickaxe) {
3171 + die_error('403 Permission denied', "Permission denied");
3172 + }
3173 }
3174 git_header_html();
3175 git_print_page_nav('','', $hash,$co{'tree'},$hash);