user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] import: run git-update-server-info when done
Date: Thu, 28 Apr 2016 02:00:33 +0000	[thread overview]
Message-ID: <20160428020033.6048-3-e@80x24.org> (raw)
In-Reply-To: <20160428020033.6048-1-e@80x24.org>

We should update $GIT_DIR/info/refs for dumb HTTP clients
whenever we make changes to the repository.  The best place
to update is immediately after making commits.

This fixes a bug where public-inbox-learn did not properly
update $GIT_DIR/info/refs after inserting or removing
messages.
---
 lib/PublicInbox/Import.pm | 17 ++++++++++++-----
 script/public-inbox-index |  2 --
 script/public-inbox-mda   |  4 ----
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index f9c05da..5a3c585 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -45,7 +45,7 @@ sub gfi_start {
 			--quiet --done --date-format=rfc2822));
 	my $rdr = { 0 => fileno($out_r), 1 => fileno($in_w) };
 	my $pid = spawn(\@cmd, undef, $rdr);
-	die "spawn failed: $!" unless defined $pid;
+	die "spawn fast-import failed: $!" unless defined $pid;
 	$out_w->autoflush(1);
 	$self->{in} = $in_r;
 	$self->{out} = $out_w;
@@ -201,13 +201,20 @@ sub done {
 	my $git_dir = $self->{git}->{git_dir};
 	my $index = "$git_dir/ssoma.index";
 	# XXX: change the following scope to: if (-e $index) # in 2018 or so..
+	my @cmd = ('git', "--git-dir=$git_dir");
 	unless ($ENV{FAST}) {
-		local $ENV{GIT_INDEX_FILE} = $index;
-		system('git', "--git-dir=$git_dir", qw(read-tree -m -v -i),
-			$self->{ref}) == 0 or
-			die "failed to update $git_dir/ssoma.index: $?\n";
+		my $env = { GIT_INDEX_FILE => $index };
+		my @rt = (@cmd, qw(read-tree -m -v -i), $self->{ref});
+		$pid = spawn(\@rt, $env, undef);
+		defined $pid or die "spawn read-tree failed: $!";
+		waitpid($pid, 0) == $pid or die 'read-tree did not finish';
+		$? == 0 or die "failed to update $git_dir/ssoma.index: $?\n";
 	}
 
+	$pid = spawn([@cmd, 'update-server-info'], undef, undef);
+	defined $pid or die "spawn update-server-info failed: $!\n";
+	waitpid($pid, 0) == $pid or die 'update-server-info did not finish';
+	$? == 0 or die "failed to update-server-info: $?\n";
 
 	my $lockfh = delete $self->{lockfh} or die "BUG: not locked: $!";
 	flock($lockfh, LOCK_UN) or die "unlock failed: $!";
diff --git a/script/public-inbox-index b/script/public-inbox-index
index 578d91d..46584c1 100755
--- a/script/public-inbox-index
+++ b/script/public-inbox-index
@@ -58,8 +58,6 @@ sub index_dir {
 	my ($git_dir) = @_;
 	-d $git_dir or die "$git_dir does not appear to be a git repository\n";
 
-	system('git', "--git-dir=$git_dir", 'update-server-info') and
-		die "git update-server-info failed for $git_dir";
 	my $s = PublicInbox::SearchIdx->new($git_dir, 1);
 	$s->index_sync;
 }
diff --git a/script/public-inbox-mda b/script/public-inbox-mda
index 6c76734..611e7c3 100755
--- a/script/public-inbox-mda
+++ b/script/public-inbox-mda
@@ -102,10 +102,6 @@ sub do_spamc {
 
 sub index_sync {
 	my ($git_dir) = @_;
-
-	# potentially user-visible, ignore errors:
-	system('git', "--git-dir=$git_dir", 'update-server-info');
-
 	eval {
 		require PublicInbox::SearchIdx;
 		PublicInbox::SearchIdx->new($git_dir, 2)->index_sync;
-- 
EW


      parent reply	other threads:[~2016-04-28  2:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-28  2:00 [PATCH 0/2] import: public API and dumb HTTP enforcement Eric Wong
2016-04-28  2:00 ` [PATCH 1/2] import: document API for public consumption Eric Wong
2016-04-28  2:00 ` Eric Wong [this message]

Reply instructions:

You may reply publicly 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: https://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=20160428020033.6048-3-e@80x24.org \
    --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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).