about summary refs log tree commit homepage
path: root/lib/PublicInbox/Config.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-28 14:56:21 +0000
committerEric Wong <e@80x24.org>2023-11-29 02:13:22 +0000
commit67ecd56a0aaf977fa1a22aa6e2378c9317c72549 (patch)
treeedb6e7d87ab1bc1b05bde1e5eb07d9b1ccab6a21 /lib/PublicInbox/Config.pm
parent10b23966ff8fa35a112f7fe2b9386dd4967d818c (diff)
downloadpublic-inbox-67ecd56a0aaf977fa1a22aa6e2378c9317c72549.tar.gz
This is a major step in solving the problem of having to
manually associate hundreds/thousands of coderepos with
hundreds/thousands of public-inboxes to power solver
(and more).
Diffstat (limited to 'lib/PublicInbox/Config.pm')
-rw-r--r--lib/PublicInbox/Config.pm39
1 files changed, 38 insertions, 1 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 9bee94b8..779e3140 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -412,8 +412,8 @@ sub get_1 {
 
 sub repo_objs {
         my ($self, $ibxish) = @_;
-        my $ibx_coderepos = $ibxish->{coderepo} // return;
         $ibxish->{-repo_objs} // do {
+                my $ibx_coderepos = $ibxish->{coderepo} // return;
                 parse_cgitrc($self, undef, 0);
                 my $coderepos = $self->{-coderepos};
                 my @repo_objs;
@@ -568,6 +568,43 @@ sub _fill_ei ($$) {
         $es;
 }
 
+sub _fill_csrch ($$) {
+        my ($self, $name) = @_; # "" is a valid name for cindex
+        return if $name ne '' && !valid_foo_name($name, 'cindex');
+        eval { require PublicInbox::CodeSearch } or return;
+        my $pfx = "cindex.$name";
+        my $d = $self->{"$pfx.topdir"} // return;
+        -d $d or return;
+        if (index($d, "\n") >= 0) {
+                warn "E: `$d' must not contain `\\n'\n";
+                return;
+        }
+        my $csrch = PublicInbox::CodeSearch->new($d, $self);
+        for my $k (qw(localprefix)) {
+                my $v = $self->{"$pfx.$k"} // next;
+                $csrch->{$k} = _array($v);
+        }
+        $csrch->{name} = $name;
+        $csrch;
+}
+
+sub lookup_cindex ($$) {
+        my ($self, $name) = @_;
+        $self->{-csrch_by_name}->{$name} //= _fill_csrch($self, $name);
+}
+
+sub each_cindex {
+        my ($self, $cb, @arg) = @_;
+        my @csrch = map {
+                lookup_cindex($self, substr($_, length('cindex.'))) // ()
+        } grep(m!\Acindex\.[^\./]*\z!, @{$self->{-section_order}});
+        if (ref($cb) eq 'CODE') {
+                $cb->($_, @arg) for @csrch;
+        } else { # string function
+                $_->$cb(@arg) for @csrch;
+        }
+}
+
 sub config_cmd {
         my ($self, $env, $opt) = @_;
         my $f = $self->{-f} // default_file();