user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [RFC] index: ensure git dumb HTTP works on mirrors
Date: Wed, 1 May 2019 12:33:36 +0000
Message-ID: <20190501123336.ebnuo7lndgzciscp@dcvr> (raw)

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


                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190501123336.ebnuo7lndgzciscp@dcvr \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox