my $cmd = shift @extra;
if (defined $cmd && length $cmd) {
- my $vcs = $VCS{$repo_info->{vcs}} or return r404();
+ my $vcs_lc = $repo_info->{vcs};
+ my $vcs = $VCS{$vcs_lc} 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";
- $LOADED{$mod} = 1 unless $@;
- }
+ $mod = load_once("PublicInbox::RepoBrowse$vcs$mod");
+ $vcs = load_once("PublicInbox::$vcs");
+ $repo_info->{$vcs_lc} ||= $vcs->new($repo_info->{path});
+
$req->{relcmd} = '../' x scalar(@extra);
my $rv = eval { $mod->new->call($cmd, $req) };
$rv || r404();
sub r404 { r(404, 'Not Found') }
+sub load_once {
+ my ($mod) = @_;
+
+ return $mod if $LOADED{$mod};
+ eval "require $mod";
+ $LOADED{$mod} = 1 unless $@;
+ $mod;
+}
+
1;
use warnings;
use base qw(PublicInbox::RepoBrowseBase);
use PublicInbox::Hval qw(utf8_html);
-use PublicInbox::Git;
use PublicInbox::RepoBrowseGit qw(git_unquote git_commit_title);
use constant GIT_FMT => '--pretty=format:'.join('%n',
sub call_git_commit {
my ($self, $req) = @_;
- my $repo_info = $req->{repo_info};
- my $dir = $repo_info->{path};
my $q = PublicInbox::RepoBrowseQuery->new($req->{cgi});
my $id = $q->{id};
$id eq '' and $id = 'HEAD';
- my $git = $repo_info->{git} ||= PublicInbox::Git->new($dir);
-
+ my $git = $req->{repo_info}->{git};
my @cmd = qw(show -z --numstat -p --cc --encoding=UTF-8
--no-notes --no-color --abbrev=10);
my @path;
use strict;
use warnings;
use base qw(PublicInbox::RepoBrowseBase);
-use PublicInbox::Git;
sub call_git_log {
my ($self, $req) = @_;
my $repo_info = $req->{repo_info};
- my $path = $repo_info->{path};
my $max = $repo_info->{max_commit_count} || 50;
$max = int($max);
$max = 50 if $max == 0;
my $ofs = $q->{ofs};
$h .= "~$ofs" if $ofs =~ /\A\d+\z/;
- my $git = $repo_info->{git} ||= PublicInbox::Git->new($path);
+ my $git = $repo_info->{git};
my $log = $git->popen(qw(log --no-notes --no-color
--abbrev-commit --abbrev=16),
"--format=$fmt", "-$max", $h);
use strict;
use warnings;
use base qw(PublicInbox::RepoBrowseBase);
-use PublicInbox::Git;
sub call_git_patch {
my ($self, $req) = @_;
- my $repo_info = $req->{repo_info};
- my $dir = $repo_info->{path};
- my $git = $repo_info->{git} ||= PublicInbox::Git->new($dir);
-
+ my $git = $req->{repo_info}->{git};
my $q = PublicInbox::RepoBrowseQuery->new($req->{cgi});
my $id = $q->{id};
$id eq '' and $id = 'HEAD';
use strict;
use warnings;
use base qw(PublicInbox::RepoBrowseBase);
-use PublicInbox::Git;
use PublicInbox::Hval qw(utf8_html);
my %GIT_MODE = (
sub git_tree_stream {
my ($self, $req, $res) = @_; # res: Plack callback
- my $repo_info = $req->{repo_info};
- my $dir = $repo_info->{path};
my @extra = @{$req->{extra}};
my $tslash;
if (@extra && $extra[-1] eq '') { # no trailing slash
$id eq '' and $id = 'HEAD';
my $obj = "$id:$tree_path";
- my $git = $repo_info->{git} ||= PublicInbox::Git->new($dir);
+ my $git = $req->{repo_info}->{git};
my ($hex, $type, $size) = $git->check($obj);
if (!defined($type) || ($type ne 'blob' && $type ne 'tree')) {