git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
BLBernhard R. Link <brl+list+git@mail.brlink.eu>
Date
Jan 26, 2012, 14:45 UTC
Message-ID
<20120126144517.GA4229@server.brlink.eu>

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(-)
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
Next: Jakub Narebski
Message 1 of 6 in “gitweb: add pf= to limit project list to a subdirectory”
  1. gitweb: add pf= to limit project list to a subdirectoryBernhard R. Link, Jan 26, 2012
  2. Jakub NarebskiJan 27, 2012
  3. Bernhard R. LinkJan 27, 2012
  4. Jakub NarebskiJan 28, 2012
  5. Bernhard R. LinkJan 28, 2012
  6. Jakub NarebskiJan 28, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.