about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-04-25 07:57:06 +0000
committerEric Wong <e@80x24.org>2019-04-25 08:00:51 +0000
commit31f2f298fe245d5762101bc229416b26c4e85679 (patch)
treebfe9fa5b5f4eb208de7784448bb3cc3da5a9a5ad /lib/PublicInbox
parent1b62a491cccb3c71d60962c798cf02c1b9344ce1 (diff)
downloadpublic-inbox-31f2f298fe245d5762101bc229416b26c4e85679.tar.gz
Document `publicinbox.cgitdata' config directive, but allow it
to be unspecified and/or missing for installations which do not
wish to serve static data at all.

For users installing cgit from source to their home directory,
we can usually infer the cgit data path based on the cgit.cgi
binary path, even.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/Cgit.pm16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/PublicInbox/Cgit.pm b/lib/PublicInbox/Cgit.pm
index 8922ec56..353f4162 100644
--- a/lib/PublicInbox/Cgit.pm
+++ b/lib/PublicInbox/Cgit.pm
@@ -35,7 +35,15 @@ sub locate_cgit ($) {
                 }
         }
         unless (defined $cgit_data) {
-                foreach my $d (qw(/var/www/htdocs/cgit /usr/share/cgit)) {
+                my @dirs = qw(/var/www/htdocs/cgit /usr/share/cgit);
+
+                # local installs of cgit from source have
+                # CGIT_SCRIPT_PATH==CGIT_DATA_PATH by default,
+                # so we can usually infer the cgit_data path from cgit_bin
+                if (defined($cgit_bin) && $cgit_bin =~ m!\A(.+?)/[^/]+\z!) {
+                        unshift @dirs, $1 if -d $1;
+                }
+                foreach my $d (@dirs) {
                         my $f = "$d/cgit.css";
                         next unless -f $f;
                         $cgit_data = $d;
@@ -90,6 +98,7 @@ my @PASS_ENV = qw(
 sub call {
         my ($self, $env) = @_;
         my $path_info = $env->{PATH_INFO};
+        my $cgit_data;
 
         # handle requests without spawning cgit iff possible:
         if ($path_info =~ m!\A/(.+?)/($PublicInbox::GitHTTPBackend::ANY)\z!ox) {
@@ -97,10 +106,11 @@ sub call {
                 if (my $git = $self->{"\0$nick"}) {
                         return serve($env, $git, $path);
                 }
-        } elsif ($path_info =~ m!$self->{static}!) {
+        } elsif ($path_info =~ m!$self->{static}! &&
+                 defined($cgit_data = $self->{cgit_data})) {
                 my $f = $1;
                 my $type = Plack::MIME->mime_type($f);
-                return static_result($env, [], "$self->{cgit_data}$f", $type);
+                return static_result($env, [], $cgit_data.$f, $type);
         }
 
         my $cgi_env = { PATH_INFO => $path_info };