{"thread":{"id":"37260","subject":"[PATCH 4/5] gitweb: optionally set project category from its pathname","startedAt":"2014-07-31T12:53:51Z","lastAt":"2014-07-31T12:53:51Z","messageCount":1,"participants":["Tony Finch"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"247043","messageId":"alpine.LSU.2.00.1407311353500.23775@hermes-1.csi.cam.ac.uk","threadId":"37260","inReplyTo":null,"subject":"[PATCH 4/5] gitweb: optionally set project category from its pathname","fromName":"Tony Finch","fromEmail":"dot@dotat.at","sentAt":"2014-07-31T12:53:51Z","receivedAt":"2014-07-31T12:53:51Z","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 d1e6b79..edbc058 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -129,6 +129,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@@ -2904,7 +2908,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@@ -5618,8 +5626,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.1.0.rc0.229.gaee38de\n"}]}