{"thread":{"id":"37258","subject":"[PATCH 2/5] gitweb: if the PATH_INFO is incomplete, use it as a project_filter","startedAt":"2014-07-31T12:53:41Z","lastAt":"2014-07-31T12:53:41Z","messageCount":1,"participants":["Tony Finch"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"247041","messageId":"alpine.LSU.2.00.1407311353400.23775@hermes-1.csi.cam.ac.uk","threadId":"37258","inReplyTo":null,"subject":"[PATCH 2/5] gitweb: if the PATH_INFO is incomplete, use it as a project_filter","fromName":"Tony Finch","fromEmail":"dot@dotat.at","sentAt":"2014-07-31T12:53:41Z","receivedAt":"2014-07-31T12:53:41Z","isPatch":true,"sender":{"key":"dot@dotat.at","avatar":"https://avatars.githubusercontent.com/u/68429?v=4"},"body":"Previously gitweb would ignore partial PATH_INFO. For example,\nit would produce a project list for the top URL\n\thttps://www.example.org/projects/\nand a project summary for\n\thttps://www.example.org/projects/git/git.git\nbut if you tried to list just the git-related projects with\n\thttps://www.example.org/projects/git/\nyou would get a list of all projects, same as the top URL.\n\nAs well as fixing that omission, this change also makes gitweb\ngenerate PATH_INFO-style URLs for project filter links, such\nas in the breadcrumbs.\n\nSigned-off-by: Tony Finch <dot@dotat.at>\n---\n gitweb/gitweb.perl | 24 +++++++++++++++++++++++-\n 1 file changed, 23 insertions(+), 1 deletion(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex a9f57d6..12aba8f 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -891,7 +891,17 @@ sub evaluate_path_info {\n \twhile ($project && !check_head_link(\"$projectroot/$project\")) {\n \t\t$project =~ s,/*[^/]*$,,;\n \t}\n-\treturn unless $project;\n+\t# If there is no project, use the PATH_INFO as a project filter if it\n+\t# is a directory in the projectroot. (It can't be a subdirectory of a\n+\t# repo because we just verified that isn't the case.)\n+\tunless ($project) {\n+\t\tif (-d \"$projectroot/$path_info\") {\n+\t\t\t$path_info =~ s,/+$,,;\n+\t\t\t$input_params{'project_filter'} = $path_info;\n+\t\t\t$path_info = \"\";\n+\t\t}\n+\t\treturn;\n+\t}\n \t$input_params{'project'} = $project;\n\n \t# do not change any parameters if an action is given using the query string\n@@ -1356,6 +1366,18 @@ sub href {\n \t}\n\n \tmy $use_pathinfo = gitweb_check_feature('pathinfo');\n+\n+\t# we have to check for a project_filter first because handling the full\n+\t# project-plus-parameters deletes some of the paramaters we check here\n+\tif (!defined $params{'project'} && $params{'project_filter'} &&\n+\t    $params{'action'} eq \"project_list\" &&\n+\t    (exists $params{-path_info} ? $params{-path_info} : $use_pathinfo)) {\n+\t\t$href =~ s,/$,,;\n+\t\t$href .= \"/\".esc_path_info($params{'project_filter'}).\"/\";\n+\t\tdelete $params{'project_filter'};\n+\t\tdelete $params{'action'};\n+\t}\n+\n \tif (defined $params{'project'} &&\n \t    (exists $params{-path_info} ? $params{-path_info} : $use_pathinfo)) {\n \t\t# try to put as many parameters as possible in PATH_INFO:\n-- \n2.1.0.rc0.229.gaee38de\n"}]}