- my $cmd = [ qw(git hash-object -w --stdin) ];
- my $env = { GIT_DIR => $binfoo };
- while (my ($label, $size) = each %bin) {
- pipe(my ($rout, $wout)) or die;
- pipe(my ($rin, $win)) or die;
- my $rdr = { 0 => $rin, 1 => $wout };
- my $pid = spawn($cmd , $env, $rdr);
- $wout = $rin = undef;
- print { $win } ("\0" x $size) or die;
- close $win or die;
- chomp($oid{$label} = <$rout>);
+ my $lk = bless { lock_path => $l }, 'PublicInbox::Lock';
+ my $acq = $lk->lock_for_scope;
+ my $stamp = "$binfoo/stamp";
+ if (open my $fh, '<', $stamp) {
+ %oid = map { chomp; split(/=/, $_) } (<$fh>);
+ } else {
+ PublicInbox::Import::init_bare($binfoo);
+ my $cmd = [ qw(git hash-object -w --stdin) ];
+ my $env = { GIT_DIR => $binfoo };
+ open my $fh, '>', "$stamp.$$" or BAIL_OUT;
+ while (my ($label, $size) = each %bin) {
+ pipe(my ($rin, $win)) or BAIL_OUT;
+ my $rout = popen_rd($cmd , $env, { 0 => $rin });
+ $rin = undef;
+ print { $win } ("\0" x $size) or BAIL_OUT;
+ close $win or BAIL_OUT;
+ chomp(my $x = <$rout>);
+ close $rout or BAIL_OUT "$?";
+ print $fh "$label=$x\n" or BAIL_OUT;
+ $oid{$label} = $x;
+ }
+ close $fh or BAIL_OUT;
+ rename("$stamp.$$", $stamp) or BAIL_OUT;