Change everything round to be /ref/ instead of /commit/ as this makes more sense
[catagits/Gitalist.git] / lib / Gitalist / Controller / Ref.pm
1 package Gitalist::Controller::Ref;
2
3 use Moose;
4 use namespace::autoclean;
5
6 BEGIN { extends 'Gitalist::Controller' }
7 with 'Gitalist::URIStructure::Ref';
8
9 sub base : Chained('/repository/find') PathPart('') CaptureArgs(0) {}
10
11 sub raw : Chained('find') Does('FilenameArgs') Args() {
12     my ($self, $c) = @_;
13     $c->forward('find_blob');
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
21 Provides a snapshot of a given commit.
22
23 =cut
24
25 sub 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
38 =head2 patch
39
40 A raw patch for a given commit.
41
42 =cut
43
44 sub patch : Chained('find') Args(0) {
45     my ($self, $c) = @_;
46     $c->detach('patches', [1]);
47 }
48
49 =head2 patches
50
51 The patcheset for a given commit ???
52
53 =cut
54
55 sub 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
66 __PACKAGE__->meta->make_immutable;