- # note: this doesn't preserve cgitrc layout, since we parse cgitrc
- # and drop the original structure
- if (defined(my $cr = $ibx->{coderepo})) {
- $$txt .= "\tcoderepo = $_\n" for @$cr;
-
- my $pi_config = $ctx->{www}->{pi_config};
- for my $cr_name (@$cr) {
- my $url = $pi_config->{"coderepo.$cr_name.cgiturl"};
- my $path = "/path/to/$cr_name";
- $cr_name = dq_escape($cr_name);
-
- $$txt .= qq([coderepo "$cr_name"]\n);
- if (defined($url)) {
- my $cpath = $path;
- if ($path !~ m![a-z0-9_/\.\-]!i) {
- $cpath = dq_escape($cpath);
- }
- $$txt .= qq(\t; git clone $url "$cpath"\n);
+# n.b. this is a perfect candidate for memoization
+sub extindex_config ($$$) {
+ my ($ctx, $hdr, $txt) = @_;
+ my $ibx = $ctx->{ibx};
+ push @$hdr, 'Content-Disposition', 'inline; filename=extindex.config';
+ my $name = dq_escape($ibx->{name});
+ my $base_url = $ibx->base_url($ctx->{env});
+ $$txt .= <<EOS;
+; Example public-inbox config snippet for the external index (extindex) at:
+; $base_url
+; See public-inbox-config(5)manpage for more details:
+; https://public-inbox.org/public-inbox-config.html
+[extindex "$name"]
+ topdir = /path/to/extindex-topdir
+ url = https://example.com/$name/
+ url = http://example.onion/$name/
+EOS
+ for my $k (qw(infourl)) {
+ defined(my $v = $ibx->{$k}) or next;
+ $$txt .= "\t$k = $v\n";
+ }
+ _coderepo_config($ctx, $txt);
+ 1;
+}
+
+sub coderepos_raw ($$) {
+ my ($ctx, $top_url) = @_;
+ my $cr = $ctx->{ibx}->{coderepo} // return ();
+ my $cfg = $ctx->{www}->{pi_cfg};
+ my @ret;
+ for my $cr_name (@$cr) {
+ $ret[0] //= do {
+ my $thing = $ctx->{ibx}->can('cloneurl') ?
+ 'public inbox' : 'external index';
+ <<EOF;
+Code repositories for project(s) associated with this $thing
+EOF
+ };
+ my $urls = $cfg->get_all("coderepo.$cr_name.cgiturl");
+ if ($urls) {
+ for (@$urls) {
+ # relative or absolute URL?, prefix relative
+ # "foo.git" with appropriate number of "../"
+ my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ :
+ $top_url.$_;
+ $ret[0] .= "\n\t" . prurl($ctx->{env}, $u);
+ }
+ } else {
+ $ret[0] .= qq[\n\t$cr_name.git (no URL configured)];
+ }
+ }
+ @ret; # may be empty, this sub is called as an arg for join()
+}
+
+sub _mirror_help ($$) {
+ my ($ctx, $txt) = @_;
+ my $ibx = $ctx->{ibx};
+ my $base_url = $ibx->base_url($ctx->{env});
+ chop $base_url; # no trailing slash for "git clone"
+ my $dir = (split(m!/!, $base_url))[-1];
+ my %seen = ($base_url => 1);
+ my $top_url = $base_url;
+ $top_url =~ s!/[^/]+\z!/!;
+ $$txt .= "public-inbox mirroring instructions\n\n";
+ if ($ibx->can('cloneurl')) { # PublicInbox::Inbox
+ $$txt .=
+ "This public inbox may be cloned and mirrored by anyone:\n";
+ my @urls;
+ my $max = $ibx->max_git_epoch;
+ # TODO: some of these URLs may be too long and we may need to
+ # do something like code_footer() above, but these are local
+ # admin-defined
+ if (defined($max)) { # v2
+ for my $i (0..$max) {
+ # old epochs my be deleted:
+ -d "$ibx->{inboxdir}/git/$i.git" or next;
+ my $url = "$base_url/$i";
+ $seen{$url} = 1;
+ push @urls, "$url $dir/git/$i.git";