All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/5] gitweb: if the PATH_INFO is incomplete, use it as a project_filter
       [not found] <5e56772f50d3d1498361d8831c4f2fba38d197b4.1426779553.git.dot@dotat.at>
@ 2015-03-19 15:39 ` Tony Finch
  2015-03-19 15:40 ` [PATCH 3/5] gitweb: add a link under the search box to clear a project filter Tony Finch
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Tony Finch @ 2015-03-19 15:39 UTC (permalink / raw)
  To: git

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] gitweb: add a link under the search box to clear a project filter
       [not found] <5e56772f50d3d1498361d8831c4f2fba38d197b4.1426779553.git.dot@dotat.at>
  2015-03-19 15:39 ` [PATCH 2/5] gitweb: if the PATH_INFO is incomplete, use it as a project_filter Tony Finch
@ 2015-03-19 15:40 ` Tony Finch
  2015-03-19 15:40 ` [PATCH 4/5] gitweb: optionally set project category from its pathname Tony Finch
  2015-03-19 15:40 ` [PATCH 5/5] gitweb: make category headings into links when they are directories Tony Finch
  3 siblings, 0 replies; 7+ messages in thread
From: Tony Finch @ 2015-03-19 15:40 UTC (permalink / raw)
  To: git

Previously when a project filter was active, the only simple way
to clear it was by clicking the home link in the breadcrumbs, which
is not very obvious.

This change adds another home link under the search box which clears
both project filter and search, next to the existing link that
clears the search and keeps the project filter.

Signed-off-by: Tony Finch <dot@dotat.at>
---
 gitweb/gitweb.perl | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 073f324..9abc5bc 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5549,10 +5549,13 @@ sub git_project_search_form {
 	      "</span>\n" .
 	      $cgi->submit(-name => 'btnS', -value => 'Search') .
 	      $cgi->end_form() . "\n" .
-	      $cgi->a({-href => href(project => undef, searchtext => undef,
-	                             project_filter => $project_filter)},
-	              esc_html("List all projects$limit")) . "<br />\n";
-	print "</div>\n";
+	      $cgi->a({-href => $my_uri}, esc_html("List all projects"));
+	print " / " .
+	      $cgi->a({-href => href(project => undef, action => "project_list",
+				     project_filter => $project_filter)},
+	              esc_html("List projects$limit"))
+	    if $project_filter;
+	print "<br />\n</div>\n";
 }

 # entry for given @keys needs filling if at least one of keys in list
-- 
2.2.1.68.g56d9796

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] gitweb: optionally set project category from its pathname
       [not found] <5e56772f50d3d1498361d8831c4f2fba38d197b4.1426779553.git.dot@dotat.at>
  2015-03-19 15:39 ` [PATCH 2/5] gitweb: if the PATH_INFO is incomplete, use it as a project_filter Tony Finch
  2015-03-19 15:40 ` [PATCH 3/5] gitweb: add a link under the search box to clear a project filter Tony Finch
@ 2015-03-19 15:40 ` Tony Finch
  2015-03-19 15:40 ` [PATCH 5/5] gitweb: make category headings into links when they are directories Tony Finch
  3 siblings, 0 replies; 7+ messages in thread
From: Tony Finch @ 2015-03-19 15:40 UTC (permalink / raw)
  To: git

When repositories are organized in a hierarchial directory tree
it is convenient if gitweb project categories can be set
automatically based on their parent directory, so that users
do not have to set the same information twice.

Signed-off-by: Tony Finch <dot@dotat.at>
---
 Documentation/gitweb.conf.txt |  6 ++++++
 gitweb/gitweb.perl            | 13 ++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
index 29f1e06..7c0de18 100644
--- a/Documentation/gitweb.conf.txt
+++ b/Documentation/gitweb.conf.txt
@@ -492,6 +492,12 @@ $projects_list_group_categories::
 	`$GIT_DIR/category` file or the `gitweb.category` variable in each
 	repository's configuration.  Disabled by default (set to 0).

