user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/5] searchidx: hoist out rlog code
Date: Tue, 15 Sep 2015 01:08:01 +0000	[thread overview]
Message-ID: <20150915010804.20084-3-e@80x24.org> (raw)
In-Reply-To: <20150915010804.20084-1-e@80x24.org>

We'll be reusing this for loading msgmap.
---
 lib/PublicInbox/SearchIdx.pm | 55 +++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index c61e161..44f6bc1 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -275,42 +275,45 @@ sub index_sync {
 	$self->with_umask(sub { $self->_index_sync($head) });
 }
 
-# indexes all unindexed messages
-sub _index_sync {
-	my ($self, $head) = @_;
-	require PublicInbox::GitCatFile;
-	my $db = $self->{xdb};
+sub rlog {
+	my ($self, $range, $add_cb, $del_cb) = @_;
 	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}$!;
+	my $git_dir = $self->{git_dir};
+	require PublicInbox::GitCatFile;
+	my $git = PublicInbox::GitCatFile->new($git_dir);
+	my @cmd = ('git', "--git-dir=$git_dir", "log",
+		    qw/--reverse --no-notes --no-color --raw -r --no-abbrev/,
+		    $range);
+	my $latest;
+	my $pid = open(my $log, '-|', @cmd) or
+		die('open` '.join(' ', @cmd) . " pipe failed: $!\n");
+	while (my $line = <$log>) {
+		if ($line =~ /$addmsg/o) {
+			$add_cb->($self, $git, $1);
+		} elsif ($line =~ /$delmsg/o) {
+			$del_cb->($self, $git, $1);
+		} elsif ($line =~ /^commit ($h40)/o) {
+			$latest = $1;
+		}
+	}
+	close $log;
+	$latest;
+}
+
+# indexes all unindexed messages
+sub _index_sync {
+	my ($self, $head) = @_;
+	my $db = $self->{xdb};
 	$head ||= 'HEAD';
 
 	$db->begin_transaction;
 	eval {
-		my $git = PublicInbox::GitCatFile->new($self->{git_dir});
-
 		my $latest = $db->get_metadata('last_commit');
 		my $range = $latest eq '' ? $head : "$latest..$head";
-		$latest = undef;
-
-		# get indexed messages
-		my @cmd = ('git', "--git-dir=$self->{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");
-
-		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) {
-				$latest = $1;
-			}
-		}
-		close $log;
+		$latest = $self->rlog($range, *index_blob, *unindex_blob);
 		$db->set_metadata('last_commit', $latest) if defined $latest;
 	};
 	if ($@) {
-- 
EW


  parent reply	other threads:[~2015-09-15  1:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-15  1:07 [PATCH 0/5] introduce SQLite message map Eric Wong
2015-09-15  1:08 ` [PATCH 1/5] msgmap: add message mapping via SQLite Eric Wong
2015-09-15  1:08 ` Eric Wong [this message]
2015-09-15  1:08 ` [PATCH 3/5] searchidx: sync Msgmap database along with Xapian Eric Wong
2015-09-15  1:08 ` [PATCH 4/5] extmsg: wire up to use msgmap for prefixes Eric Wong
2015-09-15  1:08 ` [PATCH 5/5] INSTALL: document DBD::SQLite and DBI dependencies Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150915010804.20084-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).