{"thread":{"id":"6027","subject":"[PATCH] gitweb: Make search type a popup menu","startedAt":"2006-10-24T03:15:46Z","lastAt":"2006-10-24T11:27:27Z","messageCount":3,"participants":["Petr Baudis","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"29798","messageId":"20061024031546.2877.51620.stgit@rover","threadId":"6027","inReplyTo":null,"subject":"[PATCH] gitweb: Make search type a popup menu","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-10-24T03:15:46Z","receivedAt":"2006-10-24T03:15:46Z","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 695c632..e77fc11 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -342,6 +342,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@@ -406,6 +413,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@@ -455,6 +463,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@@ -1528,6 +1537,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@@ -3573,18 +3586,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@@ -3592,23 +3595,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@@ -3650,7 +3654,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@@ -3710,6 +3714,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":"29822","messageId":"ehkfis$6da$1@sea.gmane.org","threadId":"6027","inReplyTo":"20061024031546.2877.51620.stgit@rover","subject":"Re: [PATCH] gitweb: Make search type a popup menu","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-10-24T07:33:12Z","receivedAt":"2006-10-24T07:33: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\nThis is I think good change, although I'm not sure if I like changing\nusing search operators to using additional CGI parameter.\n\nHaving help page for search is _certainly_ very good change. Perhaps\nwe should put it out-of-line, not embedded? Just a thought...\n\nThis patch changes search box into something similar to Google\n\"Advanced Search\". Yet Google \"Advanced Search\" box generates search\nquery using search operators. Search operators are just more powerfull.\nI know that gitweb doesn't use this power now (it uses only one operator,\nfirst if I remember correctly), but we can do this in the future\n(e.g. searching for both author and specified string in commit message,\nor searching for given author OR given committer). Well, we can always\nchange it back...\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"29847","messageId":"20061024112727.GZ20017@pasky.or.cz","threadId":"6027","inReplyTo":"ehkfis$6da$1@sea.gmane.org","subject":"Re: [PATCH] gitweb: Make search type a popup menu","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-10-24T11:27:27Z","receivedAt":"2006-10-24T11:27:27Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Tue, Oct 24, 2006 at 09:33:12AM CEST, I got a letter\nwhere Jakub Narebski <jnareb@gmail.com> said that...\n> 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> \n> This is I think good change, although I'm not sure if I like changing\n> using search operators to using additional CGI parameter.\n> \n> Having help page for search is _certainly_ very good change. Perhaps\n> we should put it out-of-line, not embedded? Just a thought...\n\nYou mean out-of-file? I've pondered it but I think this is simpler than\nhaving yet another external file with yet another configuration option,\nand the help file is not anyway likely something you will want to\ncustomize per-site.\n\n> This patch changes search box into something similar to Google\n> \"Advanced Search\". Yet Google \"Advanced Search\" box generates search\n> query using search operators. Search operators are just more powerfull.\n> I know that gitweb doesn't use this power now (it uses only one operator,\n> first if I remember correctly), but we can do this in the future\n> (e.g. searching for both author and specified string in commit message,\n> or searching for given author OR given committer). Well, we can always\n> change it back...\n\nWell, yes, that's something we can do when we actually implement the\noperators, but I think doing it this way is less powerful, but much more\n*useful* since users not familiar with gitweb will have an actual idea\non how to use it, and gitweb is something that will have 90% of users\nnot familiar with it. So perhaps have an \"extended\" search type which\nwill accept the keywords?\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\n#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj\n$/=unpack('H*',$_);$_=`echo 16dio\\U$k\"SK$/SM$n\\EsN0p[lN*1\nlK[d2%Sa2/d0$^Ixp\"|dc`;s/\\W//g;$_=pack('H*',/((..)*)$/)\n"}]}