From 4c7cd177148c0ae018e1f1d1c037d296d50d3562 Mon Sep 17 00:00:00 2001 From: "Bernhard R. Link" Date: Mon, 30 Jan 2012 21:05:47 +0100 Subject: gitweb: move hard coded .git suffix out of git_get_projects_list Use of the filter option of git_get_projects_list is currently limited to forks. It hard codes removal of ".git" suffixes from the filter. To make it more generic move the .git suffix removal to the callers. Signed-off-by: Bernhard R. Link Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'gitweb') diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index abb5a79af..e074cd7c6 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -2829,8 +2829,6 @@ sub git_get_projects_list { my $filter = shift || ''; my @list; - $filter =~ s/\.git$//; - if (-d $projects_list) { # search in directory my $dir = $projects_list; @@ -6005,7 +6003,9 @@ sub git_forks { die_error(400, "Unknown order parameter"); } - my @list = git_get_projects_list($project); + my $filter = $project; + $filter =~ s/\.git$//; + my @list = git_get_projects_list($filter); if (!@list) { die_error(404, "No forks found"); } @@ -6064,7 +6064,9 @@ sub git_summary { if ($check_forks) { # find forks of a project - @forklist = git_get_projects_list($project); + my $filter = $project; + $filter =~ s/\.git$//; + @forklist = git_get_projects_list($filter); # filter out forks of forks @forklist = filter_forks_from_projects_list(\@forklist) if (@forklist); -- cgit v1.2.1 From 348a6589e016669a3cf2d71c612e32dde9ef6f27 Mon Sep 17 00:00:00 2001 From: "Bernhard R. Link" Date: Mon, 30 Jan 2012 21:06:38 +0100 Subject: gitweb: prepare git_get_projects_list for use outside 'forks'. Use of the filter option of git_get_projects_list is currently limited to forks. It currently assumes the project belonging to the filter directory was already validated to be visible in the project list. To make it more generic add an optional argument to denote visibility verification is still needed. If there is a projects list file (GITWEB_LIST) only projects from this list are returned anyway, so no more checks needed. If there is no projects list file and the caller requests strict checking (GITWEB_STRICT_EXPORT), do not jump directly to the given directory but instead do a normal search and filter the results instead. The only effect of GITWEB_STRICT_EXPORT without GITWEB_LIST is to make sure no project can be viewed without also be found starting from project root. git_get_projects_list without this patch does not enforce this but all callers only call it with a filter already checked this way. With this parameter a caller can request this check if the filter cannot be checked this way. Signed-off-by: Bernhard R. Link Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gitweb') diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index e074cd7c6..48a2a375b 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -2827,6 +2827,7 @@ sub git_get_project_url_list { sub git_get_projects_list { my $filter = shift || ''; + my $paranoid = shift; my @list; if (-d $projects_list) { @@ -2837,7 +2838,7 @@ sub git_get_projects_list { my $pfxlen = length("$dir"); my $pfxdepth = ($dir =~ tr!/!!); # when filtering, search only given subdirectory - if ($filter) { + if ($filter && !$paranoid) { $dir .= "/$filter"; $dir =~ s!/+$!!; } @@ -2862,6 +2863,10 @@ sub git_get_projects_list { } my $path = substr($File::Find::name, $pfxlen + 1); + # paranoidly only filter here + if ($paranoid && $filter && $path !~ m!^\Q$filter\E/!) { + next; + } # we check related file in $projectroot if (check_export_ok("$projectroot/$path")) { push @list, { path => $path }; -- cgit v1.2.1 From 19d2d23998bba7c7f0ee87451ddbbf8906381939 Mon Sep 17 00:00:00 2001 From: "Bernhard R. Link" Date: Mon, 30 Jan 2012 21:07:37 +0100 Subject: gitweb: add project_filter to limit project list to a subdirectory This commit changes the project listing views (project_list, project_index and opml) to limit the output to only projects in a subdirectory if the new optional parameter ?pf=directory name is used. The implementation of the filter reuses the implementation used for the 'forks' action (i.e. listing all projects within that directory from the projects list file (GITWEB_LIST) or only projects in the given subdirectory of the project root directory without a projects list file). Reusing $project instead of adding a new parameter would have been nicer from a UI point-of-view (including PATH_INFO support) but would complicate the $project validating code that is currently being used to ensure nothing is exported that should not be viewable. Signed-off-by: Bernhard R. Link Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'gitweb') diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 48a2a375b..daacf87e6 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -760,6 +760,7 @@ our @cgi_param_mapping = ( search_use_regexp => "sr", ctag => "by_tag", diff_style => "ds", + project_filter => "pf", # this must be last entry (for manipulation from JavaScript) javascript => "js" ); @@ -976,7 +977,7 @@ sub evaluate_path_info { our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base, $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp, - $searchtext, $search_regexp); + $searchtext, $search_regexp, $project_filter); sub evaluate_and_validate_params { our $action = $input_params{'action'}; if (defined $action) { @@ -994,6 +995,13 @@ sub evaluate_and_validate_params { } } + our $project_filter = $input_params{'project_filter'}; + if (defined $project_filter) { + if (!validate_pathname($project_filter)) { + die_error(404, "Invalid project_filter parameter"); + } + } + our $file_name = $input_params{'file_name'}; if (defined $file_name) { if (!validate_pathname($file_name)) { @@ -3732,7 +3740,12 @@ sub run_highlighter { sub get_page_title { my $title = to_utf8($site_name); - return $title unless (defined $project); + unless (defined $project) { + if (defined $project_filter) { + $title .= " - " . to_utf8($project_filter); + } + return $title; + } $title .= " - " . to_utf8($project); return $title unless (defined $action); @@ -5982,7 +5995,7 @@ sub git_project_list { die_error(400, "Unknown order parameter"); } - my @list = git_get_projects_list(); + my @list = git_get_projects_list($project_filter, $strict_export); if (!@list) { die_error(404, "No projects found"); } @@ -6023,7 +6036,7 @@ sub git_forks { } sub git_project_index { - my @projects = git_get_projects_list(); + my @projects = git_get_projects_list($project_filter, $strict_export); if (!@projects) { die_error(404, "No projects found"); } @@ -7862,7 +7875,7 @@ sub git_atom { } sub git_opml { - my @list = git_get_projects_list(); + my @list = git_get_projects_list($project_filter, $strict_export); if (!@list) { die_error(404, "No projects found"); } @@ -7873,11 +7886,17 @@ sub git_opml { -content_disposition => 'inline; filename="opml.xml"'); my $title = esc_html($site_name); + my $filter = " within subdirectory "; + if (defined $project_filter) { + $filter .= esc_html($project_filter); + } else { + $filter = ""; + } print < - $title OPML Export + $title OPML Export$filter -- cgit v1.2.1 From 56efd9d2524694717adf5405fccad90e2791ebfa Mon Sep 17 00:00:00 2001 From: "Bernhard R. Link" Date: Mon, 30 Jan 2012 21:09:00 +0100 Subject: gitweb: limit links to alternate forms of project_list to active project_filter If project_list action is given a project_filter argument, pass that to TXT and OPML formats. This way [OPML] and [TXT] links provide the same list of projects as the projects_list page they are linked from. Signed-off-by: Bernhard R. Link Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gitweb') diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index daacf87e6..ecd4a39d2 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3979,9 +3979,11 @@ sub git_footer_html { } } else { - print $cgi->a({-href => href(project=>undef, action=>"opml"), + print $cgi->a({-href => href(project=>undef, action=>"opml", + project_filter => $project_filter), -class => $feed_class}, "OPML") . " "; - print $cgi->a({-href => href(project=>undef, action=>"project_index"), + print $cgi->a({-href => href(project=>undef, action=>"project_index", + project_filter => $project_filter), -class => $feed_class}, "TXT") . "\n"; } print "\n"; # class="page_footer" -- cgit v1.2.1 From 40efa22309458546a3ea861689034acf9fbf9d1a Mon Sep 17 00:00:00 2001 From: "Bernhard R. Link" Date: Mon, 30 Jan 2012 21:09:43 +0100 Subject: gitweb: show active project_filter in project_list page header In the page header of a project_list view with a project_filter given show breadcrumbs in the page headers showing which directory it is currently limited to and also containing links to the parent directories. Signed-off-by: Bernhard R. Link Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gitweb') diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index ecd4a39d2..7d36f563e 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3839,6 +3839,18 @@ sub print_header_links { } } +sub print_nav_breadcrumbs_path { + my $dirprefix = undef; + while (my $part = shift) { + $dirprefix .= "/" if defined $dirprefix; + $dirprefix .= $part; + print $cgi->a({-href => href(project => undef, + project_filter => $dirprefix, + action => "project_list")}, + esc_html($part)) . " / "; + } +} + sub print_nav_breadcrumbs { my %opts = @_; @@ -3857,6 +3869,8 @@ sub print_nav_breadcrumbs { print " / $opts{-action_extra}"; } print "\n"; + } elsif (defined $project_filter) { + print_nav_breadcrumbs_path(split '/', $project_filter); } } -- cgit v1.2.1 From 4426ba2919697d57ab8b6335ca63b2c14e4e6339 Mon Sep 17 00:00:00 2001 From: "Bernhard R. Link" Date: Mon, 30 Jan 2012 21:10:23 +0100 Subject: gitweb: place links to parent directories in page header Change html page headers to not only link the project root and the currently selected project but also the directories in between using project_filter. (Allowing to jump to a list of all projects within that intermediate directory directly and making the project_filter feature visible to users). Signed-off-by: Bernhard R. Link Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gitweb') diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 7d36f563e..3ab608c7f 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3856,7 +3856,10 @@ sub print_nav_breadcrumbs { print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / "; if (defined $project) { - print $cgi->a({-href => href(action=>"summary")}, esc_html($project)); + my @dirname = split '/', $project; + my $projectbasename = pop @dirname; + print_nav_breadcrumbs_path(@dirname); + print $cgi->a({-href => href(action=>"summary")}, esc_html($projectbasename)); if (defined $action) { my $action_print = $action ; if (defined $opts{-action_extra}) { -- cgit v1.2.1 From a1e1b2d77b9fc5866d12bf984214b15f1dccf4a8 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Tue, 31 Jan 2012 01:20:54 +0100 Subject: gitweb: improve usability of projects search form Refactor generating project search form into git_project_search_form(). Make text field wider and add on mouse over explanation (via "title" attribute), add an option to use regular expressions, and replace 'Search:' label with [Search] button. Also add "List all projects" link to make it easier to go back from search result to list of all projects (note that an empty search term is disallowed). Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 27 ++++++++++++++++++++++----- gitweb/static/gitweb.css | 7 ++++++- 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'gitweb') diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 3ab608c7f..c81743b0a 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -5158,6 +5158,26 @@ sub git_patchset_body { # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . +sub git_project_search_form { + my ($searchtext, $search_use_regexp); + + print "
\n"; + print $cgi->startform(-method => 'get', -action => $my_uri) . + $cgi->hidden(-name => 'a', -value => 'project_list') . "\n" . + $cgi->textfield(-name => 's', -value => $searchtext, + -title => 'Search project by name and description', + -size => 60) . "\n" . + "" . + $cgi->checkbox(-name => 'sr', -value => 1, -label => 're', + -checked => $search_use_regexp) . + "\n" . + $cgi->submit(-name => 'btnS', -value => 'Search') . + $cgi->end_form() . "\n" . + $cgi->a({-href => href(project => undef, searchtext => undef)}, + 'List all projects') . "
\n"; + print "
\n"; +} + # fills project list info (age, description, owner, category, forks) # for each project in the list, removing invalid projects from # returned list @@ -6025,11 +6045,8 @@ sub git_project_list { insert_file($home_text); print "\n"; } - print $cgi->startform(-method => "get") . - "

Search:\n" . - $cgi->textfield(-name => "s", -value => $searchtext) . "\n" . - "

" . - $cgi->end_form() . "\n"; + + git_project_search_form($searchtext, $search_use_regexp); git_project_list_body(\@list, $order); git_footer_html(); } diff --git a/gitweb/static/gitweb.css b/gitweb/static/gitweb.css index c7827e8f1..c530355a7 100644 --- a/gitweb/static/gitweb.css +++ b/gitweb/static/gitweb.css @@ -520,8 +520,13 @@ div.search { right: 12px } -p.projsearch { +div.projsearch { text-align: center; + margin: 20px 0px; +} + +div.projsearch form { + margin-bottom: 2px; } td.linenr { -- cgit v1.2.1 From abc0c9d2d7312c4b153ba1b2b9cd8ba0696f1b04 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Tue, 31 Jan 2012 01:20:55 +0100 Subject: gitweb: Make project search respect project_filter Make gitweb search within filtered projects (i.e. projects shown), and change "List all projects" to "List all projects in '$project_filter/'" if project_filter is used. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'gitweb') diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index c81743b0a..f211594c4 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -5161,11 +5161,18 @@ sub git_patchset_body { sub git_project_search_form { my ($searchtext, $search_use_regexp); + my $limit = ''; + if ($project_filter) { + $limit = " in '$project_filter/'"; + } + print "
\n"; print $cgi->startform(-method => 'get', -action => $my_uri) . - $cgi->hidden(-name => 'a', -value => 'project_list') . "\n" . - $cgi->textfield(-name => 's', -value => $searchtext, - -title => 'Search project by name and description', + $cgi->hidden(-name => 'a', -value => 'project_list') . "\n"; + print $cgi->hidden(-name => 'pf', -value => $project_filter). "\n" + if (defined $project_filter); + print $cgi->textfield(-name => 's', -value => $searchtext, + -title => "Search project by name and description$limit", -size => 60) . "\n" . "" . $cgi->checkbox(-name => 'sr', -value => 1, -label => 're', @@ -5173,8 +5180,9 @@ sub git_project_search_form { "\n" . $cgi->submit(-name => 'btnS', -value => 'Search') . $cgi->end_form() . "\n" . - $cgi->a({-href => href(project => undef, searchtext => undef)}, - 'List all projects') . "
\n"; + $cgi->a({-href => href(project => undef, searchtext => undef, + project_filter => $project_filter)}, + esc_html("List all projects$limit")) . "
\n"; print "
\n"; } -- cgit v1.2.1