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 <d...@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


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to