Commit | Line | Data |
2980657b |
1 | package Gitalist::URIStructure::Ref; |
0da7966e |
2 | use MooseX::MethodAttributes::Role; |
b6ec181b |
3 | use Moose::Autobox; |
0da7966e |
4 | use namespace::autoclean; |
5 | |
6 | requires 'base'; |
7 | |
b9423b8e |
8 | with qw/ |
9 | Gitalist::URIStructure::WithLog |
10 | /; |
11 | |
0da7966e |
12 | after 'base' => sub { |
13 | my ($self, $c) = @_; |
14 | confess("No repository in the stash") |
15 | unless $c->stash->{Repository}; |
16 | }; |
17 | |
18 | sub find : Chained('base') PathPart('') CaptureArgs(1) { |
19 | my ($self, $c, $sha1part) = @_; |
20 | # FIXME - Should not be here! |
dcb1b927 |
21 | $c->stash->{Commit} = $c->stash->{Repository}->get_object_or_head($sha1part) |
0da7966e |
22 | or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!"); |
23 | } |
24 | |
d361d955 |
25 | sub diff : Chained('find') CaptureArgs(0) {} |
26 | |
7998de12 |
27 | sub diff_fancy : Chained('diff') PathPart('') Args() { |
28 | my($self, $c, $comparison, @rest) = @_; |
29 | # FIXME - This ain't pretty |
30 | $c->stash->{parent} = $comparison |
31 | if $comparison; |
32 | $c->stash->{filename} = $rest[0] |
33 | if @rest; |
34 | } |
d361d955 |
35 | |
8254b171 |
36 | sub diff_plain : Chained('diff') PathPart('plain') Args(0) { |
37 | my($self, $c) = @_; |
38 | $c->stash->{no_wrapper} = 1; |
39 | } |
0da7966e |
40 | |
bec3aecb |
41 | sub commit : Chained('find') PathPart('commit') Args(0) {} |
0da7966e |
42 | |
b6ec181b |
43 | sub tree : Chained('find') Does('FilenameArgs') Args() {} |
0da7966e |
44 | |
ca06a177 |
45 | sub find_blob : Action { |
b132dce6 |
46 | my ($self, $c) = @_; |
894b2dc8 |
47 | my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)}; |
b132dce6 |
48 | # FIXME - Eugh! |
894b2dc8 |
49 | my $h = $object->isa('Gitalist::Git::Object::Commit') |
50 | ? $repo->hash_by_path($object->sha1, $c->stash->{filename}) |
51 | : $object->isa('Gitalist::Git::Object::Blob') |
52 | ? $object->sha1 |
53 | : die "Unknown object type for '${\$object->sha1}'"; |
54 | die "No file or sha1 provided." |
55 | unless $h; |
56 | $c->stash(blob => $repo->get_object($h)->content); |
b132dce6 |
57 | } |
1f9a47c2 |
58 | |
ca06a177 |
59 | sub blob : Chained('find') Does('FilenameArgs') Args() { |
60 | my ($self, $c) = @_; |
61 | $c->forward('find_blob'); |
62 | } |
1f9a47c2 |
63 | |
b6ec181b |
64 | sub blame : Chained('find') Does('FilenameArgs') Args() {} |
1f9a47c2 |
65 | |
b6ec181b |
66 | sub history : Chained('find') Does('FilenameArgs') Args() {} |
67 | |
0da7966e |
68 | 1; |