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

[PATCH/RFC 2/6] gitweb: Improve projects search form

From
Jakub Narebski <jnareb@gmail.com>
Date
Jul 29, 2011, 11:52 UTC
Message-ID
<1311940379-9608-3-git-send-email-jnareb@gmail.com>
In-Reply-To
<1311940379-9608-1-git-send-email-jnareb@gmail.com>

Refactor generating project search form into git_project_search_form(), make text field wider and add on mouse over explanation (via "title" attribute), add an option to use regular expressions, and replace 'Search:' label with [Search] button.

Also add "List all projects" link to make it easier to go back from search result to list of all projects.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
The most useful part is the user interface for turning on regular
expression search (it was always there, but you had to hand-edit URL),
I think.

By the way, I was reminded (on #perl IRC channel on FreeNode) that allowing regular expression search is not safe against DoS because of recursive backtracking regexps. If one worries about that, one can always change regexp engine to more safe one, for example putting the following in gitweb config file:

  use re::engine::RE2 -strict => 1;
to use RE2 fast regexp engine from Google (http://code.google.com/p/re2).

There was some concern about extended pattern '(?{ code })' that allows running arbitrary Perl code... but re(3pm) says that "no re 'eval';" is default, which means that such construct is disallowed when regular expression contains variable interpolation.

Note that if there is no match, you would get 'list all project' link twice, once from search form, one from search result... but I don't think it is something to worry about.

 gitweb/gitweb.perl       |   27 ++++++++++++++++++++++-----
 gitweb/static/gitweb.css |    7 ++++++-
 2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 7ec1621..3e69705 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4968,6 +4968,26 @@ sub git_patchset_body {
 
 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
 
+sub git_project_search_form {
+	my ($searchtext, $search_use_regexp);
+
+	print "<div class=\"projsearch\">\n";
+	print $cgi->startform(-method => 'get', -action => $my_uri) .
+	      $cgi->hidden(-name => 'a', -value => 'project_list') . "\n" .
+	      $cgi->textfield(-name => 's', -value => $searchtext,
+	                      -title => 'Search project by name and description',
+	                      -size => 60) . "\n" .
+	      "<span title=\"Extended regular expression\">" .
+	      $cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
+	                     -checked => $search_use_regexp) .
+	      "</span>\n" .
+	      $cgi->submit(-name => 'btnS', -value => 'Search') .
+	      $cgi->end_form() . "\n" .
+	      $cgi->a({-href => href(project => undef, searchtext => undef)},
+	              'List all projects') . "<br />\n";
+	print "</div>\n";
+}
+
 # fills project list info (age, description, owner, category, forks)
 # for each project in the list, removing invalid projects from
 # returned list
@@ -5835,11 +5855,8 @@ sub git_project_list {
 		insert_file($home_text);
 		print "</div>\n";
 	}
-	print $cgi->startform(-method => "get") .
-	      "<p class=\"projsearch\">Search:\n" .
-	      $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
-	      "</p>" .
-	      $cgi->end_form() . "\n";
+
+	git_project_search_form($searchtext, $search_use_regexp);
 	git_project_list_body(\@list, $order);
 	git_footer_html();
 }
diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css
index 7d88509..3cdaaa3 100644
--- a/gitweb/static/gitweb.css
+++ b/gitweb/static/gitweb.css
@@ -490,8 +490,13 @@ div.search {
 	right: 12px
 }
 
-p.projsearch {
+div.projsearch {
 	text-align: center;
+	margin: 20px 0px;
+}
+
+div.projsearch form {
+	margin-bottom: 2px;
 }
 
 td.linenr {
-- 
1.7.5
Previous: Jakub NarebskiNext: Jakub Narebski
Message 3 of 8 in “gitweb: Improve project search”
  1. 0/6 gitweb: Improve project searchJakub Narebski, Jul 29, 2011
  2. 1/6 gitweb: Allow underscore in $searchtype ('st')Jakub Narebski, Jul 29, 2011
  3. 2/6 gitweb: Improve projects search formJakub Narebski, Jul 29, 2011
  4. 3/6 gitweb: Option for filling only specified info in fill_project_list_infoJakub Narebski, Jul 29, 2011
  5. 4/6 gitweb: Faster project searchJakub Narebski, Jul 29, 2011
  6. 5/6 gitweb: Highlight matched part of project name when searching projectsJakub Narebski, Jul 29, 2011
  7. 6/6 gitweb: Highlight matched part of project description when searching projectsJakub Narebski, Jul 29, 2011
  8. 7/6 gitweb: Use esc_html_match_hl in 'grep' searchJakub Narebski, Jul 30, 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.