X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-convert;h=68b0b31a41ff57b4371517b5efb62af6b4794c05;hb=4bb77753fbbc30ab396a1b01d70cf65b629b6276;hp=9bee5e7a323b437eaa0c6077458879a0b2464301;hpb=bc75e2ff649c4aab23320994e0d5bf96319a5595;p=public-inbox.git diff --git a/script/public-inbox-convert b/script/public-inbox-convert index 9bee5e7a..68b0b31a 100755 --- a/script/public-inbox-convert +++ b/script/public-inbox-convert @@ -4,11 +4,10 @@ use strict; use warnings; use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev); -use PublicInbox::MIME; use PublicInbox::InboxWritable; use PublicInbox::Config; use PublicInbox::V2Writable; -use PublicInbox::Import; +use PublicInbox::Git; use PublicInbox::Spawn qw(spawn); use Cwd 'abs_path'; use File::Copy 'cp'; # preserves permissions: @@ -20,8 +19,8 @@ my %opts = ( '--index!' => \$index, ); GetOptions(%opts) or die "bad command-line args\n$usage"; -my $old_dir = shift or die $usage; -my $new_dir = shift or die $usage; +my $old_dir = shift(@ARGV) or die $usage; +my $new_dir = shift(@ARGV) or die $usage; die "$new_dir exists\n" if -d $new_dir; die "$old_dir not a directory\n" unless -d $old_dir; my $config = eval { PublicInbox::Config->new }; @@ -43,7 +42,7 @@ unless ($old) { $old = PublicInbox::Inbox->new($old); } $old = PublicInbox::InboxWritable->new($old); -if (($old->{version} || 1) >= 2) { +if ($old->version >= 2) { die "Only conversion from v1 inboxes is supported\n"; } my $new = { %$old }; @@ -88,7 +87,6 @@ $clone may not be valid after migrating to v2, not copying } }); my $state = ''; -my ($prev, $from); my $head = $old->{ref_head} || 'HEAD'; my ($rd, $pid) = $old->git->popen(qw(fast-export --use-done-feature), $head); $v2w->idx_init; @@ -133,11 +131,6 @@ while (<$rd>) { $last = 'd'; next; } - if (m{^from (:[0-9]+)}) { - $prev = $from; - $from = $1; - # no next - } } last if $_ eq "done\n"; $w->print($_) or $im->wfail; @@ -146,10 +139,17 @@ $w = $r = undef; close $rd or die "close fast-export: $!\n"; waitpid($pid, 0) or die "waitpid failed: $!\n"; $? == 0 or die "fast-export failed: $?\n"; -my $mm = $old->mm; -$mm->{dbh}->sqlite_backup_to_file("$new_dir/msgmap.sqlite3") if $mm; $v2w->done; -if ($index) { - $v2w->index_sync; - $v2w->done; +if (my $mm = $old->mm) { + $old->cleanup; + $mm->{dbh}->sqlite_backup_to_file("$new_dir/msgmap.sqlite3"); + + # we want to trigger a reindex, not a from scratch index if + # we're reusing the msgmap from an existing v1 installation. + $v2w->idx_init; + my $epoch0 = PublicInbox::Git->new($v2w->git_init(0)); + chop(my $cmt = $epoch0->qx(qw(rev-parse --verify), $head)); + $v2w->last_epoch_commit(0, $cmt); } +$v2w->index_sync({reindex => 1}) if $index; +$v2w->done;