зеркало из https://github.com/microsoft/git.git
gitweb: Make git_search_* subroutines render whole pages
Move git_header_html() and git_footer_html() invocation from git_search() to individual git_search_* subroutines. While at it, reorganize search-related code a bit, moving invoking of git commands before any output is generated. This has the following advantages: * gitweb now shows an error page if there was unknown search type (evaluate_and_validate_params checks only that it looks sanely); remember that we shouldn't call die_error after any output. * git_search_message is now safe agains die_error in parse_commits (though this is very unlikely). * gitweb now can check errors while invoking git commands and show error page (again, quite unlikely). Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
882541b87d
Коммит
1ae05be4aa
|
@ -5291,6 +5291,8 @@ sub git_search_message {
|
||||||
$paging_nav .= " ⋅ next";
|
$paging_nav .= " ⋅ next";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
git_header_html();
|
||||||
|
|
||||||
git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
|
git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
|
||||||
git_print_header_div('commit', esc_html($co{'title'}), $hash);
|
git_print_header_div('commit', esc_html($co{'title'}), $hash);
|
||||||
if ($page == 0 && !@commitlist) {
|
if ($page == 0 && !@commitlist) {
|
||||||
|
@ -5298,20 +5300,26 @@ sub git_search_message {
|
||||||
} else {
|
} else {
|
||||||
git_search_grep_body(\@commitlist, 0, 99, $next_link);
|
git_search_grep_body(\@commitlist, 0, 99, $next_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
git_footer_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub git_search_changes {
|
sub git_search_changes {
|
||||||
my %co = @_;
|
my %co = @_;
|
||||||
|
|
||||||
|
local $/ = "\n";
|
||||||
|
open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
|
||||||
|
'--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
|
||||||
|
($search_use_regexp ? '--pickaxe-regex' : ())
|
||||||
|
or die_error(500, "Open git-log failed");
|
||||||
|
|
||||||
|
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 class=\"pickaxe search\">\n";
|
print "<table class=\"pickaxe search\">\n";
|
||||||
my $alternate = 1;
|
my $alternate = 1;
|
||||||
local $/ = "\n";
|
|
||||||
open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
|
|
||||||
'--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
|
|
||||||
($search_use_regexp ? '--pickaxe-regex' : ());
|
|
||||||
undef %co;
|
undef %co;
|
||||||
my @files;
|
my @files;
|
||||||
while (my $line = <$fd>) {
|
while (my $line = <$fd>) {
|
||||||
|
@ -5375,21 +5383,27 @@ sub git_search_changes {
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</table>\n";
|
print "</table>\n";
|
||||||
|
|
||||||
|
git_footer_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub git_search_files {
|
sub git_search_files {
|
||||||
my %co = @_;
|
my %co = @_;
|
||||||
|
|
||||||
|
local $/ = "\n";
|
||||||
|
open my $fd, "-|", git_cmd(), 'grep', '-n',
|
||||||
|
$search_use_regexp ? ('-E', '-i') : '-F',
|
||||||
|
$searchtext, $co{'tree'}
|
||||||
|
or die_error(500, "Open git-grep failed");
|
||||||
|
|
||||||
|
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 class=\"grep_search\">\n";
|
print "<table class=\"grep_search\">\n";
|
||||||
my $alternate = 1;
|
my $alternate = 1;
|
||||||
my $matches = 0;
|
my $matches = 0;
|
||||||
local $/ = "\n";
|
|
||||||
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;
|
||||||
|
@ -5446,6 +5460,8 @@ sub git_search_files {
|
||||||
close $fd;
|
close $fd;
|
||||||
|
|
||||||
print "</table>\n";
|
print "</table>\n";
|
||||||
|
|
||||||
|
git_footer_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub git_search_grep_body {
|
sub git_search_grep_body {
|
||||||
|
@ -7016,8 +7032,6 @@ sub git_search {
|
||||||
$page = 0;
|
$page = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
git_header_html();
|
|
||||||
|
|
||||||
if ($searchtype eq 'commit' ||
|
if ($searchtype eq 'commit' ||
|
||||||
$searchtype eq 'author' ||
|
$searchtype eq 'author' ||
|
||||||
$searchtype eq 'committer') {
|
$searchtype eq 'committer') {
|
||||||
|
@ -7026,9 +7040,9 @@ sub git_search {
|
||||||
git_search_changes(%co);
|
git_search_changes(%co);
|
||||||
} elsif ($searchtype eq 'grep') {
|
} elsif ($searchtype eq 'grep') {
|
||||||
git_search_files(%co);
|
git_search_files(%co);
|
||||||
|
} else {
|
||||||
|
die_error(400, "Unknown search type");
|
||||||
}
|
}
|
||||||
|
|
||||||
git_footer_html();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub git_search_help {
|
sub git_search_help {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче