summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Finch <dot@dotat.at>2015-03-19 15:40:16 +0000
committerJunio C Hamano <gitster@pobox.com>2015-03-19 13:44:11 -0700
commit393bfac97e0d772c9d163adf048e5a4bf132dc11 (patch)
treed48c02de552f28ce3fce7c47ae0a3ea79923f6d1
parent2ff28b0f207374201e1c6bdf493d38cc86a4f3d8 (diff)
downloadgit-393bfac97e0d772c9d163adf048e5a4bf132dc11.tar.gz
gitweb: optionally set project category from its pathname
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--Documentation/gitweb.conf.txt6
-rwxr-xr-xgitweb/gitweb.perl13
2 files changed, 16 insertions, 3 deletions
diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
index 12a0de17e8..92438e706c 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 d1e6b79523..edbc0587f9 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);
}