+ if (defined($ent->{owner})) {
+ print $fh <<EOM or die "print($f): $!";
+[gitweb]
+ owner = $ent->{owner}
+EOM
+ }
+ close $fh or die "close($f): $!";
+ if (defined $ent->{head}) {
+ $f = "$edst/HEAD";
+ open $fh, '>', $f or die "open($f): $!";
+ print $fh $ent->{head}, "\n" or die "print($f): $!";
+ close $fh or die "close($f): $!";
+ }
+}
+
+sub reap_clone { # async, called via SIGCHLD
+ my ($self, $cmd) = @_;
+ my $cerr = $?;
+ $? = 0; # don't let it influence normal exit
+ if ($cerr) {
+ kill('TERM', keys %$LIVE);
+ $self->{lei}->child_error($cerr, "@$cmd failed");
+ }
+}
+
+sub v1_done { # called via OnDestroy
+ my ($self) = @_;
+ return if $self->{dry_run} || !$LIVE;
+ _write_inbox_config($self);
+ my $dst = $self->{cur_dst} // $self->{dst};
+ if (defined(my $o = $self->{-ent} ? $self->{-ent}->{owner} : undef)) {
+ run_die([qw(git config -f), "$dst/config", 'gitweb.owner', $o]);
+ }
+ my $o = "$dst/objects";
+ if (open(my $fh, '<', "$o/info/alternates")) {
+ chomp(my @l = <$fh>);
+ for (@l) { $_ = File::Spec->abs2rel($_, $o)."\n" }
+ my $f = File::Temp->new(TEMPLATE => '.XXXX', DIR => "$o/info");
+ print $f @l;
+ $f->flush or die "flush($f): $!";
+ rename($f->filename, "$o/info/alternates") or
+ die "rename($f, $o/info/alternates): $!";
+ $f->unlink_on_destroy(0);
+ }
+ write_makefile($dst, 1);
+ index_cloned_inbox($self, 1);
+}
+
+sub v2_done { # called via OnDestroy
+ my ($self) = @_;
+ return if $self->{dry_run} || !$LIVE;
+ _write_inbox_config($self);
+ require PublicInbox::MultiGit;
+ my $dst = $self->{cur_dst} // $self->{dst};
+ my $mg = PublicInbox::MultiGit->new($dst, 'all.git', 'git');
+ $mg->fill_alternates;
+ for my $i ($mg->git_epochs) { $mg->epoch_cfg_set($i) }
+ my $edst_owner = delete($self->{-owner}) // [];
+ while (@$edst_owner) {
+ my ($edst, $o) = splice(@$edst_owner);
+ run_die [qw(git config -f), "$edst/config", 'gitweb.owner', $o];
+ }
+ for my $edst (@{delete($self->{-read_only}) // []}) {
+ my @st = stat($edst) or die "stat($edst): $!";
+ chmod($st[2] & 0555, $edst) or die "chmod(a-w, $edst): $!";
+ }
+ write_makefile($dst, 2);
+ delete $self->{-locked} // die "BUG: $dst not locked"; # unlock
+ index_cloned_inbox($self, 2);
+}
+
+sub reap_live {
+ my $pid = waitpid(-1, 0) // die "waitpid(-1): $!";
+ if (my $x = delete $LIVE->{$pid}) {
+ my $cb = shift @$x;
+ $cb->(@$x);
+ } else {
+ warn "reaped unknown PID=$pid ($?)\n";
+ }