From 9877e27be55f7a8d00a613630875d647d97d7bb3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 22 Jan 2017 22:10:46 +0000 Subject: repobrowse: git summary view uses psgi_qx This reduces one synchronous dependency from the hot path, and psgi_return will be used in the future. --- lib/PublicInbox/RepobrowseGitSummary.pm | 27 +++++++++++++++++---------- 1 file 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/)); -- cgit v1.2.3-24-ge0c7