]> Sergey Matveev's repositories - public-inbox.git/commitdiff
import: APIs to support v2 use
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Wed, 14 Feb 2018 00:30:33 +0000 (00:30 +0000)
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Wed, 14 Feb 2018 00:30:33 +0000 (00:30 +0000)
Wrap "get-mark" and "checkpoint" commands for git-fast-import
while documenting/cementing parts of the API.

lib/PublicInbox/Import.pm
t/import.t

index b8e9dd03f68e7ba405ad3bc15a7e9f8f7a2b2909..811e355a16e31d40804446f445d9cc2cd0512537 100644 (file)
@@ -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};
index 92c82b992e3b9da6524c95ee1dc13822642561a6..ca597720cea45bfe03e005f22c95b64648422aa0 100644 (file)
@@ -87,6 +87,8 @@ isnt($msg->header('Subject'), $mime->header('Subject'), 'subject mismatch');
 $mime->header_set('Message-Id', '<failcheck@example.com>');
 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();