+$projects_list_directory_is_category::
+	Whether to set a project's category to its parent directory, i.e. its
+	pathname excluding the `/repo.git` leaf name. This is only used if
+	the repo has no explicit setting, and if the pathname has more than
+	one component. Disabled by default (set to 0).
+
 $project_list_default_category::
 	Default category for projects for which none is specified.  If this is
 	set to the empty string, such projects will remain uncategorized and
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 9abc5bc..0aab3e0 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -133,6 +133,10 @@ our $projects_list_description_width = 25;
 # (enabled if this variable evaluates to true)
 our $projects_list_group_categories = 0;

+# project's category defaults to its parent directory
+# (enabled if this variable evaluates to true)
+our $projects_list_directory_is_category = 0;
+
 # default category if none specified
 # (leave the empty string for no category)
 our $project_list_default_category = "";
@@ -2908,7 +2912,11 @@ sub git_get_project_description {

 sub git_get_project_category {
 	my $path = shift;
-	return git_get_file_or_project_config($path, 'category');
+	my $cat = git_get_file_or_project_config($path, 'category');
+	return $cat if $cat;
+	return $1 if $projects_list_directory_is_category
+		  && $path =~ m,^(.*)/[^/]*$,;
+	return $project_list_default_category;
 }


@@ -5622,8 +5630,7 @@ sub fill_project_list_info {
 		}
 		if ($projects_list_group_categories &&
 		    project_info_needs_filling($pr, $filter_set->('category'))) {
-			my $cat = git_get_project_category($pr->{'path'}) ||
-			                                   $project_list_default_category;
+			my $cat = git_get_project_category($pr->{'path'});
 			$pr->{'category'} = to_utf8($cat);
 		}

-- 
2.2.1.68.g56d9796

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] gitweb: make category headings into links when they are directories
       [not found] <5e56772f50d3d1498361d8831c4f2fba38d197b4.1426779553.git.dot@dotat.at>
                   ` (2 preceding siblings ...)
  2015-03-19 15:40 ` [PATCH 4/5] gitweb: optionally set project category from its pathname Tony Finch
@ 2015-03-19 15:40 ` Tony Finch
  2015-03-26 19:49   ` Junio C Hamano
  3 siblings, 1 reply; 7+ messages in thread
From: Tony Finch @ 2015-03-19 15:40 UTC (permalink / raw)
  To: git

When $projects_list_category_is_directory is turned on, project
categories can be useful as project filters, so with that setting
gitweb now makes the category headings into project_filter links
(like the breadcrumbs).

Signed-off-by: Tony Finch <dot@dotat.at>
---
 gitweb/gitweb.perl | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 0aab3e0..a02f3e4 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5838,8 +5838,18 @@ sub git_project_list_body {
 				if ($check_forks) {
 					print "<td></td>\n";
 				}
-				print "<td class=\"category\" colspan=\"5\">".esc_html($cat)."</td>\n";
-				print "</tr>\n";
+				print "<td class=\"category\" colspan=\"5\">";
+				if ($projects_list_directory_is_category) {
+					print $cgi->a({-href =>
+					    href(project => undef,
+					        project_filter => $cat,
+					        action => "project_list"),
+					    -class => "list"},
+					    esc_html($cat));
+				} else {
+					print esc_html($cat);
+				}
+				print "</td>\n</tr>\n";
 			}

 			git_project_list_rows($categories{$cat}, undef, undef, $check_forks);
-- 
2.2.1.68.g56d9796

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 5/5] gitweb: make category headings into links when they are directories
  2015-03-19 15:40 ` [PATCH 5/5] gitweb: make category headings into links when they are directories Tony Finch
@ 2015-03-26 19:49   ` Junio C Hamano
  2015-03-27  0:14     ` Tony Finch
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2015-03-26 19:49 UTC (permalink / raw)
  To: Jakub Narębski, Luben Tuikov; +Cc: git, Tony Finch

Any comments from those who use or have their own code in Gitweb on
this topic?

* tf/gitweb-project-listing (2015-03-19) 5 commits
 - gitweb: make category headings into links when they are directories
 - gitweb: optionally set project category from its pathname
 - gitweb: add a link under the search box to clear a project filter
 - gitweb: if the PATH_INFO is incomplete, use it as a project_filter
 - gitweb: fix typo in man page

 Update gitweb to make it more pleasant to deal with a hierarchical
 forest of repositories.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 5/5] gitweb: make category headings into links when they are directories
  2015-03-26 19:49   ` Junio C Hamano
