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>
This commit is contained in:

committed by
Junio C Hamano

parent
4777b0141a
commit
88ad729b73
@ -333,6 +333,8 @@ div.index_include {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div.search {
|
div.search {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: normal;
|
||||||
margin: 4px 8px;
|
margin: 4px 8px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 56px;
|
top: 56px;
|
||||||
|
@ -342,6 +342,13 @@ if (defined $searchtext) {
|
|||||||
$searchtext = quotemeta $searchtext;
|
$searchtext = quotemeta $searchtext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
our $searchtype = $cgi->param('st');
|
||||||
|
if (defined $searchtype) {
|
||||||
|
if ($searchtype =~ m/[^a-z]/) {
|
||||||
|
die_error(undef, "Invalid searchtype parameter");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# now read PATH_INFO and use it as alternative to parameters
|
# now read PATH_INFO and use it as alternative to parameters
|
||||||
sub evaluate_path_info {
|
sub evaluate_path_info {
|
||||||
return if defined $project;
|
return if defined $project;
|
||||||
@ -406,6 +413,7 @@ my %actions = (
|
|||||||
"log" => \&git_log,
|
"log" => \&git_log,
|
||||||
"rss" => \&git_rss,
|
"rss" => \&git_rss,
|
||||||
"search" => \&git_search,
|
"search" => \&git_search,
|
||||||
|
"search_help" => \&git_search_help,
|
||||||
"shortlog" => \&git_shortlog,
|
"shortlog" => \&git_shortlog,
|
||||||
"summary" => \&git_summary,
|
"summary" => \&git_summary,
|
||||||
"tag" => \&git_tag,
|
"tag" => \&git_tag,
|
||||||
@ -455,6 +463,7 @@ sub href(%) {
|
|||||||
page => "pg",
|
page => "pg",
|
||||||
order => "o",
|
order => "o",
|
||||||
searchtext => "s",
|
searchtext => "s",
|
||||||
|
searchtype => "st",
|
||||||
);
|
);
|
||||||
my %mapping = @mapping;
|
my %mapping = @mapping;
|
||||||
|
|
||||||
@ -1524,6 +1533,10 @@ EOF
|
|||||||
$cgi->hidden(-name => "p") . "\n" .
|
$cgi->hidden(-name => "p") . "\n" .
|
||||||
$cgi->hidden(-name => "a") . "\n" .
|
$cgi->hidden(-name => "a") . "\n" .
|
||||||
$cgi->hidden(-name => "h") . "\n" .
|
$cgi->hidden(-name => "h") . "\n" .
|
||||||
|
$cgi->popup_menu(-name => 'st', -default => 'commit',
|
||||||
|
-values => ['commit', 'author', 'committer', 'pickaxe']) .
|
||||||
|
$cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
|
||||||
|
" search:\n",
|
||||||
$cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
|
$cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
|
||||||
"</div>" .
|
"</div>" .
|
||||||
$cgi->end_form() . "\n";
|
$cgi->end_form() . "\n";
|
||||||
@ -3544,18 +3557,8 @@ sub git_search {
|
|||||||
die_error(undef, "Unknown commit object");
|
die_error(undef, "Unknown commit object");
|
||||||
}
|
}
|
||||||
|
|
||||||
my $commit_search = 1;
|
$searchtype ||= 'commit';
|
||||||
my $author_search = 0;
|
if ($searchtype eq 'pickaxe') {
|
||||||
my $committer_search = 0;
|
|
||||||
my $pickaxe_search = 0;
|
|
||||||
if ($searchtext =~ s/^author\\://i) {
|
|
||||||
$author_search = 1;
|
|
||||||
} elsif ($searchtext =~ s/^committer\\://i) {
|
|
||||||
$committer_search = 1;
|
|
||||||
} elsif ($searchtext =~ s/^pickaxe\\://i) {
|
|
||||||
$commit_search = 0;
|
|
||||||
$pickaxe_search = 1;
|
|
||||||
|
|
||||||
# pickaxe may take all resources of your box and run for several minutes
|
# 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
|
# with every query - so decide by yourself how public you make this feature
|
||||||
my ($have_pickaxe) = gitweb_check_feature('pickaxe');
|
my ($have_pickaxe) = gitweb_check_feature('pickaxe');
|
||||||
@ -3563,23 +3566,24 @@ sub git_search {
|
|||||||
die_error('403 Permission denied', "Permission denied");
|
die_error('403 Permission denied', "Permission denied");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
git_header_html();
|
git_header_html();
|
||||||
git_print_page_nav('','', $hash,$co{'tree'},$hash);
|
git_print_page_nav('','', $hash,$co{'tree'},$hash);
|
||||||
git_print_header_div('commit', esc_html($co{'title'}), $hash);
|
git_print_header_div('commit', esc_html($co{'title'}), $hash);
|
||||||
|
|
||||||
print "<table cellspacing=\"0\">\n";
|
print "<table cellspacing=\"0\">\n";
|
||||||
my $alternate = 1;
|
my $alternate = 1;
|
||||||
if ($commit_search) {
|
if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
|
||||||
$/ = "\0";
|
$/ = "\0";
|
||||||
open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
|
open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
|
||||||
while (my $commit_text = <$fd>) {
|
while (my $commit_text = <$fd>) {
|
||||||
if (!grep m/$searchtext/i, $commit_text) {
|
if (!grep m/$searchtext/i, $commit_text) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
|
if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
|
if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
my @commit_lines = split "\n", $commit_text;
|
my @commit_lines = split "\n", $commit_text;
|
||||||
@ -3621,7 +3625,7 @@ sub git_search {
|
|||||||
close $fd;
|
close $fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($pickaxe_search) {
|
if ($searchtype eq 'pickaxe') {
|
||||||
$/ = "\n";
|
$/ = "\n";
|
||||||
my $git_command = git_cmd_str();
|
my $git_command = git_cmd_str();
|
||||||
open my $fd, "-|", "$git_command rev-list $hash | " .
|
open my $fd, "-|", "$git_command rev-list $hash | " .
|
||||||
@ -3681,6 +3685,31 @@ sub git_search {
|
|||||||
git_footer_html();
|
git_footer_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub git_search_help {
|
||||||
|
git_header_html();
|
||||||
|
git_print_page_nav('','', $hash,$hash,$hash);
|
||||||
|
print <<EOT;
|
||||||
|
<dl>
|
||||||
|
<dt><b>commit</b></dt>
|
||||||
|
<dd>The commit messages and authorship information will be scanned for the given string.</dd>
|
||||||
|
<dt><b>author</b></dt>
|
||||||
|
<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
|
||||||
|
<dt><b>committer</b></dt>
|
||||||
|
<dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
|
||||||
|
EOT
|
||||||
|
my ($have_pickaxe) = gitweb_check_feature('pickaxe');
|
||||||
|
if ($have_pickaxe) {
|
||||||
|
print <<EOT;
|
||||||
|
<dt><b>pickaxe</b></dt>
|
||||||
|
<dd>All commits that caused the string to appear or disappear from any file (changes that
|
||||||
|
added, removed or "modified" the string) will be listed. This search can take a while and
|
||||||
|
takes a lot of strain on the server, so please use it wisely.</dd>
|
||||||
|
EOT
|
||||||
|
}
|
||||||
|
print "</dl>\n";
|
||||||
|
git_footer_html();
|
||||||
|
}
|
||||||
|
|
||||||
sub git_shortlog {
|
sub git_shortlog {
|
||||||
my $head = git_get_head_hash($project);
|
my $head = git_get_head_hash($project);
|
||||||
if (!defined $hash) {
|
if (!defined $hash) {
|
||||||
|
Reference in New Issue
Block a user