]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
repobrowse: git Atom feed uses Qspawn->psgi_qx
authorEric Wong <e@80x24.org>
Sat, 21 Jan 2017 02:29:51 +0000 (02:29 +0000)
committerEric Wong <e@80x24.org>
Sat, 21 Jan 2017 02:31:42 +0000 (02:31 +0000)
This allows pi-httpd to service other I/O while we wait on "git
symbolic-ref" to run.  And psgi_return will be used in the next
commit...

lib/PublicInbox/RepobrowseGitAtom.pm

index 7c4082a696d89e2e75f1301eed2ca161b75b33a3..3031417b157b8a850fad36aec30b8fdd6facc4a6 100644 (file)
@@ -7,6 +7,7 @@ use strict;
 use warnings;
 use PublicInbox::Hval qw(utf8_html);
 use base qw(PublicInbox::RepobrowseBase);
+use PublicInbox::Qspawn;
 my $ATOM_FMT = '--pretty=tformat:'.
                join('%x00', qw(%s %ct %an %ae %at %h %H %b), '', '');
 
@@ -21,21 +22,35 @@ sub call_git_atom {
        $max = 50 if $max == 0;
 
        my $git = $repo_info->{git};
-       my $q = PublicInbox::RepobrowseGitQuery->new($req->{env});
+       my $env = $req->{env};
+       my $q = PublicInbox::RepobrowseGitQuery->new($env);
        my $h = $q->{h};
-       $h eq '' and chomp($h = $git->qx(qw(symbolic-ref --short HEAD)));
-
-       my @cmd = (qw(log --no-notes --no-color --abbrev-commit),
-                       $git->abbrev, $ATOM_FMT, "-$max", $h, '--');
-       push @cmd, $req->{expath} if length($req->{expath});
-       my $log = $git->popen(@cmd);
-
-       sub {
-               my ($res) = @_; # Plack callback
+       my $res;
+
+       my $read_log = sub {
+               my @cmd = (qw(log --no-notes --no-color --abbrev-commit),
+                               $git->abbrev, $ATOM_FMT, "-$max", $h, '--');
+               my $expath = $req->{expath};
+               push @cmd, $expath if $expath ne '';
+               my $log = $git->popen(@cmd);
                my @h = ( 'Content-Type' => 'application/atom+xml' );
                my $fh = $res->([200, \@h]);
                $self->git_atom_stream($req, $q, $log, $fh, $h);
                $fh->close;
+       };
+
+       sub {
+               $res = $_[0];
+               return $read_log->() if $h ne '';
+
+               my $cmd = [ 'git', "--git-dir=$git->{git_dir}",
+                               qw(symbolic-ref --short HEAD) ];
+               my $rdr = { 2 => $git->err_begin };
+               my $qsp = PublicInbox::Qspawn->new($cmd, undef, undef, $rdr);
+               $qsp->psgi_qx($env, undef, sub {
+                       chomp($h = ${$_[0]});
+                       $read_log->();
+               })
        }
 }