about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-22 22:10:46 +0000
committerEric Wong <e@80x24.org>2017-01-22 22:10:46 +0000
commit9877e27be55f7a8d00a613630875d647d97d7bb3 (patch)
treed0ecda66b4955323c743d46b0822c09f1e1d64d1
parent7ed712c9bb535d621fbf4290bbf770a5d3f49d3e (diff)
downloadpublic-inbox-9877e27be55f7a8d00a613630875d647d97d7bb3.tar.gz
This reduces one synchronous dependency from the hot path,
and psgi_return will be used in the future.
-rw-r--r--lib/PublicInbox/RepobrowseGitSummary.pm27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/PublicInbox/RepobrowseGitSummary.pm b/lib/PublicInbox/RepobrowseGitSummary.pm
index 3ddfbe74..f571a4f5 100644
--- a/lib/PublicInbox/RepobrowseGitSummary.pm
+++ b/lib/PublicInbox/RepobrowseGitSummary.pm
@@ -7,12 +7,24 @@ use strict;
 use warnings;
 use PublicInbox::Hval qw(utf8_html);
 use base qw(PublicInbox::RepobrowseBase);
+use PublicInbox::Qspawn;
 
 sub call_git_summary {
         my ($self, $req) = @_;
+        my $git = $req->{repo_info}->{git};
+        my $env = $req->{env};
+
+        # n.b. we would use %(HEAD) in for-each-ref --format if we could
+        # rely on git 1.9.0+, but it's too soon for that in early 2017...
+        my $cmd = [ 'git', "--git-dir=$git->{git_dir}", qw(symbolic-ref HEAD) ];
+        my $rdr = { 2 => $git->err_begin };
+        my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
         sub {
                 my ($res) = @_; # Plack streaming callback
-                emit_summary($self, $req, $res);
+                $qsp->psgi_qx($env, undef, sub {
+                        chomp(my $head_ref = ${$_[0]});
+                        for_each_ref($self, $req, $res, $head_ref);
+                });
         }
 }
 
@@ -20,17 +32,12 @@ use constant EACH_REF_FMT => '--format=' .
                 join(' ', map { "%($_)" }
                 qw(refname objecttype objectname creatordate:short subject));
 
-sub emit_summary {
-        my ($self, $req, $res) = @_;
-        my $repo_info = $req->{repo_info};
-        my $git = $repo_info->{git};
+sub for_each_ref {
+        my ($self, $req, $res, $head_ref) = @_;
         my $count = 10; # TODO: configurable
         my $fh;
-
-        # n.b. we would use %(HEAD) in for-each-ref --format if we could
-        # rely on git 1.9.0+, but it's too soon for that in early 2016...
-        chomp(my $head_ref = $git->qx(qw(symbolic-ref HEAD)));
-
+        my $repo_info = $req->{repo_info};
+        my $git = $repo_info->{git};
         my $refs = $git->popen(qw(for-each-ref --sort=-creatordate),
                                 EACH_REF_FMT, "--count=$count",
                                 qw(refs/heads/ refs/tags/));