From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: 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.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id F3C581FA18 for ; Fri, 29 Jan 2021 07:43:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/7] git: synchronous cat_file may return type and OID Date: Fri, 29 Jan 2021 12:42:58 +0500 Message-Id: <20210129074300.14475-6-e@80x24.org> In-Reply-To: <20210129074300.14475-1-e@80x24.org> References: <20210129074300.14475-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Instead of forcing callers to set a variable to write into, we'll just rely on wantarray. --- lib/PublicInbox/Git.pm | 9 ++++----- t/git.t | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 3d97300c..c6c1c802 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -240,17 +240,16 @@ sub batch_prepare ($) { } sub _cat_file_cb { - my ($bref, undef, undef, $size, $result) = @_; - @$result = ($bref, $size); + my ($bref, $oid, $type, $size, $result) = @_; + @$result = ($bref, $oid, $type, $size); } sub cat_file { - my ($self, $oid, $sizeref) = @_; + my ($self, $oid) = @_; my $result = []; cat_async($self, $oid, \&_cat_file_cb, $result); cat_async_wait($self); - $$sizeref = $result->[1] if $sizeref; - $result->[0]; + wantarray ? @$result : $result->[0]; } sub check_async_step ($$) { diff --git a/t/git.t b/t/git.t index 377652ca..0c85e492 100644 --- a/t/git.t +++ b/t/git.t @@ -70,10 +70,10 @@ if (1) { chomp $buf; my $gcf = PublicInbox::Git->new($dir); - my $rsize; - my $x = $gcf->cat_file($buf, \$rsize); - is($rsize, $size, 'got correct size ref on big file'); - is(length($$x), $size, 'read correct number of bytes'); + my @x = $gcf->cat_file($buf); + is($x[2], 'blob', 'got blob on wantarray'); + is($x[3], $size, 'got correct size ref on big file'); + is(length(${$x[0]}), $size, 'read correct number of bytes'); my $ref = $gcf->qx(qw(cat-file blob), $buf); is($?, 0, 'no error on scalar success');