]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-convert
convert: support converting with altid defined
[public-inbox.git] / script / public-inbox-convert
index f58bf27b68e26b6d524340531120799ce08a580e..2742be79fe1d47b4d0ef79c76ab95660a7e18d11 100755 (executable)
@@ -45,7 +45,6 @@ if (($old->{version} || 1) >= 2) {
        die "Only conversion from v1 inboxes is supported\n";
 }
 my $new = { %$old };
-delete $new->{altid}; # TODO: support altid for v2
 $new->{mainrepo} = abs_path($new_dir);
 $new->{version} = 2;
 $new = PublicInbox::InboxWritable->new($new);
@@ -61,6 +60,16 @@ $old->with_umask(sub {
                        "--file=$new->{mainrepo}/all.git/config",
                        'core.sharedRepository', $sr]);
        }
+       if (my $alt = $new->{altid}) {
+               require PublicInbox::AltId;
+               foreach my $i (0..$#$alt) {
+                       my $src = PublicInbox::AltId->new($old, $alt->[$i], 0);
+                       $src->mm_alt or next;
+                       my $dst = PublicInbox::AltId->new($new, $alt->[$i], 1);
+                       $dst = $dst->{filename};
+                       $src->mm_alt->{dbh}->sqlite_backup_to_file($dst);
+               }
+       }
 });
 my $state = '';
 my ($prev, $from);
@@ -71,6 +80,7 @@ my $im = $v2w->importer;
 my ($r, $w) = $im->gfi_start;
 my $h = '[0-9a-f]';
 my %D;
+my $last;
 while (<$rd>) {
        if ($_ eq "blob\n") {
                $state = 'blob';
@@ -90,13 +100,21 @@ while (<$rd>) {
                if (m{^M 100644 :(\d+) (${h}{2}/${h}{38})}o) {
                        my ($mark, $path) = ($1, $2);
                        $D{$path} = $mark;
+                       if ($last && $last ne 'm') {
+                               $w->print("D $last\n") or $im->wfail;
+                       }
                        $w->print("M 100644 :$mark m\n") or $im->wfail;
+                       $last = 'm';
                        next;
                }
                if (m{^D (${h}{2}/${h}{38})}o) {
                        my $mark = delete $D{$1};
                        defined $mark or die "undeleted path: $1\n";
-                       $w->print("M 100644 :$mark _/D\n") or $im->wfail;
+                       if ($last && $last ne 'd') {
+                               $w->print("D $last\n") or $im->wfail;
+                       }
+                       $w->print("M 100644 :$mark d\n") or $im->wfail;
+                       $last = 'd';
                        next;
                }
                if (m{^from (:\d+)}) {
@@ -116,6 +134,6 @@ my $mm = $old->mm;
 $mm->{dbh}->sqlite_backup_to_file("$new_dir/msgmap.sqlite3") if $mm;
 $v2w->done;
 if ($index) {
-       $v2w->reindex;
+       $v2w->index_sync;
        $v2w->done;
 }