472
}
473
}
474
475
+our $search_use_regexp = $cgi->param('sr');
476
+
477
our $searchtext = $cgi->param('s');
478
our $search_regexp;
479
if (defined $searchtext) {
480
if (length($searchtext) < 2) {
481
die_error(undef, "At least two characters are required for search parameter");
482
}
481
- $search_regexp = quotemeta $searchtext;
483
+ $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
484
}
485
486
# now read PATH_INFO and use it as alternative to parameters
610
searchtype => "st",
611
snapshot_format => "sf",
612
extra_options => "opt",
613
+ search_use_regexp => "sr",
614
);
615
my %mapping = @mapping;
616
2587
$cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
2588
" search:\n",
2589
$cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
2590
+ "<span title=\"Extended regular expression\">" .
2591
+ $cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
2592
+ -checked => $search_use_regexp) .
2593
+ "</span>" .
2594
"</div>" .
2595
$cgi->end_form() . "\n";
2596
}
5263
}
5264
$greptype .= $searchtext;
5265
my @commitlist = parse_commits($hash, 101, (100 * $page), undef,
5259
- $greptype, '--fixed-strings');
5266
+ $greptype, '--regexp-ignore-case',
5267
+ $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5268
5269
my $paging_nav = '';
5270
if ($page > 0) {
5308
my $git_command = git_cmd_str();
5309
my $searchqtext = $searchtext;
5310
$searchqtext =~ s/'/'\\''/;
5311
+ my $pickaxe_flags = $search_use_regexp ? '--pickaxe-regex' : '';
5312
open my $fd, "-|", "$git_command rev-list $hash | " .
5304
- "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5313
+ "$git_command diff-tree -r --stdin -S\'$searchqtext\' $pickaxe_flags";
5314
undef %co;
5315
my @files;
5316
while (my $line = <$fd>) {
5374
my $alternate = 1;
5375
my $matches = 0;
5376
$/ = "\n";
5368
- open my $fd, "-|", git_cmd(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5377
+ open my $fd, "-|", git_cmd(), 'grep', '-n',
5378
+ $search_use_regexp ? ('-E', '-i') : '-F',
5379
+ $searchtext, $co{'tree'};
5380
my $lastfile = '';
5381
while (my $line = <$fd>) {
5382
chomp $line;
5406
print "<div class=\"binary\">Binary file</div>\n";
5407
} else {
5408
$ltext = untabify($ltext);
5398
- if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5409
+ if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5410
$ltext = esc_html($1, -nbsp=>1);
5411
$ltext .= '<span class="match">';
5412
$ltext .= esc_html($2, -nbsp=>1);
5441
git_header_html();
5442
git_print_page_nav('','', $hash,$hash,$hash);
5443
print <<EOT;
5444
+<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5445
+regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5446
+the pattern entered is recognized as the POSIX extended
5447
+<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5448
+insensitive).</p>
5449
<dl>
5450
<dt><b>commit</b></dt>
5435
-<dd>The commit messages and authorship information will be scanned for the given string.</dd>
5451
+<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5452
EOT
5453
my ($have_grep) = gitweb_check_feature('grep');
5454
if ($have_grep) {
5455
print <<EOT;
5456
<dt><b>grep</b></dt>
5457
<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5442
- a different one) are searched for the given
5443
-<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5444
-(POSIX extended) and the matches are listed. On large
5445
-trees, this search can take a while and put some strain on the server, so please use it with
5446
-some consideration.</dd>
5458
+ a different one) are searched for the given pattern. On large trees, this search can take
5459
+a while and put some strain on the server, so please use it with some consideration. Note that
5460
+due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5461
+case-sensitive.</dd>
5462
EOT
5463
}
5464
print <<EOT;
5465
<dt><b>author</b></dt>
5451
-<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5466
+<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5467
<dt><b>committer</b></dt>
5453
-<dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5468
+<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5469
EOT
5470
my ($have_pickaxe) = gitweb_check_feature('pickaxe');
5471
if ($have_pickaxe) {
5473
<dt><b>pickaxe</b></dt>
5474
<dd>All commits that caused the string to appear or disappear from any file (changes that
5475
added, removed or "modified" the string) will be listed. This search can take a while and
5461
-takes a lot of strain on the server, so please use it wisely.</dd>
5476
+takes a lot of strain on the server, so please use it wisely. Note that since you may be
5477
+interested even in changes just changing the case as well, this search is case sensitive.</dd>
5478
EOT
5479
}
5480
print "</dl>\n";