]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
repobrowse: prefix VCS-specific modules
authorEric Wong <e@80x24.org>
Tue, 22 Dec 2015 01:36:45 +0000 (01:36 +0000)
committerEric Wong <e@80x24.org>
Tue, 5 Apr 2016 18:58:27 +0000 (18:58 +0000)
Currently we only support git, but this should make it easier
to handle other VCS-es in the future.

lib/PublicInbox/RepoBrowse.pm
lib/PublicInbox/RepoBrowseBase.pm
lib/PublicInbox/RepoBrowseGitCommit.pm [moved from lib/PublicInbox/RepoBrowseCommit.pm with 98% similarity]
lib/PublicInbox/RepoBrowseGitLog.pm [moved from lib/PublicInbox/RepoBrowseLog.pm with 97% similarity]
lib/PublicInbox/RepoBrowseGitTree.pm [moved from lib/PublicInbox/RepoBrowseTree.pm with 98% similarity]

index 0b3197ea2432e7ba7c5fb29aa351c839f815a960..fcecf472de13374ec50e3c848c91776e56d957ad 100644 (file)
@@ -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 ? ''  : './';
index cd9e66de65b600935946863f338fd8f77f73d8ec..e0ea2854e97858e486badca50b01286c83c564f2 100644 (file)
@@ -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;
similarity index 98%
rename from lib/PublicInbox/RepoBrowseCommit.pm
rename to lib/PublicInbox/RepoBrowseGitCommit.pm
index 91553d1c6caeb6881a8701ad35d94572882fccc8..1e2109ecd48c73335255d4b3e4d94a7bf0037775 100644 (file)
@@ -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};
similarity index 97%
rename from lib/PublicInbox/RepoBrowseLog.pm
rename to lib/PublicInbox/RepoBrowseGitLog.pm
index 26b5204a29fe4791577326fd9296ac2c7ce36f9a..07d384ac28cece53ab11d0e05760d3af2e8d4655 100644 (file)
@@ -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};
similarity index 98%
rename from lib/PublicInbox/RepoBrowseTree.pm
rename to lib/PublicInbox/RepoBrowseGitTree.pm
index 47ecdd31914b4aa6a83e998d96437ed0e0a609ac..b176bb3f7687f6a04f4963f8b6fdeb1a817be145 100644 (file)
@@ -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, @_) };
 }