Fix a load of links, and fix blob/blame/raw/history actions to (semi) work + tests
[catagits/Gitalist.git] / lib / Gitalist / Controller / Commit.pm
CommitLineData
f6a72048 1package Gitalist::Controller::Commit;
2
3use Moose;
f6a72048 4use namespace::autoclean;
5
b6ec181b 6BEGIN { extends 'Gitalist::Controller' }
0da7966e 7with 'Gitalist::URIStructure::Commit';
f6a72048 8
9sub base : Chained('/repository/find') PathPart('') CaptureArgs(0) {}
10
ca06a177 11sub raw : Chained('find') Does('FilenameArgs') Args() {
b132dce6 12 my ($self, $c) = @_;
ca06a177 13 $c->forward('find_blob');
b132dce6 14
15 $c->response->content_type('text/plain; charset=utf-8');
16 $c->response->body(delete $c->stash->{blob});
17}
18
19=head2 snapshot
20
21Provides a snapshot of a given commit.
22
23=cut
24
25sub snapshot : Chained('base') Args() {
26 my ($self, $c, $format) = @_;
27 $format ||= 'tgz';
28 my @snap = $c->stash->{Repository}->snapshot(
29 sha1 => $c->stash->{Commit}->sha1,
30 format => $format
31 );
32 $c->response->status(200);
33 $c->response->headers->header( 'Content-Disposition' =>
34 "attachment; filename=$snap[0]");
35 $c->response->body($snap[1]);
36}
37
8fd20a28 38=head2 patch
39
40A raw patch for a given commit.
41
42=cut
43
44sub patch : Chained('find') Args(0) {
45 my ($self, $c) = @_;
46 $c->detach('patches', [1]);
47}
48
49=head2 patches
50
51The patcheset for a given commit ???
52
53=cut
54
55sub patches : Chained('find') Args(1) {
56 my ($self, $c, $count) = @_;
57 $count ||= Gitalist->config->{patches}{max};
58 my $commit = $c->stash->{Commit};
59 my $parent = $c->req->param('hp') || undef; # FIXME
60 my $patch = $commit->get_patch( $parent, $count );
61 $c->response->body($patch);
62 $c->response->content_type('text/plain');
63 $c->response->status(200);
64}
65
f6a72048 66__PACKAGE__->meta->make_immutable;