From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: Petr Baudis <pasky@suse.cz>, "J.H." <warthog19@eaglescrag.net>,
Lea Wiemann <LeWiemann@gmail.com>
Subject: [RFC/PATCH] gitweb: Project search
Date: Fri, 9 May 2008 15:23:23 +0200 [thread overview]
Message-ID: <200805091523.24591.jnareb@gmail.com> (raw)
In-Reply-To: <200805031103.14960.jnareb@gmail.com>
If the number of projects is greater than some number, currently for
testing set to 1 (in production probably to 100), then projects
listing is replaced by project search form. One can search by project
name (project path relative to $projectroot), by project description,
and by owner. There is also link to show all projects.
Before searching by some field the information we search for must be
filled in. For this fill_project_list_info() was enhanced to take
additional parameter which part of projects info to fill. This way we
can limit doing expensive calculations (like running git-for-each-ref
to get 'age' / "Last changed" info) only to projects which we will
show as search results.
To make sorting by given column of project list / project search
results, the 'sort by' links in print_sort_th() subroutine are
generated as 'replay' links.
NOTE: currently match is _not_ highlighted in search results.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch depends on earlier
"[RFC/PATCH] gitweb: Simplify git_project_list_body"
patch, and may (but should not) depend textually on
"[RFC/PATCH] gitweb: Allow project description in project_index file"
As this is quick'n'dirty proof-of-concept patch the styling of project
search form is done in HTML, instead of using CSS to do that.
This patch should reduce both server load and browser load for sites
with very large number of projects.
NOTE 1: in production one would increase threshold above which project
search is used instead of listing all projects.
NOTE 2: I think that for effective caching one would need to cache
data, not final output (to J.H. and Lea Wiemann).
What do you think about this concept?
gitweb/gitweb.perl | 92 ++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 79 insertions(+), 13 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index b117364..7e1a9b4 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -472,7 +472,7 @@ if (defined $page) {
our $searchtype = $cgi->param('st');
if (defined $searchtype) {
- if ($searchtype =~ m/[^a-z]/) {
+ if ($searchtype =~ m/[^a-z_]/) {
die_error(undef, "Invalid searchtype parameter");
}
}
@@ -3589,29 +3589,61 @@ sub git_patchset_body {
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
+sub git_project_search_form {
+ my ($projlist, $searchtype, $searchtext, $search_use_regexp);
+
+ $searchtype ||= 'descr';
+ print "\n<!-- START: project_list search form -->\n" .
+ "<div style=\"text-align: center; margin-top: 20px;\">\n";
+ print $cgi->startform(-method => 'get', -action => $my_uri) .
+ $cgi->hidden(-name => 'a', -value => 'project_list') . "\n" .
+ $cgi->popup_menu(-name => 'st', -default => $searchtype,
+ -values => ['project', 'descr', 'owner'],
+ -labels => {'project' => 'Project',
+ 'descr' => 'Description',
+ 'owner' => 'Owner'}) . "\n" .
+ $cgi->textfield(-name => 's', -value => $searchtext,
+ -size => 60) . "\n" .
+ "<span title=\"Extended regular expression\">" .
+ $cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
+ -checked => $search_use_regexp) .
+ "</span>\n" .
+ $cgi->submit(-name => 'btnS', -value => 'Search') .
+ $cgi->end_form() . "\n" .
+ $cgi->a({-href => href(project => undef, searchtype => 'list_all')},
+ 'List all projects') . "\n";
+ print "</div>\n" .
+ "<!-- END: project_list search form -->\n\n";
+}
+
# fills project list info (age, description, owner, forks) for each
-# project in the list, removing invalid projects from returned list
+# project in the list, removing invalid projects from returned list,
+# or fill only specified info (removing only when filling 'age')
sub fill_project_list_info {
- my ($projlist, $check_forks) = @_;
+ my ($projlist, $check_forks, $fill_only) = @_;
my @projects;
PROJECT:
foreach my $pr (@$projlist) {
- my (@activity) = git_get_last_activity($pr->{'path'});
- unless (@activity) {
- next PROJECT;
- }
- ($pr->{'age'}, $pr->{'age_string'}) = @activity;
- if (!defined $pr->{'descr'}) {
+ if (!exists $pr->{'age'} &&
+ (!defined $fill_only || $fill_only eq 'age')) {
+ my (@activity) = git_get_last_activity($pr->{'path'});
+ next PROJECT unless (@activity);
+ ($pr->{'age'}, $pr->{'age_string'}) = @activity;
+ }
+ if (!defined $pr->{'descr'} &&
+ (!defined $fill_only || $fill_only eq 'descr')) {
my $descr = git_get_project_description($pr->{'path'}) || "";
$descr = to_utf8($descr);
$pr->{'descr_long'} = $descr;
$pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
}
- if (!defined $pr->{'owner'}) {
+ if (!defined $pr->{'owner'} &&
+ (!defined $fill_only || $fill_only eq 'owner')) {
$pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
}
- if ($check_forks) {
+ if ($check_forks &&
+ (!defined $fill_only || $fill_only eq 'forks')) {
my $pname = $pr->{'path'};
if (($pname =~ s/\.git$//) &&
($pname !~ /\/$/) &&
@@ -3627,6 +3659,25 @@ sub fill_project_list_info {
return @projects;
}
+# show only projects which match what we search for
+sub filter_project_list {
+ my ($projlist, $searchtype, $search_regexp) = @_;
+ my %keyname = (
+ 'project' => 'path',
+ 'descr' => 'descr_long',
+ 'owner' => 'owner',
+ );
+ my $key = $keyname{$searchtype};
+
+ # fill in the field we search on
+ @$projlist = fill_project_list_info($projlist, 0, $searchtype);
+ # filter projects list
+ @$projlist = grep
+ { $_->{$key} =~ m/$search_regexp/i; } @$projlist;
+
+ return $projlist;
+}
+
sub print_sort_th {
my ($str_sort, $name, $order, $key, $header, $projlist) = @_;
$key ||= $name;
@@ -3641,7 +3692,7 @@ sub print_sort_th {
print "<th>$header</th>\n";
} else {
print "<th>" .
- $cgi->a({-href => href(project=>undef, order=>$name),
+ $cgi->a({-href => href(-replay => 1, order=>$name),
-class => "header"}, $header) .
"</th>\n";
}
@@ -4005,6 +4056,10 @@ sub git_project_list {
if (defined $order && $order !~ m/none|project|descr|owner|age/) {
die_error(undef, "Unknown order parameter");
}
+ if (defined $searchtype &&
+ $searchtype !~ m/^(project|descr|owner|list_all)$/x) {
+ die_error(undef, "Unknown searchtype parameter");
+ }
my @list = git_get_projects_list();
if (!@list) {
@@ -4019,7 +4074,18 @@ sub git_project_list {
close $fd;
print "</div>\n";
}
- git_project_list_body(\@list, $order);
+ # 'defined $searchtype' serves as "was search performed" test
+ if (@list > 1 || defined $searchtype) {
+ git_project_search_form(\@list, $searchtype,
+ $searchtext, $search_use_regexp);
+ if (defined $searchtype) {
+ filter_project_list(\@list, $searchtype, $search_regexp)
+ unless ($searchtype eq 'list_all');
+ git_project_list_body(\@list, $order);
+ }
+ } else {
+ git_project_list_body(\@list, $order);
+ }
git_footer_html();
}
--
1.5.5
next prev parent reply other threads:[~2008-05-09 13:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-01 10:20 [RFC/PATCH] gitweb: Simplify git_project_list_body Jakub Narebski
2008-05-02 10:30 ` [RFC/PATCH] gitweb: Allow project description in project_index file Jakub Narebski
2008-05-02 13:04 ` Miklos Vajna
2008-05-03 9:03 ` Jakub Narebski
2008-05-04 2:03 ` Miklos Vajna
2008-05-09 13:23 ` Jakub Narebski [this message]
2008-05-10 9:28 ` [RFC/PATCH] gitweb: Paginate project list Jakub Narebski
2008-05-10 18:28 ` J.H.
2008-05-10 22:32 ` Jakub Narebski
2008-05-11 5:53 ` J.H.
2008-05-11 23:51 ` Jakub Narebski
[not found] ` <8c5c35580805102356p7e5532aah319af921f9b19392@mail.gmail.com>
2008-05-12 7:03 ` Jakub Narebski
2008-05-12 15:43 ` Lars Hjemli
2008-05-13 6:55 ` Jakub Narebski
[not found] ` <8c5c35580805130939m1a1ef8e0yd72402f3c79190ea@mail.gmail.com>
2008-05-13 16:46 ` Lars Hjemli
2008-05-13 17:04 ` Jakub Narebski
2008-05-13 19:11 ` Kristian Høgsberg
2008-05-13 19:30 ` Lars Hjemli
2008-05-13 23:28 ` Jakub Narebski
2008-05-14 7:59 ` Jakub Narebski
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=200805091523.24591.jnareb@gmail.com \
--to=jnareb@gmail.com \
--cc=LeWiemann@gmail.com \
--cc=git@vger.kernel.org \
--cc=pasky@suse.cz \
--cc=warthog19@eaglescrag.net \
/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).