about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/PublicInbox/Repo.pm11
-rw-r--r--lib/PublicInbox/RepoGitAtom.pm15
-rw-r--r--lib/PublicInbox/RepoGitBlob.pm5
-rw-r--r--lib/PublicInbox/RepoGitCommit.pm3
-rw-r--r--lib/PublicInbox/RepoGitDiffCommon.pm1
-rw-r--r--lib/PublicInbox/RepoGitLog.pm5
-rw-r--r--lib/PublicInbox/RepoGitPatch.pm5
-rw-r--r--lib/PublicInbox/RepoGitPlain.pm5
-rw-r--r--lib/PublicInbox/RepoGitSnapshot.pm2
-rw-r--r--lib/PublicInbox/RepoGitSummary.pm17
-rw-r--r--lib/PublicInbox/RepoGitTree.pm16
-rw-r--r--lib/PublicInbox/Repobrowse.pm1
12 files changed, 43 insertions, 43 deletions
diff --git a/lib/PublicInbox/Repo.pm b/lib/PublicInbox/Repo.pm
index ceebe5c4..f0cb4b3d 100644
--- a/lib/PublicInbox/Repo.pm
+++ b/lib/PublicInbox/Repo.pm
@@ -46,4 +46,15 @@ sub cloneurl {
         $self->{cloneurl} = $url;
 }
 
+sub tip {
+        my ($self) = @_;
+        $self->{-tip} ||= do {
+                if ($self->{vcs} eq 'git') {
+                        my $t = $self->{git}->qx(qw(symbolic-ref --short HEAD));
+                        chomp $t;
+                        $t;
+                }
+        };
+}
+
 1;
