X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FFetch.pm;h=3b6aa389f383405981a17c047d8a9bcaddddfedf;hb=d922fc44d1afb5e4400f2606c475e42aee087c24;hp=5ada1f49e4dc28ba39e2c0278208869575e4456a;hpb=55c8753c483d697fa0574b45ae77dec40509bb7f;p=public-inbox.git diff --git a/lib/PublicInbox/Fetch.pm b/lib/PublicInbox/Fetch.pm index 5ada1f49..3b6aa389 100644 --- a/lib/PublicInbox/Fetch.pm +++ b/lib/PublicInbox/Fetch.pm @@ -31,13 +31,32 @@ sub fetch_args ($$) { } sub remote_url ($$) { - my ($lei, $dir) = @_; # TODO: support non-"origin"? - my $cmd = [ qw(git config remote.origin.url) ]; - my $fh = popen_rd($cmd, undef, { -C => $dir, 2 => $lei->{2} }); - my $url = <$fh>; - close $fh or return; - $url =~ s!/*\n!!s; - $url; + my ($lei, $dir) = @_; + my $rn = $lei->{opt}->{'try-remote'} // [ 'origin', '_grokmirror' ]; + for my $r (@$rn) { + my $cmd = [ qw(git config), "remote.$r.url" ]; + my $fh = popen_rd($cmd, undef, { -C => $dir, 2 => $lei->{2} }); + my $url = <$fh>; + close $fh or next; + $url =~ s!/*\n!!s; + return $url; + } + undef +} + +# PSGI mount prefixes and manifest.js.gz prefixes don't always align... +# TODO: remove, handle multi-inbox fetch +sub deduce_epochs ($$) { + my ($m, $path) = @_; + my ($v1_ent, @v2_epochs); + my $path_pfx = ''; + $path =~ s!/+\z!!; + do { + $v1_ent = $m->{$path}; + @v2_epochs = grep(m!\A\Q$path\E/git/[0-9]+\.git\z!, keys %$m); + } while (!defined($v1_ent) && !@v2_epochs && + $path =~ s!\A(/[^/]+)/!/! and $path_pfx .= $1); + ($path_pfx, $v1_ent ? $path : undef, @v2_epochs); } sub do_manifest ($$$) { @@ -52,7 +71,7 @@ sub do_manifest ($$$) { $m0 = eval { PublicInbox::LeiMirror::decode_manifest($fh, $mf, $mf) }; - $lei->err($@) if $@; + warn($@) if $@; } my ($bn) = ($fn =~ m!/([^/]+)\z!); my $curl_cmd = $lei->{curl}->for_uri($lei, $muri, qw(-R -o), $bn); @@ -84,7 +103,7 @@ sub do_manifest ($$$) { return; } my (undef, $v1_path, @v2_epochs) = - PublicInbox::LeiMirror::deduce_epochs($mdiff, $ibx_uri->path); + deduce_epochs($mdiff, $ibx_uri->path); [ 200, $muri, $v1_path, \@v2_epochs, $ft, $mf, $m1 ]; } @@ -110,7 +129,7 @@ sub do_fetch { # main entry point my ($ibx_uri, @git_dir, @epochs, $mg, @new_epoch, $skip); if ($ibx_ver == 1) { my $url = remote_url($lei, $dir) // - die "E: $dir missing remote.origin.url\n"; + die "E: $dir missing remote.*.url\n"; $ibx_uri = URI->new($url); } else { # v2: require PublicInbox::MultiGit; @@ -128,7 +147,7 @@ sub do_fetch { # main entry point $git_url = $url; $epoch = $nr; } else { - warn "W: $edir missing remote.origin.url\n"; + warn "W: $edir missing remote.*.url\n"; my $pid = spawn([qw(git config -l)], undef, { 1 => $lei->{2}, 2 => $lei->{2} }); waitpid($pid, 0); @@ -214,13 +233,14 @@ EOM } for my $i (@new_epoch) { $mg->epoch_cfg_set($i) } if ($ft) { - my $fn = $ft->filename; if ($mculled) { my $json = PublicInbox::Config->json->encode($m1); + my $fn = $ft->filename; + my $mtime = (stat($fn))[9]; gzip(\$json => $fn) or die "gzip: $GzipError"; + utime($mtime, $mtime, $fn) or die "utime(..., $fn): $!"; } - rename($fn, $mf) or die "E: rename($fn, $mf): $!\n"; - $ft->unlink_on_destroy(0); + PublicInbox::LeiMirror::ft_rename($ft, $mf, 0666); } $lei->child_error($xit << 8) if $fp2 && $xit; }