Bump version to 0.002008, regen README, update Changes.
[catagits/Gitalist.git] / lib / Gitalist / Controller / Ref.pm
CommitLineData
2980657b 1package Gitalist::Controller::Ref;
f6a72048 2
3use Moose;
f6a72048 4use namespace::autoclean;
5
b6ec181b 6BEGIN { extends 'Gitalist::Controller' }
2980657b 7with 'Gitalist::URIStructure::Ref';
f6a72048 8
e172b6b8 9use File::Type;
10use File::Type::WebImages ();
11
f6a72048 12sub base : Chained('/repository/find') PathPart('') CaptureArgs(0) {}
13
ae36e02c 14after commit => sub {
15 my($self, $c) = @_;
16
586572a7 17 $c->stash->{diff_tree} = ( $c->stash->{Commit}->diff )[0];
ae36e02c 18};
19
ca06a177 20sub 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
b132dce6 34 $c->response->body(delete $c->stash->{blob});
35}
36
37=head2 snapshot
38
39Provides a snapshot of a given commit.
40
41=cut
42
d423d020 43sub snapshot : Chained('find') PathPart('snapshot') Args() {
b132dce6 44 my ($self, $c, $format) = @_;
45 $format ||= 'tgz';
46 my @snap = $c->stash->{Repository}->snapshot(
47 sha1 => $c->stash->{Commit}->sha1,
48 format => $format
49 );
50 $c->response->status(200);
51 $c->response->headers->header( 'Content-Disposition' =>
52 "attachment; filename=$snap[0]");
53 $c->response->body($snap[1]);
54}
55
8fd20a28 56=head2 patch
57
58A raw patch for a given commit.
59
60=cut
61
62sub patch : Chained('find') Args(0) {
63 my ($self, $c) = @_;
64 $c->detach('patches', [1]);
65}
66
67=head2 patches
68
69The patcheset for a given commit ???
70
71=cut
72
73sub patches : Chained('find') Args(1) {
74 my ($self, $c, $count) = @_;
75 $count ||= Gitalist->config->{patches}{max};
76 my $commit = $c->stash->{Commit};
77 my $parent = $c->req->param('hp') || undef; # FIXME
78 my $patch = $commit->get_patch( $parent, $count );
79 $c->response->body($patch);
80 $c->response->content_type('text/plain');
81 $c->response->status(200);
82}
83
f6a72048 84__PACKAGE__->meta->make_immutable;