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 | |
11 | sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {} |
12 | |
7998de12 |
13 | sub _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 |
33 | after diff_fancy => sub { |
34 | my ($self, $c) = @_; |
7998de12 |
35 | $self->_diff($c); |
d361d955 |
36 | $c->forward('View::SyntaxHighlight'); |
37 | }; |
38 | |
39 | after diff_plain => sub { |
40 | my ($self, $c) = @_; |
7998de12 |
41 | $self->_diff($c); |
493327c8 |
42 | }; |
43 | |
1b33f63b |
44 | after tree => sub { |
b6ec181b |
45 | my ( $self, $c ) = @_; |
1b33f63b |
46 | my $repository = $c->stash->{Repository}; |
47 | my $commit = $c->stash->{Commit}; |
b6ec181b |
48 | my $tree = $c->stash->{filename} |
49 | ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename})) |
1b33f63b |
50 | : $repository->get_object($commit->tree_sha1) |
51 | ; |
52 | $c->stash( |
53 | tree => $tree, |
54 | tree_list => [$repository->list_tree($tree->sha1)], |
b6ec181b |
55 | path => $c->stash->{filename}, # FIXME? |
1b33f63b |
56 | ); |
57 | }; |
58 | |
571348f6 |
59 | after 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 | # XXX Hack hack hack, see View::SyntaxHighlight |
b6ec181b |
68 | language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''), |
571348f6 |
69 | blob => join("\n", map $_->{line}, @$blame), |
70 | ); |
71 | |
72 | $c->forward('View::SyntaxHighlight') |
73 | unless $c->stash->{no_wrapper}; |
74 | }; |
75 | |
85aed493 |
76 | =head2 blob |
77 | |
78 | The blob action i.e the contents of a file. |
79 | |
80 | =cut |
81 | |
82 | after blob => sub { |
b6ec181b |
83 | my ( $self, $c ) = @_; |
85aed493 |
84 | $c->stash( |
85aed493 |
85 | # XXX Hack hack hack, see View::SyntaxHighlight |
b6ec181b |
86 | language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''), |
85aed493 |
87 | ); |
88 | |
89 | $c->forward('View::SyntaxHighlight') |
90 | unless $c->stash->{no_wrapper}; |
91 | }; |
92 | |
18fdf3d0 |
93 | after history => sub { |
94 | my ($self, $c) = @_; |
95 | my $repository = $c->stash->{Repository}; |
96 | my $filename = $c->stash->{filename}; |
97 | |
98 | my %logargs = ( |
99 | sha1 => $c->stash->{Commit}->sha1, |
100 | count => 25, #Gitalist->config->{paging}{log} || 25, |
101 | ($filename ? (file => $filename) : ()) |
102 | ); |
103 | |
104 | my $file = $repository->get_object( |
105 | $repository->hash_by_path( |
106 | $repository->head_hash, |
107 | $filename |
108 | ) |
109 | ); |
110 | |
111 | my $page = $c->req->param('pg') || 0; |
112 | $logargs{skip} = $c->req->param('pg') * $logargs{count} |
113 | if $c->req->param('pg'); |
114 | |
115 | $c->stash( |
116 | log_lines => [$repository->list_revs(%logargs)], |
117 | refs => $repository->references, |
118 | filename => $filename, |
119 | filetype => $file->type, |
120 | ); |
121 | }; |
122 | |
0da7966e |
123 | __PACKAGE__->meta->make_immutable; |