From 16b1fbe36cc39a351ef9810b9018d36df833a941 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 2 Mar 2017 23:39:49 +0000 Subject: [PATCH] repobrowse: rename "tree" endpoint to "src" This is shorter, and makes more sense as the endpoint displays both tree listings and actual blob sources. This will also make rewriting existing URLs from cgit installations easier. --- MANIFEST | 4 ++-- lib/PublicInbox/RepoGitCommit.pm | 6 +++--- lib/PublicInbox/RepoGitDiffCommon.pm | 8 ++++---- lib/PublicInbox/{RepoGitTree.pm => RepoGitSrc.pm} | 10 +++++----- lib/PublicInbox/RepoGitSummary.pm | 4 ++-- lib/PublicInbox/Repobrowse.pm | 4 ++-- t/{repobrowse_git_tree.t => repobrowse_git_src.t} | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) rename lib/PublicInbox/{RepoGitTree.pm => RepoGitSrc.pm} (97%) rename t/{repobrowse_git_tree.t => repobrowse_git_src.t} (88%) diff --git a/MANIFEST b/MANIFEST index 495a63e6e..d49b45cea 100644 --- a/MANIFEST +++ b/MANIFEST @@ -97,9 +97,9 @@ lib/PublicInbox/RepoGitRaw.pm lib/PublicInbox/RepoGitSearch.pm lib/PublicInbox/RepoGitSearchIdx.pm lib/PublicInbox/RepoGitSnapshot.pm +lib/PublicInbox/RepoGitSrc.pm lib/PublicInbox/RepoGitSummary.pm lib/PublicInbox/RepoGitTag.pm -lib/PublicInbox/RepoGitTree.pm lib/PublicInbox/RepoRoot.pm lib/PublicInbox/Repobrowse.pm lib/PublicInbox/SaPlugin/ListMirror.pm @@ -197,7 +197,7 @@ t/repobrowse_git_httpd.t t/repobrowse_git_log.t t/repobrowse_git_raw.t t/repobrowse_git_snapshot.t -t/repobrowse_git_tree.t +t/repobrowse_git_src.t t/search.t t/spamcheck_spamc.t t/spawn.t diff --git a/lib/PublicInbox/RepoGitCommit.pm b/lib/PublicInbox/RepoGitCommit.pm index 34f7acc3b..8add3006a 100644 --- a/lib/PublicInbox/RepoGitCommit.pm +++ b/lib/PublicInbox/RepoGitCommit.pm @@ -40,7 +40,7 @@ sub commit_header { my $rel = $req->{relcmd}; my $x = $self->html_start($req, $s) . "\n" . qq( commit $H (patch)\n) . - qq( tree $t); + qq( tree $t); my $git = $req->{-repo}->{git}; # extra show path information, if any @@ -55,7 +55,7 @@ sub commit_header { my $e = PublicInbox::Hval->utf8($_, join('/', @t)); $ep = $e->as_path; my $eh = $e->as_html; - $ep = "${rel}tree/$ep/$H"; + $ep = "${rel}src/$ep/$H"; qq($eh); } @$extra); $path = "/$ep"; @@ -185,7 +185,7 @@ sub show_unchanged { $p = $p->as_path; $fn = utf8_html($fn); $$dst .= qq(\t); + $$dst .= qq(\nid="$anchor"\nhref="${rel}src/$p">); $$dst .= "$fn\n"; } } diff --git a/lib/PublicInbox/RepoGitDiffCommon.pm b/lib/PublicInbox/RepoGitDiffCommon.pm index 46e243ed0..b60a5fbce 100644 --- a/lib/PublicInbox/RepoGitDiffCommon.pm +++ b/lib/PublicInbox/RepoGitDiffCommon.pm @@ -68,7 +68,7 @@ sub git_diff_ab_hunk ($$$$) { $na = defined $na ? "#n$na" : ''; my $p = $req->{p}->[0]; $rv .= qq({path_a}$na">); + $rv .= qq(\nhref="${rel}src/$p/$req->{path_a}$na">); $rv .= "$ca"; } $rv .= ' '; @@ -77,7 +77,7 @@ sub git_diff_ab_hunk ($$$$) { } else { $nb = defined $nb ? "#n$nb" : ''; $rv .= qq({-tip}/$req->{path_b}$nb">); + $rv .= qq(\nhref="${rel}src/$req->{-tip}/$req->{path_b}$nb">); $rv .= "$cb"; } $rv . ' @@' . utf8_html($ctx); @@ -121,14 +121,14 @@ sub git_diff_cc_hunk { } } - # we can use the normal 'tree' endpoint for the result + # we can use the normal 'src' endpoint for the result my ($n) = ($last =~ /\A\+(\d+)/); # line number if ($n == 0) { # deleted file (does this happen with --cc?) $rv .= " $last"; } else { my $H = $req->{H}; $rv .= qq( $last); + $rv .= qq(\nhref="${rel}src/$H/$path#n$n">$last); } $rv .= " $at" . utf8_html($ctx); } diff --git a/lib/PublicInbox/RepoGitTree.pm b/lib/PublicInbox/RepoGitSrc.pm similarity index 97% rename from lib/PublicInbox/RepoGitTree.pm rename to lib/PublicInbox/RepoGitSrc.pm index e8c34a699..1546830f0 100644 --- a/lib/PublicInbox/RepoGitTree.pm +++ b/lib/PublicInbox/RepoGitSrc.pm @@ -1,6 +1,6 @@ # Copyright (C) 2015 all contributors # License: AGPL-3.0+ -package PublicInbox::RepoGitTree; +package PublicInbox::RepoGitSrc; use strict; use warnings; use base qw(PublicInbox::RepoBase); @@ -19,7 +19,7 @@ my $BINARY_MSG = "Binary file, save using the 'raw' link above"; my $MAX_ASYNC = 65536; # same as pipe size on Linux my $BIN_DETECT = 8000; # same as git (buffer_is_binary in git.git) -sub call_git_tree { +sub call_git_src { my ($self, $req) = @_; my $repo = $req->{-repo}; my $git = $repo->{git}; @@ -63,7 +63,7 @@ sub cur_path { my $rel = $req->{relcmd}; # avoid relative paths, here, we don't want to propagate # trailing-slash URLs although we tolerate them - $s = "root/"; + $s = "root/"; my $cur = pop @ex; my @t; $s .= join('/', (map { @@ -71,7 +71,7 @@ sub cur_path { my $e = PublicInbox::Hval->utf8($_, join('/', @t)); my $ep = $e->as_path; my $eh = $e->as_html; - "$eh"; + "$eh"; } @ex), ''.utf8_html($cur).''); } @@ -230,7 +230,7 @@ sub git_tree_show { } elsif (defined(my $tip = $req->{tip})) { $pfx = $tip; } else { - $pfx = 'tree/' . $req->{-repo}->tip; + $pfx = 'src/' . $req->{-repo}->tip; } $req->{tpfx} = $pfx; my $env = $req->{env}; diff --git a/lib/PublicInbox/RepoGitSummary.pm b/lib/PublicInbox/RepoGitSummary.pm index 5eb8087de..96ae9be91 100644 --- a/lib/PublicInbox/RepoGitSummary.pm +++ b/lib/PublicInbox/RepoGitSummary.pm @@ -84,14 +84,14 @@ sub readme_path_links { my ($req, $rel, $readme) = @_; my @path = split(m!/+!, $readme); my $tip = $req->{-repo}->tip; - my $s = "tree root/"; + 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 = "$eh"; + $e = "$eh"; # bold the last one scalar(@t) == scalar(@path) ? "$e" : $e; } @path)); diff --git a/lib/PublicInbox/Repobrowse.pm b/lib/PublicInbox/Repobrowse.pm index aad0e8ba2..5ef9e59a7 100644 --- a/lib/PublicInbox/Repobrowse.pm +++ b/lib/PublicInbox/Repobrowse.pm @@ -22,7 +22,7 @@ use strict; use warnings; use PublicInbox::RepoConfig; -my %CMD = map { lc($_) => $_ } qw(Log Commit Tree Patch Blob Raw Tag Atom +my %CMD = map { lc($_) => $_ } qw(Log Commit Src Patch Blob Raw Tag Atom Diff Snapshot); my %VCS = (git => 'Git'); my %LOADED; @@ -93,7 +93,7 @@ sub call { } # URL syntax: / repo [ / cmd [ / head [ / path ] ] ] - # cmd: log | commit | diff | tree | view | blob | snapshot + # cmd: log | commit | diff | src | view | blob | snapshot # repo and path (@extra) may both contain '/' my $path_info = $env->{PATH_INFO}; my (undef, $repo_path, @extra) = split(m{/+}, $path_info, -1); diff --git a/t/repobrowse_git_tree.t b/t/repobrowse_git_src.t similarity index 88% rename from t/repobrowse_git_tree.t rename to t/repobrowse_git_src.t index d91cfdc99..4d16eac4f 100644 --- a/t/repobrowse_git_tree.t +++ b/t/repobrowse_git_src.t @@ -7,7 +7,7 @@ my $test = require './t/repobrowse_common_git.perl'; test_psgi($test->{app}, sub { my ($cb) = @_; - my $req = 'http://example.com/test.git/tree/HEAD/dir'; + my $req = 'http://example.com/test.git/src/HEAD/dir'; my $res = $cb->(GET($req)); is(200, $res->code, 'got 200 response from dir'); my $noslash_body = dechunk($res); @@ -19,7 +19,7 @@ test_psgi($test->{app}, sub { is(301, $r2->code, 'got 301 response from dir with slash'); is($req, $r2->header('Location'), 'redirected w/o slash'); - $req = 'http://example.com/test.git/tree/master/foo.txt'; + $req = 'http://example.com/test.git/src/master/foo.txt'; my $blob = $cb->(GET($req)); is($blob->header('Content-Type'), 'text/html; charset=UTF-8', 'got text/html blob'); -- 2.47.3