From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 05/13] support publicinbox.cgitrc directive
Date: Tue, 12 Mar 2019 04:00:38 +0000 [thread overview]
Message-ID: <20190312040046.4619-6-e@80x24.org> (raw)
In-Reply-To: <20190312040046.4619-1-e@80x24.org>
We can save admins the trouble of declaring [coderepo "..."]
sections in the public-inbox config by parsing the cgitrc
directly.
Macro expansion (e.g. $HTTP_HOST) expansion is not supported,
yet; but may be in the future.
---
Documentation/public-inbox-config.pod | 15 +++++++-
lib/PublicInbox/Config.pm | 54 +++++++++++++++++++++++++--
lib/PublicInbox/Git.pm | 13 ++++++-
lib/PublicInbox/SolverGit.pm | 5 ++-
4 files changed, 77 insertions(+), 10 deletions(-)
diff --git a/Documentation/public-inbox-config.pod b/Documentation/public-inbox-config.pod
index 27d27e4..5ee93e2 100644
--- a/Documentation/public-inbox-config.pod
+++ b/Documentation/public-inbox-config.pod
@@ -188,16 +188,27 @@ be treated as the default value.
Default: 25
-=item coderepo.<name>.dir
+=item coderepo.<nick>.dir
The path to a git repository for "publicinbox.<name>.coderepo"
-=item coderepo.<name>.cgitUrl
+=item coderepo.<nick>.cgitUrl
The URL of the cgit instance associated with the coderepo.
Default: none
+=item publicinbox.cgitrc
+
+A path to a L<cgitrc(5)> file. "repo.url" directives in the cgitrc
+will be mapped to the nickname of a coderepo (without trailing slash),
+and "repo.path" directives map to "coderepo.<nick>.dir".
+Use of this directive allows admins of existing cgit installations
+to skip declaring coderepo sections and map inboxes directly to
+code repositories known to cgit.
+
+Macro expansion (e.g. C<$HTTP_HOST>) is not yet supported.
+
=back
=head2 NAMED LIMITER (PSGI)
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index da443e5..490b4c4 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -196,15 +196,59 @@ sub valid_inbox_name ($) {
1;
}
+sub cgit_repo_merge ($$) {
+ my ($self, $repo) = @_;
+ # $repo = { url => 'foo.git', path => '/path/to/foo.git' }
+ my $nick = $repo->{url};
+ $self->{"coderepo.$nick.dir"} ||= $repo->{path};
+ $self->{"coderepo.$nick.cgiturl"} ||= $nick;
+}
+
+sub parse_cgitrc {
+ my ($self, $cgitrc, $nesting) = @_;
+
+ # same limit as cgit/configfile.c::parse_configfile
+ return if $nesting > 8;
+
+ open my $fh, '<', $cgitrc or do {
+ warn "failed to open cgitrc=$cgitrc: $!\n";
+ return;
+ };
+
+ # FIXME: this doesn't support macro expansion via $VARS, yet
+ my $repo;
+ foreach (<$fh>) {
+ chomp;
+ if (m!\Arepo\.url=(.+?)/*\z!) {
+ my $nick = $1;
+ cgit_repo_merge($self, $repo) if $repo;
+ $repo = { url => $nick };
+ } elsif (m!\Arepo\.path=(.+)\z!) {
+ if (defined $repo) {
+ $repo->{path} = $1;
+ } else {
+ warn "$_ without repo.url\n";
+ }
+ } elsif (m!\Ainclude=(.+)\z!) {
+ parse_cgitrc($self, $1, $nesting + 1);
+ }
+ }
+ cgit_repo_merge($self, $repo) if $repo;
+}
+
# parse a code repo
# Only git is supported at the moment, but SVN and Hg are possibilities
sub _fill_code_repo {
my ($self, $nick) = @_;
my $pfx = "coderepo.$nick";
+ # TODO: support gitweb and other repository viewers?
+ if (defined(my $cgitrc = delete $self->{'publicinbox.cgitrc'})) {
+ parse_cgitrc($self, $cgitrc, 0);
+ }
my $dir = $self->{"$pfx.dir"}; # aka "GIT_DIR"
unless (defined $dir) {
- warn "$pfx.repodir unset";
+ warn "$pfx.dir unset";
return;
}
@@ -225,8 +269,6 @@ sub _fill_code_repo {
} @$cgits;
}
}
- # TODO: support gitweb and other repository viewers?
- # TODO: parse cgitrc
$git;
}
@@ -291,7 +333,11 @@ sub _fill {
my $code_repos = $self->{-code_repos};
my $repo_objs = $rv->{-repo_objs} = [];
foreach my $nick (@$ibx_code_repos) {
- valid_inbox_name($nick) or next;
+ my @parts = split(m!/!, $nick);
+ my $valid = 0;
+ $valid += valid_inbox_name($_) foreach (@parts);
+ $valid == scalar(@parts) or next;
+
my $repo = $code_repos->{$nick} ||=
_fill_code_repo($self, $nick);
push @$repo_objs, $repo if $repo;
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 265c3fb..8a96e10 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -288,10 +288,19 @@ sub src_blob_url {
local_nick($self);
}
+sub host_prefix_url ($$) {
+ my ($env, $url) = @_;
+ return $url if index($url, '//') >= 0;
+ my $scheme = $env->{'psgi.url_scheme'};
+ my $host_port = $env->{HTTP_HOST} ||
+ "$env->{SERVER_NAME}:$env->{SERVER_PORT}";
+ "$scheme://$host_port". ($env->{SCRIPT_NAME} || '/') . $url;
+}
+
sub pub_urls {
- my ($self) = @_;
+ my ($self, $env) = @_;
if (my $urls = $self->{cgit_url}) {
- return @$urls;
+ return map { host_prefix_url($env, $_) } @$urls;
}
local_nick($self);
}
diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index cd0f94a..3841c56 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -85,7 +85,8 @@ sub solve_existing ($$) {
# push @ambiguous, [ $git, @oids ];
dbg($self, "`$oid_b' ambiguous in " .
- join("\n\t", $git->pub_urls) . "\n" .
+ join("\n\t", $git->pub_urls($self->{psgi_env}))
+ . "\n" .
join('', map { "$_ blob\n" } @oids));
}
scalar(@ambiguous) ? \@ambiguous : undef;
@@ -483,7 +484,7 @@ sub resolve_patch ($$) {
if (my $existing = solve_existing($self, $want)) {
my ($found_git, undef, $type, undef) = @$existing;
dbg($self, "found $cur_want in " .
- join("\n", $found_git->pub_urls));
+ join("\n", $found_git->pub_urls($self->{psgi_env})));
if ($cur_want eq $self->{oid_want} || $type ne 'blob') {
eval { delete($self->{user_cb})->($existing) };
--
EW
next prev parent reply other threads:[~2019-03-12 4:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-12 4:00 [PATCH 00/13] support parsing cgitrc and spawning cgit Eric Wong
2019-03-12 4:00 ` [PATCH 01/13] git: add "commit_title" method Eric Wong
2019-03-12 4:00 ` [PATCH 02/13] viewvcs: preliminary support for showing non-blobs Eric Wong
2019-03-12 4:00 ` [PATCH 03/13] viewvcs: match 8000-byte lookup for git Eric Wong
2019-03-12 4:00 ` [PATCH 04/13] spawn: support RLIMIT_CPU, RLIMIT_DATA and RLIMIT_CORE Eric Wong
2019-03-12 4:00 ` Eric Wong [this message]
2019-03-12 4:00 ` [PATCH 06/13] githttpbackend: move more psgi.input handling into subroutine Eric Wong
2019-03-12 4:00 ` [PATCH 07/13] githttpbackend: check for other errors and relax CRLF check Eric Wong
2019-03-12 4:00 ` [PATCH 08/13] spawn: support absolute paths Eric Wong
2019-03-12 4:00 ` [PATCH 09/13] cgit: support running cgit as a standalone CGI Eric Wong
2019-03-12 4:00 ` [PATCH 10/13] www: wire up cgit as a 404 handler if cgitrc is configured Eric Wong
2019-03-12 4:00 ` [PATCH 11/13] qspawn: wire up RLIMIT_* handling to limiters Eric Wong
2019-03-12 4:00 ` [PATCH 12/13] cgit: use a dedicated named limiter Eric Wong
2019-03-12 4:00 ` [PATCH 13/13] spawn: require soft and hard vals for RLIMIT_* params Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190312040046.4619-6-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).