From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id ADDA11FAED for ; Thu, 15 Feb 2018 11:08:45 +0000 (UTC) From: "Eric Wong (Contractor, The Linux Foundation)" To: meta@public-inbox.org Subject: [WIP 11/17] import: APIs to support v2 use Date: Thu, 15 Feb 2018 11:08:34 +0000 Message-Id: <20180215110840.30413-12-e@80x24.org> In-Reply-To: <20180215110840.30413-1-e@80x24.org> References: <20180215105509.GA22409@dcvr> <20180215110840.30413-1-e@80x24.org> List-Id: Wrap "get-mark" and "checkpoint" commands for git-fast-import while documenting/cementing parts of the API. --- lib/PublicInbox/Import.pm | 28 ++++++++++++++++++++++------ t/import.t | 4 +++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index b8e9dd0..811e355 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -138,9 +138,27 @@ sub check_remove_v1 { (undef, $cur); } +# used for v2 (maybe) +sub checkpoint { + my ($self) = @_; + return unless $self->{pid}; + print { $self->{out} } "checkpoint\n" or wfail; + undef; +} + +# used for v2 +sub get_mark { + my ($self, $mark) = @_; + die "not active\n" unless $self->{pid}; + my ($r, $w) = $self->gfi_start; + print $w "get-mark $mark\n" or wfail; + defined(my $oid = <$r>) or die "get-mark failed, need git 2.6.0+\n"; + $oid; +} + # returns undef on non-existent -# ('MISMATCH', msg) on mismatch -# (:MARK, msg) on success +# ('MISMATCH', Email::MIME) on mismatch +# (:MARK, Email::MIME) on success # # For v2 inboxes, the content_id is returned instead of the msg # v2 callers should check with Xapian before calling this as @@ -189,6 +207,7 @@ sub remove { } # returns undef on duplicate +# returns the :MARK of the most recent commit sub add { my ($self, $mime, $check_cb) = @_; # mime = Email::MIME @@ -234,10 +253,7 @@ sub add { # v2: we need this for Xapian if ($self->{want_object_id}) { - print $w "get-mark :$blob\n" or wfail; - defined(my $object_id = <$r>) or - die "get-mark failed, need git 2.6.0+\n"; - chomp($self->{last_object_id} = $object_id); + chomp($self->{last_object_id} = $self->get_mark(":$blob")); } my $ref = $self->{ref}; diff --git a/t/import.t b/t/import.t index 92c82b9..ca59772 100644 --- a/t/import.t +++ b/t/import.t @@ -87,6 +87,8 @@ isnt($msg->header('Subject'), $mime->header('Subject'), 'subject mismatch'); $mime->header_set('Message-Id', ''); is($im->add($mime, sub { undef }), undef, 'check callback fails'); is($im->remove($mime), undef, 'message not added, so not removed'); - +is(undef, $im->checkpoint, 'checkpoint works before ->done'); $im->done; +is(undef, $im->checkpoint, 'checkpoint works after ->done'); +$im->checkpoint; done_testing(); -- EW