From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: John 'Warthog9' Hawley <warthog9@kernel.org>,
admin@repo.or.cz, Jakub Narebski <jnareb@gmail.com>
Subject: [PATCH 5/5] gitweb: Make git_search_* subroutines render whole pages
Date: Wed, 22 Jun 2011 17:28:55 +0200 [thread overview]
Message-ID: <1308756535-29701-6-git-send-email-jnareb@gmail.com> (raw)
In-Reply-To: <1308756535-29701-1-git-send-email-jnareb@gmail.com>
This means moving 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>
---
gitweb/gitweb.perl | 38 ++++++++++++++++++++++++++------------
1 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 1c06476..f8df027 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5577,6 +5577,8 @@ sub git_search_message {
$paging_nav .= " ⋅ next";
}
+ git_header_html();
+
git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
git_print_header_div('commit', esc_html($co{'title'}), $hash);
if ($page == 0 && !@commitlist) {
@@ -5584,20 +5586,26 @@ sub git_search_message {
} else {
git_search_grep_body(\@commitlist, 0, 99, $next_link);
}
+
+ git_footer_html();
}
sub git_search_changes {
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_header_div('commit', esc_html($co{'title'}), $hash);
print "<table class=\"pickaxe search\">\n";
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;
my @files;
while (my $line = <$fd>) {
@@ -5661,21 +5669,27 @@ sub git_search_changes {
}
print "</table>\n";
+
+ git_footer_html();
}
sub git_search_files {
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_header_div('commit', esc_html($co{'title'}), $hash);
print "<table class=\"grep_search\">\n";
my $alternate = 1;
my $matches = 0;
- local $/ = "\n";
- open my $fd, "-|", git_cmd(), 'grep', '-n',
- $search_use_regexp ? ('-E', '-i') : '-F',
- $searchtext, $co{'tree'};
my $lastfile = '';
while (my $line = <$fd>) {
chomp $line;
@@ -5732,6 +5746,8 @@ sub git_search_files {
close $fd;
print "</table>\n";
+
+ git_footer_html();
}
sub git_search_grep_body {
@@ -7319,8 +7335,6 @@ sub git_search {
$page = 0;
}
- git_header_html();
-
if ($searchtype eq 'commit' ||
$searchtype eq 'author' ||
$searchtype eq 'committer') {
@@ -7329,9 +7343,9 @@ sub git_search {
git_search_changes(%co);
} elsif ($searchtype eq 'grep') {
git_search_files(%co);
+ } else {
+ die_error(400, "Unknown search type");
}
-
- git_footer_html();
}
sub git_search_help {
--
1.7.5
next prev parent reply other threads:[~2011-06-22 15:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-22 15:28 [PATCH 0/5] gitweb: Improve search code Jakub Narebski
2011-06-22 15:28 ` [PATCHv3 1/5] gitweb: 'pickaxe' and 'grep' features requires 'search' to be enabled Jakub Narebski
2011-06-22 15:28 ` [PATCH 2/5] gitweb: Check permissions first in git_search Jakub Narebski
2011-06-22 15:28 ` [PATCH 3/5] gitweb: Split body of git_search into subroutines Jakub Narebski
2011-06-22 15:28 ` [PATCH 4/5] gitweb: Clean up code in git_search_* subroutines Jakub Narebski
2011-06-22 15:28 ` Jakub Narebski [this message]
2011-06-22 17:10 ` [PATCH 0/5] gitweb: Improve search code Phil Hord
2011-06-22 18:00 ` Jakub Narebski
2011-06-22 19:24 ` Phil Hord
2011-06-22 18:55 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1308756535-29701-6-git-send-email-jnareb@gmail.com \
--to=jnareb@gmail.com \
--cc=admin@repo.or.cz \
--cc=git@vger.kernel.org \
--cc=warthog9@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).