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 | |
cbcd8397 |
6 | use Gitalist::Git::Types qw/SHA1/; |
7 | |
0da7966e |
8 | requires 'base'; |
9 | |
b9423b8e |
10 | with qw/ |
11 | Gitalist::URIStructure::WithLog |
12 | /; |
13 | |
0da7966e |
14 | after 'base' => sub { |
15 | my ($self, $c) = @_; |
16 | confess("No repository in the stash") |
17 | unless $c->stash->{Repository}; |
18 | }; |
19 | |
20 | sub find : Chained('base') PathPart('') CaptureArgs(1) { |
21 | my ($self, $c, $sha1part) = @_; |
22 | # FIXME - Should not be here! |
944f7f7b |
23 | $c->stash->{Commit} = $c->stash->{Repository}->get_object($sha1part) |
0da7966e |
24 | or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!"); |
2057d9bd |
25 | $c->stash->{data} = $c->stash->{Commit}; |
0da7966e |
26 | } |
27 | |
d361d955 |
28 | sub diff : Chained('find') CaptureArgs(0) {} |
29 | |
cbcd8397 |
30 | sub _set_diff_args { |
31 | my($self, $c, @rest) = @_; |
32 | |
7998de12 |
33 | # FIXME - This ain't pretty |
cbcd8397 |
34 | $c->stash(parent => shift @rest) |
c4ed9eb3 |
35 | if @rest == 2 |
36 | # Check that the single arg is unlikely to be a path. |
944f7f7b |
37 | or @rest && to_SHA1($rest[0]) && $c->stash->{Repository}->get_object($rest[0]); |
cbcd8397 |
38 | $c->stash(filename => $rest[-1]) |
7998de12 |
39 | if @rest; |
40 | } |
d361d955 |
41 | |
cbcd8397 |
42 | sub diff_fancy : Chained('diff') PathPart('') Args() { |
43 | my($self, $c, @rest) = @_; |
44 | |
45 | $self->_set_diff_args($c, @rest); |
46 | } |
47 | |
65f0ead5 |
48 | sub diff_plain : Chained('diff') PathPart('plain') Args() { |
49 | my($self, $c, $comparison, @rest) = @_; |
cbcd8397 |
50 | |
51 | $self->_set_diff_args($c, @rest); |
52 | |
65f0ead5 |
53 | $c->stash(no_wrapper => 1); |
54 | $c->response->content_type('text/plain; charset=utf-8'); |
8254b171 |
55 | } |
0da7966e |
56 | |
bec3aecb |
57 | sub commit : Chained('find') PathPart('commit') Args(0) {} |
0da7966e |
58 | |
5dc23a14 |
59 | sub file_commit_info : Chained('find') Does('FilenameArgs') Args() {} |
60 | |
b6ec181b |
61 | sub tree : Chained('find') Does('FilenameArgs') Args() {} |
0da7966e |
62 | |
ca06a177 |
63 | sub find_blob : Action { |
b132dce6 |
64 | my ($self, $c) = @_; |
592fa490 |
65 | my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)}; |
b9708061 |
66 | |
b132dce6 |
67 | # FIXME - Eugh! |
b9708061 |
68 | my $blob; |
69 | if ($object->isa('Gitalist::Git::Object::Commit')) { |
70 | $blob = $object->sha_by_path($c->stash->{filename}); |
71 | } elsif ($object->isa('Gitalist::Git::Object::Blob')) { |
72 | $blob = $object; |
73 | } else { |
74 | die "Unknown object type for '${\$object->sha1}'"; |
75 | } |
592fa490 |
76 | die "No file or sha1 provided." |
b9708061 |
77 | unless $blob; |
78 | |
79 | $c->stash(blob => $blob->content); |
b132dce6 |
80 | } |
1f9a47c2 |
81 | |
ca06a177 |
82 | sub blob : Chained('find') Does('FilenameArgs') Args() { |
83 | my ($self, $c) = @_; |
84 | $c->forward('find_blob'); |
85 | } |
1f9a47c2 |
86 | |
b6ec181b |
87 | sub blame : Chained('find') Does('FilenameArgs') Args() {} |
1f9a47c2 |
88 | |
b6ec181b |
89 | sub history : Chained('find') Does('FilenameArgs') Args() {} |
90 | |
0da7966e |
91 | 1; |