git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/5] gitweb: Check permissions first in git_search

From
Jakub Narebski <jnareb@gmail.com>
Date
Jun 22, 2011, 15:28 UTC
Message-ID
<1308756535-29701-3-git-send-email-jnareb@gmail.com>
In-Reply-To
<1308756535-29701-1-git-send-email-jnareb@gmail.com>

Check first if relevant features: 'search', 'pickaxe', 'grep', as appropriate, are enabled before doing anything else in git_search. This should make git_search code more clear.

While at it, expand a bit error message (e.g. 'Pickaxe' -> 'Pickaxe search').

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index fd93d45..32e50b4 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -7094,7 +7094,23 @@ sub git_history {
 }
 
 sub git_search {
-	gitweb_check_feature('search') or die_error(403, "Search is disabled");
+	$searchtype ||= 'commit';
+
+	# check if appropriate features are enabled
+	gitweb_check_feature('search')
+		or die_error(403, "Search is disabled");
+	if ($searchtype eq 'pickaxe') {
+		# pickaxe may take all resources of your box and run for several minutes
+		# with every query - so decide by yourself how public you make this feature
+		gitweb_check_feature('pickaxe')
+			or die_error(403, "Pickaxe search is disabled");
+	}
+	if ($searchtype eq 'grep') {
+		# grep search might be potentially CPU-intensive, too
+		gitweb_check_feature('grep')
+			or die_error(403, "Grep search is disabled");
+	}
+
 	if (!defined $searchtext) {
 		die_error(400, "Text field is empty");
 	}
@@ -7109,18 +7125,6 @@ sub git_search {
 		$page = 0;
 	}
 
-	$searchtype ||= 'commit';
-	if ($searchtype eq 'pickaxe') {
-		# pickaxe may take all resources of your box and run for several minutes
-		# with every query - so decide by yourself how public you make this feature
-		gitweb_check_feature('pickaxe')
-		    or die_error(403, "Pickaxe is disabled");
-	}
-	if ($searchtype eq 'grep') {
-		gitweb_check_feature('grep')
-		    or die_error(403, "Grep is disabled");
-	}
-
 	git_header_html();
 
 	if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
-- 
1.7.5
Previous: Jakub NarebskiNext: Jakub Narebski
Message 3 of 10 in “gitweb: Improve search code”
  1. 0/5 gitweb: Improve search codeJakub Narebski, Jun 22, 2011
  2. 1/5 gitweb: 'pickaxe' and 'grep' features requires 'search' to be enabledJakub Narebski, Jun 22, 2011
  3. 2/5 gitweb: Check permissions first in git_searchJakub Narebski, Jun 22, 2011
  4. 3/5 gitweb: Split body of git_search into subroutinesJakub Narebski, Jun 22, 2011
  5. 4/5 gitweb: Clean up code in git_search_* subroutinesJakub Narebski, Jun 22, 2011
  6. 5/5 gitweb: Make git_search_* subroutines render whole pagesJakub Narebski, Jun 22, 2011
  7. Phil HordJun 22, 2011
  8. Jakub NarebskiJun 22, 2011
  9. Phil HordJun 22, 2011
  10. Junio C HamanoJun 22, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.