Skip to content

Commit 19d2d23

Browse files
Bernhard R. Linkgitster
authored andcommitted
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 <[email protected]> Acked-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 348a658 commit 19d2d23

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

gitweb/gitweb.perl

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ sub check_loadavg {
760760
search_use_regexp => "sr",
761761
ctag => "by_tag",
762762
diff_style => "ds",
763+
project_filter => "pf",
763764
# this must be last entry (for manipulation from JavaScript)
764765
javascript => "js"
765766
);
@@ -976,7 +977,7 @@ sub evaluate_path_info {
976977

977978
our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
978979
$hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
979-
$searchtext, $search_regexp);
980+
$searchtext, $search_regexp, $project_filter);
980981
sub evaluate_and_validate_params {
981982
our $action = $input_params{'action'};
982983
if (defined $action) {
@@ -994,6 +995,13 @@ sub evaluate_and_validate_params {
994995
}
995996
}
996997

998+
our $project_filter = $input_params{'project_filter'};
999+
if (defined $project_filter) {
1000+
if (!validate_pathname($project_filter)) {
1001+
die_error(404, "Invalid project_filter parameter");
1002+
}
1003+
}
1004+
9971005
our $file_name = $input_params{'file_name'};
9981006
if (defined $file_name) {
9991007
if (!validate_pathname($file_name)) {
@@ -3732,7 +3740,12 @@ sub run_highlighter {
37323740
sub get_page_title {
37333741
my $title = to_utf8($site_name);
37343742

3735-
return $title unless (defined $project);
3743+
unless (defined $project) {
3744+
if (defined $project_filter) {
3745+
$title .= " - " . to_utf8($project_filter);
3746+
}
3747+
return $title;
3748+
}
37363749
$title .= " - " . to_utf8($project);
37373750

37383751
return $title unless (defined $action);
@@ -5982,7 +5995,7 @@ sub git_project_list {
59825995
die_error(400, "Unknown order parameter");
59835996
}
59845997

5985-
my @list = git_get_projects_list();
5998+
my @list = git_get_projects_list($project_filter, $strict_export);
59865999
if (!@list) {
59876000
die_error(404, "No projects found");
59886001
}
@@ -6023,7 +6036,7 @@ sub git_forks {
60236036
}
60246037

60256038
sub git_project_index {
6026-
my @projects = git_get_projects_list();
6039+
my @projects = git_get_projects_list($project_filter, $strict_export);
60276040
if (!@projects) {
60286041
die_error(404, "No projects found");
60296042
}
@@ -7862,7 +7875,7 @@ sub git_atom {
78627875
}
78637876

78647877
sub git_opml {
7865-
my @list = git_get_projects_list();
7878+
my @list = git_get_projects_list($project_filter, $strict_export);
78667879
if (!@list) {
78677880
die_error(404, "No projects found");
78687881
}
@@ -7873,11 +7886,17 @@ sub git_opml {
78737886
-content_disposition => 'inline; filename="opml.xml"');
78747887

78757888
my $title = esc_html($site_name);
7889+
my $filter = " within subdirectory ";
7890+
if (defined $project_filter) {
7891+
$filter .= esc_html($project_filter);
7892+
} else {
7893+
$filter = "";
7894+
}
78767895
print <<XML;
78777896
<?xml version="1.0" encoding="utf-8"?>
78787897
<opml version="1.0">
78797898
<head>
7880-
<title>$title OPML Export</title>
7899+
<title>$title OPML Export$filter</title>
78817900
</head>
78827901
<body>
78837902
<outline text="git RSS feeds">

0 commit comments

Comments
 (0)