]> Sergey Matveev's repositories - public-inbox.git/commitdiff
import: run git-update-server-info when done
authorEric Wong <e@80x24.org>
Thu, 28 Apr 2016 01:03:31 +0000 (01:03 +0000)
committerEric Wong <e@80x24.org>
Thu, 28 Apr 2016 01:03:31 +0000 (01:03 +0000)
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
script/public-inbox-index
script/public-inbox-mda

index f9c05da80945297ec8d38055fcd9633fcad5a353..5a3c58510cef977fbb97ed4dc86c6a6dcca28f7b 100644 (file)
@@ -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: $!";
index 578d91d5bf50b767171b490594215b295a52e64f..46584c1fff3502c71a087240fa0e1ab6215a24b1 100755 (executable)
@@ -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;
 }
index 6c76734c4a1be513cb159de6069bba69ca880464..611e7c3887035d35d49381056bcca1937185ea24 100755 (executable)
@@ -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;