Provided support for blobdiff_plain legacy URIs.
[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 after commit => sub {
12   my($self, $c) = @_;
13
14   $c->stash->{diff_tree} = ($c->stash->{Repository}->diff(
15     commit => $c->stash->{Commit},
16   ))[0];
17 };
18
19 sub raw : Chained('find') Does('FilenameArgs') Args() {
20     my ($self, $c) = @_;
21     $c->forward('find_blob');
22
23     $c->response->content_type('text/plain; charset=utf-8');
24     $c->response->body(delete $c->stash->{blob});
25 }
26
27 =head2 snapshot
28
29 Provides a snapshot of a given commit.
30
31 =cut
32
33 sub snapshot : Chained('base') Args() {
34     my ($self, $c, $format) = @_;
35     $format ||= 'tgz';
36     my @snap = $c->stash->{Repository}->snapshot(
37         sha1 => $c->stash->{Commit}->sha1,
38         format => $format
39     );
40     $c->response->status(200);
41     $c->response->headers->header( 'Content-Disposition' =>
42                                        "attachment; filename=$snap[0]");
43     $c->response->body($snap[1]);
44 }
45
46 =head2 patch
47
48 A raw patch for a given commit.
49
50 =cut
51
52 sub patch : Chained('find') Args(0) {
53     my ($self, $c) = @_;
54     $c->detach('patches', [1]);
55 }
56
57 =head2 patches
58
59 The patcheset for a given commit ???
60
61 =cut
62
63 sub patches : Chained('find') Args(1) {
64     my ($self, $c, $count) = @_;
65     $count ||= Gitalist->config->{patches}{max};
66     my $commit = $c->stash->{Commit};
67     my $parent = $c->req->param('hp') || undef; # FIXME
68     my $patch = $commit->get_patch( $parent, $count );
69     $c->response->body($patch);
70     $c->response->content_type('text/plain');
71     $c->response->status(200);
72 }
73
74 __PACKAGE__->meta->make_immutable;