From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id BBE181F453; Wed, 1 May 2019 12:33:36 +0000 (UTC) Date: Wed, 1 May 2019 12:33:36 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [RFC] index: ensure git dumb HTTP works on mirrors Message-ID: <20190501123336.ebnuo7lndgzciscp@dcvr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline List-Id: Since our -mda and -watch deliveries run update-server-info to support dumb HTTP, ensure mirrors using public-inbox-index also support dumb HTTP. post-update hooks aren't enabled by default on mirrors, but if they are, the worst case is we needlessly update the timestamp of the $GIT_DIR/info/refs file. In v1, we must explicitly tell index_sync to update; since the API was designed around indexing being optional. In v2, index_sync is only used by the -index tool on mirrors. --- I'm pretty sure the minor timestamp descrepancy and extra writes iff an existing post-update hook is enabled would not be a big deal. Perhaps update-server-info could be idempotent and not perform unnecessary writes in the future. lib/PublicInbox/SearchIdx.pm | 6 ++++++ lib/PublicInbox/V2Writable.pm | 9 ++++++++- script/public-inbox-index | 2 +- t/convert-compact.t | 9 +++++++-- t/v2mirror.t | 3 +++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index db0495b..6f98cf2 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -519,6 +519,7 @@ sub do_cat_mail { sub index_sync { my ($self, $opts) = @_; + $self->{server_info} = $opts->{server_info}; $self->{-inbox}->with_umask(sub { $self->_index_sync($opts) }) } @@ -573,6 +574,11 @@ sub read_log { $del_cb->($self, $mime); } $batch_cb->($latest, $newest); + if (defined $latest && $self->{server_info}) { + require PublicInbox::Import; + my @git = ('git', "--git-dir=$git->{git_dir}"); + PublicInbox::Import::run_die([@git, 'update-server-info']); + } } sub _msgmap_init { diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 6829a34..b213d1d 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -960,7 +960,14 @@ sub index_sync { } $fh = undef; delete $self->{reindex_pipe}; - $self->update_last_commit($git, $i, $cmt) if defined $cmt; + if (defined $cmt) { + $self->update_last_commit($git, $i, $cmt); + $self->{-inbox}->with_umask(sub { + PublicInbox::Import::run_die([ + 'git', "--git-dir=$git_dir", + 'update-server-info' ]); + }); + } } # unindex is required for leftovers if "deletes" affect messages diff --git a/script/public-inbox-index b/script/public-inbox-index index 5adb6e7..f1a105a 100755 --- a/script/public-inbox-index +++ b/script/public-inbox-index @@ -88,6 +88,6 @@ sub index_dir { $v2w->index_sync({ reindex => $reindex, prune => $prune }); } else { my $s = PublicInbox::SearchIdx->new($repo, 1); - $s->index_sync({ reindex => $reindex }); + $s->index_sync({ reindex => $reindex, server_info => 1 }); } } diff --git a/t/convert-compact.t b/t/convert-compact.t index 491486d..6c22b32 100644 --- a/t/convert-compact.t +++ b/t/convert-compact.t @@ -98,10 +98,15 @@ is(((stat("$tmpdir/v2/msgmap.sqlite3"))[2]) & 07777, 0644, @xdir = (glob("$tmpdir/v2/git/*.git/objects/*/*"), glob("$tmpdir/v2/git/*.git/objects/pack/*")); +my $msg = 'sharedRepository respected after v2 compact'; foreach (@xdir) { my @st = stat($_); - is($st[2] & 07777, -f _ ? 0444 : 0755, - 'sharedRepository respected after v2 compact'); + my $mode = $st[2] & 07777; + if ($_ =~ m!/objects/info/packs\z!) { + is(-f _ && $mode, 0644, $msg); + } else { + is($mode, -f _ ? 0444 : 0755, $msg); + } } my $msgs = $ibx->recent({limit => 1000}); is($msgs->[0]->{mid}, 'a-mid@b', 'message exists in history'); diff --git a/t/v2mirror.t b/t/v2mirror.t index ef9a540..694604b 100644 --- a/t/v2mirror.t +++ b/t/v2mirror.t @@ -90,6 +90,9 @@ foreach my $i (0..$epoch_max) { 'alt@example.com'); is(system(@cmd), 0, 'initialized public-inbox -V2'); is(system("$script-index", "$tmpdir/m"), 0, 'indexed'); +foreach my $i (0..$epoch_max) { + ok(-r "$tmpdir/m/git/$i.git/info/refs", "#$i info/refs exists"); +} my $mibx = { mainrepo => "$tmpdir/m", address => 'alt@example.com' }; $mibx = PublicInbox::Inbox->new($mibx); -- EW