Make the top row of actions generate uris which work again (partially)
[catagits/Gitalist.git] / lib / Gitalist / Controller / Fragment / Commit.pm
CommitLineData
0da7966e 1package Gitalist::Controller::Fragment::Commit;
2use Moose;
3use namespace::autoclean;
4
5BEGIN { extends 'Catalyst::Controller' }
6with 'Gitalist::URIStructure::Commit';
7
8sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
9
493327c8 10after diff => sub {
11 my ($self, $c) = @_;
12 my $commit = $c->stash->{Commit};
13 my($tree, $patch) = $c->stash->{Repository}->diff(
14 commit => $commit,
15 parent => $c->req->param('hp') || undef,
16 patch => 1,
17 );
18 $c->stash(
19 diff_tree => $tree,
20 diff => $patch,
21 # XXX Hack hack hack, see View::SyntaxHighlight
22 blobs => [map $_->{diff}, @$patch],
23 language => 'Diff',
24 );
d361d955 25};
493327c8 26
d361d955 27after diff_fancy => sub {
28 my ($self, $c) = @_;
29 $c->forward('View::SyntaxHighlight');
30};
31
32after diff_plain => sub {
33 my ($self, $c) = @_;
34 $c->response->content_type('text/plain; charset=utf-8');
493327c8 35};
36
1b33f63b 37after tree => sub {
38 my ( $self, $c, @fn ) = @_;
39 my $repository = $c->stash->{Repository};
40 my $commit = $c->stash->{Commit};
41 my $filename = join('/', @fn);
42 my $tree = $filename
43 ? $repository->get_object($repository->hash_by_path($commit->sha1, $filename))
44 : $repository->get_object($commit->tree_sha1)
45 ;
46 $c->stash(
47 tree => $tree,
48 tree_list => [$repository->list_tree($tree->sha1)],
49 path => $filename,
50 );
51};
52
571348f6 53after blame => sub {
54 my($self, $c, @fn) = @_;
55
56 my $repository = $c->stash->{Repository};
57 my $filename = join('/', @fn);
58
59 # WTF?
60 my $blame = $c->stash->{Commit}->blame($filename, $c->stash->{Commit}->sha1);
61 $c->stash(
62 blame => $blame,
63 filename => $filename,
64
65 # XXX Hack hack hack, see View::SyntaxHighlight
66 language => ($filename =~ /\.p[lm]$/i ? 'Perl' : ''),
67 blob => join("\n", map $_->{line}, @$blame),
68 );
69
70 $c->forward('View::SyntaxHighlight')
71 unless $c->stash->{no_wrapper};
72};
73
0da7966e 74__PACKAGE__->meta->make_immutable;