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: AS24961 193.111.136.0/21 X-Spam-Status: No, score=-2.1 required=3.0 tests=AWL,BAYES_00, RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,SPF_FAIL,SPF_HELO_FAIL, TO_EQ_FM_DOM_SPF_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (10.tor.exit.babylon.network [193.111.136.162]) by dcvr.yhbt.net (Postfix) with ESMTP id E07671F859 for ; Tue, 16 Aug 2016 21:33:57 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] import: hoist out _check_path function Date: Tue, 16 Aug 2016 21:33:53 +0000 Message-Id: <20160816213353.15880-1-e@80x24.org> List-Id: We will be using it again in a new function. --- lib/PublicInbox/Import.pm | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index c2beb19..09dd38d 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -75,6 +75,15 @@ sub norm_body ($) { $b } +sub _check_path ($$$$) { + my ($r, $w, $tip, $path) = @_; + return if $tip eq ''; + print $w "ls $tip $path\n" or wfail; + local $/ = "\n"; + defined(my $info = <$r>) or die "EOF from fast-import: $!"; + $info =~ /\Amissing / ? undef : $info; +} + # returns undef on non-existent # ('MISMATCH', msg) on mismatch # (:MARK, msg) on success @@ -86,20 +95,16 @@ sub remove { my ($r, $w) = $self->gfi_start; my $tip = $self->{tip}; - return ('MISSING', undef) if $tip eq ''; - - print $w "ls $tip $path\n" or wfail; - local $/ = "\n"; - my $check = <$r>; - defined $check or die "EOF from fast-import / ls: $!"; - return ('MISSING', undef) if $check =~ /\Amissing /; - $check =~ m!\A100644 blob ([a-f0-9]{40})\t!s or die "not blob: $check"; + my $info = _check_path($r, $w, $tip, $path) or return ('MISSING',undef); + $info =~ m!\A100644 blob ([a-f0-9]{40})\t!s or die "not blob: $info"; my $blob = $1; + print $w "cat-blob $blob\n" or wfail; - $check = <$r>; - defined $check or die "EOF from fast-import / cat-blob: $!"; - $check =~ /\A[a-f0-9]{40} blob (\d+)\n\z/ or - die "unexpected cat-blob response: $check"; + local $/ = "\n"; + $info = <$r>; + defined $info or die "EOF from fast-import / cat-blob: $!"; + $info =~ /\A[a-f0-9]{40} blob (\d+)\n\z/ or + die "unexpected cat-blob response: $info"; my $left = $1; my $offset = 0; my $buf = ''; @@ -162,13 +167,7 @@ sub add { my ($r, $w) = $self->gfi_start; my $tip = $self->{tip}; - if ($tip ne '') { - print $w "ls $tip $path\n" or wfail; - local $/ = "\n"; - my $check = <$r>; - defined $check or die "EOF from fast-import: $!"; - return unless $check =~ /\Amissing /; - } + _check_path($r, $w, $tip, $path) and return; # kill potentially confusing/misleading headers $mime->header_set($_) for qw(bytes lines content-length status); -- EW