]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiMirror.pm
clone: --dry-run unconditionally runs show-ref
[public-inbox.git] / lib / PublicInbox / LeiMirror.pm
index d6d2c69eb90e981b57eeafbf7f8f8bf7576c769d..bfbfd8434a2f5d51c5051df64ecb269235c4de3b 100644 (file)
@@ -461,7 +461,11 @@ EOM
 }
 
 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): $!";
@@ -487,8 +491,10 @@ sub cmp_fp_do {
        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 {
@@ -675,6 +681,22 @@ sub atomic_write ($$$) {
        ft_rename($ft, "$dn/$bn", 0666);
 }
 
+sub run_next_puh {
+       my ($self) = @_;
+       my $puh = shift @{$self->{-puh_todo}} // return;
+       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_post_update_hooks {
+       my ($self) = @_;
+       my $puh = $self->{-puh} // return;
+       @{$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) = @_;
@@ -766,6 +788,7 @@ sub v1_done { # called via OnDestroy
        }
        eval { set_description($self) };
        warn $@ if $@;
+       run_post_update_hooks($self);
        return if ($self->{-is_epoch} ||
                $self->{lei}->{opt}->{'inbox-config'} ne 'always');
        write_makefile($dst, 1);
@@ -960,9 +983,13 @@ sub clone_all {
                        # 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
@@ -1154,6 +1181,13 @@ sub do_mirror { # via wq_io_do or public-inbox-clone
        $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};
+       if (defined(my $puh = $lei->{opt}->{'post-update-hook'})) {
+               require Text::ParseWords;
+               for (@$puh) {
+                       my $pfx = [ Text::ParseWords::shellwords($_) ];
+                       push @{$self->{-puh}}, $pfx;
+               }
+       }
        eval {
                my $ic = $lei->{opt}->{'inbox-config'} //= 'always';
                $ic =~ /\A(?:v1|v2|always|never)\z/s or die <<"";