From: "Bernhard R. Link" <brl+git@mail.brlink.eu>
To: Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH v4 1/2] gitweb: add project_filter to limit project list to a subdirectory
Date: Sun, 29 Jan 2012 17:06:15 +0100 [thread overview]
Message-ID: <20120129160615.GA13937@server.brlink.eu> (raw)
In-Reply-To: <201201291354.50241.jnareb@gmail.com>
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 change is quite minimal as git_get_projects_list already can limit
itself to a subdirectory (though that was previously only used for
'forks').
If there is a GITWEB_LIST file, the contents are just filtered like
with the forks action.
Without a GITWEB_LIST file only the given subdirectory is searched
for projects (like with forks) unless GITWEB_STRICT_EXPORT is enabled.
In the later case GITWEB_PROJECTROOT is traversed normally (unlike
with forks) and projects not in the directory ignored.
(As there is no check if the filter_path would have been found in
the usual search as the project path is checked with forks).
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 <brlink@debian.org>
---
* Jakub Narebski <jnareb@gmail.com> [120129 13:54]:
> On Sun, 29 Jan 2012, Bernhard R. Link wrote:
> Though I am not sure if this "paranoid mode" is really necessary. I don't
> see how you could get in situation where scanning from $project_list and
> filtering with $project_filter prefix, and scanning from
> $project_list/$project_filter would give different results.
>
> I think you are overly paranoid here, but perhaps it is better to be
> overly strict, and then relax it if it turns out to be not necessary.
As far as I do understand it, this is the only (hopefully unecessary)
effect strict_export without a project_list has in gitweb, so I did not
want to remove that with this change.
> Excuse me changing my mind, but I think that as far as this patch series
> is applied as whole, it would be better for maintability to keep those
> two patches split; though put the above as a [part of] commit message
> in 2/2 patch.
Split again, though this time only the change for existing pages in the
second commit and the code duplication you spoke against removed.
gitweb/gitweb.perl | 43 ++++++++++++++++++++++++++++++++++++-------
1 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index abb5a79..f0e03d8 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)) {
@@ -2827,6 +2835,7 @@ sub git_get_project_url_list {
sub git_get_projects_list {
my $filter = shift || '';
+ my $paranoid = shift;
my @list;
$filter =~ s/\.git$//;
@@ -2839,7 +2848,7 @@ sub git_get_projects_list {
my $pfxlen = length("$dir");
my $pfxdepth = ($dir =~ tr!/!!);
# when filtering, search only given subdirectory
- if ($filter) {
+ if ($filter and not $paranoid) {
$dir .= "/$filter";
$dir =~ s!/+$!!;
}
@@ -2864,6 +2873,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 };
@@ -3823,6 +3836,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 = @_;
@@ -3841,6 +3866,8 @@ sub print_nav_breadcrumbs {
print " / $opts{-action_extra}";
}
print "\n";
+ } elsif (defined $project_filter) {
+ print_nav_breadcrumbs_path(split '/', $project_filter);
}
}
@@ -3963,9 +3990,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 "</div>\n"; # class="page_footer"
@@ -5979,7 +6008,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");
}
@@ -6018,7 +6047,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");
}
@@ -7855,7 +7884,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");
}
--
1.7.8.3
next prev parent reply other threads:[~2012-01-29 16:06 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-28 16:56 [PATCH v2 1/2] gitweb: add project_filter to limit project list to a subdirectory Bernhard R. Link
2012-01-28 16:57 ` [PATCH v2 2/2] gitweb: place links to parent directories in page header Bernhard R. Link
2012-01-28 22:54 ` Jakub Narebski
2012-01-28 22:45 ` [PATCH v2 1/2] gitweb: add project_filter to limit project list to a subdirectory Jakub Narebski
2012-01-29 1:22 ` [PATCH v3] " Bernhard R. Link
2012-01-29 12:54 ` Jakub Narebski
2012-01-29 16:06 ` Bernhard R. Link [this message]
2012-01-29 16:13 ` [PATCH v4 2/2] gitweb: place links to parent directories in page header Bernhard R. Link
2012-01-29 16:46 ` Jakub Narebski
2012-01-29 16:41 ` [PATCH v4 1/2] gitweb: add project_filter to limit project list to a subdirectory Jakub Narebski
2012-01-29 21:06 ` Junio C Hamano
2012-01-29 23:06 ` Jakub Narebski
2012-01-30 9:52 ` Bernhard R. Link
2012-01-30 11:44 ` [PATCH v5 1/5] gitweb: prepare git_get_projects_list for use outside 'forks' Bernhard R. Link
2012-01-30 13:42 ` Jakub Narebski
2012-01-30 14:55 ` [PATCH v5.5 " Bernhard R. Link
2012-01-30 15:40 ` Jakub Narebski
2012-01-30 16:29 ` Bernhard R. Link
2012-01-30 11:45 ` [PATCH v5 2/5] gitweb: add project_filter to limit project list to a subdirectory Bernhard R. Link
2012-01-30 15:57 ` Jakub Narebski
2012-01-30 20:03 ` Bernhard R. Link
2012-01-30 20:05 ` [PATCH 1/6] gitweb: move hard coded .git suffix out of git_get_projects_list Bernhard R. Link
2012-01-30 20:06 ` [PATCH v6 2/6] gitweb: prepare git_get_projects_list for use outside 'forks' Bernhard R. Link
2012-01-30 20:07 ` [PATCH v6 3/6] gitweb: add project_filter to limit project list to a subdirectory Bernhard R. Link
2012-01-30 20:09 ` [PATCH v6 4/6] gitweb: limit links to alternate forms of project_list to active project_filter Bernhard R. Link
2012-01-30 20:09 ` [PATCH v6 5/6] gitweb: show active project_filter in project_list page header Bernhard R. Link
2012-01-30 20:10 ` [PATCH v6 6/6] gitweb: place links to parent directories in " Bernhard R. Link
2012-01-30 20:34 ` [PATCH v5 2/5] gitweb: add project_filter to limit project list to a subdirectory Junio C Hamano
2012-01-30 20:48 ` Jakub Narebski
2012-01-30 21:05 ` Junio C Hamano
2012-01-30 21:08 ` Junio C Hamano
2012-01-30 20:48 ` Bernhard R. Link
2012-02-01 16:59 ` Bernhard R. Link
2012-02-01 20:55 ` Junio C Hamano
2012-01-30 11:47 ` [PATCH 3/5] gitweb: limit links to alternate forms of project_list to active project_filter Bernhard R. Link
2012-01-30 16:09 ` Jakub Narebski
2012-01-30 11:48 ` [PATCH v5 4/5] gitweb: show active project_filter in project_list page header Bernhard R. Link
2012-01-30 16:38 ` Jakub Narebski
2012-01-30 11:50 ` [PATCH v5 5/5] gitweb: place links to parent directories in " Bernhard R. Link
2012-01-30 17:10 ` 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120129160615.GA13937@server.brlink.eu \
--to=brl+git@mail.brlink.eu \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).