about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-21 02:29:51 +0000
committerEric Wong <e@80x24.org>2017-01-21 02:31:42 +0000
commitb7df48261532049b640ad55548363381423ebabd (patch)
tree11213699589da9544e8fa856c280c306389ffeef
parent984df62e41cd7c90fda9b7f129616d1b30fa02e4 (diff)
downloadpublic-inbox-b7df48261532049b640ad55548363381423ebabd.tar.gz
repobrowse: git Atom feed uses Qspawn->psgi_qx
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...
-rw-r--r--lib/PublicInbox/RepobrowseGitAtom.pm35
1 files changed, 25 insertions, 10 deletions
diff --git a/lib/PublicInbox/RepobrowseGitAtom.pm b/lib/PublicInbox/RepobrowseGitAtom.pm
index 7c4082a6..3031417b 100644
--- a/lib/PublicInbox/RepobrowseGitAtom.pm
+++ b/lib/PublicInbox/RepobrowseGitAtom.pm
@@ -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->();
+                })
         }
 }