]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiMirror.pm
lei_mirror: show non-ASCII owner properly w/ --verbose
[public-inbox.git] / lib / PublicInbox / LeiMirror.pm
index db249eceff64bc759b619ddb4f9c5e6a9cf1f180..afe12bb30dd719e545224b348575ff52b82b3f92 100644 (file)
@@ -16,9 +16,10 @@ use Carp qw(croak);
 use URI;
 use PublicInbox::Config;
 use PublicInbox::Inbox;
+use PublicInbox::Git;
 use PublicInbox::LeiCurl;
 use PublicInbox::OnDestroy;
-use Digest::SHA qw(sha256_hex sha1_hex);
+use PublicInbox::SHA qw(sha256_hex sha1_hex);
 use POSIX qw(strftime);
 
 our $LIVE; # pid => callback
@@ -31,9 +32,8 @@ sub keep_going ($) {
                $_[0]->{lei}->{opt}->{'keep-going'});
 }
 
-sub _wq_done_wait { # dwaitpid callback (via wq_eof)
-       my ($arg, $pid) = @_;
-       my ($mrr, $lei) = @$arg;
+sub _wq_done_wait { # awaitpid cb (via wq_eof)
+       my ($pid, $mrr, $lei) = @_;
        if ($?) {
                $lei->child_error($?);
        } elsif (!$lei->{child_error}) {
@@ -236,7 +236,7 @@ sub index_cloned_inbox {
                        my ($k) = ($sw =~ /\A([\w-]+)/);
                        $opt->{$k} = $lei->{opt}->{$k};
                }
-               # force synchronous dwaitpid for v2:
+               # force synchronous awaitpid for v2:
                local $PublicInbox::DS::in_loop = 0;
                my $cfg = PublicInbox::Config->new(undef, $lei->{2});
                my $env = PublicInbox::Admin::index_prepare($opt, $cfg);
@@ -259,7 +259,8 @@ sub run_reap {
 sub start_cmd {
        my ($self, $cmd, $opt, $fini) = @_;
        do_reap($self);
-       $self->{lei}->qerr("# @$cmd");
+       utf8::decode(my $msg = "# @$cmd");
+       $self->{lei}->qerr($msg);
        return if $self->{dry_run};
        $LIVE->{spawn($cmd, undef, $opt)} = [ \&reap_cmd, $self, $cmd, $fini ]
 }
@@ -276,6 +277,8 @@ sub fetch_args ($$) {
                        ($lei->{opt}->{jobs} // 1) > 1;
        push @cmd, '-v' if $lei->{opt}->{verbose};
        push(@cmd, '-p') if $lei->{opt}->{prune};
+       PublicInbox::Git::version() >= ((2 << 24) | (29 << 16)) and
+               push(@cmd, '--no-write-fetch-head');
        @cmd;
 }
 
@@ -505,12 +508,9 @@ sub resume_fetch {
        my $dst = $self->{cur_dst} // $self->{dst};
        my @git = ('git', "--git-dir=$dst");
        my $opt = { 2 => $self->{lei}->{2} };
-       my $rn = 'origin'; # configurable?
+       my $rn = 'random'.int(rand(1 << 30));
        for ("url=$uri", "fetch=+refs/*:refs/*", 'mirror=true') {
-               my @kv = split(/=/, $_, 2);
-               $kv[0] = "remote.$rn.$kv[0]";
-               next if $self->{dry_run};
-               run_die([@git, 'config', @kv], undef, $opt);
+               push @git, '-c', "remote.$rn.$_";
        }
        my $cmd = [ @{$self->{-torsocks}}, @git,
                        fetch_args($self->{lei}, $opt), $rn ];
@@ -1056,7 +1056,8 @@ EOM
 
        my (undef, $dn, $bn) = File::Spec->splitpath($f);
        $self->{chg}->{nr_chg} += scalar(@remote) + scalar(@local);
-       atomic_write($dn, $bn, join("\n", @list, ''));
+       my $new = join("\n", @list, '');
+       atomic_write($dn, $bn, $new) if $new ne $old;
 }
 
 # FIXME: this gets confused by single inbox instance w/ global manifest.js.gz