@ 2015-03-27  0:14     ` Tony Finch
  0 siblings, 0 replies; 7+ messages in thread
From: Tony Finch @ 2015-03-27  0:14 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jakub Narębski, Luben Tuikov, git


> On 26 Mar 2015, at 19:49, Junio C Hamano <gitster@pobox.com> wrote:
> 
> Any comments from those who use or have their own code in Gitweb on
> this topic?

Thanks for chasing up my patches. I should have written a covering letter, to say that you can see these patches in action at https://git.csx.cam.ac.uk/x/ucs/ - try clicking on the category headings, and observe the pathinfo, breadcrumbs, and links under the search box.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/5] gitweb: optionally set project category from its pathname
@ 2014-07-31 12:53 Tony Finch
  0 siblings, 0 replies; 7+ messages in thread
From: Tony Finch @ 2014-07-31 12:53 UTC (permalink / raw)
  To: git

When repositories are organized in a hierarchial directory tree
it is convenient if gitweb project categories can be set
automatically based on their parent directory, so that users
do not have to set the same information twice.

Signed-off-by: Tony Finch <dot@dotat.at>
---
 Documentation/gitweb.conf.txt |  6 ++++++
 gitweb/gitweb.perl            | 13 ++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
index 29f1e06..7c0de18 100644
--- a/Documentation/gitweb.conf.txt
+++ b/Documentation/gitweb.conf.txt
@@ -492,6 +492,12 @@ $projects_list_group_categories::
 	`$GIT_DIR/category` file or the `gitweb.category` variable in each
 	repository's configuration.  Disabled by default (set to 0).

+$projects_list_directory_is_category::
+	Whether to set a project's category to its parent directory, i.e. its
+	pathname excluding the `/repo.git` leaf name. This is only used if
+	the repo has no explicit setting, and if the pathname has more than
+	one component. Disabled by default (set to 0).
+
 $project_list_default_category::
 	Default category for projects for which none is specified.  If this is
 	set to the empty string, such projects will remain uncategorized and
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index d1e6b79..edbc058 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -129,6 +129,10 @@ our $projects_list_description_width = 25;
 # (enabled if this variable evaluates to true)
 our $projects_list_group_categories = 0;

+# project's category defaults to its parent directory
+# (enabled if this variable evaluates to true)
+our $projects_list_directory_is_category = 0;
+
 # default category if none specified
 # (leave the empty string for no category)
 our $project_list_default_category = "";
@@ -2904,7 +2908,11 @@ sub git_get_project_description {

 sub git_get_project_category {
 	my $path = shift;
-	return git_get_file_or_project_config($path, 'category');
+	my $cat = git_get_file_or_project_config($path, 'category');
+	return $cat if $cat;
+	return $1 if $projects_list_directory_is_category
+		  && $path =~ m,^(.*)/[^/]*$,;
+	return $project_list_default_category;
 }


@@ -5618,8 +5626,7 @@ sub fill_project_list_info {
 		}
 		if ($projects_list_group_categories &&
 		    project_info_needs_filling($pr, $filter_set->('category'))) {
-			my $cat = git_get_project_category($pr->{'path'}) ||
-			                                   $project_list_default_category;
+			my $cat = git_get_project_category($pr->{'path'});
 			$pr->{'category'} = to_utf8($cat);
 		}

-- 
2.1.0.rc0.229.gaee38de

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-03-27  0:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5e56772f50d3d1498361d8831c4f2fba38d197b4.1426779553.git.dot@dotat.at>
2015-03-19 15:39 ` [PATCH 2/5] gitweb: if the PATH_INFO is incomplete, use it as a project_filter Tony Finch
2015-03-19 15:40 ` [PATCH 3/5] gitweb: add a link under the search box to clear a project filter Tony Finch
2015-03-19 15:40 ` [PATCH 4/5] gitweb: optionally set project category from its pathname Tony Finch
2015-03-19 15:40 ` [PATCH 5/5] gitweb: make category headings into links when they are directories Tony Finch
2015-03-26 19:49   ` Junio C Hamano
2015-03-27  0:14     ` Tony Finch
2014-07-31 12:53 [PATCH 4/5] gitweb: optionally set project category from its pathname Tony Finch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.