{"thread":{"id":"5893","subject":"[PATCH] gitweb: Make search type a popup menu","startedAt":"2006-10-11T20:58:17Z","lastAt":"2006-10-11T21:15:12Z","messageCount":2,"participants":["Petr Baudis","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"28631","messageId":"20061011205817.1855.31725.stgit@rover","threadId":"5893","inReplyTo":null,"subject":"[PATCH] gitweb: Make search type a popup menu","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-10-11T20:58:17Z","receivedAt":"2006-10-11T20:58:17Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"This makes the multiple search types actually usable by the user;\nif you don't read the gitweb source, you don't even have an idea\nthat you can write things like that there.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n gitweb/gitweb.css  |    2 ++\n gitweb/gitweb.perl |   61 ++++++++++++++++++++++++++++++++++++++--------------\n 2 files changed, 47 insertions(+), 16 deletions(-)\n\ndiff --git a/gitweb/gitweb.css b/gitweb/gitweb.css\nindex 3f62b6d..0eda982 100644\n--- a/gitweb/gitweb.css\n+++ b/gitweb/gitweb.css\n@@ -333,6 +333,8 @@ div.index_include {\n }\n \n div.search {\n+\tfont-size: 12px;\n+\tfont-weight: normal;\n \tmargin: 4px 8px;\n \tposition: absolute;\n \ttop: 56px;\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 18c0d52..28c7932 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -347,6 +347,13 @@ if (defined $searchtext) {\n \t$searchtext = quotemeta $searchtext;\n }\n \n+our $searchtype = $cgi->param('st');\n+if (defined $searchtype) {\n+\tif ($searchtype =~ m/[^a-z]/) {\n+\t\tdie_error(undef, \"Invalid searchtype parameter\");\n+\t}\n+}\n+\n # now read PATH_INFO and use it as alternative to parameters\n sub evaluate_path_info {\n \treturn if defined $project;\n@@ -411,6 +418,7 @@ my %actions = (\n \t\"log\" => \\&git_log,\n \t\"rss\" => \\&git_rss,\n \t\"search\" => \\&git_search,\n+\t\"search_help\" => \\&git_search_help,\n \t\"shortlog\" => \\&git_shortlog,\n \t\"summary\" => \\&git_summary,\n \t\"tag\" => \\&git_tag,\n@@ -460,6 +468,7 @@ sub href(%) {\n \t\tpage => \"pg\",\n \t\torder => \"o\",\n \t\tsearchtext => \"s\",\n+\t\tsearchtype => \"st\",\n \t);\n \tmy %mapping = @mapping;\n \n@@ -1562,6 +1571,10 @@ #provides backwards capability for those\n \t\t      $cgi->hidden(-name => \"p\") . \"\\n\" .\n \t\t      $cgi->hidden(-name => \"a\") . \"\\n\" .\n \t\t      $cgi->hidden(-name => \"h\") . \"\\n\" .\n+\t\t      $cgi->popup_menu(-name => 'st', -default => 'commit',\n+\t\t\t\t       -values => ['commit', 'author', 'committer', 'pickaxe']) .\n+\t\t      $cgi->sup($cgi->a({-href => href(action=>\"search_help\")}, \"?\")) .\n+\t\t      \" search:\\n\",\n \t\t      $cgi->textfield(-name => \"s\", -value => $searchtext) . \"\\n\" .\n \t\t      \"</div>\" .\n \t\t      $cgi->end_form() . \"\\n\";\n@@ -3601,18 +3614,8 @@ sub git_search {\n \t\tdie_error(undef, \"Unknown commit object\");\n \t}\n \n-\tmy $commit_search = 1;\n-\tmy $author_search = 0;\n-\tmy $committer_search = 0;\n-\tmy $pickaxe_search = 0;\n-\tif ($searchtext =~ s/^author\\\\://i) {\n-\t\t$author_search = 1;\n-\t} elsif ($searchtext =~ s/^committer\\\\://i) {\n-\t\t$committer_search = 1;\n-\t} elsif ($searchtext =~ s/^pickaxe\\\\://i) {\n-\t\t$commit_search = 0;\n-\t\t$pickaxe_search = 1;\n-\n+\t$searchtype ||= 'commit';\n+\tif ($searchtype eq 'pickaxe') {\n \t\t# pickaxe may take all resources of your box and run for several minutes\n \t\t# with every query - so decide by yourself how public you make this feature\n \t\tmy ($have_pickaxe) = gitweb_check_feature('pickaxe');\n@@ -3620,23 +3623,24 @@ sub git_search {\n \t\t\tdie_error('403 Permission denied', \"Permission denied\");\n \t\t}\n \t}\n+\n \tgit_header_html();\n \tgit_print_page_nav('','', $hash,$co{'tree'},$hash);\n \tgit_print_header_div('commit', esc_html($co{'title'}), $hash);\n \n \tprint \"<table cellspacing=\\\"0\\\">\\n\";\n \tmy $alternate = 1;\n-\tif ($commit_search) {\n+\tif ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {\n \t\t$/ = \"\\0\";\n \t\topen my $fd, \"-|\", git_cmd(), \"rev-list\", \"--header\", \"--parents\", $hash or next;\n \t\twhile (my $commit_text = <$fd>) {\n \t\t\tif (!grep m/$searchtext/i, $commit_text) {\n \t\t\t\tnext;\n \t\t\t}\n-\t\t\tif ($author_search && !grep m/\\nauthor .*$searchtext/i, $commit_text) {\n+\t\t\tif ($searchtype eq 'author' && !grep m/\\nauthor .*$searchtext/i, $commit_text) {\n \t\t\t\tnext;\n \t\t\t}\n-\t\t\tif ($committer_search && !grep m/\\ncommitter .*$searchtext/i, $commit_text) {\n+\t\t\tif ($searchtype eq 'committer' && !grep m/\\ncommitter .*$searchtext/i, $commit_text) {\n \t\t\t\tnext;\n \t\t\t}\n \t\t\tmy @commit_lines = split \"\\n\", $commit_text;\n@@ -3678,7 +3682,7 @@ sub git_search {\n \t\tclose $fd;\n \t}\n \n-\tif ($pickaxe_search) {\n+\tif ($searchtype eq 'pickaxe') {\n \t\t$/ = \"\\n\";\n \t\tmy $git_command = git_cmd_str();\n \t\topen my $fd, \"-|\", \"$git_command rev-list $hash | \" .\n@@ -3738,6 +3742,31 @@ sub git_search {\n \tgit_footer_html();\n }\n \n+sub git_search_help {\n+\tgit_header_html();\n+\tgit_print_page_nav('','', $hash,$hash,$hash);\n+\tprint <<EOT;\n+<dl>\n+<dt><b>commit</b></dt>\n+<dd>The commit messages and authorship information will be scanned for the given string.</dd>\n+<dt><b>author</b></dt>\n+<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>\n+<dt><b>committer</b></dt>\n+<dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>\n+EOT\n+\tmy ($have_pickaxe) = gitweb_check_feature('pickaxe');\n+\tif ($have_pickaxe) {\n+\t\tprint <<EOT;\n+<dt><b>pickaxe</b></dt>\n+<dd>All commits that caused the string to appear or disappear from any file (changes that\n+added, removed or \"modified\" the string) will be listed. This search can take a while and\n+takes a lot of strain on the server, so please use it wisely.</dd>\n+EOT\n+\t}\n+\tprint \"</dl>\\n\";\n+\tgit_footer_html();\n+}\n+\n sub git_shortlog {\n \tmy $head = git_get_head_hash($project);\n \tif (!defined $hash) {\n"},{"id":"28634","messageId":"egjmt3$bpn$1@sea.gmane.org","threadId":"5893","inReplyTo":"20061011205817.1855.31725.stgit@rover","subject":"Re: [PATCH] gitweb: Make search type a popup menu","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-10-11T21:15:12Z","receivedAt":"2006-10-11T21:15:12Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Petr Baudis wrote:\n\n> This makes the multiple search types actually usable by the user;\n> if you don't read the gitweb source, you don't even have an idea\n> that you can write things like that there.\n\nIt is on one hand a good idea, for users who doesn't read gitweb\nsources. It is like \"advanced search\" in web search engines.\n\nOn the other hand it confirms the notion that search types are exclusive.\nCurrently pickaxe search is exclusive with log message search, but it is\nnot necessary. Search operators (now limited) and combining them gives\ngreat search power... or rather would give.\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"}]}