From e983376326eab20daac9c2bfbb65b88c4fd248a2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 28 Apr 2016 01:03:31 +0000 Subject: import: run git-update-server-info when done 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 f9c05da8..5a3c5851 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 578d91d5..46584c1f 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 6c76734c..611e7c38 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; -- cgit v1.2.3-24-ge0c7