about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-08-15 09:28:31 +0000
committerEric Wong <e@80x24.org>2015-08-15 19:15:33 +0000
commit885250c3c289c96764e0eb9f432a389136d07088 (patch)
tree3eb8ca6e8ccbe53b985d8ab3639004c918a5c249 /lib/PublicInbox
parent675494c58ef7a39a92c79cbf02975b9da3991c0b (diff)
downloadpublic-inbox-885250c3c289c96764e0eb9f432a389136d07088.tar.gz
We need to make the indexer executable and installable
while we're at it.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/Search.pm39
1 files changed, 38 insertions, 1 deletions
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index fe4984e5..15bb9f62 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -226,7 +226,6 @@ sub remove_message {
         } else {
                 $db->commit_transaction;
         }
-        $db->commit;
         $doc_id;
 }
 
@@ -536,4 +535,42 @@ sub enquire {
         $self->{enquire} ||= Search::Xapian::Enquire->new($self->{xdb});
 }
 
+# indexes all unindexed messages
+sub index_sync {
+        my ($self, $git) = @_;
+        my $db = $self->{xdb};
+        my $latest = $db->get_metadata('last_commit');
+        my $range = length $latest ? "$latest..HEAD" : 'HEAD';
+        $latest = undef;
+
+        my $hex = '[a-f0-9]';
+        my $h40 = $hex .'{40}';
+        my $addmsg = qr!^:000000 100644 \S+ ($h40) A\t${hex}{2}/${hex}{38}$!;
+        my $delmsg = qr!^:100644 000000 ($h40) \S+ D\t${hex}{2}/${hex}{38}$!;
+
+        # get indexed messages
+        my @cmd = ('git', "--git-dir=$git->{git_dir}", "log",
+                    qw/--reverse --no-notes --no-color --raw -r --no-abbrev/,
+                    $range);
+
+        my $pid = open(my $log, '-|', @cmd) or
+                die('open` '.join(' ', @cmd) . " pipe failed: $!\n");
+        my $last;
+        while (my $line = <$log>) {
+                if ($line =~ /$addmsg/o) {
+                        $self->index_blob($git, $1);
+                } elsif ($line =~ /$delmsg/o) {
+                        $self->unindex_blob($git, $1);
+                } elsif ($line =~ /^commit ($h40)/o) {
+                        my $commit = $1;
+                        if (defined $latest) {
+                                $db->set_metadata('last_commit', $latest)
+                        }
+                        $latest = $commit;
+                }
+        }
+        close $log;
+        $db->set_metadata('last_commit', $latest) if defined $latest;
+}
+
 1;