From 6158b3e3476cd49a2e6c32fad88a7905ec88de8f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 22 Feb 2017 03:01:24 +0000 Subject: repobrowse: fixup revision handling Revisions passed in the URL must not be ignored. This fixes some bugs introduced in commit f6244586ba4f5a5e7575e1254be8c9bbe303fce9 ("repobrowse: switch to new URL format to avoid query strings") --- lib/PublicInbox/RepoGitAtom.pm | 2 +- lib/PublicInbox/RepoGitCommit.pm | 4 ++-- lib/PublicInbox/RepoGitDiff.pm | 3 ++- lib/PublicInbox/RepoGitLog.pm | 12 +++--------- lib/PublicInbox/RepoGitRaw.pm | 3 ++- lib/PublicInbox/RepoGitSnapshot.pm | 2 +- lib/PublicInbox/RepoGitTag.pm | 6 +++--- lib/PublicInbox/RepoGitTree.pm | 9 ++++----- lib/PublicInbox/Repobrowse.pm | 6 +++--- 9 files changed, 21 insertions(+), 26 deletions(-) diff --git a/lib/PublicInbox/RepoGitAtom.pm b/lib/PublicInbox/RepoGitAtom.pm index 615c8927..c30c6184 100644 --- a/lib/PublicInbox/RepoGitAtom.pm +++ b/lib/PublicInbox/RepoGitAtom.pm @@ -141,7 +141,7 @@ sub call_git_atom { my $git = $repo->{git}; my $env = $req->{env}; - my $tip = $req->{h} || $repo->tip; + my $tip = $req->{tip} || $repo->tip; my $read_log = sub { my $cmd = $git->cmd(qw(log --no-notes --no-color --abbrev-commit), $git->abbrev, diff --git a/lib/PublicInbox/RepoGitCommit.pm b/lib/PublicInbox/RepoGitCommit.pm index 22a2742c..34f7acc3 100644 --- a/lib/PublicInbox/RepoGitCommit.pm +++ b/lib/PublicInbox/RepoGitCommit.pm @@ -124,11 +124,11 @@ sub call_git_commit { # RepoBase calls this my $relup = join('', map { '../' } @{$req->{extra}}); return $self->r(301, $req, "$relup#".to_attr($expath)); } - + my $tip = $req->{tip} || $req->{-repo}->tip; my $git = $req->{-repo}->{git}; my $cmd = $git->cmd(qw(show -z --numstat -p --encoding=UTF-8 --no-notes --no-color -c --no-abbrev), - GIT_FMT, $req->{-repo}->tip, '--'); + GIT_FMT, $tip, '--'); my $rdr = { 2 => $git->err_begin }; my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr); $env->{'qspawn.quiet'} = 1; diff --git a/lib/PublicInbox/RepoGitDiff.pm b/lib/PublicInbox/RepoGitDiff.pm index 26728402..643d5cb7 100644 --- a/lib/PublicInbox/RepoGitDiff.pm +++ b/lib/PublicInbox/RepoGitDiff.pm @@ -32,9 +32,10 @@ sub git_diff_sed ($$) { } } +# $REPO/diff/$BEFORE..$AFTER sub call_git_diff { my ($self, $req) = @_; - my ($id, $id2) = split(/\.\./, $req->{h}); + my ($id, $id2) = split(/\.\./, $req->{tip}); my $env = $req->{env}; my $git = $req->{-repo}->{git}; my $cmd = $git->cmd(qw(diff-tree -z --numstat -p --encoding=UTF-8 diff --git a/lib/PublicInbox/RepoGitLog.pm b/lib/PublicInbox/RepoGitLog.pm index 38097ed3..1ad83fc0 100644 --- a/lib/PublicInbox/RepoGitLog.pm +++ b/lib/PublicInbox/RepoGitLog.pm @@ -124,22 +124,16 @@ sub call_git_log { my ($self, $req) = @_; my $repo = $req->{-repo}; my $max = $repo->{max_commit_count} || 50; - my $h = $req->{h}; + my $tip = $req->{tip} || $repo->tip; + $req->{lpfx} = $req->{relcmd}; $max = int($max); $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 --no-abbrev), $LOG_FMT, "-$max", $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} . $tip; - } + my $title = 'log: '.$repo->{repo}.' ('.utf8_html($tip).')'; $req->{lhtml} = $self->html_start($req, $title) . "\n\n"; my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr); $qsp->psgi_return($env, undef, sub { diff --git a/lib/PublicInbox/RepoGitRaw.pm b/lib/PublicInbox/RepoGitRaw.pm index a38d7deb..f02439ad 100644 --- a/lib/PublicInbox/RepoGitRaw.pm +++ b/lib/PublicInbox/RepoGitRaw.pm @@ -12,7 +12,8 @@ sub call_git_raw { my ($self, $req) = @_; my $repo = $req->{-repo}; my $git = $repo->{git}; - my $id = $repo->tip . ':' . $req->{expath}; + my $tip = $req->{tip} || $repo->tip; + my $id = $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 3d53fa6d..49d51033 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->{h} || $req->{-repo}->tip; + my $ref = $req->{tip} || $req->{-repo}->tip; my $orig_fn = $ref; # just in case git changes refname rules, don't allow wonky filenames diff --git a/lib/PublicInbox/RepoGitTag.pm b/lib/PublicInbox/RepoGitTag.pm index 6a35f61c..785de6b1 100644 --- a/lib/PublicInbox/RepoGitTag.pm +++ b/lib/PublicInbox/RepoGitTag.pm @@ -19,11 +19,11 @@ my %cmd_map = ( # type => action sub call_git_tag { my ($self, $req) = @_; - my $h = $req->{h}; - defined $h or return git_tag_list($self, $req); + my $tip = $req->{tip}; + defined $tip or return git_tag_list($self, $req); sub { my ($res) = @_; - git_tag_show($self, $req, $h, $res); + git_tag_show($self, $req, $tip, $res); } } diff --git a/lib/PublicInbox/RepoGitTree.pm b/lib/PublicInbox/RepoGitTree.pm index 5e880ee3..64ab9e6f 100644 --- a/lib/PublicInbox/RepoGitTree.pm +++ b/lib/PublicInbox/RepoGitTree.pm @@ -22,7 +22,7 @@ sub call_git_tree { my @extra = @{$req->{extra}}; my $repo = $req->{-repo}; my $git = $repo->{git}; - my $tip = $repo->tip; + my $tip = $req->{tip} || $repo->tip; my $obj = "$tip:$req->{expath}"; my ($hex, $type, $size) = $git->check($obj); @@ -31,8 +31,7 @@ sub call_git_tree { } my $opts = { nofollow => 1 }; - my $title = $req->{expath}; - $title = $title eq '' ? 'tree' : utf8_html($title); + my $title = "tree: ".utf8_html($req->{expath}); if ($type eq 'tree') { $opts->{noindex} = 1; $req->{thtml} = $self->html_start($req, $title, $opts) . "\n"; @@ -193,8 +192,8 @@ sub git_tree_show { $req->{thtml} .= "\npath: $t\n\nmode\tsize\tname\n"; if (defined(my $last = $req->{extra}->[-1])) { $pfx = PublicInbox::Hval->utf8($last)->as_path; - } elsif (defined $req->{h}) { - $pfx = $req->{-repo}->tip; + } elsif (defined(my $tip = $req->{tip})) { + $pfx = $tip; } else { $pfx = 'tree/' . $req->{-repo}->tip; } diff --git a/lib/PublicInbox/Repobrowse.pm b/lib/PublicInbox/Repobrowse.pm index 94e78b80..aad0e8ba 100644 --- a/lib/PublicInbox/Repobrowse.pm +++ b/lib/PublicInbox/Repobrowse.pm @@ -118,11 +118,11 @@ sub call { my $vcs_lc = $repo->{vcs}; my $vcs = $VCS{$vcs_lc} or return r404(); my $mod; - my $h; + my $tip; if (defined $cmd && length $cmd) { $mod = $CMD{$cmd}; if ($mod) { - $h = shift @extra if @extra; + $tip = shift @extra if @extra; } else { unshift @extra, $cmd; $mod = 'Fallback'; @@ -141,7 +141,7 @@ sub call { while (@extra && $extra[-1] eq '') { pop @extra; } - $req->{h} = $h; + $req->{tip} = $tip; $mod = load_once("PublicInbox::Repo$vcs$mod"); $vcs = load_once("PublicInbox::$vcs"); -- cgit v1.2.3-24-ge0c7