1 package Gitalist::Controller::Fragment::Commit;
3 use namespace::autoclean;
5 BEGIN { extends 'Catalyst::Controller' }
6 with 'Gitalist::URIStructure::Commit';
8 sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
12 my $commit = $c->stash->{Commit};
13 my($tree, $patch) = $c->stash->{Repository}->diff(
15 parent => $c->req->param('hp') || undef,
21 # XXX Hack hack hack, see View::SyntaxHighlight
22 blobs => [map $_->{diff}, @$patch],
27 after diff_fancy => sub {
29 $c->forward('View::SyntaxHighlight');
32 after diff_plain => sub {
34 $c->response->content_type('text/plain; charset=utf-8');
38 my ( $self, $c, @fn ) = @_;
39 my $repository = $c->stash->{Repository};
40 my $commit = $c->stash->{Commit};
41 my $filename = join('/', @fn);
43 ? $repository->get_object($repository->hash_by_path($commit->sha1, $filename))
44 : $repository->get_object($commit->tree_sha1)
48 tree_list => [$repository->list_tree($tree->sha1)],
54 my($self, $c, @fn) = @_;
56 my $repository = $c->stash->{Repository};
57 my $filename = join('/', @fn);
59 my $blame = $c->stash->{Commit}->blame($filename, $c->stash->{Commit}->sha1);
62 filename => $filename,
64 # XXX Hack hack hack, see View::SyntaxHighlight
65 language => ($filename =~ /\.p[lm]$/i ? 'Perl' : ''),
66 blob => join("\n", map $_->{line}, @$blame),
69 $c->forward('View::SyntaxHighlight')
70 unless $c->stash->{no_wrapper};
75 The blob action i.e the contents of a file.
80 my ( $self, $c, @fn ) = @_;
82 my $filename = join('/', @fn);
83 my $repository = $c->stash->{Repository};
85 $repository->hash_by_path($c->stash->{Commit}->sha1, $filename)
86 || die "No file or sha1 provided.";
87 my $blob = $repository->get_object($h);
89 blob => $blob->content,
90 filename => $filename,
91 # XXX Hack hack hack, see View::SyntaxHighlight
92 language => ($filename =~ /\.p[lm]$/i ? 'Perl' : ''),
95 $c->forward('View::SyntaxHighlight')
96 unless $c->stash->{no_wrapper};
99 __PACKAGE__->meta->make_immutable;