Commit | Line | Data |
2980657b |
1 | package Gitalist::Controller::Fragment::Ref; |
0da7966e |
2 | use Moose; |
3 | use namespace::autoclean; |
4 | |
b6ec181b |
5 | BEGIN { extends 'Gitalist::Controller' } |
b9423b8e |
6 | with qw/ |
7 | Gitalist::URIStructure::Ref |
8 | Gitalist::URIStructure::Fragment::WithLog |
9 | /; |
0da7966e |
10 | |
e172b6b8 |
11 | use File::Type::WebImages (); |
12 | |
0da7966e |
13 | sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {} |
14 | |
7998de12 |
15 | sub _diff { |
493327c8 |
16 | my ($self, $c) = @_; |
586572a7 |
17 | my %diff_args = ( patch => 1 ); |
18 | foreach my $arg qw/filename parent/ { |
19 | if (defined $c->stash->{$arg}) { |
20 | $diff_args{$arg} = $c->stash->{$arg}; |
21 | }; |
22 | }; |
23 | my ($tree, $patch) = $c->stash->{Commit}->diff( |
24 | %diff_args, |
493327c8 |
25 | ); |
26 | $c->stash( |
27 | diff_tree => $tree, |
28 | diff => $patch, |
29 | # XXX Hack hack hack, see View::SyntaxHighlight |
30 | blobs => [map $_->{diff}, @$patch], |
31 | language => 'Diff', |
32 | ); |
7998de12 |
33 | } |
493327c8 |
34 | |
d361d955 |
35 | after diff_fancy => sub { |
36 | my ($self, $c) = @_; |
7998de12 |
37 | $self->_diff($c); |
d361d955 |
38 | $c->forward('View::SyntaxHighlight'); |
39 | }; |
40 | |
41 | after diff_plain => sub { |
42 | my ($self, $c) = @_; |
7998de12 |
43 | $self->_diff($c); |
493327c8 |
44 | }; |
45 | |
1b33f63b |
46 | after tree => sub { |
b6ec181b |
47 | my ( $self, $c ) = @_; |
1b33f63b |
48 | my $repository = $c->stash->{Repository}; |
49 | my $commit = $c->stash->{Commit}; |
b6ec181b |
50 | my $tree = $c->stash->{filename} |
51 | ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename})) |
1b33f63b |
52 | : $repository->get_object($commit->tree_sha1) |
53 | ; |
54 | $c->stash( |
55 | tree => $tree, |
56 | tree_list => [$repository->list_tree($tree->sha1)], |
1b33f63b |
57 | ); |
58 | }; |
59 | |
571348f6 |
60 | after 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 | |
79 | The blob action i.e the contents of a file. |
80 | |
81 | =cut |
82 | |
83 | after blob => sub { |
b6ec181b |
84 | my ( $self, $c ) = @_; |
85aed493 |
85 | $c->stash( |
85aed493 |
86 | # XXX Hack hack hack, see View::SyntaxHighlight |
e172b6b8 |
87 | language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''), |
88 | is_image => File::Type::WebImages::mime_type($c->stash->{blob}), |
53a9d6de |
89 | is_binary => Gitalist::Utils::is_binary($c->stash->{blob}), |
85aed493 |
90 | ); |
91 | |
92 | $c->forward('View::SyntaxHighlight') |
93 | unless $c->stash->{no_wrapper}; |
94 | }; |
95 | |
18fdf3d0 |
96 | after history => sub { |
97 | my ($self, $c) = @_; |
98 | my $repository = $c->stash->{Repository}; |
99 | my $filename = $c->stash->{filename}; |
100 | |
101 | my %logargs = ( |
102 | sha1 => $c->stash->{Commit}->sha1, |
103 | count => 25, #Gitalist->config->{paging}{log} || 25, |
104 | ($filename ? (file => $filename) : ()) |
105 | ); |
106 | |
107 | my $file = $repository->get_object( |
108 | $repository->hash_by_path( |
109 | $repository->head_hash, |
110 | $filename |
111 | ) |
112 | ); |
113 | |
114 | my $page = $c->req->param('pg') || 0; |
115 | $logargs{skip} = $c->req->param('pg') * $logargs{count} |
116 | if $c->req->param('pg'); |
117 | |
118 | $c->stash( |
119 | log_lines => [$repository->list_revs(%logargs)], |
120 | refs => $repository->references, |
121 | filename => $filename, |
122 | filetype => $file->type, |
123 | ); |
124 | }; |
125 | |
0da7966e |
126 | __PACKAGE__->meta->make_immutable; |