Fixed the links in the history view.
[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
7998de12 13sub _diff {
493327c8 14 my ($self, $c) = @_;
15 my $commit = $c->stash->{Commit};
7998de12 16 my %filename = $c->stash->{filename} ? (filename => $c->stash->{filename}) : ();
493327c8 17 my($tree, $patch) = $c->stash->{Repository}->diff(
18 commit => $commit,
7998de12 19 parent => $c->stash->{parent},
493327c8 20 patch => 1,
7998de12 21 %filename,
493327c8 22 );
23 $c->stash(
24 diff_tree => $tree,
25 diff => $patch,
26 # XXX Hack hack hack, see View::SyntaxHighlight
27 blobs => [map $_->{diff}, @$patch],
28 language => 'Diff',
7998de12 29 %filename,
493327c8 30 );
7998de12 31}
493327c8 32
d361d955 33after diff_fancy => sub {
34 my ($self, $c) = @_;
7998de12 35 $self->_diff($c);
d361d955 36 $c->forward('View::SyntaxHighlight');
37};
38
39after diff_plain => sub {
40 my ($self, $c) = @_;
7998de12 41 $self->_diff($c);
d361d955 42 $c->response->content_type('text/plain; charset=utf-8');
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)],
b6ec181b 56 path => $c->stash->{filename}, # FIXME?
1b33f63b 57 );
58};
59
571348f6 60after blame => sub {
b6ec181b 61 my($self, $c) = @_;
571348f6 62
63 my $repository = $c->stash->{Repository};
571348f6 64 # WTF?
b6ec181b 65 my $blame = $c->stash->{Commit}->blame($c->stash->{filename}, $c->stash->{Commit}->sha1);
571348f6 66 $c->stash(
67 blame => $blame,
571348f6 68 # XXX Hack hack hack, see View::SyntaxHighlight
b6ec181b 69 language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
571348f6 70 blob => join("\n", map $_->{line}, @$blame),
71 );
72
73 $c->forward('View::SyntaxHighlight')
74 unless $c->stash->{no_wrapper};
75};
76
85aed493 77=head2 blob
78
79The blob action i.e the contents of a file.
80
81=cut
82
83after blob => sub {
b6ec181b 84 my ( $self, $c ) = @_;
85aed493 85 $c->stash(
85aed493 86 # XXX Hack hack hack, see View::SyntaxHighlight
b6ec181b 87 language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
85aed493 88 );
89
90 $c->forward('View::SyntaxHighlight')
91 unless $c->stash->{no_wrapper};
92};
93
18fdf3d0 94after history => sub {
95 my ($self, $c) = @_;
96 my $repository = $c->stash->{Repository};
97 my $filename = $c->stash->{filename};
98
99 my %logargs = (
100 sha1 => $c->stash->{Commit}->sha1,
101 count => 25, #Gitalist->config->{paging}{log} || 25,
102 ($filename ? (file => $filename) : ())
103 );
104
105 my $file = $repository->get_object(
106 $repository->hash_by_path(
107 $repository->head_hash,
108 $filename
109 )
110 );
111
112 my $page = $c->req->param('pg') || 0;
113 $logargs{skip} = $c->req->param('pg') * $logargs{count}
114 if $c->req->param('pg');
115
116 $c->stash(
117 log_lines => [$repository->list_revs(%logargs)],
118 refs => $repository->references,
119 filename => $filename,
120 filetype => $file->type,
121 );
122};
123
0da7966e 124__PACKAGE__->meta->make_immutable;