gitweb: add pf= to limit project list to a subdirectory
PATCH 1/1 gitweb: add pf= to limit project list to a subdirectory
This commit changes the project listings (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.
It uses the infrastructure already there for 'forks' (which also filters projects but needs a project called like the filter directory to work).
This feature is disabled if strict_export is used and there is no projects_list to avoid showing more than intended.
Without strict_export enabled this change should not show any projects one could not get details from anyway. So if the validate_pathname checks are not sufficient this would at most make it easier to get a list of viewable content.
Reusing $project instead of adding a new parameter would have been nicer from a UI point-of-view (including PATH_INFO support) but complicate the $project validating code that is currently being used to ensure nothing is exported that should not be viewable.
---
As most parameters are not documented in documentation/gitweb.txt, I did not add documentation for this one either.
gitweb/gitweb.perl | 26 ++++++++++++++++++++++---- 1 files changed, 22 insertions(+), 4 deletions(-)
gitweb/gitweb.perl +22 -4
@@ -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,16 @@ sub evaluate_and_validate_params { } } + our $project_filter = $input_params{'project_filter'}; + if (defined $project_filter) { + if ($strict_export and -d $projects_list) { + die_error(404, "project_filter disabled"); + } + 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)) {
@@ -3962,6 +3973,13 @@ sub git_footer_html { -class => $feed_class}, $format)."\n"; } + } elsif (defined $project_filter) { + 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", + project_filter => $project_filter), + -class => $feed_class}, "TXT") . "\n"; } else { print $cgi->a({-href => href(project=>undef, action=>"opml"), -class => $feed_class}, "OPML") . " ";
@@ -5979,7 +5997,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); if (!@list) { die_error(404, "No projects found"); }
@@ -6018,7 +6036,7 @@ sub git_forks { } sub git_project_index { - my @projects = git_get_projects_list(); + my @projects = git_get_projects_list($project_filter); if (!@projects) { die_error(404, "No projects found"); }
@@ -7855,7 +7873,7 @@ sub git_atom { } sub git_opml { - my @list = git_get_projects_list(); + my @list = git_get_projects_list($project_filter); if (!@list) { die_error(404, "No projects found"); }
Signature · 1 line
1.7.8.3
Quoted 3 lines · Bernhard R. Link
This commit changes the project listings (
project_list,project_indexand opml) to limit the output to only projects in a subdirectory if the new optional parameter ?pf=directory name is used.
Could you explain why you want this feature, and why for example project search just does not cut it?
Quoted 2 lines
It uses the infrastructure already there for 'forks' (which also filters projects but needs a project called like the filter directory to work).
It is not entirely clear for me that what you mean here is (I think) that using
git_get_projects_list($project_filter);
just works thanks to forks filtering infrastructure.
Quoted 6 lines
This feature is disabled if
strict_exportis used and there is noprojects_listto avoid showing more than intended.
Withoutstrict_exportenabled this change should not show any projects one could not get details from anyway. So if thevalidate_pathnamechecks are not sufficient this would at most make it easier to get a list of viewable content.
I don't wuite understand this reasoning. Why project filtering is disabled with strict_export? It should just filter, regardless if project are from scanning $project_filter subdirectory, or filtering out project names from $projects_list file that do not begin with $project_filter prefix.
Quoted 4 lines
Reusing $project instead of adding a new parameter would have been nicer from a UI point-of-view (including
PATH_INFOsupport) but complicate the $project validating code that is currently being used to ensure nothing is exported that should not be viewable.
That is I think quite reasonable.
Quoted 5 lines
Signed-off-by Bernhard R. Link <[email protected]>---
As most parameters are not documented indocumentation/gitweb.txt, I did not add documentation for this one either.
On the other hand IIRC getting list of projects is quite well documented in gitweb manpage (or at least it should be).
[...]
Quoted 4 lines
gitweb/gitweb.perl +0
-0@@ -3962,6 +3973,13 @@ sub git_footer_html { -class => $feed_class}, $format)."\n"; }
gitweb/gitweb.perl sub git_footer_html { · line 3985
Quoted 10 lines
gitweb/gitweb.perl +7
-0+ } elsif (defined $project_filter) { + 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", + project_filter => $project_filter), + -class => $feed_class}, "TXT") . "\n"; } else { print $cgi->a({-href => href(project=>undef, action=>"opml"), -class => $feed_class}, "OPML") . " ";
I wonder if perhaps a better solution wouldn't be to use -replay=>1 in generating projects list in other formats (OPML and TXT).
Quoted 19 lines
gitweb/gitweb.perl +2
-2@@ -5979,7 +5997,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); if (!@list) { die_error(404, "No projects found"); }@@ -6018,7 +6036,7 @@ sub git_forks { } sub git_project_index { - my @projects = git_get_projects_list(); + my @projects = git_get_projects_list($project_filter); if (!@projects) { die_error(404, "No projects found"); }
gitweb/gitweb.perl sub git_atom { · line 7879
Quoted 8 lines
gitweb/gitweb.perl +1
-1@@ -7855,7 +7873,7 @@ sub git_atom { } sub git_opml { - my @list = git_get_projects_list(); + my @list = git_get_projects_list($project_filter); if (!@list) { die_error(404, "No projects found"); }
Nice!
Signature · 1 line
Jakub Narebski
Quoted 6 lines · Jakub Narebski
Quoted 3 lines
This commit changes the project listings (
project_list,project_indexand opml) to limit the output to only projects in a subdirectory if the new optional parameter ?pf=directory name is used.Could you explain why you want this feature, and why for example project search just does not cut it?
The project list takes often a very long time and searching in that list takes the same time (and would also show projects not starting with the text).
I'd for example like to be able to place a link to all projects shown at http://anonscm.debian.org/gitweb/ which are below mirrorer/ and get a not having to wait for description information being extracted for all the other projects.
Quoted 9 lines
Quoted 2 lines
It uses the infrastructure already there for 'forks' (which also filters projects but needs a project called like the filter directory to work).
It is not entirely clear for me that what you mean here is (I think) that using
git_get_projects_list($project_filter);just works thanks to forks filtering infrastructure.
Yes, it uses the optional git_get_projects_list argument which is currently only used by action=forks.
Quoted 7 lines
Quoted 6 lines
This feature is disabled if
strict_exportis used and there is noprojects_listto avoid showing more than intended.
Withoutstrict_exportenabled this change should not show any projects one could not get details from anyway. So if thevalidate_pathnamechecks are not sufficient this would at most make it easier to get a list of viewable content.
Quoted 5 lines
I don't wuite understand this reasoning. Why project filtering is disabled with
strict_export? It should just filter, regardless if project are from scanning $project_filter subdirectory, or filtering out project names from $projects_list file that do not begin with $project_filter prefix.
strict_export is a security switch to make sure that no unintended information is exported. Without a project_list all that strict_export ensures is that there is no way to escape the project_root by giving some path to a project outside that is not catched by the simple check against /./ and /../. As the new code would allow a way around this check, I think the sane thing is to simply disable this new feature in case of this paranoid check being activated. (And reporting an error message if it is used).
Quoted 6 lines
Quoted 3 lines
---
As most parameters are not documented indocumentation/gitweb.txt, I did not add documentation for this one either.On the other hand IIRC getting list of projects is quite well documented in gitweb manpage (or at least it should be).
In Documentation/gitweb.txt there is only a list of possible actions, but no documentation of any of the other arguments. (none of the order argument to project_list nor anything else). If actions like blob_plain do list essential arguments like f= then giving this option special rooms does not seem to fit very well with the rest.
Quoted 6 lines
[...]
Quoted 4 lines
gitweb/gitweb.perl +0
-0@@ -3962,6 +3973,13 @@ sub git_footer_html { -class => $feed_class}, $format)."\n"; }
Quoted 13 lines
gitweb/gitweb.perl sub git_footer_html { · line 3985
Quoted 10 lines
gitweb/gitweb.perl +7
-0+ } elsif (defined $project_filter) { + 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", + project_filter => $project_filter), + -class => $feed_class}, "TXT") . "\n"; } else { print $cgi->a({-href => href(project=>undef, action=>"opml"), -class => $feed_class}, "OPML") . " ";I wonder if perhaps a better solution wouldn't be to use -replay=>1 in generating projects list in other formats (OPML and TXT).
Wouldn't that also replay options like "order"?
Bernhard R. Link
Quoted 6 lines · Bernhard R. Link
Quoted 4 lines · Jakub Narebski
Quoted 3 lines
This commit changes the project listings (
project_list,project_indexand opml) to limit the output to only projects in a subdirectory if the new optional parameter ?pf=directory name is used.
Quoted 6 lines
Quoted 2 lines
Could you explain why you want this feature, and why for example project search just does not cut it?
The project list takes often a very long time and searching in that list takes the same time (and would also show projects not starting with the text).
There are at least two ways to speed up getting projects list page.
First is to limit number of projects shown, like e.g. http://repo.or.cz
which shows only search form and tag cloud, but no projects, or at least paginate (divide into pages of e.g. 100 projects) list of projects.
I have some patches improving projects list and searching projects, including slight speedup to search result generation and project list pagination in my StGit stack. I'll clean them up and (re)send them to git mailing list for discussion.
Second solution would be to finally add caching support to gitweb, either on the level of caching git command output like Lea Wiemann work from GSoC2008, or caching intermediate Perl data structures used by gitweb like in old patches by Petr 'Pasky' Baudis (though only for projects list page), or caching of final HTML output like in
http://git.kernel.org fork of gitweb.
There is some work in progress that I have in gitweb/cache branch and in gitweb/cache-kernel* branches in my repository (either on
http://github.com/jnareb/git or http://repo.or.cz/w/git/jnareb-git.git).
The problem with cleaning it up to the form suitable for inclusion is that it is quite a bit of code, and it very much requires splitting gitweb. Splitting gitweb in turn requires reworking of current hacky "longjump" based (non-local goto) error handling into exception based error handling. That in turn would be best handled using non-core CPAN modules, namely Try::Tiny and HTTP::Exception or at least Exception::Class. For that we need I think a way of bundling requirements with gitweb in inc/ a la Module::Install.
Ehhh...
Quoted 4 lines
I'd for example like to be able to place a link to all projects shown at http://anonscm.debian.org/gitweb/ which are below mirrorer/ and get a not having to wait for description information being extracted for all the other projects.
I would prefer instead of introducing yet another arbitrary parameter extend project searching, so that you can specify that you want to search project names only (IIRC I have a patch for that, or beginnings of one, in my StGit stack), and use prefix search by the way of regexp search.
So
pf=mirrorer/
would be
s=^mirrorer/;sr=1;st=project_name
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
It uses the infrastructure already there for 'forks' (which also filters projects but needs a project called like the filter directory to work).
It is not entirely clear for me that what you mean here is (I think) that using
Quoted 6 lines
Quoted 3 lines
git_get_projects_list($project_filter);just works thanks to forks filtering infrastructure.
Yes, it uses the optional
git_get_projects_listargument which is currently only used by action=forks.
This needs to be stated more clearly in the commit message.
Quoted 13 lines
Quoted 7 lines
Quoted 6 lines
This feature is disabled if
strict_exportis used and there is noprojects_listto avoid showing more than intended.
Withoutstrict_exportenabled this change should not show any projects one could not get details from anyway. So if thevalidate_pathnamechecks are not sufficient this would at most make it easier to get a list of viewable content.Quoted 5 lines
I don't quite understand this reasoning. Why project filtering is disabled with
strict_export? It should just filter, regardless if project are from scanning $project_filter subdirectory, or filtering out project names from $projects_list file that do not begin with $project_filter prefix.
Quoted 8 lines
strict_exportis a security switch to make sure that no unintended information is exported. Without aproject_listall thatstrict_exportensures is that there is no way to escape theproject_rootby giving some path to a project outside that is not catched by the simple check against /./ and /../. As the new code would allow a way around this check, I think the sane thing is to simply disable this new feature in case of this paranoid check being activated. (And reporting an error message if it is used).
Hmmm... I think this new feature can be made compatible with strict export... if it is not replaced by search extension, as I have proposed above.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
---
As most parameters are not documented indocumentation/gitweb.txt, I did not add documentation for this one either.
Quoted 8 lines
Quoted 2 lines
On the other hand IIRC getting list of projects is quite well documented in gitweb manpage (or at least it should be).
In
Documentation/gitweb.txtthere is only a list of possible actions, but no documentation of any of the other arguments. (none of the order argument toproject_listnor anything else). If actions likeblob_plaindo list essential arguments like f= then giving this option special rooms does not seem to fit very well with the rest.
I was thinking about "Controlling access to git repositories" section in Documentation/gitweb.txt, but after closer examination I think it wouldn't fit there.
Quoted 20 lines
Quoted 6 lines
[...]
Quoted 4 lines
gitweb/gitweb.perl +0
-0@@ -3962,6 +3973,13 @@ sub git_footer_html { -class => $feed_class}, $format)."\n"; }Quoted 13 lines
gitweb/gitweb.perl sub git_footer_html { · line 3985
Quoted 10 lines
gitweb/gitweb.perl +7
-0+ } elsif (defined $project_filter) { + 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", + project_filter => $project_filter), + -class => $feed_class}, "TXT") . "\n"; } else { print $cgi->a({-href => href(project=>undef, action=>"opml"), -class => $feed_class}, "OPML") . " ";I wonder if perhaps a better solution wouldn't be to use -replay=>1 in generating projects list in other formats (OPML and TXT).
Quoted 1 line
Wouldn't that also replay options like "order"?
Right. My mistake.
Anyway
+ 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",
+ project_filter => $project_filter),
+ -class => $feed_class}, "TXT") . "\n";
would do the right thing because of the way href() works when passed key-value pair with undefined key.
In other words there is no need for conditional; just add
project_filter => $project_filter
and href() would do the right thing.
Signature · 2 lines
Jakub Narebski Poland
Quoted 6 lines · Jakub Narebski
Quoted 3 lines · Bernhard R. Link
The project list takes often a very long time and searching in that list takes the same time (and would also show projects not starting with the text).
There are at least two ways to speed up getting projects list page.
There are other ways, but they are both limited and quite backward:
Instead of showing me the information I want (what is in that directory), I guess to search in the larger pool of information needing all sort of half-working tricks causing all kinds of other problems working around the issue that much more information never used must be collected first.
Subversion's ViewVC for example only shows what is in some directory directory and available subdirectories. (That of course has the disadvantage to make it harder to find a project one does not know the subdirectory it is in, but why shouldn't gitweb offer the best of both worlds?)
Quoted 3 lines
First is to limit number of projects shown, like e.g. http://repo.or.cz
which shows only search form and tag cloud, but no projects, or at least paginate (divide into pages of e.g. 100 projects) list of projects.
But a page showing all projects (as long as it is possible) is something I'd quite miss if it is gone. What I want is some way to have that and to also be able to look at some subset interesting to me directly in an effective way.
Quoted 1 line
Second solution would be to finally add caching support to gitweb,
But caching also means new projects or changes will take some time to show up. And again it would not be a solution to by original problem. (Showing effectively what is in some directory).
Quoted 11 lines
Quoted 4 lines
I'd for example like to be able to place a link to all projects shown at http://anonscm.debian.org/gitweb/ which are below mirrorer/ and get a not having to wait for description information being extracted for all the other projects.
I would prefer instead of introducing yet another arbitrary parameter extend project searching, so that you can specify that you want to search project names only (IIRC I have a patch for that, or beginnings of one, in my StGit stack), and use prefix search by the way of regexp search.
Quoted 7 lines
So
pf=mirrorer/
would be
s=^mirrorer/;sr=1;st=project_name
That might be a workaround, but still need to look at quite some amount of unecessary data (i.e. it would need to run at least as long as a
http://anonscm.debian.org/gitweb/?a=project_index would not to load, wouldn't it?)
Bernhard R. Link
Quoted 16 lines · Bernhard R. Link
Quoted 7 lines · Jakub Narebski
Quoted 3 lines · Bernhard R. Link
The project list takes often a very long time and searching in that list takes the same time (and would also show projects not starting with the text).
There are at least two ways to speed up getting projects list page.
There are other ways, but they are both limited and quite backward:
Instead of showing me the information I want (what is in that directory), I guess to search in the larger pool of information needing all sort of half-working tricks causing all kinds of other problems working around the issue that much more information never used must be collected first.
Quoted 5 lines
Subversion's ViewVC for example only shows what is in some directory directory and available subdirectories. (That of course has the disadvantage to make it harder to find a project one does not know the subdirectory it is in, but why shouldn't gitweb offer the best of both worlds?)
Well, ViewVC follows Subversion concepts... including broken-by-design branching by copying ;-)
Anyway, I think I am getting convinced that supporting project filtering by subdirectory, in a way similar to existing support for forks (and reusing it implementation) could be a good idea.
The one serious disadvantage of "pf=" is that it is not solution for a faster gitweb homepage. It works _only_ when you have pf=subdirectory/ link.
And I'd rather it worked with strict export, correctly and safely, if "pf=" is to be included in gitweb.
Quoted 8 lines
Quoted 3 lines
First is to limit number of projects shown, like e.g. http://repo.or.cz
which shows only search form and tag cloud, but no projects, or at least paginate (divide into pages of e.g. 100 projects) list of projects.But a page showing all projects (as long as it is possible) is something I'd quite miss if it is gone. What I want is some way to have that and to also be able to look at some subset interesting to me directly in an effective way.
The http://repo.or.cz homepage has 'Show all projects' link, but it is at explicit request.
Quoted 5 lines
Quoted 1 line
Second solution would be to finally add caching support to gitweb,
But caching also means new projects or changes will take some time to show up. And again it would not be a solution to by original problem. (Showing effectively what is in some directory).
Well, it would solve "The project list takes often a very long time" part of your problem. Though very large list of projects can cause performance problems rendering on client side, I guess...
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
I'd for example like to be able to place a link to all projects shown at http://anonscm.debian.org/gitweb/ which are below mirrorer/ and get a not having to wait for description information being extracted for all the other projects.
I would prefer instead of introducing yet another arbitrary parameter extend project searching, so that you can specify that you want to search project names only (IIRC I have a patch for that, or beginnings of one, in my StGit stack), and use prefix search by the way of regexp search.
So
pf=mirrorer/
Quoted 8 lines
Quoted 3 lines
would be
s=^mirrorer/;sr=1;st=project_name
That might be a workaround, but still need to look at quite some amount of unecessary data (i.e. it would need to run at least as long as a
http://anonscm.debian.org/gitweb/?a=project_index would not to load, wouldn't it?)
Not with 'gitweb: Faster project search' from this series of commits
# gitweb: Allow underscore in $searchtype ('st')
# gitweb: Improve projects search form
# gitweb: Option for filling only specified info in fill_project_list_info # gitweb: Faster project search
# gitweb: Highlight matched part of project name when searching projects # gitweb: Highlight matched part of project description when searching projects
which does not search for description nor check for latest changes in repository for repositories it doesn't show.
Signature · 2 lines
Jakub Narebski Poland