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-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.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 04F161F934 for ; Thu, 29 Apr 2021 09:46:21 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/4] content_hash: git_sha: allow unblessed SCALAR refs Date: Thu, 29 Apr 2021 09:46:17 +0000 Message-Id: <20210429094620.15195-2-e@80x24.org> In-Reply-To: <20210429094620.15195-1-e@80x24.org> References: <20210429094620.15195-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This will be convenient to avoid the overhead of PublicInbox::Eml for verifying synchronization in lei. --- lib/PublicInbox/ContentHash.pm | 6 +++--- lib/PublicInbox/LeiViewText.pm | 1 - t/solver_git.t | 7 ++----- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/ContentHash.pm b/lib/PublicInbox/ContentHash.pm index 112b1ea6..cc4a54c9 100644 --- a/lib/PublicInbox/ContentHash.pm +++ b/lib/PublicInbox/ContentHash.pm @@ -97,9 +97,9 @@ sub content_hash ($) { sub git_sha ($$) { my ($n, $eml) = @_; my $dig = Digest::SHA->new($n); - my $buf = $eml->as_string; - $dig->add('blob '.length($buf)."\0"); - $dig->add($buf); + my $bref = ref($eml) eq 'SCALAR' ? $eml : \($eml->as_string); + $dig->add('blob '.length($$bref)."\0"); + $dig->add($$bref); $dig; } diff --git a/lib/PublicInbox/LeiViewText.pm b/lib/PublicInbox/LeiViewText.pm index d0f8b7f4..340a6648 100644 --- a/lib/PublicInbox/LeiViewText.pm +++ b/lib/PublicInbox/LeiViewText.pm @@ -7,7 +7,6 @@ package PublicInbox::LeiViewText; use strict; use v5.10.1; use PublicInbox::MsgIter qw(msg_part_text); -use PublicInbox::ContentHash qw(git_sha); use PublicInbox::MID qw(references); use PublicInbox::View; use PublicInbox::Hval; diff --git a/t/solver_git.t b/t/solver_git.t index 6875e26b..75387b2a 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -7,7 +7,6 @@ use PublicInbox::TestCommon; use Cwd qw(abs_path); require_git(2.6); use PublicInbox::ContentHash qw(git_sha); -use PublicInbox::Eml; use PublicInbox::Spawn qw(popen_rd which); require_mods(qw(DBD::SQLite Search::Xapian Plack::Util)); my $git_dir = xqx([qw(git rev-parse --git-dir)], undef, {2 => \(my $null)}); @@ -41,8 +40,7 @@ test_lei({tmpdir => $tmpdir}, sub { "--mail won't run solver"); lei_ok('blob', '69df7d5', '-I', $ibx->{inboxdir}); - is(git_sha(1, PublicInbox::Eml->new($lei_out))->hexdigest, - $expect, 'blob contents output'); + is(git_sha(1, \$lei_out)->hexdigest, $expect, 'blob contents output'); my $prev = $lei_out; lei_ok(qw(blob --no-mail 69df7d5 -I), $ibx->{inboxdir}); is($lei_out, $prev, '--no-mail works'); @@ -239,8 +237,7 @@ EOF test_lei({tmpdir => "$tmpdir/ext"}, sub { my $rurl = "$url/$name"; lei_ok(qw(blob --no-mail 69df7d5 -I), $rurl); - my $eml = PublicInbox::Eml->new($lei_out); - is(git_sha(1, $eml)->hexdigest, $expect, + is(git_sha(1, \$lei_out)->hexdigest, $expect, 'blob contents output'); ok(!lei(qw(blob -I), $rurl, $non_existent), 'non-existent blob fails');