A manual cherry-picking of f012b0, making use of syn_engines work mostly.
[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
e172b6b8 11use File::Type::WebImages ();
12
0da7966e 13sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
14
7998de12 15sub _diff {
493327c8 16 my ($self, $c) = @_;
17 my $commit = $c->stash->{Commit};
7998de12 18 my %filename = $c->stash->{filename} ? (filename => $c->stash->{filename}) : ();
493327c8 19 my($tree, $patch) = $c->stash->{Repository}->diff(
20 commit => $commit,
7998de12 21 parent => $c->stash->{parent},
493327c8 22 patch => 1,
7998de12 23 %filename,
493327c8 24 );
25 $c->stash(
26 diff_tree => $tree,
27 diff => $patch,
28 # XXX Hack hack hack, see View::SyntaxHighlight
29 blobs => [map $_->{diff}, @$patch],
7998de12 30 %filename,
493327c8 31 );
7998de12 32}
493327c8 33
d361d955 34after diff_fancy => sub {
35 my ($self, $c) = @_;
7998de12 36 $self->_diff($c);
5424d43c 37 $c->forward('Model::ContentMangler');
d361d955 38};
39
40after diff_plain => sub {
41 my ($self, $c) = @_;
7998de12 42 $self->_diff($c);
493327c8 43};
44
1b33f63b 45after tree => sub {
b6ec181b 46 my ( $self, $c ) = @_;
1b33f63b 47 my $repository = $c->stash->{Repository};
48 my $commit = $c->stash->{Commit};
b6ec181b 49 my $tree = $c->stash->{filename}
50 ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename}))
1b33f63b 51 : $repository->get_object($commit->tree_sha1)
52 ;
53 $c->stash(
54 tree => $tree,
55 tree_list => [$repository->list_tree($tree->sha1)],
1b33f63b 56 );
57};
58
571348f6 59after blame => sub {
b6ec181b 60 my($self, $c) = @_;
571348f6 61
62 my $repository = $c->stash->{Repository};
571348f6 63 # WTF?
b6ec181b 64 my $blame = $c->stash->{Commit}->blame($c->stash->{filename}, $c->stash->{Commit}->sha1);
571348f6 65 $c->stash(
66 blame => $blame,
571348f6 67 blob => join("\n", map $_->{line}, @$blame),
68 );
69
5424d43c 70 $c->forward('Model::ContentMangler')
571348f6 71 unless $c->stash->{no_wrapper};
72};
73
85aed493 74=head2 blob
75
76The blob action i.e the contents of a file.
77
78=cut
79
80after blob => sub {
b6ec181b 81 my ( $self, $c ) = @_;
85aed493 82 $c->stash(
e172b6b8 83 is_image => File::Type::WebImages::mime_type($c->stash->{blob}),
53a9d6de 84 is_binary => Gitalist::Utils::is_binary($c->stash->{blob}),
85aed493 85 );
86
5424d43c 87 $c->forward('Model::ContentMangler')
85aed493 88 unless $c->stash->{no_wrapper};
89};
90
18fdf3d0 91after history => sub {
92 my ($self, $c) = @_;
93 my $repository = $c->stash->{Repository};
94 my $filename = $c->stash->{filename};
95
96 my %logargs = (
97 sha1 => $c->stash->{Commit}->sha1,
98 count => 25, #Gitalist->config->{paging}{log} || 25,
99 ($filename ? (file => $filename) : ())
100 );
101
102 my $file = $repository->get_object(
103 $repository->hash_by_path(
104 $repository->head_hash,
105 $filename
106 )
107 );
108
109 my $page = $c->req->param('pg') || 0;
110 $logargs{skip} = $c->req->param('pg') * $logargs{count}
111 if $c->req->param('pg');
112
113 $c->stash(
114 log_lines => [$repository->list_revs(%logargs)],
115 refs => $repository->references,
116 filename => $filename,
117 filetype => $file->type,
118 );
119};
120
0da7966e 121__PACKAGE__->meta->make_immutable;