use IO::Capture::Stdout;
use File::Slurp qw(slurp);
-#sub default :Path {
sub run_gitweb {
my ( $self, $c ) = @_;
);
}
+sub blob : Local {
+ my ( $self, $c ) = @_;
+
+ my $git = $c->model('Git');
+ my $req = $c->req;
+ my $filename = $req->param('f') || $req->param('filename');
+ my $hash = $req->param('hb') || $req->param('hashbase')
+ || $git->get_head_hash($req->param('p') || $req->param('project'));
+ my $filehash = $git->get_hash_by_path($hash, $filename, 'blob');
+
+ my $blob = $git->run_cmd('cat-file' => blob => $filehash);
+
+ $c->stash(
+ blob => encode_entities($blob),
+ action => 'blob',
+ );
+}
+
sub auto : Private {
my($self, $c) = @_;
if(defined $project) {
$c->stash(
- search_text => $c->req->param('s') || $c->req->param('searchtext'),
- search_hash => $c->req->param('hb') || $c->req->param('hashbase')
+ search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
+ search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
|| $c->req->param('h') || $c->req->param('hash')
- || 'HEAD'
+ || 'HEAD' ),
);
}
}
return $output;
}
+sub get_hash_by_path {
+ my($self, $base, $path, $type) = @_;
+
+ $path =~ s{/+$}();
+
+ my $line = $self->run_cmd('ls-tree', $base, '--', $path)
+ or return;
+
+ #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
+ $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
+ return defined $type && $type ne $2
+ ? ()
+ : return $3;
+}
+
sub cat_file {
my ($self, $project, $object) = @_;
END;
IF action;
- # XXX Err ... yeah, slight hack here ... ahem.
- INCLUDE "index.tt2";
+ SET actmpl = action _ ".tt2";
+ INCLUDE $actmpl;
ELSE;
# The output of gitweb.cgi is injected at this point.
content;