From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS28753 46.165.192.0/18 X-Spam-Status: No, score=-2.0 required=3.0 tests=AWL,BAYES_00,LOTS_OF_MONEY, RCVD_IN_XBL shortcircuit=no autolearn=no version=3.3.2 X-Original-To: meta@public-inbox.org Received: from 80x24.org (tor-exit.dhalgren.org [46.165.230.5]) by dcvr.yhbt.net (Postfix) with ESMTP id A26491F6D6 for ; Tue, 15 Sep 2015 01:08:48 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/5] searchidx: hoist out rlog code Date: Tue, 15 Sep 2015 01:08:01 +0000 Message-Id: <20150915010804.20084-3-e@80x24.org> In-Reply-To: <20150915010804.20084-1-e@80x24.org> References: <20150915010804.20084-1-e@80x24.org> List-Id: 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