]> Sergey Matveev's repositories - public-inbox.git/commitdiff
content_hash: git_sha: allow unblessed SCALAR refs
authorEric Wong <e@80x24.org>
Thu, 29 Apr 2021 09:46:17 +0000 (09:46 +0000)
committerEric Wong <e@80x24.org>
Fri, 30 Apr 2021 06:41:36 +0000 (06:41 +0000)
This will be convenient to avoid the overhead of
PublicInbox::Eml for verifying synchronization in lei.

lib/PublicInbox/ContentHash.pm
lib/PublicInbox/LeiViewText.pm
t/solver_git.t

index 112b1ea6c1e660722cf1e68982745edb93912599..cc4a54c922d09c9788cfb63b03097631ecc7bcb0 100644 (file)
@@ -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;
 }
 
index d0f8b7f43aa1cc3cc9896183767a422ca7a479ec..340a66481225fbcc0a25867a95ff83933de06435 100644 (file)
@@ -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;
index 6875e26b8f49311a1ac97bbcf60158be4ecd166b..75387b2a2e913b351f1a5c747ff2fb8bedd3eb65 100644 (file)
@@ -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');