user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <20210429094620.15195-2-e@80x24.org> (raw)
In-Reply-To: <20210429094620.15195-1-e@80x24.org>

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');

  reply	other threads:[~2021-04-29  9:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-29  9:46 [PATCH 0/4] some lei synchronization work Eric Wong
2021-04-29  9:46 ` Eric Wong [this message]
2021-04-29  9:46 ` [PATCH 2/4] lei import: avoid IMAPTracker, use LeiMailSync more Eric Wong
2021-04-29  9:46 ` [PATCH 3/4] lei import: support UIDVALIDITY in IMAP URL Eric Wong
2021-04-29  9:46 ` [PATCH 4/4] lei import: support shell completion of known folders Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210429094620.15195-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).