X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FController%2FFragment%2FRef.pm;h=8f58ce09c3395e6f419bfc2b659e4090c174b0eb;hb=2298d93ff984748b0c15d19bad6fdebb1d81c4f1;hp=e537896a31bd415f2f2dba9860eee82aea2af443;hpb=3a58f004e86fccfa384065e6da7d268917afb1b8;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Controller/Fragment/Ref.pm b/lib/Gitalist/Controller/Fragment/Ref.pm index e537896..8f58ce0 100644 --- a/lib/Gitalist/Controller/Fragment/Ref.pm +++ b/lib/Gitalist/Controller/Fragment/Ref.pm @@ -8,32 +8,35 @@ with qw/ Gitalist::URIStructure::Fragment::WithLog /; +use File::Type::WebImages (); +use JSON::XS qw(encode_json); + sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {} sub _diff { my ($self, $c) = @_; - my $commit = $c->stash->{Commit}; - my %filename = $c->stash->{filename} ? (filename => $c->stash->{filename}) : (); - my($tree, $patch) = $c->stash->{Repository}->diff( - commit => $commit, - parent => $c->stash->{parent}, - patch => 1, - %filename, + my %diff_args = ( patch => 1 ); + foreach my $arg qw/filename parent/ { + if (defined $c->stash->{$arg}) { + $diff_args{$arg} = $c->stash->{$arg}; + }; + }; + my ($tree, $patch) = $c->stash->{Commit}->diff( + %diff_args, ); $c->stash( diff_tree => $tree, diff => $patch, # XXX Hack hack hack, see View::SyntaxHighlight blobs => [map $_->{diff}, @$patch], - language => 'Diff', - %filename, + %diff_args, ); } after diff_fancy => sub { my ($self, $c) = @_; $self->_diff($c); - $c->forward('View::SyntaxHighlight'); + $c->forward('Model::ContentMangler'); }; after diff_plain => sub { @@ -45,13 +48,13 @@ after tree => sub { my ( $self, $c ) = @_; my $repository = $c->stash->{Repository}; my $commit = $c->stash->{Commit}; - my $tree = $c->stash->{filename} - ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename})) - : $repository->get_object($commit->tree_sha1) + my $tree_obj = $c->stash->{filename} + ? $commit->sha_by_path($c->stash->{filename}) + : $commit->tree->[0] ; $c->stash( - tree => $tree, - tree_list => [$repository->list_tree($tree->sha1)], + tree => $tree_obj, + tree_list => $tree_obj->tree, ); }; @@ -59,19 +62,22 @@ after blame => sub { my($self, $c) = @_; my $repository = $c->stash->{Repository}; - # WTF? + my $blame = $c->stash->{Commit}->blame($c->stash->{filename}, $c->stash->{Commit}->sha1); $c->stash( blame => $blame, - # XXX Hack hack hack, see View::SyntaxHighlight - language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''), blob => join("\n", map $_->{line}, @$blame), ); - $c->forward('View::SyntaxHighlight') - unless $c->stash->{no_wrapper}; + $c->forward('Model::ContentMangler'); }; +=encoding UTF-8 + +=head1 NAME + +Gitalist::Controller::Fragment::Ref - Fragment::Ref module for Gitalist::Controller + =head2 blob The blob action i.e the contents of a file. @@ -81,12 +87,10 @@ The blob action i.e the contents of a file. after blob => sub { my ( $self, $c ) = @_; $c->stash( - # XXX Hack hack hack, see View::SyntaxHighlight - language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''), + is_image => File::Type::WebImages::mime_type($c->stash->{blob}), + is_binary => Gitalist::Utils::is_binary($c->stash->{blob}), ); - - $c->forward('View::SyntaxHighlight') - unless $c->stash->{no_wrapper}; + $c->forward('Model::ContentMangler'); }; after history => sub { @@ -96,16 +100,12 @@ after history => sub { my %logargs = ( sha1 => $c->stash->{Commit}->sha1, - count => 25, #Gitalist->config->{paging}{log} || 25, + count => Gitalist->config->{paging}{log} || 25, ($filename ? (file => $filename) : ()) ); - my $file = $repository->get_object( - $repository->hash_by_path( - $repository->head_hash, - $filename - ) - ); + my $commit = $repository->get_object('HEAD'); + my $file = $commit->sha_by_path($filename); my $page = $c->req->param('pg') || 0; $logargs{skip} = $c->req->param('pg') * $logargs{count} @@ -116,7 +116,32 @@ after history => sub { refs => $repository->references, filename => $filename, filetype => $file->type, + page => $page, + ); +}; + +after file_commit_info => sub { + my ($self, $c) = @_; + + my $repository = $c->stash->{Repository}; + + my($commit) = $repository->list_revs( + sha1 => $c->stash->{Commit}->sha1, + count => 1, + file => $c->stash->{filename}, ); + + my $json_obj = !$commit + ? { } + : { + sha1 => $commit->sha1, + comment => $c->stash->{short_cmt}->($commit->comment), + age => $c->stash->{time_since}->($commit->authored_time), + }; + + $c->response->content_type('application/json'); + # XXX Make use of the json branch + $c->response->body( encode_json $json_obj ); }; __PACKAGE__->meta->make_immutable;