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