{"thread":{"id":"38857","subject":"[PATCH 4/5] gitweb: optionally set project category from its pathname","startedAt":"2015-03-19T15:39:59Z","lastAt":"2015-03-27T00:14:08Z","messageCount":6,"participants":["Tony Finch","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"258033","messageId":"alpine.LSU.2.00.1503191539570.23307@hermes-1.csi.cam.ac.uk","threadId":"38857","inReplyTo":"5e56772f50d3d1498361d8831c4f2fba38d197b4.1426779553.git.dot@dotat.at","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":"2015-03-19T15:39:59Z","receivedAt":"2015-03-19T15:39:59Z","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 7a5b23a..073f324 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -895,7 +895,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@@ -1360,6 +1370,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.2.1.68.g56d9796\n"},{"id":"258032","messageId":"alpine.LSU.2.00.1503191540090.23307@hermes-1.csi.cam.ac.uk","threadId":"38857","inReplyTo":"5e56772f50d3d1498361d8831c4f2fba38d197b4.1426779553.git.dot@dotat.at","subject":"[PATCH 3/5] gitweb: add a link under the search box to clear a project filter","fromName":"Tony Finch","fromEmail":"dot@dotat.at","sentAt":"2015-03-19T15:40:10Z","receivedAt":"2015-03-19T15:40:10Z","isPatch":true,"sender":{"key":"dot@dotat.at","avatar":"https://avatars.githubusercontent.com/u/68429?v=4"},"body":"Previously when a project filter was active, the only simple way\nto clear it was by clicking the home link in the breadcrumbs, which\nis not very obvious.\n\nThis change adds another home link under the search box which clears\nboth project filter and search, next to the existing link that\nclears the search and keeps the project filter.\n\nSigned-off-by: Tony Finch <dot@dotat.at>\n---\n gitweb/gitweb.perl | 11 +++++++----\n 1 file changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 073f324..9abc5bc 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -5549,10 +5549,13 @@ sub git_project_search_form {\n \t      \"</span>\\n\" .\n \t      $cgi->submit(-name => 'btnS', -value => 'Search') .\n \t      $cgi->end_form() . \"\\n\" .\n-\t      $cgi->a({-href => href(project => undef, searchtext => undef,\n-\t                             project_filter => $project_filter)},\n-\t              esc_html(\"List all projects$limit\")) . \"<br />\\n\";\n-\tprint \"</div>\\n\";\n+\t      $cgi->a({-href => $my_uri}, esc_html(\"List all projects\"));\n+\tprint \" / \" .\n+\t      $cgi->a({-href => href(project => undef, action => \"project_list\",\n+\t\t\t\t     project_filter => $project_filter)},\n+\t              esc_html(\"List projects$limit\"))\n+\t    if $project_filter;\n+\tprint \"<br />\\n</div>\\n\";\n }\n\n # entry for given @keys needs filling if at least one of keys in list\n-- \n2.2.1.68.g56d9796\n"},{"id":"258029","messageId":"alpine.LSU.2.00.1503191540150.23307@hermes-1.csi.cam.ac.uk","threadId":"38857","inReplyTo":"5e56772f50d3d1498361d8831c4f2fba38d197b4.1426779553.git.dot@dotat.at","subject":"[PATCH 4/5] gitweb: optionally set project category from its pathname","fromName":"Tony Finch","fromEmail":"dot@dotat.at","sentAt":"2015-03-19T15:40:16Z","receivedAt":"2015-03-19T15:40:16Z","isPatch":true,"sender":{"key":"dot@dotat.at","avatar":"https://avatars.githubusercontent.com/u/68429?v=4"},"body":"When repositories are organized in a hierarchial directory tree\nit is convenient if gitweb project categories can be set\nautomatically based on their parent directory, so that users\ndo not have to set the same information twice.\n\nSigned-off-by: Tony Finch <dot@dotat.at>\n---\n Documentation/gitweb.conf.txt |  6 ++++++\n gitweb/gitweb.perl            | 13 ++++++++++---\n 2 files changed, 16 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt\nindex 29f1e06..7c0de18 100644\n--- a/Documentation/gitweb.conf.txt\n+++ b/Documentation/gitweb.conf.txt\n@@ -492,6 +492,12 @@ $projects_list_group_categories::\n \t`$GIT_DIR/category` file or the `gitweb.category` variable in each\n \trepository's configuration.  Disabled by default (set to 0).\n\n+$projects_list_directory_is_category::\n+\tWhether to set a project's category to its parent directory, i.e. its\n+\tpathname excluding the `/repo.git` leaf name. This is only used if\n+\tthe repo has no explicit setting, and if the pathname has more than\n+\tone component. Disabled by default (set to 0).\n+\n $project_list_default_category::\n \tDefault category for projects for which none is specified.  If this is\n \tset to the empty string, such projects will remain uncategorized and\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 9abc5bc..0aab3e0 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -133,6 +133,10 @@ our $projects_list_description_width = 25;\n # (enabled if this variable evaluates to true)\n our $projects_list_group_categories = 0;\n\n+# project's category defaults to its parent directory\n+# (enabled if this variable evaluates to true)\n+our $projects_list_directory_is_category = 0;\n+\n # default category if none specified\n # (leave the empty string for no category)\n our $project_list_default_category = \"\";\n@@ -2908,7 +2912,11 @@ sub git_get_project_description {\n\n sub git_get_project_category {\n \tmy $path = shift;\n-\treturn git_get_file_or_project_config($path, 'category');\n+\tmy $cat = git_get_file_or_project_config($path, 'category');\n+\treturn $cat if $cat;\n+\treturn $1 if $projects_list_directory_is_category\n+\t\t  && $path =~ m,^(.*)/[^/]*$,;\n+\treturn $project_list_default_category;\n }\n\n\n@@ -5622,8 +5630,7 @@ sub fill_project_list_info {\n \t\t}\n \t\tif ($projects_list_group_categories &&\n \t\t    project_info_needs_filling($pr, $filter_set->('category'))) {\n-\t\t\tmy $cat = git_get_project_category($pr->{'path'}) ||\n-\t\t\t                                   $project_list_default_category;\n+\t\t\tmy $cat = git_get_project_category($pr->{'path'});\n \t\t\t$pr->{'category'} = to_utf8($cat);\n \t\t}\n\n-- \n2.2.1.68.g56d9796\n"},{"id":"258031","messageId":"alpine.LSU.2.00.1503191540020.23307@hermes-1.csi.cam.ac.uk","threadId":"38857","inReplyTo":"5e56772f50d3d1498361d8831c4f2fba38d197b4.1426779553.git.dot@dotat.at","subject":"[PATCH 5/5] gitweb: make category headings into links when they are directories","fromName":"Tony Finch","fromEmail":"dot@dotat.at","sentAt":"2015-03-19T15:40:19Z","receivedAt":"2015-03-19T15:40:19Z","isPatch":true,"sender":{"key":"dot@dotat.at","avatar":"https://avatars.githubusercontent.com/u/68429?v=4"},"body":"When $projects_list_category_is_directory is turned on, project\ncategories can be useful as project filters, so with that setting\ngitweb now makes the category headings into project_filter links\n(like the breadcrumbs).\n\nSigned-off-by: Tony Finch <dot@dotat.at>\n---\n gitweb/gitweb.perl | 14 ++++++++++++--\n 1 file changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 0aab3e0..a02f3e4 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -5838,8 +5838,18 @@ sub git_project_list_body {\n \t\t\t\tif ($check_forks) {\n \t\t\t\t\tprint \"<td></td>\\n\";\n \t\t\t\t}\n-\t\t\t\tprint \"<td class=\\\"category\\\" colspan=\\\"5\\\">\".esc_html($cat).\"</td>\\n\";\n-\t\t\t\tprint \"</tr>\\n\";\n+\t\t\t\tprint \"<td class=\\\"category\\\" colspan=\\\"5\\\">\";\n+\t\t\t\tif ($projects_list_directory_is_category) {\n+\t\t\t\t\tprint $cgi->a({-href =>\n+\t\t\t\t\t    href(project => undef,\n+\t\t\t\t\t        project_filter => $cat,\n+\t\t\t\t\t        action => \"project_list\"),\n+\t\t\t\t\t    -class => \"list\"},\n+\t\t\t\t\t    esc_html($cat));\n+\t\t\t\t} else {\n+\t\t\t\t\tprint esc_html($cat);\n+\t\t\t\t}\n+\t\t\t\tprint \"</td>\\n</tr>\\n\";\n \t\t\t}\n\n \t\t\tgit_project_list_rows($categories{$cat}, undef, undef, $check_forks);\n-- \n2.2.1.68.g56d9796\n"},{"id":"258562","messageId":"xmqqwq23y1xl.fsf@gitster.dls.corp.google.com","threadId":"38857","inReplyTo":"alpine.LSU.2.00.1503191540020.23307@hermes-1.csi.cam.ac.uk","subject":"Re: [PATCH 5/5] gitweb: make category headings into links when they are directories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-03-26T19:49:10Z","receivedAt":"2015-03-26T19:49:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Any comments from those who use or have their own code in Gitweb on\nthis topic?\n\n* tf/gitweb-project-listing (2015-03-19) 5 commits\n - gitweb: make category headings into links when they are directories\n - gitweb: optionally set project category from its pathname\n - gitweb: add a link under the search box to clear a project filter\n - gitweb: if the PATH_INFO is incomplete, use it as a project_filter\n - gitweb: fix typo in man page\n\n Update gitweb to make it more pleasant to deal with a hierarchical\n forest of repositories.\n"},{"id":"258576","messageId":"28AB00ED-7EA7-43C1-84BE-BD290E09318F@dotat.at","threadId":"38857","inReplyTo":"xmqqwq23y1xl.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 5/5] gitweb: make category headings into links when they are directories","fromName":"Tony Finch","fromEmail":"dot@dotat.at","sentAt":"2015-03-27T00:14:08Z","receivedAt":"2015-03-27T00:14:08Z","isPatch":true,"sender":{"key":"dot@dotat.at","avatar":"https://avatars.githubusercontent.com/u/68429?v=4"},"body":"\n> On 26 Mar 2015, at 19:49, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> Any comments from those who use or have their own code in Gitweb on\n> this topic?\n\nThanks 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.\n\nTony.\n-- \nf.anthony.n.finch  <dot@dotat.at>  http://dotat.at"}]}