our $LIVE; # pid => callback
our $FGRP_TODO; # objstore -> [ fgrp mirror objects ]
our $TODO; # reference => [ non-fgrp mirror objects ]
+our @PUH; # post-update hooks
sub keep_going ($) {
$LIVE && (!$_[0]->{lei}->{child_error} ||
my $cmd = [ 'git', "--git-dir=$fgrp->{cur_dst}",
qw(update-ref --stdin -z) ];
my $lei = $fgrp->{lei};
- my $pack = PublicInbox::OnDestroy->new($$, \&pack_dst, $fgrp);
+ my $pack = PublicInbox::OnDestroy->new($$, \&satellite_done, $fgrp);
start_cmd($fgrp, $cmd, { 0 => $r, 2 => $lei->{2} }, $pack);
close $r or die "close(r): $!";
return if $fgrp->{dry_run};
close($w) or warn "E: close(update-ref --stdin): $! (need git 1.8.5+)\n";
}
-sub pack_dst { # packs lightweight satellite repos
+sub satellite_done {
my ($fgrp) = @_;
pack_refs($fgrp, $fgrp->{cur_dst});
+ run_puh($fgrp);
}
sub pack_refs {
my $key = $self->{-key} // die 'BUG: no -key';
my $rn = substr(sha256_hex($key), 0, 16);
if (!-d $self->{cur_dst} && !$self->{dry_run}) {
- my $alt = File::Spec->rel2abs("$dir/objects");
PublicInbox::Import::init_bare($self->{cur_dst});
- my $o = "$self->{cur_dst}/objects";
- my $f = "$o/info/alternates";
- my $l = File::Spec->abs2rel($alt, File::Spec->rel2abs($o));
- open my $fh, '+>>', $f or die "open($f): $!";
- seek($fh, SEEK_SET, 0) or die "seek($f): $!";
- chomp(my @cur = <$fh>);
- if (!grep(/\A\Q$l\E\z/, @cur)) {
- say $fh $l or die "say($f): $!";
- }
- close $fh or die "close($f): $!";
- $f = "$self->{cur_dst}/config";
- open $fh, '+>>', $f or die "open:($f): $!";
+ my $f = "$self->{cur_dst}/config";
+ open my $fh, '+>>', $f or die "open:($f): $!";
print $fh <<EOM or die "print($f): $!";
; rely on the "$rn" remote in the
; $fg fork group for fetches
EOM
close $fh or die "close($f): $!";
}
+ if (!$self->{dry_run}) {
+ my $alt = File::Spec->rel2abs("$dir/objects");
+ my $o = "$self->{cur_dst}/objects";
+ my $f = "$o/info/alternates";
+ my $l = File::Spec->abs2rel($alt, File::Spec->rel2abs($o));
+ open my $fh, '+>>', $f or die "open($f): $!";
+ seek($fh, SEEK_SET, 0) or die "seek($f): $!";
+ chomp(my @cur = <$fh>);
+ if (!grep(/\A\Q$l\E\z/, @cur)) {
+ say $fh $l or die "say($f): $!";
+ }
+ close $fh or die "close($f): $!";
+ }
bless {
%$self, -osdir => $dir, -remote => $rn, -uri => $uri
}, __PACKAGE__;
}
sub fp_done {
- my ($self, $cb, @arg) = @_;
+ my ($self, $cmd, $cb, @arg) = @_;
+ if ($?) {
+ $self->{lei}->err("@$cmd failed (\$?=$?) (non-fatal)");
+ $? = 0; # don't let it influence normal exit
+ }
return if !keep_going($self);
my $fh = delete $self->{-show_ref} // die 'BUG: no show-ref output';
seek($fh, SEEK_SET, 0) or die "seek(show_ref): $!";
my $opt = { 2 => $self->{lei}->{2} };
open($opt->{1}, '+>', undef) or die "open(tmp): $!";
$self->{-show_ref} = $opt->{1};
- my $done = PublicInbox::OnDestroy->new($$, \&fp_done, $self, $cb, @arg);
- start_cmd($self, $cmd, $opt, $done);
+ do_reap($self);
+ $self->{lei}->qerr("# @$cmd");
+ $LIVE->{spawn($cmd, undef, $opt)} = [ \&fp_done, $self, $cmd,
+ $cb, @arg ];
}
sub resume_fetch {
my $cmd = [ @{$self->{-torsocks}}, @git,
fetch_args($self->{lei}, $opt), $rn ];
push @$cmd, '-P' if $self->{lei}->{prune}; # --prune-tags implied
- start_cmd($self, $cmd, $opt, $fini);
+ my $run_puh = PublicInbox::OnDestroy->new($$, \&run_puh, $self, $fini);
+ start_cmd($self, $cmd, $opt, $run_puh);
}
sub fgrp_enqueue {
"$self->{dst}$ref";
}
}
- start_cmd($self, $cmd, $opt, $fini);
+ start_cmd($self, $cmd, $opt, PublicInbox::OnDestroy->new($$,
+ \&run_puh, $self, $fini));
}
if (!$self->{-is_epoch} && $lei->{opt}->{'inbox-config'} =~
/\A(?:always|v1)\z/s) {
ft_rename($ft, "$dn/$bn", 0666);
}
+sub run_next_puh {
+ my ($self) = @_;
+ my $puh = shift @{$self->{-puh_todo}} // return delete($self->{-fini});
+ my $fini = PublicInbox::OnDestroy->new($$, \&run_next_puh, $self);
+ my $cmd = [ @$puh, ($self->{cur_dst} // $self->{dst}) ];
+ my $opt = +{ map { $_ => $self->{lei}->{$_} } (0..2) };
+ start_cmd($self, $cmd, undef, $opt, $fini);
+}
+
+sub run_puh {
+ my ($self, $fini) = @_;
+ $self->{-fini} = $fini;
+ @{$self->{-puh_todo}} = @PUH;
+ run_next_puh($self);
+}
+
# modifies the to-be-written manifest entry, and sets values from it, too
sub update_ent {
my ($self) = @_;
}
if (my $symlinks = $self->{-ent}->{symlinks}) {
my $top = File::Spec->rel2abs($self->{dst});
+ push @{$self->{-new_symlinks}}, @$symlinks;
for my $p (@$symlinks) {
my $ln = "$top/$p";
$ln =~ tr!/!/!s;
# resolve multi-level references
while ($m && defined($nxt = $m->{$x}->{reference})) {
exists($todo->{$nxt}) or last;
- die <<EOM if ++$nr > 1000;
-E: dependency loop detected (`$x' => `$nxt')
+ if (++$nr > 1000) {
+ $m->{$x}->{reference} = undef;
+ $m->{$nxt}->{reference} = undef;
+ warn <<EOM
+E: dependency loop detected (`$x' => `$nxt'), breaking
EOM
+ }
$x = $nxt;
}
my $y = delete $todo->{$x} // next; # already done
$new{substr($_, 1)} = 1 for keys %$m; # drop leading '/'
my @list = sort keys %new;
my @remote = grep { !defined($new{$_}) } @list;
+ my %lnk = map { substr($_, 1) => undef } @{$self->{-new_symlinks}};
+ @remote = grep { !exists($lnk{$_}) } @remote;
warn <<EOM if @remote;
The following local repositories are ignored/gone from $self->{src}:
}
local $self->{chg} = {};
local $self->{-local_manifest} = load_current_manifest($self);
+ local $self->{-new_symlinks} = [];
my ($path_pfx, $n, $multi) = multi_inbox($self, \$path, $m);
return $lei->child_error(1, $multi) if !ref($multi);
my $v2 = delete $multi->{v2};
$self->{dry_run} = 1 if $lei->{opt}->{'dry-run'};
umask($lei->{client_umask}) if defined $lei->{client_umask};
$self->{-initial_clone} = 1 if !-d $self->{dst};
+ local @PUH;
+ if (defined(my $puh = $lei->{opt}->{'post-update-hook'})) {
+ require Text::ParseWords;
+ @PUH = map { [ Text::ParseWords::shellwords($_) ] } @$puh;
+ }
eval {
my $ic = $lei->{opt}->{'inbox-config'} //= 'always';
$ic =~ /\A(?:v1|v2|always|never)\z/s or die <<"";