bf2d5ea9d7c5b295f3f7a0a258a5fe057d680bd0
[catagits/Gitalist.git] / lib / Gitalist / URIStructure / Commit.pm
1 package Gitalist::URIStructure::Commit;
2 use MooseX::MethodAttributes::Role;
3 use Moose::Autobox;
4 use namespace::autoclean;
5
6 requires 'base';
7
8 after 'base' => sub {
9     my ($self, $c) = @_;
10     confess("No repository in the stash")
11         unless $c->stash->{Repository};
12 };
13
14 sub find : Chained('base') PathPart('') CaptureArgs(1) {
15     my ($self, $c, $sha1part) = @_;
16     # FIXME - Should not be here!
17     $c->stash->{Commit} = $c->stash->{Repository}->get_object_or_head($sha1part)
18         or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!");
19 }
20
21 sub diff : Chained('find') CaptureArgs(0) {}
22
23 sub diff_fancy : Chained('diff') PathPart('') Args(0) {}
24
25 sub diff_plain : Chained('diff') PathPart('plain') Args(0) {}
26
27 sub commit : Chained('find') PathPart('commit') Args(0) {}
28
29 sub tree : Chained('find') Does('FilenameArgs') Args() {}
30
31 sub find_blob : Action {
32     my ($self, $c) = @_;
33     # FIXME - Eugh!
34     my $h  = $c->stash->{Repository}->hash_by_path($c->stash->{Commit}->sha1, $c->stash->{filename})
35            || die "No file or sha1 provided.";
36     $c->stash(blob => $c->stash->{Repository}->get_object($h)->content);
37 }
38
39 sub blob : Chained('find') Does('FilenameArgs') Args() {
40     my ($self, $c) = @_;
41     $c->forward('find_blob');
42 }
43
44 sub blame : Chained('find') Does('FilenameArgs') Args() {}
45
46 sub history : Chained('find') Does('FilenameArgs') Args() {}
47
48 sub shortlog : Chained('find') Does('FilenameArgs') Args() {}
49
50 sub longlog : Chained('find') Does('FilenameArgs') PathPart('log') Args() {}
51
52 1;