@matheusbsbs / matheus-bagliano / commits / 88ad729b73
Fork 0

gitweb: Make search type a popup menu

This makes the multiple search types actually usable by the user; if you don't read the gitweb source, you don't even have an idea that you can write things like that there. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>

Petr Baudis committed Oct 24, 2006 at 05:15 UTC 88ad729b73264025d2d4c187ff74432d7cacafb2
2 files changed +47 -16
gitweb/gitweb.css
+2
@@ -333,6 +333,8 @@ div.index_include {
333 }
334
335 div.search {
336 + font-size: 12px;
337 + font-weight: normal;
338 margin: 4px 8px;
339 position: absolute;
340 top: 56px;
gitweb/gitweb.perl
+45 -16
@@ -342,6 +342,13 @@ if (defined $searchtext) {
342 $searchtext = quotemeta $searchtext;
343 }
344
345 +our $searchtype = $cgi->param('st');
346 +if (defined $searchtype) {
347 + if ($searchtype =~ m/[^a-z]/) {
348 + die_error(undef, "Invalid searchtype parameter");
349 + }
350 +}
351 +
352 # now read PATH_INFO and use it as alternative to parameters
353 sub evaluate_path_info {
354 return if defined $project;
@@ -406,6 +413,7 @@ my %actions = (
413 "log" => \&git_log,
414 "rss" => \&git_rss,
415 "search" => \&git_search,
416 + "search_help" => \&git_search_help,
417 "shortlog" => \&git_shortlog,
418 "summary" => \&git_summary,
419 "tag" => \&git_tag,
@@ -455,6 +463,7 @@ sub href(%) {
463 page => "pg",
464 order => "o",
465 searchtext => "s",
466 + searchtype => "st",
467 );
468 my %mapping = @mapping;
469
@@ -1524,6 +1533,10 @@ EOF
1533 $cgi->hidden(-name => "p") . "\n" .
1534 $cgi->hidden(-name => "a") . "\n" .
1535 $cgi->hidden(-name => "h") . "\n" .
1536 + $cgi->popup_menu(-name => 'st', -default => 'commit',
1537 + -values => ['commit', 'author', 'committer', 'pickaxe']) .
1538 + $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
1539 + " search:\n",
1540 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
1541 "</div>" .
1542 $cgi->end_form() . "\n";
@@ -3544,18 +3557,8 @@ sub git_search {
3557 die_error(undef, "Unknown commit object");
3558 }
3559
3547 - my $commit_search = 1;
3548 - my $author_search = 0;
3549 - my $committer_search = 0;
3550 - my $pickaxe_search = 0;
3551 - if ($searchtext =~ s/^author\\://i) {
3552 - $author_search = 1;
3553 - } elsif ($searchtext =~ s/^committer\\://i) {
3554 - $committer_search = 1;
3555 - } elsif ($searchtext =~ s/^pickaxe\\://i) {
3556 - $commit_search = 0;
3557 - $pickaxe_search = 1;
3558 -
3560 + $searchtype ||= 'commit';
3561 + if ($searchtype eq 'pickaxe') {
3562 # pickaxe may take all resources of your box and run for several minutes
3563 # with every query - so decide by yourself how public you make this feature
3564 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
@@ -3563,23 +3566,24 @@ sub git_search {
3566 die_error('403 Permission denied', "Permission denied");
3567 }
3568 }
3569 +
3570 git_header_html();
3571 git_print_page_nav('','', $hash,$co{'tree'},$hash);
3572 git_print_header_div('commit', esc_html($co{'title'}), $hash);
3573
3574 print "<table cellspacing=\"0\">\n";
3575 my $alternate = 1;
3572 - if ($commit_search) {
3576 + if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3577 $/ = "\0";
3578 open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
3579 while (my $commit_text = <$fd>) {
3580 if (!grep m/$searchtext/i, $commit_text) {
3581 next;
3582 }
3579 - if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3583 + if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3584 next;
3585 }
3582 - if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3586 + if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3587 next;
3588 }
3589 my @commit_lines = split "\n", $commit_text;
@@ -3621,7 +3625,7 @@ sub git_search {
3625 close $fd;
3626 }
3627
3624 - if ($pickaxe_search) {
3628 + if ($searchtype eq 'pickaxe') {
3629 $/ = "\n";
3630 my $git_command = git_cmd_str();
3631 open my $fd, "-|", "$git_command rev-list $hash | " .
@@ -3681,6 +3685,31 @@ sub git_search {
3685 git_footer_html();
3686 }
3687
3688 +sub git_search_help {
3689 + git_header_html();
3690 + git_print_page_nav('','', $hash,$hash,$hash);
3691 + print <<EOT;
3692 +<dl>
3693 +<dt><b>commit</b></dt>
3694 +<dd>The commit messages and authorship information will be scanned for the given string.</dd>
3695 +<dt><b>author</b></dt>
3696 +<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
3697 +<dt><b>committer</b></dt>
3698 +<dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
3699 +EOT
3700 + my ($have_pickaxe) = gitweb_check_feature('pickaxe');
3701 + if ($have_pickaxe) {
3702 + print <<EOT;
3703 +<dt><b>pickaxe</b></dt>
3704 +<dd>All commits that caused the string to appear or disappear from any file (changes that
3705 +added, removed or "modified" the string) will be listed. This search can take a while and
3706 +takes a lot of strain on the server, so please use it wisely.</dd>
3707 +EOT
3708 + }
3709 + print "</dl>\n";
3710 + git_footer_html();
3711 +}
3712 +
3713 sub git_shortlog {
3714 my $head = git_get_head_hash($project);
3715 if (!defined $hash) {