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:44 +0000
committerEric Wong <e@80x24.org>2022-11-28 23:38:56 +0000
commit195e26acf93f5f13bf3dd33c0370b4fb7426377b (patch)
treecf9fead2d3c4a545686f9f9cc2b73ac2f8db5bc6 /lib/PublicInbox
parentf75f1c1033ed0474e22247a41a517cc8b46aed05 (diff)
downloadpublic-inbox-195e26acf93f5f13bf3dd33c0370b4fb7426377b.tar.gz
lei_mirror: ensure git <1.8.5 fallback can use torsocks
Since we fall back to `git fetch' on versions of git without
`git update-ref --stdin' support, we must also support
torsocks use on Tor .onion URLs
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LeiMirror.pm15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index 163f45ee..6efe23fa 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -283,7 +283,7 @@ sub fetch_args ($$) {
 
 sub fgrp_update_old ($) { # for git <1.8.5
         my ($fgrp) = @_;
-        my $cmd = [ 'git', "--git-dir=$fgrp->{cur_dst}",
+        my $cmd = [ @{$fgrp->{-torsocks}}, 'git', "--git-dir=$fgrp->{cur_dst}",
                 fetch_args($fgrp->{lei}, my $opt = {}) ];
         $fgrp->{lei}->qerr("# @$cmd");
         do_reap($fgrp);
@@ -370,8 +370,8 @@ sub fgrp_fetched {
 }
 
 sub fgrp_fetch {
-        my ($fgrp, $pfx, $fini) = @_;
-        my $cmd = [ @$pfx, 'git', "--git-dir=$fgrp->{-osdir}",
+        my ($fgrp, $fini) = @_;
+        my $cmd = [ @{$fgrp->{-torsocks}}, 'git', "--git-dir=$fgrp->{-osdir}",
                         fetch_args($fgrp->{lei}, my $opt = {}),
                         $fgrp->{-remote} ];
         $fgrp->{-fini} = $fini;
@@ -436,10 +436,11 @@ sub clone_v1 {
         my $uri = URI->new($self->{cur_src} // $self->{src});
         defined($lei->{opt}->{epoch}) and
                 die "$uri is a v1 inbox, --epoch is not supported\n";
-        my $pfx = $curl->torsocks($lei, $uri) or return;
+        $self->{-torsocks} //= $curl->torsocks($lei, $uri) or return;
         my $dst = $self->{cur_dst} // $self->{dst};
         my $fini = PublicInbox::OnDestroy->new($$, \&v1_done, $self);
-        my $cmd = [ @$pfx, clone_cmd($lei, my $opt = {}), "$uri", $dst ];
+        my $cmd = [ @{$self->{-torsocks}}, clone_cmd($lei, my $opt = {}),
+                "$uri", $dst ];
         my $fgrp = forkgroup_prep($self, $uri);
         if (!defined($fgrp) && defined($self->{-ent})) {
                 if (defined(my $ref = $self->{-ent}->{reference})) {
@@ -447,7 +448,7 @@ sub clone_v1 {
                                 push @$cmd, '--reference', "$self->{dst}$ref";
                 }
         }
-        $fgrp ? fgrp_fetch($fgrp, $pfx, $fini) :
+        $fgrp ? fgrp_fetch($fgrp, $fini) :
                 start_clone($self, $cmd, $opt, $fini);
 
         if (!$self->{-is_epoch} && $lei->{opt}->{'inbox-config'} =~
@@ -604,7 +605,7 @@ sub clone_v2_prep ($$;$) {
         my $lei = $self->{lei};
         my $curl = $self->{curl} //= PublicInbox::LeiCurl->new($lei) or return;
         my $first_uri = (map { $_->[0] } values %$v2_epochs)[0];
-        my $pfx = $curl->torsocks($lei, $first_uri) or return;
+        $self->{-torsocks} //= $curl->torsocks($lei, $first_uri) or return;
         my $dst = $self->{cur_dst} // $self->{dst};
         my $want = parse_epochs($lei->{opt}->{epoch}, $v2_epochs);
         my $task = $m ? bless { %$self }, __PACKAGE__ : $self;