]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/MiscIdx.pm
support multiple CODE_URLs
[public-inbox.git] / lib / PublicInbox / MiscIdx.pm
index edc70f9b37c358e7b556d3c92a1133971538ee25..64591d0516ddcfef135ee77c697f61b85012f583 100644 (file)
@@ -20,6 +20,7 @@ use PublicInbox::Spawn qw(nodatacow_dir);
 use Carp qw(croak);
 use File::Path ();
 use PublicInbox::MiscSearch;
+use PublicInbox::Config;
 
 sub new {
        my ($class, $eidx) = @_;
@@ -52,6 +53,22 @@ sub commit_txn {
        delete($self->{xdb})->commit_transaction;
 }
 
+sub remove_eidx_key {
+       my ($self, $eidx_key) = @_;
+       my $xdb = $self->{xdb};
+       my $head = $xdb->postlist_begin('Q'.$eidx_key);
+       my $tail = $xdb->postlist_end('Q'.$eidx_key);
+       my @docids; # only one, unless we had bugs
+       for (; $head != $tail; $head++) {
+               push @docids, $head->get_docid;
+       }
+       for my $docid (@docids) {
+               $xdb->delete_document($docid);
+               warn "I: remove inbox docid #$docid ($eidx_key)\n";
+       }
+}
+
+# adds or updates according to $eidx_key
 sub index_ibx {
        my ($self, $ibx) = @_;
        my $eidx_key = $ibx->eidx_key;
@@ -97,6 +114,23 @@ EOF
                }
        }
        index_text($self, $ibx->{name}, 1, 'XNAME');
+       my $data = {};
+       if (defined(my $max = $ibx->max_git_epoch)) { # v2
+               my $desc = $ibx->description;
+               my $pfx = "/$ibx->{name}/git/";
+               for my $epoch (0..$max) {
+                       my $git = $ibx->git_epoch($epoch) or return;
+                       if (my $ent = $git->manifest_entry($epoch, $desc)) {
+                               $data->{"$pfx$epoch.git"} = $ent;
+                               $ent->{git_dir} = $git->{git_dir};
+                       }
+                       $git->cleanup; # ->modified starts cat-file --batch
+               }
+       } elsif (my $ent = $ibx->git->manifest_entry) { # v1
+               $ent->{git_dir} = $ibx->{inboxdir};
+               $data->{"/$ibx->{name}"} = $ent;
+       }
+       $doc->set_data(PublicInbox::Config::json()->encode($data));
        if (defined $docid) {
                $xdb->replace_document($docid, $doc);
        } else {