about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchIdx.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-08-02 08:32:09 +0000
committerEric Wong <e@80x24.org>2016-08-02 08:41:43 +0000
commit4caa17ef5aa8554d78b8c013096f12429c58e050 (patch)
tree651bda4a566e7625445e194270be6f01d5c8aa3f /lib/PublicInbox/SearchIdx.pm
parentb7c4bca292fb1f7ac4d73ff96b2ce95185b4fc66 (diff)
downloadpublic-inbox-4caa17ef5aa8554d78b8c013096f12429c58e050.tar.gz
For reindexing, fresh Xapian DBs do not count as a reindex,
allowing users to blindly use --reindex on the first
run on a clean repo.

While we're at it, allow indexing to override HEAD ref for
multi-head git repos.
Diffstat (limited to 'lib/PublicInbox/SearchIdx.pm')
-rw-r--r--lib/PublicInbox/SearchIdx.pm18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 6a34ce71..f0a3687d 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -374,7 +374,7 @@ sub rlog {
 # indexes all unindexed messages
 sub _index_sync {
         my ($self, $opts) = @_;
-        my $head = 'HEAD';
+        my $tip = $opts->{ref} || 'HEAD';
         my $mm = $self->{mm} = eval {
                 require PublicInbox::Msgmap;
                 PublicInbox::Msgmap->new($self->{git_dir}, 1);
@@ -382,8 +382,13 @@ sub _index_sync {
         my $xdb = $self->{xdb};
         $xdb->begin_transaction;
         my $reindex = $opts->{reindex};
-        my $mkey = $reindex ? undef : 'last_commit';
-        my $lx = $reindex ? '' : $xdb->get_metadata('last_commit');
+        my $mkey = 'last_commit';
+        my $last_commit = $xdb->get_metadata($mkey);
+        my $lx = $last_commit;
+        if ($reindex) {
+                $lx = '';
+                $mkey = undef if $last_commit ne '';
+        }
         my $dbh;
         my $cb = sub {
                 my ($commit, $more) = @_;
@@ -398,7 +403,7 @@ sub _index_sync {
                 $xdb = _xdb_acquire($self);
         };
 
-        my $range = $lx eq '' ? $head : "$lx..$head";
+        my $range = $lx eq '' ? $tip : "$lx..$tip";
         if ($mm) {
                 $dbh = $mm->{dbh};
                 $dbh->begin_work;
@@ -413,14 +418,15 @@ sub _index_sync {
                         # This happens if we have to reindex Xapian since
                         # msgmap is a frozen format and our Xapian format
                         # is evolving.
-                        my $r = $lm eq '' ? $head : "$lm..$head";
+                        my $r = $lm eq '' ? $tip : "$lm..$tip";
 
                         # first, ensure msgmap is up-to-date:
+                        my $mkey_prev = $mkey;
                         $mkey = undef; # ignore xapian, for now
                         rlog($self, $r, *index_mm, *unindex_mm, $cb);
 
                         # now deal with Xapian
-                        $mkey = 'last_commit' unless $reindex;
+                        $mkey = $mkey_prev;
                         $dbh = undef;
                         rlog($self, $range, *index_mm2, *unindex_mm2, $cb);
                 }