From aca6555ed4696ba1f24296a63afa7450a5afde2a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 27 Mar 2021 11:45:51 +0000 Subject: lei blob: aka "git-show-harder" for blobs This implements blob reconstruction via SolverGit, emulating the functionality of /$INBOX/$OID/s/ endpoint in PublicInbox::WWW. It uses the current working tree as a coderepo, and accepts any number of --git-dir=$PATH args. Remote externals are not yet supported. v2: use absolute path for git repos --- t/lei-import.t | 2 ++ t/solver_git.t | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/lei-import.t b/t/lei-import.t index fa40ad01..33ce490d 100644 --- a/t/lei-import.t +++ b/t/lei-import.t @@ -54,6 +54,8 @@ is($res->[0]->{'m'}, 'x@y', 'got expected message'); is($res->[0]->{kw}, undef, 'Status ignored for eml'); lei_ok(qw(q -f mboxrd m:x@y)); unlike($lei_out, qr/^Status:/, 'no Status: in imported message'); +lei_ok('blob', $res->[0]->{blob}); +is($lei_out, "From: a\@b\nMessage-ID: \n", 'got blob back'); $eml->header_set('Message-ID', ''); diff --git a/t/solver_git.t b/t/solver_git.t index 99ffb9e3..22714ae5 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -6,6 +6,7 @@ use v5.10.1; use PublicInbox::TestCommon; use Cwd qw(abs_path); require_git(2.6); +use Digest::SHA qw(sha1_hex); use PublicInbox::Spawn qw(popen_rd); require_mods(qw(DBD::SQLite Search::Xapian Plack::Util)); my $git_dir = xqx([qw(git rev-parse --git-dir)], undef, {2 => \(my $null)}); @@ -27,6 +28,18 @@ my $ibx = create_inbox 'v2', version => 2, }; my $v1_0_0_tag = 'cb7c42b1e15577ed2215356a2bf925aef59cdd8d'; my $v1_0_0_tag_short = substr($v1_0_0_tag, 0, 16); +my $expect = '69df7d565d49fbaaeb0a067910f03dc22cd52bd0'; + +test_lei({tmpdir => $tmpdir}, sub { + lei_ok('blob', '69df7d5', '-I', $ibx->{inboxdir}); + is(sha1_hex("blob ".length($lei_out)."\0".$lei_out), + $expect, 'blob contents output'); + + # fallbacks + lei_ok('blob', $v1_0_0_tag, '-I', $ibx->{inboxdir}); + lei_ok('blob', $v1_0_0_tag_short, '-I', $ibx->{inboxdir}); +}); + my $git = PublicInbox::Git->new($git_dir); $ibx->{-repo_objs} = [ $git ]; my $res; @@ -38,7 +51,6 @@ $solver->solve($psgi_env, $log, '69df7d5', {}); ok($res, 'solved a blob!'); my $wt_git = $res->[0]; is(ref($wt_git), 'PublicInbox::Git', 'got a git object for the blob'); -my $expect = '69df7d565d49fbaaeb0a067910f03dc22cd52bd0'; is($res->[1], $expect, 'resolved blob to unabbreviated identifier'); is($res->[2], 'blob', 'type specified'); is($res->[3], 4405, 'size returned'); -- cgit v1.2.3-24-ge0c7