Merge branch 'jn/gitweb-grep'
* jn/gitweb-grep: gitweb: Clearly distinguish regexp / exact match searches gitweb: Simplify fixed string search gitweb: Change parse_commits signature to allow for multiple optionsmaint
commit
4bea4b8451
|
@ -472,13 +472,15 @@ if (defined $searchtype) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
our $search_use_regexp = $cgi->param('sr');
|
||||||
|
|
||||||
our $searchtext = $cgi->param('s');
|
our $searchtext = $cgi->param('s');
|
||||||
our $search_regexp;
|
our $search_regexp;
|
||||||
if (defined $searchtext) {
|
if (defined $searchtext) {
|
||||||
if (length($searchtext) < 2) {
|
if (length($searchtext) < 2) {
|
||||||
die_error(undef, "At least two characters are required for search parameter");
|
die_error(undef, "At least two characters are required for search parameter");
|
||||||
}
|
}
|
||||||
$search_regexp = quotemeta $searchtext;
|
$search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
|
||||||
}
|
}
|
||||||
|
|
||||||
# now read PATH_INFO and use it as alternative to parameters
|
# now read PATH_INFO and use it as alternative to parameters
|
||||||
|
@ -608,6 +610,7 @@ sub href(%) {
|
||||||
searchtype => "st",
|
searchtype => "st",
|
||||||
snapshot_format => "sf",
|
snapshot_format => "sf",
|
||||||
extra_options => "opt",
|
extra_options => "opt",
|
||||||
|
search_use_regexp => "sr",
|
||||||
);
|
);
|
||||||
my %mapping = @mapping;
|
my %mapping = @mapping;
|
||||||
|
|
||||||
|
@ -2079,7 +2082,7 @@ sub parse_commit {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub parse_commits {
|
sub parse_commits {
|
||||||
my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
|
my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
|
||||||
my @cos;
|
my @cos;
|
||||||
|
|
||||||
$maxcount ||= 1;
|
$maxcount ||= 1;
|
||||||
|
@ -2089,7 +2092,7 @@ sub parse_commits {
|
||||||
|
|
||||||
open my $fd, "-|", git_cmd(), "rev-list",
|
open my $fd, "-|", git_cmd(), "rev-list",
|
||||||
"--header",
|
"--header",
|
||||||
($arg ? ($arg) : ()),
|
@args,
|
||||||
("--max-count=" . $maxcount),
|
("--max-count=" . $maxcount),
|
||||||
("--skip=" . $skip),
|
("--skip=" . $skip),
|
||||||
@extra_options,
|
@extra_options,
|
||||||
|
@ -2584,6 +2587,10 @@ EOF
|
||||||
$cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
|
$cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
|
||||||
" search:\n",
|
" search:\n",
|
||||||
$cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
|
$cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
|
||||||
|
"<span title=\"Extended regular expression\">" .
|
||||||
|
$cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
|
||||||
|
-checked => $search_use_regexp) .
|
||||||
|
"</span>" .
|
||||||
"</div>" .
|
"</div>" .
|
||||||
$cgi->end_form() . "\n";
|
$cgi->end_form() . "\n";
|
||||||
}
|
}
|
||||||
|
@ -5172,7 +5179,7 @@ sub git_history {
|
||||||
$ftype = git_get_type($hash);
|
$ftype = git_get_type($hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
my @commitlist = parse_commits($hash_base, 101, (100 * $page), "--full-history", $file_name);
|
my @commitlist = parse_commits($hash_base, 101, (100 * $page), $file_name, "--full-history");
|
||||||
|
|
||||||
my $paging_nav = '';
|
my $paging_nav = '';
|
||||||
if ($page > 0) {
|
if ($page > 0) {
|
||||||
|
@ -5254,14 +5261,17 @@ sub git_search {
|
||||||
} elsif ($searchtype eq 'committer') {
|
} elsif ($searchtype eq 'committer') {
|
||||||
$greptype = "--committer=";
|
$greptype = "--committer=";
|
||||||
}
|
}
|
||||||
$greptype .= $search_regexp;
|
$greptype .= $searchtext;
|
||||||
my @commitlist = parse_commits($hash, 101, (100 * $page), $greptype);
|
my @commitlist = parse_commits($hash, 101, (100 * $page), undef,
|
||||||
|
$greptype, '--regexp-ignore-case',
|
||||||
|
$search_use_regexp ? '--extended-regexp' : '--fixed-strings');
|
||||||
|
|
||||||
my $paging_nav = '';
|
my $paging_nav = '';
|
||||||
if ($page > 0) {
|
if ($page > 0) {
|
||||||
$paging_nav .=
|
$paging_nav .=
|
||||||
$cgi->a({-href => href(action=>"search", hash=>$hash,
|
$cgi->a({-href => href(action=>"search", hash=>$hash,
|
||||||
searchtext=>$searchtext, searchtype=>$searchtype)},
|
searchtext=>$searchtext,
|
||||||
|
searchtype=>$searchtype)},
|
||||||
"first");
|
"first");
|
||||||
$paging_nav .= " ⋅ " .
|
$paging_nav .= " ⋅ " .
|
||||||
$cgi->a({-href => href(-replay=>1, page=>$page-1),
|
$cgi->a({-href => href(-replay=>1, page=>$page-1),
|
||||||
|
@ -5298,8 +5308,9 @@ sub git_search {
|
||||||
my $git_command = git_cmd_str();
|
my $git_command = git_cmd_str();
|
||||||
my $searchqtext = $searchtext;
|
my $searchqtext = $searchtext;
|
||||||
$searchqtext =~ s/'/'\\''/;
|
$searchqtext =~ s/'/'\\''/;
|
||||||
|
my $pickaxe_flags = $search_use_regexp ? '--pickaxe-regex' : '';
|
||||||
open my $fd, "-|", "$git_command rev-list $hash | " .
|
open my $fd, "-|", "$git_command rev-list $hash | " .
|
||||||
"$git_command diff-tree -r --stdin -S\'$searchqtext\'";
|
"$git_command diff-tree -r --stdin -S\'$searchqtext\' $pickaxe_flags";
|
||||||
undef %co;
|
undef %co;
|
||||||
my @files;
|
my @files;
|
||||||
while (my $line = <$fd>) {
|
while (my $line = <$fd>) {
|
||||||
|
@ -5363,7 +5374,9 @@ sub git_search {
|
||||||
my $alternate = 1;
|
my $alternate = 1;
|
||||||
my $matches = 0;
|
my $matches = 0;
|
||||||
$/ = "\n";
|
$/ = "\n";
|
||||||
open my $fd, "-|", git_cmd(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
|
open my $fd, "-|", git_cmd(), 'grep', '-n',
|
||||||
|
$search_use_regexp ? ('-E', '-i') : '-F',
|
||||||
|
$searchtext, $co{'tree'};
|
||||||
my $lastfile = '';
|
my $lastfile = '';
|
||||||
while (my $line = <$fd>) {
|
while (my $line = <$fd>) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
|
@ -5393,7 +5406,7 @@ sub git_search {
|
||||||
print "<div class=\"binary\">Binary file</div>\n";
|
print "<div class=\"binary\">Binary file</div>\n";
|
||||||
} else {
|
} else {
|
||||||
$ltext = untabify($ltext);
|
$ltext = untabify($ltext);
|
||||||
if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
|
if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
|
||||||
$ltext = esc_html($1, -nbsp=>1);
|
$ltext = esc_html($1, -nbsp=>1);
|
||||||
$ltext .= '<span class="match">';
|
$ltext .= '<span class="match">';
|
||||||
$ltext .= esc_html($2, -nbsp=>1);
|
$ltext .= esc_html($2, -nbsp=>1);
|
||||||
|
@ -5428,27 +5441,31 @@ sub git_search_help {
|
||||||
git_header_html();
|
git_header_html();
|
||||||
git_print_page_nav('','', $hash,$hash,$hash);
|
git_print_page_nav('','', $hash,$hash,$hash);
|
||||||
print <<EOT;
|
print <<EOT;
|
||||||
|
<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
|
||||||
|
regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
|
||||||
|
the pattern entered is recognized as the POSIX extended
|
||||||
|
<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
|
||||||
|
insensitive).</p>
|
||||||
<dl>
|
<dl>
|
||||||
<dt><b>commit</b></dt>
|
<dt><b>commit</b></dt>
|
||||||
<dd>The commit messages and authorship information will be scanned for the given string.</dd>
|
<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
|
||||||
EOT
|
EOT
|
||||||
my ($have_grep) = gitweb_check_feature('grep');
|
my ($have_grep) = gitweb_check_feature('grep');
|
||||||
if ($have_grep) {
|
if ($have_grep) {
|
||||||
print <<EOT;
|
print <<EOT;
|
||||||
<dt><b>grep</b></dt>
|
<dt><b>grep</b></dt>
|
||||||
<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
|
<dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
|
||||||
a different one) are searched for the given
|
a different one) are searched for the given pattern. On large trees, this search can take
|
||||||
<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
|
a while and put some strain on the server, so please use it with some consideration. Note that
|
||||||
(POSIX extended) and the matches are listed. On large
|
due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
|
||||||
trees, this search can take a while and put some strain on the server, so please use it with
|
case-sensitive.</dd>
|
||||||
some consideration.</dd>
|
|
||||||
EOT
|
EOT
|
||||||
}
|
}
|
||||||
print <<EOT;
|
print <<EOT;
|
||||||
<dt><b>author</b></dt>
|
<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>
|
<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
|
||||||
<dt><b>committer</b></dt>
|
<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>
|
<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
|
||||||
EOT
|
EOT
|
||||||
my ($have_pickaxe) = gitweb_check_feature('pickaxe');
|
my ($have_pickaxe) = gitweb_check_feature('pickaxe');
|
||||||
if ($have_pickaxe) {
|
if ($have_pickaxe) {
|
||||||
|
@ -5456,7 +5473,8 @@ EOT
|
||||||
<dt><b>pickaxe</b></dt>
|
<dt><b>pickaxe</b></dt>
|
||||||
<dd>All commits that caused the string to appear or disappear from any file (changes that
|
<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
|
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>
|
takes a lot of strain on the server, so please use it wisely. Note that since you may be
|
||||||
|
interested even in changes just changing the case as well, this search is case sensitive.</dd>
|
||||||
EOT
|
EOT
|
||||||
}
|
}
|
||||||
print "</dl>\n";
|
print "</dl>\n";
|
||||||
|
@ -5507,7 +5525,7 @@ sub git_feed {
|
||||||
|
|
||||||
# log/feed of current (HEAD) branch, log of given branch, history of file/directory
|
# log/feed of current (HEAD) branch, log of given branch, history of file/directory
|
||||||
my $head = $hash || 'HEAD';
|
my $head = $hash || 'HEAD';
|
||||||
my @commitlist = parse_commits($head, 150, 0, undef, $file_name);
|
my @commitlist = parse_commits($head, 150, 0, $file_name);
|
||||||
|
|
||||||
my %latest_commit;
|
my %latest_commit;
|
||||||
my %latest_date;
|
my %latest_date;
|
||||||
|
|
Loading…
Reference in New Issue