gitweb: Modularized git_get_project_description to be more generic
Introduce a git_get_file_or_project_config utility function to retrieve a repository variable either from a plain text file in the $GIT_DIR or else from 'gitweb.$variable' in the repository config (e.g. 'description'). This would be used in next commit to retrieve category for a project, which is to be stored in the same way as project description. Signed-off-by: Sebastien Cevey <seb@cine7.net> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sebastien Cevey committed
Apr 29, 2011 at 19:52 UTC
e4e3b32bd2317ab73f03d692ab3f7231e2e6787d
1 file changed
+16
-8
gitweb/gitweb.perl
+16
-8
@@ -2562,18 +2562,26 @@ sub git_get_path_by_hash {
2562
## ......................................................................
2563
## git utility functions, directly accessing git repository
2564
2565
-sub git_get_project_description {
2566
- my $path = shift;
2565
+# get the value of config variable either from file named as the variable
2566
+# itself in the repository ($GIT_DIR/$name file), or from gitweb.$name
2567
+# configuration variable in the repository config file.
2568
+sub git_get_file_or_project_config {
2569
+ my ($path, $name) = @_;
2570
2571
$git_dir = "$projectroot/$path";
2569
- open my $fd, '<', "$git_dir/description"
2570
- or return git_get_project_config('description');
2571
- my $descr = <$fd>;
2572
+ open my $fd, '<', "$git_dir/$name"
2573
+ or return git_get_project_config($name);
2574
+ my $conf = <$fd>;
2575
close $fd;
2573
- if (defined $descr) {
2574
- chomp $descr;
2576
+ if (defined $conf) {
2577
+ chomp $conf;
2578
}
2576
- return $descr;
2579
+ return $conf;
2580
+}
2581
+
2582
+sub git_get_project_description {
2583
+ my $path = shift;
2584
+ return git_get_file_or_project_config($path, 'description');
2585
}
2586
2587
# supported formats: