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

[PATCH 2/5] gitweb: if the PATH_INFO is incomplete, use it as a project_filter

From
Tony Finch <dot@dotat.at>
Date
Mar 19, 2015, 15:39 UTC
Message-ID
<alpine.LSU.2.00.1503191539570.23307@hermes-1.csi.cam.ac.uk>
In-Reply-To
<5e56772f50d3d1498361d8831c4f2fba38d197b4.1426779553.git.dot@dotat.at>
Previously gitweb would ignore partial PATH_INFO. For example,
it would produce a project list for the top URL
	https://www.example.org/projects/
and a project summary for
	https://www.example.org/projects/git/git.git
but if you tried to list just the git-related projects with
	https://www.example.org/projects/git/
you would get a list of all projects, same as the top URL.

As well as fixing that omission, this change also makes gitweb generate PATH_INFO-style URLs for project filter links, such as in the breadcrumbs.

Signed-off-by: Tony Finch <dot@dotat.at>
---
 gitweb/gitweb.perl | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 7a5b23a..073f324 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -895,7 +895,17 @@ sub evaluate_path_info {
 	while ($project && !check_head_link("$projectroot/$project")) {
 		$project =~ s,/*[^/]*$,,;
 	}
-	return unless $project;
+	# If there is no project, use the PATH_INFO as a project filter if it
+	# is a directory in the projectroot. (It can't be a subdirectory of a
+	# repo because we just verified that isn't the case.)
+	unless ($project) {
+		if (-d "$projectroot/$path_info") {
+			$path_info =~ s,/+$,,;
+			$input_params{'project_filter'} = $path_info;
+			$path_info = "";
+		}
+		return;
+	}
 	$input_params{'project'} = $project;

 	# do not change any parameters if an action is given using the query string
@@ -1360,6 +1370,18 @@ sub href {
 	}

 	my $use_pathinfo = gitweb_check_feature('pathinfo');
+
+	# we have to check for a project_filter first because handling the full
+	# project-plus-parameters deletes some of the paramaters we check here
+	if (!defined $params{'project'} && $params{'project_filter'} &&
+	    $params{'action'} eq "project_list" &&
+	    (exists $params{-path_info} ? $params{-path_info} : $use_pathinfo)) {
+		$href =~ s,/$,,;
+		$href .= "/".esc_path_info($params{'project_filter'})."/";
+		delete $params{'project_filter'};
+		delete $params{'action'};
+	}
+
 	if (defined $params{'project'} &&
 	    (exists $params{-path_info} ? $params{-path_info} : $use_pathinfo)) {
 		# try to put as many parameters as possible in PATH_INFO:
-- 
2.2.1.68.g56d9796
Next: Tony Finch
Message 1 of 6 in “gitweb: if the PATH_INFO is incomplete, use it as a project_filter”
  1. 2/5 gitweb: if the PATH_INFO is incomplete, use it as a project_filterTony Finch, Mar 19, 2015
  2. 3/5 gitweb: add a link under the search box to clear a project filterTony Finch, Mar 19, 2015
  3. 4/5 gitweb: optionally set project category from its pathnameTony Finch, Mar 19, 2015
  4. 5/5 gitweb: make category headings into links when they are directoriesTony Finch, Mar 19, 2015
  5. Junio C HamanoMar 26, 2015
  6. Tony FinchMar 27, 2015

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.