Commit | Line | Data |
2980657b |
1 | package Gitalist::Controller::Ref; |
f6a72048 |
2 | |
3 | use Moose; |
f6a72048 |
4 | use namespace::autoclean; |
5 | |
b6ec181b |
6 | BEGIN { extends 'Gitalist::Controller' } |
2980657b |
7 | with 'Gitalist::URIStructure::Ref'; |
f6a72048 |
8 | |
e172b6b8 |
9 | use File::Type; |
10 | use File::Type::WebImages (); |
11 | |
f6a72048 |
12 | sub base : Chained('/repository/find') PathPart('') CaptureArgs(0) {} |
13 | |
ae36e02c |
14 | after commit => sub { |
15 | my($self, $c) = @_; |
16 | |
586572a7 |
17 | $c->stash->{diff_tree} = ( $c->stash->{Commit}->diff )[0]; |
ae36e02c |
18 | }; |
19 | |
ca06a177 |
20 | sub raw : Chained('find') Does('FilenameArgs') Args() { |
b132dce6 |
21 | my ($self, $c) = @_; |
ca06a177 |
22 | $c->forward('find_blob'); |
b132dce6 |
23 | |
53a9d6de |
24 | if(!Gitalist::Utils::is_binary($c->stash->{blob})) { |
6ee49ff4 |
25 | $c->response->content_type('text/plain; charset=utf-8'); |
e172b6b8 |
26 | } else { |
6ee49ff4 |
27 | my $ft = File::Type->new(); |
28 | $c->response->content_type( |
29 | File::Type::WebImages::mime_type($c->stash->{blob}) |
30 | || File::Type->new->mime_type($c->stash->{blob}) |
31 | ); |
e172b6b8 |
32 | } |
33 | |
606ffc33 |
34 | utf8::decode($c->stash->{blob}); |
b132dce6 |
35 | $c->response->body(delete $c->stash->{blob}); |
36 | } |
37 | |
38 | =head2 snapshot |
39 | |
40 | Provides a snapshot of a given commit. |
41 | |
42 | =cut |
43 | |
d423d020 |
44 | sub snapshot : Chained('find') PathPart('snapshot') Args() { |
b132dce6 |
45 | my ($self, $c, $format) = @_; |
46 | $format ||= 'tgz'; |
47 | my @snap = $c->stash->{Repository}->snapshot( |
48 | sha1 => $c->stash->{Commit}->sha1, |
49 | format => $format |
50 | ); |
51 | $c->response->status(200); |
52 | $c->response->headers->header( 'Content-Disposition' => |
53 | "attachment; filename=$snap[0]"); |
54 | $c->response->body($snap[1]); |
55 | } |
56 | |
8fd20a28 |
57 | =head2 patch |
58 | |
59 | A raw patch for a given commit. |
60 | |
61 | =cut |
62 | |
63 | sub patch : Chained('find') Args(0) { |
64 | my ($self, $c) = @_; |
65 | $c->detach('patches', [1]); |
66 | } |
67 | |
68 | =head2 patches |
69 | |
70 | The patcheset for a given commit ??? |
71 | |
72 | =cut |
73 | |
74 | sub patches : Chained('find') Args(1) { |
75 | my ($self, $c, $count) = @_; |
76 | $count ||= Gitalist->config->{patches}{max}; |
77 | my $commit = $c->stash->{Commit}; |
78 | my $parent = $c->req->param('hp') || undef; # FIXME |
79 | my $patch = $commit->get_patch( $parent, $count ); |
80 | $c->response->body($patch); |
81 | $c->response->content_type('text/plain'); |
82 | $c->response->status(200); |
83 | } |
84 | |
f6a72048 |
85 | __PACKAGE__->meta->make_immutable; |