about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-12-22 01:36:45 +0000
committerEric Wong <e@80x24.org>2016-04-05 18:58:27 +0000
commitc2a9bc53532ace22dbb143ef7df65cf063ae6e4f (patch)
treef0eb8c44f4c1b74ac8998472a109c092fc3c330a /lib/PublicInbox
parent4a6dbe24f2e5abb30be6aa4c5602ca7e9d33689f (diff)
downloadpublic-inbox-c2a9bc53532ace22dbb143ef7df65cf063ae6e4f.tar.gz
Currently we only support git, but this should make it easier
to handle other VCS-es in the future.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/RepoBrowse.pm15
-rw-r--r--lib/PublicInbox/RepoBrowseBase.pm4
-rw-r--r--lib/PublicInbox/RepoBrowseGitCommit.pm (renamed from lib/PublicInbox/RepoBrowseCommit.pm)4
-rw-r--r--lib/PublicInbox/RepoBrowseGitLog.pm (renamed from lib/PublicInbox/RepoBrowseLog.pm)4
-rw-r--r--lib/PublicInbox/RepoBrowseGitTree.pm (renamed from lib/PublicInbox/RepoBrowseTree.pm)4
5 files changed, 17 insertions, 14 deletions
diff --git a/lib/PublicInbox/RepoBrowse.pm b/lib/PublicInbox/RepoBrowse.pm
index 0b3197ea..fcecf472 100644
--- a/lib/PublicInbox/RepoBrowse.pm
+++ b/lib/PublicInbox/RepoBrowse.pm
@@ -24,6 +24,8 @@ use URI::Escape qw(uri_escape_utf8 uri_unescape);
 use PublicInbox::RepoConfig;
 
 my %CMD = map { lc($_) => $_ } qw(Log Commit Tree);
+my %VCS = (git => 'Git');
+my %LOADED;
 
 sub new {
         my ($class, $file) = @_;
@@ -61,15 +63,16 @@ sub run {
 
         my $cmd = shift @extra;
         if (defined $cmd && length $cmd) {
-                my $mod = $CMD{$cmd};
-                return r404() unless defined $mod;
-                if (index($mod, ':') < 0) {
-                        $mod = "PublicInbox::RepoBrowse$mod";
+                my $vcs = $VCS{$repo_info->{vcs}} or return r404();
+                my $mod = $CMD{$cmd} or return r404();
+                return r404() unless defined $mod && defined $vcs;
+                $mod = "PublicInbox::RepoBrowse$vcs$mod";
+                unless ($LOADED{$mod}) {
                         eval "require $mod";
-                        $CMD{$cmd} = $mod unless $@;
+                        $LOADED{$mod} = 1;
                 }
                 $req->{relcmd} = '../' x scalar(@extra);
-                my $rv = eval { $mod->new->call($req) };
+                my $rv = eval { $mod->new->call($cmd, $req) };
                 $rv || r404();
         } else {
                 $req->{relcmd} = defined $cmd ? ''  : './';
diff --git a/lib/PublicInbox/RepoBrowseBase.pm b/lib/PublicInbox/RepoBrowseBase.pm
index cd9e66de..e0ea2854 100644
--- a/lib/PublicInbox/RepoBrowseBase.pm
+++ b/lib/PublicInbox/RepoBrowseBase.pm
@@ -9,11 +9,11 @@ require PublicInbox::Hval;
 sub new { bless {}, shift }
 
 sub call {
-        my ($self, $req) = @_;
+        my ($self, $cmd, $req) = @_;
         my $vcs = $req->{repo_info}->{vcs};
         my $rv = eval {
                 no strict 'refs';
-                my $sub = 'call_'.$vcs;
+                my $sub = "call_${vcs}_$cmd";
                 $self->$sub($req);
         };
         $@ ? [ 500, ['Content-Type'=>'text/plain'], [] ] : $rv;
diff --git a/lib/PublicInbox/RepoBrowseCommit.pm b/lib/PublicInbox/RepoBrowseGitCommit.pm
index 91553d1c..1e2109ec 100644
--- a/lib/PublicInbox/RepoBrowseCommit.pm
+++ b/lib/PublicInbox/RepoBrowseGitCommit.pm
@@ -1,7 +1,7 @@
 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
-package PublicInbox::RepoBrowseCommit;
+package PublicInbox::RepoBrowseGitCommit;
 use strict;
 use warnings;
 use base qw(PublicInbox::RepoBrowseBase);
@@ -84,7 +84,7 @@ sub git_commit_stream {
         $fh->write('</pre></body></html>');
 }
 
-sub call_git {
+sub call_git_commit {
         my ($self, $req) = @_;
         my $repo_info = $req->{repo_info};
         my $path = $repo_info->{path};
diff --git a/lib/PublicInbox/RepoBrowseLog.pm b/lib/PublicInbox/RepoBrowseGitLog.pm
index 26b5204a..07d384ac 100644
--- a/lib/PublicInbox/RepoBrowseLog.pm
+++ b/lib/PublicInbox/RepoBrowseGitLog.pm
@@ -1,13 +1,13 @@
 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
-package PublicInbox::RepoBrowseLog;
+package PublicInbox::RepoBrowseGitLog;
 use strict;
 use warnings;
 use base qw(PublicInbox::RepoBrowseBase);
 use PublicInbox::Git;
 
-sub call_git {
+sub call_git_log {
         my ($self, $req) = @_;
         my $repo_info = $req->{repo_info};
         my $path = $repo_info->{path};
diff --git a/lib/PublicInbox/RepoBrowseTree.pm b/lib/PublicInbox/RepoBrowseGitTree.pm
index 47ecdd31..b176bb3f 100644
--- a/lib/PublicInbox/RepoBrowseTree.pm
+++ b/lib/PublicInbox/RepoBrowseGitTree.pm
@@ -1,6 +1,6 @@
 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-package PublicInbox::RepoBrowseTree;
+package PublicInbox::RepoBrowseGitTree;
 use strict;
 use warnings;
 use base qw(PublicInbox::RepoBrowseBase);
@@ -54,7 +54,7 @@ sub git_tree_stream {
         $fh->close;
 }
 
-sub call_git {
+sub call_git_tree {
         my ($self, $req) = @_;
         sub { git_tree_stream($self, $req, @_) };
 }