diff --git a/lib/PublicInbox/RepoGitAtom.pm b/lib/PublicInbox/RepoGitAtom.pm
index 531d8b9d..615c8927 100644
--- a/lib/PublicInbox/RepoGitAtom.pm
+++ b/lib/PublicInbox/RepoGitAtom.pm
@@ -66,8 +66,9 @@ sub git_atom_sed ($$) {
         my $state = 0;
         my $rel = $req->{relcmd};
         my $repo = $req->{-repo};
+        my $tip = $repo->tip;
         my $title = join('/', $repo->{repo}, @{$req->{extra}});
-        $title = utf8_html("$title, $req->{-tip}");
+        $title = utf8_html("$title, $tip");
         my $url = repo_root_url($self, $req);
         my $hdr = {};
         my $subtitle = $repo->desc_html;
@@ -140,7 +141,7 @@ sub call_git_atom {
 
         my $git = $repo->{git};
         my $env = $req->{env};
-        my $tip = $req->{-tip};
+        my $tip = $req->{h} || $repo->tip;
         my $read_log = sub {
                 my $cmd = $git->cmd(qw(log --no-notes --no-color
                                         --abbrev-commit), $git->abbrev,
@@ -154,15 +155,7 @@ sub call_git_atom {
 
         sub {
                 $env->{'qspawn.response'} = $_[0];
-                return $read_log->() if $tip ne '';
-
-                my $cmd = $git->cmd(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($tip = ${$_[0]});
-                        $read_log->();
-                })
+                $read_log->();
         }
 }
 
diff --git a/lib/PublicInbox/RepoGitBlob.pm b/lib/PublicInbox/RepoGitBlob.pm
index ca8a3c2f..b535b0ad 100644
--- a/lib/PublicInbox/RepoGitBlob.pm
+++ b/lib/PublicInbox/RepoGitBlob.pm
@@ -11,8 +11,9 @@ our @EXPORT = qw(git_blob_mime_type git_blob_stream_response);
 
 sub call_git_blob {
         my ($self, $req) = @_;
-        my $git = $req->{-repo}->{git};
-        my $id = $req->{-tip} . ':' . $req->{expath};
+        my $repo = $req->{-repo};
+        my $git = $repo->{git};
+        my $id = $repo->tip . ':' . $req->{expath};
 
         my ($cat, $hex, $type, $size) = $git->cat_file_begin($id);
         return unless defined $cat;
diff --git a/lib/PublicInbox/RepoGitCommit.pm b/lib/PublicInbox/RepoGitCommit.pm
index 21f450ea..1a10b13c 100644
--- a/lib/PublicInbox/RepoGitCommit.pm
+++ b/lib/PublicInbox/RepoGitCommit.pm
@@ -117,7 +117,6 @@ sub git_commit_sed ($$) {
 sub call_git_commit { # RepoBase calls this
         my ($self, $req) = @_;
         my $env = $req->{env};
-        my $tip = $req->{-tip};
 
         my $expath = $req->{expath};
         if ($expath ne '') {
@@ -128,7 +127,7 @@ sub call_git_commit { # RepoBase calls this
         my $git = $req->{-repo}->{git};
         my $cmd = $git->cmd(qw(show -z --numstat -p --encoding=UTF-8
                         --no-notes --no-color -c),
-                        $git->abbrev, GIT_FMT, $tip, '--');
+                        $git->abbrev, GIT_FMT, $req->{-repo}->tip, '--');
         my $rdr = { 2 => $git->err_begin };
         my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
         $env->{'qspawn.quiet'} = 1;
diff --git a/lib/PublicInbox/RepoGitDiffCommon.pm b/lib/PublicInbox/RepoGitDiffCommon.pm
index 3e3ea4ee..67adca68 100644
--- a/lib/PublicInbox/RepoGitDiffCommon.pm
+++ b/lib/PublicInbox/RepoGitDiffCommon.pm
@@ -162,6 +162,7 @@ sub DSTATE_LINES () { 2 }
 sub git_diff_sed_init ($) {
         my ($req) = @_;
         $req->{dbuf} = '';
+        $req->{-tip} = $req->{-repo}->tip;
         $req->{ndiff} = $req->{nchg} = $req->{nadd} = $req->{ndel} = 0;
         $req->{dstate} = DSTATE_INIT;
 }
diff --git a/lib/PublicInbox/RepoGitLog.pm b/lib/PublicInbox/RepoGitLog.pm
index b759a5c0..4e0997e0 100644
--- a/lib/PublicInbox/RepoGitLog.pm
+++ b/lib/PublicInbox/RepoGitLog.pm
@@ -128,16 +128,17 @@ sub call_git_log {
         $max = 50 if $max == 0;
         my $env = $req->{env};
         my $git = $repo->{git};
+        my $tip = $req->{-repo}->tip;
         my $cmd = $git->cmd(qw(log --no-notes --no-color --abbrev-commit),
                                 $git->abbrev, $LOG_FMT, "-$max",
-                                $req->{-tip}, '--');
+                                $tip, '--');
         my $rdr = { 2 => $git->err_begin };
         my $title = "log: $repo->{repo}";
         if (defined $h) {
                 $title .= ' ('. utf8_html($h). ')';
                 $req->{lpfx} = $req->{relcmd};
         } else {
-                $req->{lpfx} = $req->{relcmd}.$req->{-tip};
+                $req->{lpfx} = $req->{relcmd} . $tip;
         }
         $req->{lhtml} = $self->html_start($req, $title) . "\n\n";
         my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
diff --git a/lib/PublicInbox/RepoGitPatch.pm b/lib/PublicInbox/RepoGitPatch.pm
index e1431f39..3e4eabe9 100644
--- a/lib/PublicInbox/RepoGitPatch.pm
+++ b/lib/PublicInbox/RepoGitPatch.pm
@@ -15,9 +15,10 @@ my $sig = '--signature=git '.join(' ', @CMD);
 
 sub call_git_patch {
         my ($self, $req) = @_;
-        my $git = $req->{-repo}->{git};
+        my $repo = $req->{-repo};
+        my $git = $repo->{git};
         my $env = $req->{env};
-        my $tip = $req->{-tip};
+        my $tip = $repo->tip;
         $tip =~ /\A[\w-]+([~\^][~\^\d])*\z/;
 
         # limit scope, don't take extra args to avoid wasting server
diff --git a/lib/PublicInbox/RepoGitPlain.pm b/lib/PublicInbox/RepoGitPlain.pm
index 79a15be6..8aff2177 100644
--- a/lib/PublicInbox/RepoGitPlain.pm
+++ b/lib/PublicInbox/RepoGitPlain.pm
@@ -10,8 +10,9 @@ use PublicInbox::Qspawn;
 
 sub call_git_plain {
         my ($self, $req) = @_;
-        my $git = $req->{-repo}->{git};
-        my $id = $req->{-tip} . ':' . $req->{expath};
+        my $repo = $req->{-repo};
+        my $git = $repo->{git};
+        my $id = $repo->tip . ':' . $req->{expath};
         my ($cat, $hex, $type, $size) = $git->cat_file_begin($id);
         return unless defined $cat;
 
diff --git a/lib/PublicInbox/RepoGitSnapshot.pm b/lib/PublicInbox/RepoGitSnapshot.pm
index 44a6bd59..3d53fa6d 100644
--- a/lib/PublicInbox/RepoGitSnapshot.pm
+++ b/lib/PublicInbox/RepoGitSnapshot.pm
@@ -36,7 +36,7 @@ our %FMT_TYPES = (
 sub call_git_snapshot ($$) { # invoked by PublicInbox::RepoBase::call
         my ($self, $req) = @_;
 
-        my $ref = $req->{-tip};
+        my $ref = $req->{h} || $req->{-repo}->tip;
         my $orig_fn = $ref;
 
         # just in case git changes refname rules, don't allow wonky filenames
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 <a\nhref=\"${rel}tree/$req->{-tip}\">root</a>/";
+        my $tip = $req->{-repo}->tip;
+        my $s = "tree <a\nhref=\"${rel}tree/$tip\">root</a>/";
         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 = "<a\nhref=\"${rel}tree/$req->{-tip}/$ep\">$eh</a>";
+                $e = "<a\nhref=\"${rel}tree/$tip/$ep\">$eh</a>";
                 # bold the last one
                 scalar(@t) == scalar(@path) ? "<b>$e</b>" : $e;
         } @path));
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 '<b>root</b>';
         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};
diff --git a/lib/PublicInbox/Repobrowse.pm b/lib/PublicInbox/Repobrowse.pm
index 7f50a877..34ffd542 100644
--- a/lib/PublicInbox/Repobrowse.pm
+++ b/lib/PublicInbox/Repobrowse.pm
@@ -141,7 +141,6 @@ sub call {
                 ++$tslash;
         }
         $req->{h} = $h;
-        $req->{-tip} = defined $h ? $h : 'HEAD';
         return no_tslash($env) if ($tslash && $NO_TSLASH{$mod});
 
         $req->{tslash} = $tslash;