about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-11-28 05:31:16 +0000
committerEric Wong <e@80x24.org>2022-11-28 23:38:54 +0000
commit74fe3d0dc688202adc634cfc6a9e57f1aa28d85d (patch)
treea271f7a26e6bee2ba40e5ce193475b9775c85553
parentc89fbee4be1ab3e3f5544cda2d88ec7472aaadb2 (diff)
downloadpublic-inbox-74fe3d0dc688202adc634cfc6a9e57f1aa28d85d.tar.gz
This is mainly for coderepos, but sometimes public-inboxes
get shared via cgit/gitweb, too.
-rw-r--r--lib/PublicInbox/LeiMirror.pm28
-rw-r--r--t/www_listing.t2
2 files changed, 25 insertions, 5 deletions
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index d0bc7384..5e1b1c64 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -8,7 +8,7 @@ use v5.10.1;
 use parent qw(PublicInbox::IPC);
 use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
 use IO::Compress::Gzip qw(gzip $GzipError);
-use PublicInbox::Spawn qw(popen_rd spawn);
+use PublicInbox::Spawn qw(popen_rd spawn run_die);
 use File::Path ();
 use File::Temp ();
 use Fcntl qw(SEEK_SET O_CREAT O_EXCL O_WRONLY);
@@ -303,8 +303,8 @@ EOM
         $want
 }
 
-sub init_placeholder ($$) {
-        my ($src, $edst) = @_;
+sub init_placeholder ($$$) {
+        my ($src, $edst, $owner) = @_;
         PublicInbox::Import::init_bare($edst);
         my $f = "$edst/config";
         open my $fh, '>>', $f or die "open($f): $!";
@@ -318,6 +318,12 @@ sub init_placeholder ($$) {
 ; will not fetch updates for it unless write permission is added.
 ; Hint: chmod +w $edst
 EOM
+        if (defined($owner)) {
+                print $fh <<EOM or die "print($f): $!";
+[gitweb]
+        owner = $owner
+EOM
+        }
         close $fh or die "close:($f): $!";
 }
 
@@ -334,7 +340,11 @@ sub reap_clone { # async, called via SIGCHLD
 sub v1_done { # called via OnDestroy
         my ($self) = @_;
         _write_inbox_config($self);
-        write_makefile($self->{cur_dst} // $self->{dst}, 1);
+        my $dst = $self->{cur_dst} // $self->{dst};
+        if (defined(my $o = $self->{-ent} ? $self->{-ent}->{owner} : undef)) {
+                run_die([qw(git config -f), "$dst/config", 'gitweb.owner', $o]);
+        }
+        write_makefile($dst, 1);
         index_cloned_inbox($self, 1);
 }
 
@@ -346,6 +356,11 @@ sub v2_done { # called via OnDestroy
         my $mg = PublicInbox::MultiGit->new($dst, 'all.git', 'git');
         $mg->fill_alternates;
         for my $i ($mg->git_epochs) { $mg->epoch_cfg_set($i) }
+        my $edst_owner = delete($self->{-owner}) // [];
+        while (@$edst_owner) {
+                my ($edst, $o) = splice(@$edst_owner);
+                run_die [qw(git config -f), "$edst/config", 'gitweb.owner', $o];
+        }
         for my $edst (@{delete($self->{-read_only}) // []}) {
                 my @st = stat($edst) or die "stat($edst): $!";
                 chmod($st[2] & 0555, $edst) or die "chmod(a-w, $edst): $!";
@@ -384,10 +399,13 @@ failed to extract epoch number from $src
 
                 $1 + 0 == $nr or die "BUG: <$uri> miskeyed $1 != $nr";
                 $edst .= "/git/$nr.git";
+                $m->{$key} // die "BUG: `$key' not in manifest.js.gz";
                 if (!$want || $want->{$nr}) {
                         push @src_edst, $src, $edst;
+                        my $o = $m->{$key}->{owner};
+                        push(@{$task->{-owner}}, $edst, $o) if defined($o);
                 } else { # create a placeholder so users only need to chmod +w
-                        init_placeholder($src, $edst);
+                        init_placeholder($src, $edst, $m->{$key}->{owner});
                         push @{$task->{-read_only}}, $edst;
                         push @skip, $key;
                 }
diff --git a/t/www_listing.t b/t/www_listing.t
index e6bb1bda..c13d8f90 100644
--- a/t/www_listing.t
+++ b/t/www_listing.t
@@ -150,6 +150,8 @@ EOM
                 undef, $opt), 'clone w/include') or diag "clone_err=$clone_err";
         ok(-d "$tmpdir/incl/alt", 'alt cloned');
         ok(!-d "$tmpdir/incl/v2" && !-d "$tmpdir/incl/bare", 'only alt cloned');
+        is(xqx([qw(git config -f), "$tmpdir/incl/alt/config", 'gitweb.owner']),
+                "lorelei \xc4\x80\n", 'gitweb.owner set by -clone');
 
         undef $td;