threads / patch / 29452

patchgitweb: add pf= to limit project list to a subdirectory

Subject: [PATCH] gitweb: add pf= to limit project list to a subdirectory

## tl;dr

6 messages between Jan 26, 2012 and Jan 28, 2012. Diffs are folded; open one to read it.

replies: 5people: 2as markdown or json

Bernhard R. Link· Jan 26, 2012, 14:45 UTC · lore

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.

Signed-off-by: Bernhard R. Link <brlink@debian.org>

--- 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(-)
Show changes to gitweb/gitweb.perl +22 −4
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index abb5a79..00dd79e 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,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");
 	}
-- 
1.7.8.3
Jakub Narebski· Jan 27, 2012, 22:33 UTC · re: Bernhard R. Link · lore

Re: [PATCH] gitweb: add pf= to limit project list to a subdirectory

"Bernhard R. Link" <brl+list+git@mail.brlink.eu> writes:
> 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.
Could you explain why you want this feature, and why for example
project search just does not cut it?
 
> 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.
Show 6 quoted lines
> 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.
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.
 
> 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.
That is I think quite reasonable.
 
Show 5 quoted lines
> Signed-off-by: Bernhard R. Link <brlink@debian.org>
> 
> ---
> As most parameters are not documented in documentation/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).
 
[...]
Show 14 quoted lines
> @@ -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") . " ";

I wonder if perhaps a better solution wouldn't be to use -replay=>1 in generating projects list in other formats (OPML and TXT).

Show 27 quoted lines
> @@ -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");
>  	}
Nice!
-- 
Jakub Narebski
Bernhard R. Link· Jan 27, 2012, 23:53 UTC · re: Jakub Narebski · lore

Re: [PATCH] gitweb: add pf= to limit project list to a subdirectory

* Jakub Narebski <jnareb@gmail.com> [120127 23:33]:
Show 6 quoted lines
> > 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.
>
> 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.

Show 9 quoted 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.

Show 12 quoted lines
> > 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.
> 
> 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).

Show 6 quoted lines
> > ---
> > As most parameters are not documented in documentation/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.

Show 19 quoted lines
>  
> [...]
> > @@ -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") . " ";
> 
> 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
Jakub Narebski· Jan 28, 2012, 14:53 UTC · re: Bernhard R. Link · lore

Re: [PATCH] gitweb: add pf= to limit project list to a subdirectory

On Sat, 28 Jan 2012, Bernhard R. Link wrote:
> * Jakub Narebski <jnareb@gmail.com> [120127 23:33]:
Show 10 quoted lines
> > > 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.
> >
> > 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...
> 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
 
Show 12 quoted 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.
This needs to be stated more clearly in the commit message.
 
Show 21 quoted lines
> > > 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.
> > 
> > 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.
> 
> 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).

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.

Show 12 quoted lines
> > > ---
> > > As most parameters are not documented in documentation/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.

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.

Show 21 quoted lines
> >  
> > [...]
> > > @@ -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") . " ";
> > 
> > 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"?
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.
-- 
Jakub Narebski
Poland
Bernhard R. Link· Jan 28, 2012, 15:37 UTC · re: Jakub Narebski · lore

Re: [PATCH] gitweb: add pf= to limit project list to a subdirectory

* Jakub Narebski <jnareb@gmail.com> [120128 15:53]:
Show 6 quoted lines
> On Sat, 28 Jan 2012, Bernhard R. Link wrote:
> > 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?)

> 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.

> 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).

Show 10 quoted 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.
Show 7 quoted 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
Jakub Narebski· Jan 28, 2012, 16:03 UTC · re: Bernhard R. Link · lore

Re: [PATCH] gitweb: add pf= to limit project list to a subdirectory

On Sat, 28 Jan 2012, Bernhard R. Link wrote:
> * Jakub Narebski <jnareb@gmail.com> [120128 15:53]:
> > On Sat, 28 Jan 2012, Bernhard R. Link wrote:
Show 18 quoted lines
> > > 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?)

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.
 
Show 8 quoted 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.

Show 5 quoted lines
> > 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...
 
Show 23 quoted 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
> 
> 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.

-- 
Jakub Narebski
Poland

← back to recent threads