about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-11-28 05:31:51 +0000
committerEric Wong <e@80x24.org>2022-11-28 23:38:56 +0000
commit449f87dee7c811466aabdf2c5cb19db11c3e8e53 (patch)
treee23c703f876520956285146dc4529a822d5e1eb6 /lib/PublicInbox
parent550d283867c0f8a39207f368c49b5d7496045320 (diff)
downloadpublic-inbox-449f87dee7c811466aabdf2c5cb19db11c3e8e53.tar.gz
lei_mirror: drop git <1.8.5 support
Supporting git <1.8.5 via fetch on non-forkgroup repos would
make auto-GC dangerous, and I want to support auto-GC instead
of relying on the preciousObjects extension.

Since git 1.8.5 is 9 years old at this point, and grokmirror
(used by the only CentOS 7.x user I know of) already relies on
newer git, simplify our code and only fetch into forkgroups.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LeiMirror.pm41
1 files changed, 15 insertions, 26 deletions
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index 1138a82d..28fef6f9 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -21,7 +21,6 @@ use PublicInbox::OnDestroy;
 use Digest::SHA qw(sha256_hex);
 
 our $LIVE; # pid => callback
-my $update_ref_stdin = $ENV{GIT_CAN_UPDATE_REF_STDIN} // 1;
 
 sub _wq_done_wait { # dwaitpid callback (via wq_eof)
         my ($arg, $pid) = @_;
@@ -279,15 +278,6 @@ sub fetch_args ($$) {
         @cmd;
 }
 
-sub fgrp_update_old ($) { # for git <1.8.5
-        my ($fgrp) = @_;
-        my $cmd = [ @{$fgrp->{-torsocks}}, 'git', "--git-dir=$fgrp->{cur_dst}",
-                fetch_args($fgrp->{lei}, my $opt = {}) ];
-        $fgrp->{lei}->qerr("# @$cmd");
-        do_reap($fgrp);
-        $LIVE->{spawn($cmd, undef, $opt)} = [ \&reap_cmd, $fgrp, $cmd ];
-}
-
 sub upr { # feed `git update-ref --stdin -z' verbosely
         my ($lei, $w, $op, $ref, $oid) = @_;
         $lei->qerr("# $op $ref $oid") if $lei->{opt}->{verbose};
@@ -324,15 +314,9 @@ sub fgrp_update {
         while (my ($ref, $oid) = each %src) {
                 upr($lei, $w, 'create', $ref, $oid);
         }
-        if (close($w)) { # git >= 1.8.5
-                $LIVE->{$pid} = [ \&reap_cmd, $fgrp, $cmd ];
-                do_reap($fgrp);
-        } else { # git <1.8.5 w/o update-ref --stdin
-                warn "E: close(update-ref --stdin): $!\n";
-                $update_ref_stdin = 0;
-                waitpid($pid, 0) // die "waitpid(update-ref --stdin): $!";
-                fgrp_update_old($fgrp);
-        }
+        close($w) or warn "E: close(update-ref --stdin): $! (need git 1.8.5+)\n";
+        $LIVE->{$pid} = [ \&reap_cmd, $fgrp, $cmd ];
+        do_reap($fgrp);
 }
 
 sub pack_refs {
@@ -351,8 +335,6 @@ sub fgrp_fetched {
         my %opt = map { $_ => $fgrp->{lei}->{$_} } (0..2);
         pack_refs($fgrp, $fgrp->{-osdir}); # objstore refs always packed
 
-        $update_ref_stdin or return fgrp_update_old($fgrp);
-
         my $update_ref = PublicInbox::OnDestroy->new($$, \&fgrp_update, $fgrp);
 
         my $src = [ 'git', "--git-dir=$fgrp->{-osdir}", 'for-each-ref',
@@ -427,11 +409,18 @@ sub forkgroup_prep {
                         say $fh $l or die "say($f): $!";
                 }
                 close $fh or die "close($f): $!";
-                @cmd = ('git', "--git-dir=$self->{cur_dst}",
-                        qw(remote add --mirror=fetch origin), "$uri");
-                my $pid = spawn(\@cmd, undef, $opt);
-                waitpid($pid, 0) // die "waitpid(@cmd): $!";
-                die "E: @cmd: \$?=$?" if ($? && ($? >> 8) != 3);
+                $f = "$self->{cur_dst}/config";
+                open $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
+; only uncomment the following iff you detach from fork groups
+; [remote "origin"]
+;        url = $uri
+;        fetch = +refs/*:refs/*
+;        mirror = true
+EOM
+                close $fh or die "close($f): $!";
         }
         bless { %$self, -osdir => $dir, -remote => $rn }, __PACKAGE__;
 }