]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
repobrowse: src/ endpoint requires a tip to be specified
authorEric Wong <e@80x24.org>
Fri, 3 Mar 2017 22:07:19 +0000 (22:07 +0000)
committerEric Wong <e@80x24.org>
Fri, 3 Mar 2017 22:12:19 +0000 (22:12 +0000)
Implying a tip would make for ambiguous URLs and ruin
caching, so try to get everybody to hit the same URL.
This also simplifies some of our other code since
the tip is always in the request.

lib/PublicInbox/RepoBase.pm
lib/PublicInbox/RepoGitSrc.pm
t/repobrowse_git_src.t

index e600b1dfd7408b1a98110465a0a495cbd38c25e5..5d38579cbf37226b8d50e9d942ef0e6f00eca1e4 100644 (file)
@@ -86,7 +86,7 @@ sub r {
                my $env = $req->{env};
                my $base = PublicInbox::Repobrowse::base_url($env);
                my ($redir) = @extra;
-               if ($redir =~ m!\A\.\./!) { # relative redirect
+               if (index($redir, '/') != 0) { # relative redirect
                        my @orig = split(m!/+!, $env->{PATH_INFO});
                        my @dest = split(m!/+!, $redir);
 
@@ -98,7 +98,7 @@ sub r {
                        $end = pop @dest if $dest[-1] =~ /\A[#\?]/;
                        $redir = $base . join('/', @orig, @dest) . $end;
                } else {
-                       $redir = $base . '/' . $redir;
+                       $redir = $base . $redir;
                }
                push @h, qw(Content-Type text/plain Location), $redir;
 
index de068940cb92cf1efc9378598bcaa3db002f0717..38108442299bbe0c5c669c05eaa480093a222e32 100644 (file)
@@ -23,7 +23,7 @@ sub call_git_src {
        my ($self, $req) = @_;
        my $repo = $req->{-repo};
        my $git = $repo->{git};
-       my $tip = $req->{tip} || $req->{repo}->tip;
+       my $tip = $req->{tip} or return $self->r(302, $req, $repo->tip);
        sub {
                my ($res) = @_;
                $git->check_async($req->{env}, "$tip:$req->{expath}", sub {
@@ -57,7 +57,7 @@ sub cur_path {
        my ($req) = @_;
        my @ex = @{$req->{extra}} or return '<b>root</b>';
        my $s;
-       my $tip = $req->{tip} || $req->{repo}->tip;
+       my $tip = $req->{tip};
        my $rel = $req->{relcmd};
        # avoid relative paths, here, we don't want to propagate
        # trailing-slash URLs although we tolerate them
@@ -81,7 +81,7 @@ sub git_blob_sed ($$$) {
        my @lines;
        my $buf = '';
        my $rel = $req->{relcmd};
-       my $tip = $req->{tip} || $req->{repo}->tip;
+       my $tip = $req->{tip};
        my $raw = join('/', "${rel}raw", $tip, @{$req->{extra}});
        $raw = PublicInbox::Hval->utf8($raw)->as_path;
        my $t = cur_path($req);
@@ -220,10 +220,8 @@ sub git_tree_show {
        $req->{thtml} .= "\npath: $t\n\n<b>mode\tsize\tname</b>\n";
        if (defined(my $last = $req->{extra}->[-1])) {
                $pfx = PublicInbox::Hval->utf8($last)->as_path;
-       } elsif (defined(my $tip = $req->{tip})) {
-               $pfx = $tip;
        } else {
-               $pfx = 'src/' . $req->{-repo}->tip;
+               $pfx = 'src/' . $req->{tip};
        }
        $req->{tpfx} = $pfx;
        my $env = $req->{env};
index 4d16eac4f0a23ae54f96c29d33f564fce2a0ba47..aa341d38fc8726aa2162ebceaab22652f9b99060 100644 (file)
@@ -14,6 +14,11 @@ test_psgi($test->{app}, sub {
        like($noslash_body, qr{href="dir/dur">dur/</a>},
                'path ok w/o slash');
 
+       $req = 'http://example.com/test.git/src';
+       $res = $cb->(GET($req));
+       is(302, $res->code, 'got 302 response from dir');
+       is("$req/master", $res->header('Location'), 'redirected to tip');
+
        my $slash = $req . '/';
        my $r2 = $cb->(GET($slash));
        is(301, $r2->code, 'got 301 response from dir with slash');