From 74fe3d0dc688202adc634cfc6a9e57f1aa28d85d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 28 Nov 2022 05:31:16 +0000 Subject: [PATCH] lei_mirror: set gitweb.owner from manifest This is mainly for coderepos, but sometimes public-inboxes get shared via cgit/gitweb, too. --- lib/PublicInbox/LeiMirror.pm | 28 +++++++++++++++++++++++----- t/www_listing.t | 2 ++ 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 <{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; -- 2.44.0