use PublicInbox::RepoConfig;
my %CMD = map { lc($_) => $_ } qw(Log Commit Tree);
+my %VCS = (git => 'Git');
+my %LOADED;
sub new {
my ($class, $file) = @_;
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 ? '' : './';
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;
# 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);
$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};
# 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};
# 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);
$fh->close;
}
-sub call_git {
+sub call_git_tree {
my ($self, $req) = @_;
sub { git_tree_stream($self, $req, @_) };
}