From e7dc3224ad0b497da6ef242e3a9c612c5702514e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 16 Feb 2017 23:26:01 +0000 Subject: repobrowse: memoize git symbolic-ref resolution The "HEAD" symbolic ref is rarely changed, so memoize it for now and avoid exposing it in URLs. --- lib/PublicInbox/RepoGitSummary.pm | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'lib/PublicInbox/RepoGitSummary.pm') diff --git a/lib/PublicInbox/RepoGitSummary.pm b/lib/PublicInbox/RepoGitSummary.pm index 76d9c2b9..38fce1f5 100644 --- a/lib/PublicInbox/RepoGitSummary.pm +++ b/lib/PublicInbox/RepoGitSummary.pm @@ -13,18 +13,9 @@ sub call_git_summary { my ($self, $req) = @_; my $git = $req->{-repo}->{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->cmd(qw(symbolic-ref HEAD)); - my $rdr = { 2 => $git->err_begin }; - my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr); sub { my ($res) = @_; # Plack streaming callback - $qsp->psgi_qx($env, undef, sub { - chomp(my $head_ref = ${$_[0]}); - for_each_ref($self, $req, $res, $head_ref); - }); + for_each_ref($self, $req, $res, $req->{-repo}->tip); } } @@ -92,15 +83,15 @@ sub for_each_ref { sub readme_path_links { my ($req, $rel, $readme) = @_; my @path = split(m!/+!, $readme); - - my $s = "tree {-tip}\">root/"; + my $tip = $req->{-repo}->tip; + my $s = "tree root/"; my @t; $s .= join('/', (map { push @t, $_; my $e = PublicInbox::Hval->utf8($_, join('/', @t)); my $ep = $e->as_path; my $eh = $e->as_html; - $e = "{-tip}/$ep\">$eh"; + $e = "$eh"; # bold the last one scalar(@t) == scalar(@path) ? "$e" : $e; } @path)); -- cgit v1.2.3-24-ge0c7