user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 1/2] v2writable: make remove return-compatible w/ Import::remove
Date: Mon, 24 Feb 2020 08:08:21 +0000
Message-ID: <20200224080823.16809-2-e@yhbt.net> (raw)
In-Reply-To: <20200224080823.16809-1-e@yhbt.net>

Import::remove is a documented interface, and the return
value of the V2Writable work-alike should try to be compatible
with what Import implements.
---
 lib/PublicInbox/V2Writable.pm | 23 +++++++++++++----------
 t/v2writable.t                |  7 +++++--
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index fc2f33f9..573a92aa 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -381,7 +381,7 @@ sub rewrite_internal ($$;$$$) {
 	}
 	my $over = $self->{over};
 	my $cids = content_ids($old_mime);
-	my $removed;
+	my @removed;
 	my $mids = mids($old_mime->header_obj);
 
 	# We avoid introducing new blobs into git since the raw content
@@ -391,7 +391,7 @@ sub rewrite_internal ($$;$$$) {
 	my $mark;
 
 	foreach my $mid (@$mids) {
-		my %gone; # num => [ smsg, raw ]
+		my %gone; # num => [ smsg, $mime, raw ]
 		my ($id, $prev);
 		while (my $smsg = $over->next_by_mid($mid, \$id, \$prev)) {
 			my $msg = get_blob($self, $smsg);
@@ -402,8 +402,7 @@ sub rewrite_internal ($$;$$$) {
 			my $orig = $$msg;
 			my $cur = PublicInbox::MIME->new($msg);
 			if (content_matches($cids, $cur)) {
-				$smsg->{mime} = $cur;
-				$gone{$smsg->{num}} = [ $smsg, \$orig ];
+				$gone{$smsg->{num}} = [ $smsg, $cur, \$orig ];
 			}
 		}
 		my $n = scalar keys %gone;
@@ -413,15 +412,16 @@ sub rewrite_internal ($$;$$$) {
 				join(',', sort keys %gone), "\n";
 		}
 		foreach my $num (keys %gone) {
-			my ($smsg, $orig) = @{$gone{$num}};
-			# $removed should only be set once assuming
+			my ($smsg, $mime, $orig) = @{$gone{$num}};
+			# @removed should only be set once assuming
 			# no bugs in our deduplication code:
-			$removed = $smsg;
+			@removed = (undef, $mime, $smsg);
 			my $oid = $smsg->{blob};
 			if ($replace_map) {
 				$replace_map->{$oid} = $sref;
 			} else {
 				($mark, undef) = $im->remove($orig, $cmt_msg);
+				$removed[0] = $mark;
 			}
 			$orig = undef;
 			if ($need_reindex) { # ->replace
@@ -441,15 +441,18 @@ sub rewrite_internal ($$;$$$) {
 		my $rewrites = _replace_oids($self, $new_mime, $replace_map);
 		return { rewrites => $rewrites, need_reindex => $need_reindex };
 	}
-	$removed;
+	defined($mark) ? @removed : undef;
 }
 
-# public
+# public (see PublicInbox::Import->remove), but note the 3rd element
+# (retval[2]) is not part of the stable API shared with Import->remove
 sub remove {
 	my ($self, $mime, $cmt_msg) = @_;
+	my @ret;
 	$self->{-inbox}->with_umask(sub {
-		rewrite_internal($self, $mime, $cmt_msg);
+		@ret = rewrite_internal($self, $mime, $cmt_msg);
 	});
+	defined($ret[0]) ? @ret : undef;
 }
 
 sub _replace ($$;$$) {
diff --git a/t/v2writable.t b/t/v2writable.t
index 77bd68d4..cdcfe4d0 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use Test::More;
 use PublicInbox::MIME;
-use PublicInbox::ContentId qw(content_digest);
+use PublicInbox::ContentId qw(content_digest content_id);
 use PublicInbox::TestCommon;
 use Cwd qw(abs_path);
 require_git(2.6);
@@ -206,7 +206,10 @@ EOF
 	my $before = $git0->qx(@log, qw(--pretty=raw --raw -r));
 	$im = PublicInbox::V2Writable->new($ibx, {nproc => 2});
 	is($im->{shards}, 1, 'detected single shard from previous');
-	my $smsg = $im->remove($mime, 'test removal');
+	my ($mark, $rm_mime, $smsg) = $im->remove($mime, 'test removal');
+	is(content_id($rm_mime), content_id($mime),
+			'removed object returned matches');
+	ok(defined($mark), 'mark set');
 	$im->done;
 	my @after = $git0->qx(@log, qw(--pretty=oneline));
 	my $tip = shift @after;

  reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-24  8:08 [PATCH 0/2] v2writable: reduce smsg->{mime} impact Eric Wong
2020-02-24  8:08 ` Eric Wong [this message]
2020-02-24  8:08 ` [PATCH 2/2] v2writable: lookup_content => content_exists Eric Wong
2020-02-24  8:08 ` [PATCH] " 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=20200224080823.16809-2-e@yhbt.net \
    --to=e@yhbt.net \
    --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

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git