]> Sergey Matveev's repositories - public-inbox.git/blobdiff - scripts/import_vger_from_mbox
v2writable: initial cut for repo-rotation
[public-inbox.git] / scripts / import_vger_from_mbox
index 9b3afc888b6fa38bec9e90992f8f0f790cbcf930..c45dc4ee1a4986f38d15d96ba9cfe2d706d00019 100644 (file)
@@ -3,25 +3,35 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
+use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
+use Date::Parse qw/str2time/;
 use Email::MIME;
 $Email::MIME::ContentType::STRICT_PARAMS = 0; # user input is imperfect
-use PublicInbox::Git;
-use PublicInbox::Import;
-my $usage = "usage: $0 NAME EMAIL <MBOX\n";
-chomp(my $git_dir = `git rev-parse --git-dir`);
-my $git = PublicInbox::Git->new($git_dir);
+use PublicInbox::V2Writable;
+my $usage = "usage: $0 NAME EMAIL DIR <MBOX\n";
+my $dry_run;
+my %opts = ( 'n|dry-run' => \$dry_run );
+GetOptions(%opts) or die $usage;
 my $name = shift or die $usage; # git
 my $email = shift or die $usage; # git@vger.kernel.org
-my $im = PublicInbox::Import->new($git, $name, $email);
+my $mainrepo = shift or die $usage; # /path/to/v2/repo
+my $v2ibx = {
+       mainrepo => $mainrepo,
+       name => $name,
+       -primary_address => $email,
+};
+my $im = $dry_run ? undef : PublicInbox::V2Writable->new($v2ibx, 1);
 binmode STDIN;
 my $msg = '';
 use PublicInbox::Filter::Vger;
 my $vger = PublicInbox::Filter::Vger->new;
+
 sub do_add ($$) {
        my ($im, $msg) = @_;
        $$msg =~ s/(\r?\n)+\z/$1/s;
        $msg = Email::MIME->new($$msg);
        $msg = $vger->scrub($msg);
+       return unless $im;
        $im->add($msg) or
                warn "duplicate: ",
                        $msg->header_obj->header_raw('Message-ID'), "\n";
@@ -44,4 +54,4 @@ while (defined(my $l = <STDIN>)) {
        $msg .= $l;
 }
 do_add($im, \$msg) if $msg;
-$im->done;
+$im->done if $im;