]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Import.pm
v1writable: new wrapper which is closer to v2writable
[public-inbox.git] / lib / PublicInbox / Import.pm
index fd4255cf867d6ca1a40dcce1fe19265f536803e6..12abf39995ffbcd1677f94be807828449e06c96c 100644 (file)
@@ -18,19 +18,22 @@ use PublicInbox::MDA;
 use POSIX qw(strftime);
 
 sub new {
+       # we can't change arg order, this is documented in POD
+       # and external projects may rely on it:
        my ($class, $git, $name, $email, $ibx) = @_;
        my $ref = 'refs/heads/master';
        if ($ibx) {
                $ref = $ibx->{ref_head} || 'refs/heads/master';
                $name ||= $ibx->{name};
                $email ||= $ibx->{-primary_address};
+               $git ||= $ibx->git;
        }
        bless {
                git => $git,
                ident => "$name <$email>",
                mark => 1,
                ref => $ref,
-               inbox => $ibx,
+               -inbox => $ibx,
                path_type => '2/38', # or 'v2'
                lock_path => "$git->{git_dir}/ssoma.lock", # v2 changes this
                bytes_added => 0,
@@ -178,8 +181,8 @@ sub _update_git_info ($$) {
        run_die([@cmd, 'update-server-info'], undef);
        ($self->{path_type} eq '2/38') and eval {
                require PublicInbox::SearchIdx;
-               my $inbox = $self->{inbox} || $git_dir;
-               my $s = PublicInbox::SearchIdx->new($inbox);
+               my $ibx = $self->{-inbox} || $git_dir;
+               my $s = PublicInbox::SearchIdx->new($ibx);
                $s->index_sync({ ref => $self->{ref} });
        };
        eval { run_die([@cmd, qw(gc --auto)], undef) } if $do_gc;
@@ -433,6 +436,16 @@ sub run_die ($;$$) {
        $? == 0 or die join(' ', @$cmd) . " failed: $?\n";
 }
 
+sub init_bare {
+       my ($dir) = @_;
+       my @cmd = (qw(git init --bare -q), $dir);
+       run_die(\@cmd);
+       # set a reasonable default:
+       @cmd = (qw/git config/, "--file=$dir/config",
+               'repack.writeBitmaps', 'true');
+       run_die(\@cmd);
+}
+
 sub done {
        my ($self) = @_;
        my $w = delete $self->{out} or return;
@@ -495,7 +508,7 @@ sub purge_oids {
        my $old = $self->{'ref'};
        my $git = $self->{git};
        my @export = (qw(fast-export --no-data --use-done-feature), $old);
-       my ($rd, $pid) = $git->popen(@export);
+       my $rd = $git->popen(@export);
        my ($r, $w) = $self->gfi_start;
        my @buf;
        my $npurge = 0;
@@ -550,6 +563,7 @@ sub purge_oids {
                        push @buf, $_;
                }
        }
+       close $rd or die "close fast-export failed: $?";
        if (@buf) {
                $w->print(@buf) or wfail;
        }
@@ -585,7 +599,7 @@ __END__
 
 =head1 NAME
 
-PublicInbox::Import - message importer for public-inbox
+PublicInbox::Import - message importer for public-inbox v1 inboxes
 
 =head1 VERSION