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/RepoGitTree.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/PublicInbox/RepoGitTree.pm') diff --git a/lib/PublicInbox/RepoGitTree.pm b/lib/PublicInbox/RepoGitTree.pm index 716dfe02..a4add619 100644 --- a/lib/PublicInbox/RepoGitTree.pm +++ b/lib/PublicInbox/RepoGitTree.pm @@ -20,8 +20,10 @@ my $BINARY_MSG = "Binary file, save using the 'raw' link above"; sub call_git_tree { my ($self, $req) = @_; my @extra = @{$req->{extra}}; - my $git = $req->{-repo}->{git}; - my $obj = "$req->{-tip}:$req->{expath}"; + my $repo = $req->{-repo}; + my $git = $repo->{git}; + my $tip = $repo->tip; + my $obj = "$tip:$req->{expath}"; my ($hex, $type, $size) = $git->check($obj); unless (defined($type)) { @@ -57,7 +59,7 @@ sub cur_path { my @ex = @{$req->{extra}} or return 'root'; my $s; - my $tip = $req->{-tip}; + my $tip = $req->{-repo}->tip; my $rel = $req->{relcmd}; # avoid relative paths, here, we don't want to propagate # trailing-slash URLs although we tolerate them @@ -80,9 +82,9 @@ sub git_blob_show { my $text_p; my $n = 0; - my $tip = $req->{-tip}; my $rel = $req->{relcmd}; - my $plain = join('/', "${rel}plain/$tip", @{$req->{extra}}); + my $plain = join('/', + "${rel}plain", $req->{-repo}->tip, @{$req->{extra}}); $plain = PublicInbox::Hval->utf8($plain)->as_path; my $t = cur_path($req); my $s = qq{\npath: $t\n\nblob $hex}; @@ -194,9 +196,9 @@ sub git_tree_show { } elsif (defined(my $last = $req->{extra}->[-1])) { $pfx = PublicInbox::Hval->utf8($last)->as_path; } elsif (defined $req->{h}) { - $pfx = $req->{-tip}; + $pfx = $req->{-repo}->tip; } else { - $pfx = 'tree/' . $req->{-tip}; + $pfx = 'tree/' . $req->{-repo}->tip; } $req->{tpfx} = $pfx; my $env = $req->{env}; -- cgit v1.2.3-24-ge0c7