1 package Gitalist::URIStructure::Ref;
2 use MooseX::MethodAttributes::Role;
4 use namespace::autoclean;
6 use Gitalist::Git::Types qw/SHA1/;
11 Gitalist::URIStructure::WithLog
16 confess("No repository in the stash")
17 unless $c->stash->{Repository};
20 sub find : Chained('base') PathPart('') CaptureArgs(1) {
21 my ($self, $c, $sha1part) = @_;
22 # FIXME - Should not be here!
23 $c->stash->{Commit} = $c->stash->{Repository}->get_object_or_head($sha1part)
24 or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!");
27 sub diff : Chained('find') CaptureArgs(0) {}
30 my($self, $c, @rest) = @_;
32 # FIXME - This ain't pretty
33 $c->stash(parent => shift @rest)
35 # Check that the single arg is unlikely to be a path.
36 or @rest && to_SHA1($rest[0]) && $c->stash->{Repository}->get_object_or_head($rest[0]);
37 $c->stash(filename => $rest[-1])
41 sub diff_fancy : Chained('diff') PathPart('') Args() {
42 my($self, $c, @rest) = @_;
44 $self->_set_diff_args($c, @rest);
47 sub diff_plain : Chained('diff') PathPart('plain') Args() {
48 my($self, $c, $comparison, @rest) = @_;
50 $self->_set_diff_args($c, @rest);
52 $c->stash(no_wrapper => 1);
53 $c->response->content_type('text/plain; charset=utf-8');
56 sub commit : Chained('find') PathPart('commit') Args(0) {}
58 sub tree : Chained('find') Does('FilenameArgs') Args() {}
60 sub find_blob : Action {
62 my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)};
64 my $h = $object->isa('Gitalist::Git::Object::Commit')
65 ? $repo->hash_by_path($object->sha1, $c->stash->{filename})
66 : $object->isa('Gitalist::Git::Object::Blob')
68 : die "Unknown object type for '${\$object->sha1}'";
69 die "No file or sha1 provided."
71 $c->stash(blob => $repo->get_object($h)->content);
74 sub blob : Chained('find') Does('FilenameArgs') Args() {
76 $c->forward('find_blob');
79 sub blame : Chained('find') Does('FilenameArgs') Args() {}
81 sub history : Chained('find') Does('FilenameArgs') Args() {}